Given the following C code and unoptimized assembly code, your task is to generate highly optimized x86-64 assembly code.
C Code:

```c
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

int max(int a, int b){
  return a >= b ? a : b;
}
int min(int a, int b){
  return b >= a ? a : b;
}
int sei(int a){
  return a>0 ? a : 0;
}
int factorial(int n) {
    if (n > 0) return n*factorial(n - 1);
		else return 1;
}
int compare_up_int(const void *a, const void *b){
   return *(int*)a - *(int*)b;
}
int compare_down_int(const void *a, const void *b){
   return *(int*)b - *(int*)a;
}
int euclid(int a, int b){
  if(a < b){int tmp = a;a = b;b = tmp;}
  int r = a % b;
  if(r < 0) r += b;
  while(r != 0){
    a = b;b = r;r = a % b;
    if(r < 0) r += b;
  }
  return b;
}

int main(){
  int num[3],count=0;
  scanf("%d %d %d",&num[0],&num[1],&num[2]);
  qsort(num,3,sizeof(int),compare_up_int);
  if((num[2]-(num[0]+num[2]-num[1]))%2 == 0){
    int a = num[2]-num[1];
    printf("%d\n",a+(num[2]-num[0]-a)/2);
  }
  else{
    num[0]+=1;num[2]+=1;
    int a = num[2]-num[1];
    printf("%d\n",a+(num[2]-num[0]-a)/2 + 1);
  }
  return 0;
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	max
	.type	max, @function
max:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -4(%rbp)
	movl	%esi, -8(%rbp)
	movl	-4(%rbp), %edx
	movl	-8(%rbp), %eax
	cmpl	%eax, %edx
	cmovge	%edx, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	max, .-max
	.globl	min
	.type	min, @function
min:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -4(%rbp)
	movl	%esi, -8(%rbp)
	movl	-4(%rbp), %edx
	movl	-8(%rbp), %eax
	cmpl	%eax, %edx
	cmovle	%edx, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	min, .-min
	.globl	sei
	.type	sei, @function
sei:
.LFB8:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -4(%rbp)
	movl	-4(%rbp), %eax
	movl	$0, %edx
	testl	%eax, %eax
	cmovs	%edx, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.size	sei, .-sei
	.globl	factorial
	.type	factorial, @function
factorial:
.LFB9:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	movl	%edi, -4(%rbp)
	cmpl	$0, -4(%rbp)
	jle	.L8
	movl	-4(%rbp), %eax
	subl	$1, %eax
	movl	%eax, %edi
	call	factorial
	imull	-4(%rbp), %eax
	jmp	.L9
.L8:
	movl	$1, %eax
.L9:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE9:
	.size	factorial, .-factorial
	.globl	compare_up_int
	.type	compare_up_int, @function
compare_up_int:
.LFB10:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -8(%rbp)
	movq	%rsi, -16(%rbp)
	movq	-8(%rbp), %rax
	movl	(%rax), %edx
	movq	-16(%rbp), %rax
	movl	(%rax), %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE10:
	.size	compare_up_int, .-compare_up_int
	.globl	compare_down_int
	.type	compare_down_int, @function
compare_down_int:
.LFB11:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -8(%rbp)
	movq	%rsi, -16(%rbp)
	movq	-16(%rbp), %rax
	movl	(%rax), %edx
	movq	-8(%rbp), %rax
	movl	(%rax), %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE11:
	.size	compare_down_int, .-compare_down_int
	.globl	euclid
	.type	euclid, @function
euclid:
.LFB12:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -20(%rbp)
	movl	%esi, -24(%rbp)
	movl	-20(%rbp), %eax
	cmpl	-24(%rbp), %eax
	jge	.L15
	movl	-20(%rbp), %eax
	movl	%eax, -4(%rbp)
	movl	-24(%rbp), %eax
	movl	%eax, -20(%rbp)
	movl	-4(%rbp), %eax
	movl	%eax, -24(%rbp)
.L15:
	movl	-20(%rbp), %eax
	cltd
	idivl	-24(%rbp)
	movl	%edx, -8(%rbp)
	cmpl	$0, -8(%rbp)
	jns	.L17
	movl	-24(%rbp), %eax
	addl	%eax, -8(%rbp)
	jmp	.L17
.L18:
	movl	-24(%rbp), %eax
	movl	%eax, -20(%rbp)
	movl	-8(%rbp), %eax
	movl	%eax, -24(%rbp)
	movl	-20(%rbp), %eax
	cltd
	idivl	-24(%rbp)
	movl	%edx, -8(%rbp)
	cmpl	$0, -8(%rbp)
	jns	.L17
	movl	-24(%rbp), %eax
	addl	%eax, -8(%rbp)
.L17:
	cmpl	$0, -8(%rbp)
	jne	.L18
	movl	-24(%rbp), %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE12:
	.size	euclid, .-euclid
	.section	.rodata
.LC0:
	.string	"%d %d %d"
.LC1:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB13:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$32, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -32(%rbp)
	leaq	-20(%rbp), %rax
	leaq	8(%rax), %rcx
	leaq	-20(%rbp), %rax
	leaq	4(%rax), %rdx
	leaq	-20(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	leaq	-20(%rbp), %rax
	leaq	compare_up_int(%rip), %rdx
	movq	%rdx, %rcx
	movl	$4, %edx
	movl	$3, %esi
	movq	%rax, %rdi
	call	qsort@PLT
	movl	-12(%rbp), %eax
	movl	-20(%rbp), %ecx
	movl	-12(%rbp), %edx
	addl	%ecx, %edx
	movl	-16(%rbp), %ecx
	subl	%ecx, %edx
	subl	%edx, %eax
	andl	$1, %eax
	testl	%eax, %eax
	jne	.L21
	movl	-12(%rbp), %eax
	movl	-16(%rbp), %edx
	subl	%edx, %eax
	movl	%eax, -24(%rbp)
	movl	-12(%rbp), %eax
	movl	-20(%rbp), %edx
	subl	%edx, %eax
	subl	-24(%rbp), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	movl	%eax, %edx
	movl	-24(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	jmp	.L22
.L21:
	movl	-20(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -20(%rbp)
	movl	-12(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -12(%rbp)
	movl	-12(%rbp), %eax
	movl	-16(%rbp), %edx
	subl	%edx, %eax
	movl	%eax, -28(%rbp)
	movl	-12(%rbp), %eax
	movl	-20(%rbp), %edx
	subl	%edx, %eax
	subl	-28(%rbp), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	movl	%eax, %edx
	movl	-28(%rbp), %eax
	addl	%edx, %eax
	addl	$1, %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
.L22:
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L24
	call	__stack_chk_fail@PLT
.L24:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE13:
	.size	main, .-main
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:
```

Only output the optimized assembly code. Do not include any other text. Do not write any comments in the assembly code. Wrap the assembly code in ```assembly``` tags.
user
	.file	"temp.c"
	.text
	.p2align 4
	.globl	compare_up_int
	.type	compare_up_int, @function
compare_up_int:
.LFB55:
	.cfi_startproc
	endbr64
	movl	(%rdi), %eax
	subl	(%rsi), %eax
	ret
	.cfi_endproc
.LFE55:
	.size	compare_up_int, .-compare_up_int
	.p2align 4
	.globl	max
	.type	max, @function
max:
.LFB51:
	.cfi_startproc
	endbr64
	cmpl	%esi, %edi
	movl	%esi, %eax
	cmovge	%edi, %eax
	ret
	.cfi_endproc
.LFE51:
	.size	max, .-max
	.p2align 4
	.globl	min
	.type	min, @function
min:
.LFB52:
	.cfi_startproc
	endbr64
	cmpl	%esi, %edi
	movl	%esi, %eax
	cmovle	%edi, %eax
	ret
	.cfi_endproc
.LFE52:
	.size	min, .-min
	.p2align 4
	.globl	sei
	.type	sei, @function
sei:
.LFB53:
	.cfi_startproc
	endbr64
	xorl	%eax, %eax
	testl	%edi, %edi
	cmovns	%edi, %eax
	ret
	.cfi_endproc
.LFE53:
	.size	sei, .-sei
	.p2align 4
	.globl	factorial
	.type	factorial, @function
factorial:
.LFB54:
	.cfi_startproc
	endbr64
	movl	$1, %eax
	testl	%edi, %edi
	jle	.L9
	.p2align 4,,10
	.p2align 3
.L8:
	imull	%edi, %eax
	subl	$1, %edi
	jne	.L8
	ret
	.p2align 4,,10
	.p2align 3
.L9:
	ret
	.cfi_endproc
.LFE54:
	.size	factorial, .-factorial
	.p2align 4
	.globl	compare_down_int
	.type	compare_down_int, @function
compare_down_int:
.LFB56:
	.cfi_startproc
	endbr64
	movl	(%rsi), %eax
	subl	(%rdi), %eax
	ret
	.cfi_endproc
.LFE56:
	.size	compare_down_int, .-compare_down_int
	.p2align 4
	.globl	euclid
	.type	euclid, @function
euclid:
.LFB57:
	.cfi_startproc
	endbr64
	movl	%edi, %eax
	cmpl	%esi, %edi
	jge	.L13
	movl	%esi, %eax
	movl	%edi, %esi
.L13:
	cltd
	idivl	%esi
	leal	(%rdx,%rsi), %r8d
	testl	%edx, %edx
	cmovns	%edx, %r8d
	testl	%r8d, %r8d
	jne	.L17
	jmp	.L20
	.p2align 4,,10
	.p2align 3
.L19:
	movl	%edx, %r8d
.L17:
	movl	%esi, %eax
	movl	%r8d, %esi
	cltd
	idivl	%r8d
	leal	(%rdx,%r8), %eax
	testl	%edx, %edx
	cmovs	%eax, %edx
	testl	%edx, %edx
	jne	.L19
	movl	%r8d, %eax
	ret
	.p2align 4,,10
	.p2align 3
.L20:
	movl	%esi, %r8d
	movl	%r8d, %eax
	ret
	.cfi_endproc
.LFE57:
	.size	euclid, .-euclid
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d %d %d"
.LC1:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB58:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	leaq	.LC0(%rip), %rdi
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rbp
	leaq	20(%rsp), %rcx
	leaq	16(%rsp), %rdx
	movq	%rbp, %rsi
	call	__isoc99_scanf@PLT
	leaq	compare_up_int(%rip), %rcx
	movl	$3, %esi
	movq	%rbp, %rdi
	movl	$4, %edx
	call	qsort@PLT
	movl	16(%rsp), %edi
	movl	12(%rsp), %esi
	movl	20(%rsp), %ecx
	movl	%edi, %eax
	subl	%esi, %eax
	testb	$1, %al
	jne	.L22
	movl	%edi, %eax
	subl	%edi, %ecx
	movl	$1, %edi
	subl	%esi, %eax
	movl	$2, %esi
	cltd
	idivl	%esi
	leaq	.LC1(%rip), %rsi
	leal	(%rax,%rcx), %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L23:
	movq	24(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L26
	addq	$32, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 16
	xorl	%eax, %eax
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
.L22:
	.cfi_restore_state
	leal	1(%rsi), %eax
	leal	1(%rcx), %r8d
	movl	%eax, 12(%rsp)
	movl	%ecx, %eax
	movl	$2, %ecx
	subl	%esi, %eax
	movl	%r8d, 20(%rsp)
	subl	%edi, %r8d
	leaq	.LC1(%rip), %rsi
	subl	%r8d, %eax
	movl	$1, %edi
	cltd
	idivl	%ecx
	leal	1(%r8,%rax), %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L23
.L26:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE58:
	.size	main, .-main
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:

rule
	.file	"temp.c"
	.text
	.p2align 4
	.globl	compare_up_int
	.type	compare_up_int, @function
compare_up_int:
.LFB55:
	.cfi_startproc
	endbr64
	movl	(%rdi), %eax
	subl	(%rsi), %eax
	ret
	.cfi_endproc
.LFE55:
	.size	compare_up_int, .-compare_up_int
	.p2align 4
	.globl	max
	.type	max, @function
max:
.LFB51:
	.cfi_startproc
	endbr64
	cmpl	%esi, %edi
	movl	%esi, %eax
	cmovge	%edi, %eax
	ret
	.cfi_endproc
.LFE51:
	.size	max, .-max
	.p2align 4
	.globl	min
	.type	min, @function
min:
.LFB52:
	.cfi_startproc
	endbr64
	cmpl	%esi, %edi
	movl	%esi, %eax
	cmovle	%edi, %eax
	ret
	.cfi_endproc
.LFE52:
	.size	min, .-min
	.p2align 4
	.globl	sei
	.type	sei, @function
sei:
.LFB53:
	.cfi_startproc
	endbr64
	xorl	%eax, %eax
	testl	%edi, %edi
	cmovns	%edi, %eax
	ret
	.cfi_endproc
.LFE53:
	.size	sei, .-sei
	.p2align 4
	.globl	factorial
	.type	factorial, @function
factorial:
.LFB54:
	.cfi_startproc
	endbr64
	movl	$1, %eax
	testl	%edi, %edi
	jle	.L9
	.p2align 4,,10
	.p2align 3
.L8:
	imull	%edi, %eax
	subl	$1, %edi
	jne	.L8
	ret
	.p2align 4,,10
	.p2align 3
.L9:
	ret
	.cfi_endproc
.LFE54:
	.size	factorial, .-factorial
	.p2align 4
	.globl	compare_down_int
	.type	compare_down_int, @function
compare_down_int:
.LFB56:
	.cfi_startproc
	endbr64
	movl	(%rsi), %eax
	subl	(%rdi), %eax
	ret
	.cfi_endproc
.LFE56:
	.size	compare_down_int, .-compare_down_int
	.p2align 4
	.globl	euclid
	.type	euclid, @function
euclid:
.LFB57:
	.cfi_startproc
	endbr64
	movl	%edi, %eax
	cmpl	%esi, %edi
	jge	.L13
	movl	%esi, %eax
	movl	%edi, %esi
.L13:
	cltd
	idivl	%esi
	leal	(%rdx,%rsi), %r8d
	testl	%edx, %edx
	cmovns	%edx, %r8d
	testl	%r8d, %r8d
	jne	.L17
	jmp	.L20
	.p2align 4,,10
	.p2align 3
.L19:
	movl	%edx, %r8d
.L17:
	movl	%esi, %eax
	movl	%r8d, %esi
	cltd
	idivl	%r8d
	leal	(%rdx,%r8), %eax
	testl	%edx, %edx
	cmovs	%eax, %edx
	testl	%edx, %edx
	jne	.L19
	movl	%r8d, %eax
	ret
	.p2align 4,,10
	.p2align 3
.L20:
	movl	%esi, %r8d
	movl	%r8d, %eax
	ret
	.cfi_endproc
.LFE57:
	.size	euclid, .-euclid
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d %d %d"
.LC1:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB58:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	leaq	.LC0(%rip), %rdi
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rbp
	leaq	20(%rsp), %rcx
	leaq	16(%rsp), %rdx
	movq	%rbp, %rsi
	call	__isoc99_scanf@PLT
	leaq	compare_up_int(%rip), %rcx
	movl	$3, %esi
	movq	%rbp, %rdi
	movl	$4, %edx
	call	qsort@PLT
	movl	16(%rsp), %edi
	movl	12(%rsp), %esi
	movl	20(%rsp), %ecx
	movl	%edi, %eax
	subl	%esi, %eax
	testb	$1, %al
	jne	.L22
	movl	%edi, %eax
	subl	%edi, %ecx
	movl	$1, %edi
	subl	%esi, %eax
	movl	$2, %esi
	cltd
	idivl	%esi
	leaq	.LC1(%rip), %rsi
	leal	(%rax,%rcx), %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L23:
	movq	24(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L26
	addq	$32, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 16
	xorl	%eax, %eax
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
.L22:
	.cfi_restore_state
	leal	1(%rsi), %eax
	leal	1(%rcx), %r8d
	movl	%eax, 12(%rsp)
	movl	%ecx, %eax
	movl	$2, %ecx
	subl	%esi, %eax
	movl	%r8d, 20(%rsp)
	subl	%edi, %r8d
	leaq	.LC1(%rip), %rsi
	subl	%r8d, %eax
	movl	$1, %edi
	cltd
	idivl	%ecx
	leal	1(%r8,%rax), %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L23
.L26:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE58:
	.size	main, .-main
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

int max(int a, int b){
  return a >= b ? a : b;
}
int min(int a, int b){
  return b >= a ? a : b;
}
int sei(int a){
  return a>0 ? a : 0;
}
int factorial(int n) {
    if (n > 0) return n*factorial(n - 1);
		else return 1;
}
int compare_up_int(const void *a, const void *b){
   return *(int*)a - *(int*)b;
}
int compare_down_int(const void *a, const void *b){
   return *(int*)b - *(int*)a;
}
int euclid(int a, int b){
  if(a < b){int tmp = a;a = b;b = tmp;}
  int r = a % b;
  if(r < 0) r += b;
  while(r != 0){
    a = b;b = r;r = a % b;
    if(r < 0) r += b;
  }
  return b;
}

int main(){
  int num[3],count=0;
  scanf("%d %d %d",&num[0],&num[1],&num[2]);
  qsort(num,3,sizeof(int),compare_up_int);
  if((num[2]-(num[0]+num[2]-num[1]))%2 == 0){
    int a = num[2]-num[1];
    printf("%d\n",a+(num[2]-num[0]-a)/2);
  }
  else{
    num[0]+=1;num[2]+=1;
    int a = num[2]-num[1];
    printf("%d\n",a+(num[2]-num[0]-a)/2 + 1);
  }
  return 0;
}

2 5 4

2

Given the following C code and unoptimized assembly code, your task is to generate highly optimized x86-64 assembly code.
C Code:

```c
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

int max(int a, int b){
  return a >= b ? a : b;
}
int min(int a, int b){
  return b >= a ? a : b;
}
int sei(int a){
  return a>0 ? a : 0;
}
int factorial(int n) {
    if (n > 0) return n*factorial(n - 1);
		else return 1;
}
int compare_up_int(const void *a, const void *b){
   return *(int*)a - *(int*)b;
}
int compare_down_int(const void *a, const void *b){
   return *(int*)b - *(int*)a;
}
int euclid(int a, int b){
  if(a < b){int tmp = a;a = b;b = tmp;}
  int r = a % b;
  if(r < 0) r += b;
  while(r != 0){
    a = b;b = r;r = a % b;
    if(r < 0) r += b;
  }
  return b;
}

int main(){
  int num[3],count=0;
  scanf("%d %d %d",&num[0],&num[1],&num[2]);
  qsort(num,3,sizeof(int),compare_up_int);
  if((num[2]-(num[0]+num[2]-num[1]))%2 == 0){
    int a = num[2]-num[1];
    printf("%d\n",a+(num[2]-num[0]-a)/2);
  }
  else{
    num[0]+=1;num[2]+=1;
    int a = num[2]-num[1];
    printf("%d\n",a+(num[2]-num[0]-a)/2 + 1);
  }
  return 0;
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	max
	.type	max, @function
max:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -4(%rbp)
	movl	%esi, -8(%rbp)
	movl	-4(%rbp), %edx
	movl	-8(%rbp), %eax
	cmpl	%eax, %edx
	cmovge	%edx, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	max, .-max
	.globl	min
	.type	min, @function
min:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -4(%rbp)
	movl	%esi, -8(%rbp)
	movl	-4(%rbp), %edx
	movl	-8(%rbp), %eax
	cmpl	%eax, %edx
	cmovle	%edx, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	min, .-min
	.globl	sei
	.type	sei, @function
sei:
.LFB8:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -4(%rbp)
	movl	-4(%rbp), %eax
	movl	$0, %edx
	testl	%eax, %eax
	cmovs	%edx, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.size	sei, .-sei
	.globl	factorial
	.type	factorial, @function
factorial:
.LFB9:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	movl	%edi, -4(%rbp)
	cmpl	$0, -4(%rbp)
	jle	.L8
	movl	-4(%rbp), %eax
	subl	$1, %eax
	movl	%eax, %edi
	call	factorial
	imull	-4(%rbp), %eax
	jmp	.L9
.L8:
	movl	$1, %eax
.L9:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE9:
	.size	factorial, .-factorial
	.globl	compare_up_int
	.type	compare_up_int, @function
compare_up_int:
.LFB10:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -8(%rbp)
	movq	%rsi, -16(%rbp)
	movq	-8(%rbp), %rax
	movl	(%rax), %edx
	movq	-16(%rbp), %rax
	movl	(%rax), %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE10:
	.size	compare_up_int, .-compare_up_int
	.globl	compare_down_int
	.type	compare_down_int, @function
compare_down_int:
.LFB11:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -8(%rbp)
	movq	%rsi, -16(%rbp)
	movq	-16(%rbp), %rax
	movl	(%rax), %edx
	movq	-8(%rbp), %rax
	movl	(%rax), %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE11:
	.size	compare_down_int, .-compare_down_int
	.globl	euclid
	.type	euclid, @function
euclid:
.LFB12:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -20(%rbp)
	movl	%esi, -24(%rbp)
	movl	-20(%rbp), %eax
	cmpl	-24(%rbp), %eax
	jge	.L15
	movl	-20(%rbp), %eax
	movl	%eax, -4(%rbp)
	movl	-24(%rbp), %eax
	movl	%eax, -20(%rbp)
	movl	-4(%rbp), %eax
	movl	%eax, -24(%rbp)
.L15:
	movl	-20(%rbp), %eax
	cltd
	idivl	-24(%rbp)
	movl	%edx, -8(%rbp)
	cmpl	$0, -8(%rbp)
	jns	.L17
	movl	-24(%rbp), %eax
	addl	%eax, -8(%rbp)
	jmp	.L17
.L18:
	movl	-24(%rbp), %eax
	movl	%eax, -20(%rbp)
	movl	-8(%rbp), %eax
	movl	%eax, -24(%rbp)
	movl	-20(%rbp), %eax
	cltd
	idivl	-24(%rbp)
	movl	%edx, -8(%rbp)
	cmpl	$0, -8(%rbp)
	jns	.L17
	movl	-24(%rbp), %eax
	addl	%eax, -8(%rbp)
.L17:
	cmpl	$0, -8(%rbp)
	jne	.L18
	movl	-24(%rbp), %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE12:
	.size	euclid, .-euclid
	.section	.rodata
.LC0:
	.string	"%d %d %d"
.LC1:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB13:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$32, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -32(%rbp)
	leaq	-20(%rbp), %rax
	leaq	8(%rax), %rcx
	leaq	-20(%rbp), %rax
	leaq	4(%rax), %rdx
	leaq	-20(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	leaq	-20(%rbp), %rax
	leaq	compare_up_int(%rip), %rdx
	movq	%rdx, %rcx
	movl	$4, %edx
	movl	$3, %esi
	movq	%rax, %rdi
	call	qsort@PLT
	movl	-12(%rbp), %eax
	movl	-20(%rbp), %ecx
	movl	-12(%rbp), %edx
	addl	%ecx, %edx
	movl	-16(%rbp), %ecx
	subl	%ecx, %edx
	subl	%edx, %eax
	andl	$1, %eax
	testl	%eax, %eax
	jne	.L21
	movl	-12(%rbp), %eax
	movl	-16(%rbp), %edx
	subl	%edx, %eax
	movl	%eax, -24(%rbp)
	movl	-12(%rbp), %eax
	movl	-20(%rbp), %edx
	subl	%edx, %eax
	subl	-24(%rbp), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	movl	%eax, %edx
	movl	-24(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	jmp	.L22
.L21:
	movl	-20(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -20(%rbp)
	movl	-12(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -12(%rbp)
	movl	-12(%rbp), %eax
	movl	-16(%rbp), %edx
	subl	%edx, %eax
	movl	%eax, -28(%rbp)
	movl	-12(%rbp), %eax
	movl	-20(%rbp), %edx
	subl	%edx, %eax
	subl	-28(%rbp), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	movl	%eax, %edx
	movl	-28(%rbp), %eax
	addl	%edx, %eax
	addl	$1, %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
.L22:
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L24
	call	__stack_chk_fail@PLT
.L24:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE13:
	.size	main, .-main
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:
```

Only output the optimized assembly code. Do not include any other text. Do not write any comments in the assembly code. Wrap the assembly code in ```assembly``` tags.
train
	.file	"temp.c"
	.text
	.globl	max
	.type	max, @function
max:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -4(%rbp)
	movl	%esi, -8(%rbp)
	movl	-4(%rbp), %edx
	movl	-8(%rbp), %eax
	cmpl	%eax, %edx
	cmovge	%edx, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	max, .-max
	.globl	min
	.type	min, @function
min:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -4(%rbp)
	movl	%esi, -8(%rbp)
	movl	-4(%rbp), %edx
	movl	-8(%rbp), %eax
	cmpl	%eax, %edx
	cmovle	%edx, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	min, .-min
	.globl	sei
	.type	sei, @function
sei:
.LFB8:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -4(%rbp)
	movl	-4(%rbp), %eax
	movl	$0, %edx
	testl	%eax, %eax
	cmovs	%edx, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.size	sei, .-sei
	.globl	factorial
	.type	factorial, @function
factorial:
.LFB9:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	movl	%edi, -4(%rbp)
	cmpl	$0, -4(%rbp)
	jle	.L8
	movl	-4(%rbp), %eax
	subl	$1, %eax
	movl	%eax, %edi
	call	factorial
	imull	-4(%rbp), %eax
	jmp	.L9
.L8:
	movl	$1, %eax
.L9:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE9:
	.size	factorial, .-factorial
	.globl	compare_up_int
	.type	compare_up_int, @function
compare_up_int:
.LFB10:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -8(%rbp)
	movq	%rsi, -16(%rbp)
	movq	-8(%rbp), %rax
	movl	(%rax), %edx
	movq	-16(%rbp), %rax
	movl	(%rax), %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE10:
	.size	compare_up_int, .-compare_up_int
	.globl	compare_down_int
	.type	compare_down_int, @function
compare_down_int:
.LFB11:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -8(%rbp)
	movq	%rsi, -16(%rbp)
	movq	-16(%rbp), %rax
	movl	(%rax), %edx
	movq	-8(%rbp), %rax
	movl	(%rax), %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE11:
	.size	compare_down_int, .-compare_down_int
	.globl	euclid
	.type	euclid, @function
euclid:
.LFB12:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -20(%rbp)
	movl	%esi, -24(%rbp)
	movl	-20(%rbp), %eax
	cmpl	-24(%rbp), %eax
	jge	.L15
	movl	-20(%rbp), %eax
	movl	%eax, -4(%rbp)
	movl	-24(%rbp), %eax
	movl	%eax, -20(%rbp)
	movl	-4(%rbp), %eax
	movl	%eax, -24(%rbp)
.L15:
	movl	-20(%rbp), %eax
	cltd
	idivl	-24(%rbp)
	movl	%edx, -8(%rbp)
	cmpl	$0, -8(%rbp)
	jns	.L17
	movl	-24(%rbp), %eax
	addl	%eax, -8(%rbp)
	jmp	.L17
.L18:
	movl	-24(%rbp), %eax
	movl	%eax, -20(%rbp)
	movl	-8(%rbp), %eax
	movl	%eax, -24(%rbp)
	movl	-20(%rbp), %eax
	cltd
	idivl	-24(%rbp)
	movl	%edx, -8(%rbp)
	cmpl	$0, -8(%rbp)
	jns	.L17
	movl	-24(%rbp), %eax
	addl	%eax, -8(%rbp)
.L17:
	cmpl	$0, -8(%rbp)
	jne	.L18
	movl	-24(%rbp), %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE12:
	.size	euclid, .-euclid
	.section	.rodata
.LC0:
	.string	"%d %d %d"
.LC1:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB13:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$32, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -32(%rbp)
	leaq	-20(%rbp), %rax
	leaq	8(%rax), %rcx
	leaq	-20(%rbp), %rax
	leaq	4(%rax), %rdx
	leaq	-20(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	leaq	-20(%rbp), %rax
	leaq	compare_up_int(%rip), %rdx
	movq	%rdx, %rcx
	movl	$4, %edx
	movl	$3, %esi
	movq	%rax, %rdi
	call	qsort@PLT
	movl	-12(%rbp), %eax
	movl	-20(%rbp), %ecx
	movl	-12(%rbp), %edx
	addl	%ecx, %edx
	movl	-16(%rbp), %ecx
	subl	%ecx, %edx
	subl	%edx, %eax
	andl	$1, %eax
	testl	%eax, %eax
	jne	.L21
	movl	-12(%rbp), %eax
	movl	-16(%rbp), %edx
	subl	%edx, %eax
	movl	%eax, -24(%rbp)
	movl	-12(%rbp), %eax
	movl	-20(%rbp), %edx
	subl	%edx, %eax
	subl	-24(%rbp), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	movl	%eax, %edx
	movl	-24(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	jmp	.L22
.L21:
	movl	-20(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -20(%rbp)
	movl	-12(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -12(%rbp)
	movl	-12(%rbp), %eax
	movl	-16(%rbp), %edx
	subl	%edx, %eax
	movl	%eax, -28(%rbp)
	movl	-12(%rbp), %eax
	movl	-20(%rbp), %edx
	subl	%edx, %eax
	subl	-28(%rbp), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	movl	%eax, %edx
	movl	-28(%rbp), %eax
	addl	%edx, %eax
	addl	$1, %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
.L22:
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L24
	call	__stack_chk_fail@PLT
.L24:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE13:
	.size	main, .-main
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:
