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<math.h>
#define LEN 100000

int max(int arr[], int n){
	int i;
	int m=0;
	for(i=0;i<n;i++){
		if(m<arr[i]){
			m = arr[i];
		}
	}
	return m;
}

int check(int arr[], int m, int n){
	int c;
	int i;
	int a=500000000;
	int p;
	c = m / 2;
	for(i=0;i<n;i++){
		if(a>abs(arr[i]-c)&&arr[i]!=m){
			a = abs(arr[i]-c);
			p = arr[i];
		}
	}
	return p;
}

int main(void){
	int n;
	int arr[LEN];
	int i;
	int m1;
	int m2;
	scanf("%d", &n);
	for(i=0;i<n;i++){
		scanf("%d", &arr[i]);
	}
	m1 = max(arr, n);
	m2 = check(arr, m1, n);
	printf("%d %d", ((m1>m2)?m1:m2), ((m1>m2)?m2:m1));
	return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	max
	.type	max, @function
max:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -24(%rbp)
	movl	%esi, -28(%rbp)
	movl	$0, -4(%rbp)
	movl	$0, -8(%rbp)
	jmp	.L2
.L4:
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	cmpl	%eax, -4(%rbp)
	jge	.L3
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, -4(%rbp)
.L3:
	addl	$1, -8(%rbp)
.L2:
	movl	-8(%rbp), %eax
	cmpl	-28(%rbp), %eax
	jl	.L4
	movl	-4(%rbp), %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	max, .-max
	.globl	check
	.type	check, @function
check:
.LFB1:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -24(%rbp)
	movl	%esi, -28(%rbp)
	movl	%edx, -32(%rbp)
	movl	$500000000, -12(%rbp)
	movl	-28(%rbp), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	movl	%eax, -4(%rbp)
	movl	$0, -16(%rbp)
	jmp	.L7
.L9:
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	subl	-4(%rbp), %eax
	movl	%eax, %edx
	negl	%edx
	cmovns	%edx, %eax
	cmpl	%eax, -12(%rbp)
	jle	.L8
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	cmpl	%eax, -28(%rbp)
	je	.L8
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	subl	-4(%rbp), %eax
	movl	%eax, %edx
	negl	%edx
	cmovns	%edx, %eax
	movl	%eax, -12(%rbp)
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, -8(%rbp)
.L8:
	addl	$1, -16(%rbp)
.L7:
	movl	-16(%rbp), %eax
	cmpl	-32(%rbp), %eax
	jl	.L9
	movl	-8(%rbp), %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.size	check, .-check
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d %d"
	.text
	.globl	main
	.type	main, @function
main:
.LFB2:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	leaq	-397312(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$2720, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-400032(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -400028(%rbp)
	jmp	.L12
.L13:
	leaq	-400016(%rbp), %rdx
	movl	-400028(%rbp), %eax
	cltq
	salq	$2, %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -400028(%rbp)
.L12:
	movl	-400032(%rbp), %eax
	cmpl	%eax, -400028(%rbp)
	jl	.L13
	movl	-400032(%rbp), %edx
	leaq	-400016(%rbp), %rax
	movl	%edx, %esi
	movq	%rax, %rdi
	call	max
	movl	%eax, -400024(%rbp)
	movl	-400032(%rbp), %edx
	movl	-400024(%rbp), %ecx
	leaq	-400016(%rbp), %rax
	movl	%ecx, %esi
	movq	%rax, %rdi
	call	check
	movl	%eax, -400020(%rbp)
	movl	-400024(%rbp), %edx
	movl	-400020(%rbp), %eax
	cmpl	%eax, %edx
	cmovle	%edx, %eax
	movl	%eax, %ecx
	movl	-400020(%rbp), %edx
	movl	-400024(%rbp), %eax
	cmpl	%eax, %edx
	cmovge	%edx, %eax
	movl	%ecx, %edx
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L15
	call	__stack_chk_fail@PLT
.L15:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE2:
	.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	max
	.type	max, @function
max:
.LFB23:
	.cfi_startproc
	endbr64
	movl	%esi, %edx
	testl	%esi, %esi
	jle	.L7
	leal	-1(%rsi), %eax
	cmpl	$2, %eax
	jbe	.L8
	movl	%esi, %ecx
	movq	%rdi, %rax
	pxor	%xmm2, %xmm2
	shrl	$2, %ecx
	subl	$1, %ecx
	salq	$4, %rcx
	leaq	16(%rdi,%rcx), %rcx
	.p2align 4,,10
	.p2align 3
.L4:
	movdqu	(%rax), %xmm0
	addq	$16, %rax
	movdqa	%xmm0, %xmm1
	pcmpgtd	%xmm2, %xmm1
	pand	%xmm1, %xmm0
	pandn	%xmm2, %xmm1
	movdqa	%xmm1, %xmm2
	por	%xmm0, %xmm2
	cmpq	%rcx, %rax
	jne	.L4
	movdqa	%xmm2, %xmm0
	movl	%edx, %ecx
	psrldq	$8, %xmm0
	andl	$-4, %ecx
	movdqa	%xmm0, %xmm1
	pcmpgtd	%xmm2, %xmm1
	pand	%xmm1, %xmm0
	pandn	%xmm2, %xmm1
	por	%xmm0, %xmm1
	movdqa	%xmm1, %xmm2
	psrldq	$4, %xmm2
	movdqa	%xmm2, %xmm0
	pcmpgtd	%xmm1, %xmm0
	pand	%xmm0, %xmm2
	pandn	%xmm1, %xmm0
	por	%xmm2, %xmm0
	movd	%xmm0, %eax
	testb	$3, %dl
	je	.L11
.L3:
	movslq	%ecx, %rsi
	leaq	0(,%rsi,4), %r8
	movl	(%rdi,%rsi,4), %esi
	cmpl	%esi, %eax
	cmovl	%esi, %eax
	leal	1(%rcx), %esi
	cmpl	%esi, %edx
	jle	.L1
	movl	4(%rdi,%r8), %esi
	cmpl	%esi, %eax
	cmovl	%esi, %eax
	addl	$2, %ecx
	cmpl	%ecx, %edx
	jle	.L1
	movl	8(%rdi,%r8), %edx
	cmpl	%edx, %eax
	cmovl	%edx, %eax
	ret
	.p2align 4,,10
	.p2align 3
.L7:
	xorl	%eax, %eax
.L1:
	ret
	.p2align 4,,10
	.p2align 3
.L11:
	ret
.L8:
	xorl	%eax, %eax
	xorl	%ecx, %ecx
	jmp	.L3
	.cfi_endproc
.LFE23:
	.size	max, .-max
	.p2align 4
	.globl	check
	.type	check, @function
check:
.LFB24:
	.cfi_startproc
	endbr64
	movl	%esi, %r9d
	movl	%esi, %r10d
	shrl	$31, %r9d
	addl	%esi, %r9d
	sarl	%r9d
	testl	%edx, %edx
	jle	.L17
	leal	-1(%rdx), %eax
	xorl	%r8d, %r8d
	movl	$500000000, %esi
	leaq	4(%rdi,%rax,4), %r11
	.p2align 4,,10
	.p2align 3
.L16:
	movl	(%rdi), %ecx
	movl	%ecx, %edx
	subl	%r9d, %edx
	movl	%edx, %eax
	negl	%eax
	cmovs	%edx, %eax
	cmpl	%esi, %eax
	jge	.L14
	cmpl	%ecx, %r10d
	setne	%dl
	testb	%dl, %dl
	cmovne	%ecx, %r8d
	cmovne	%eax, %esi
.L14:
	addq	$4, %rdi
	cmpq	%rdi, %r11
	jne	.L16
	movl	%r8d, %eax
	ret
	.p2align 4,,10
	.p2align 3
.L17:
	xorl	%r8d, %r8d
	movl	%r8d, %eax
	ret
	.cfi_endproc
.LFE24:
	.size	check, .-check
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d"
.LC1:
	.string	"%d %d"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB25:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	leaq	-397312(%rsp), %r11
	.cfi_def_cfa 11, 397360
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$2720, %rsp
	.cfi_def_cfa_offset 400080
	leaq	.LC0(%rip), %r13
	movq	%r13, %rdi
	movq	%fs:40, %rax
	movq	%rax, 400024(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rsi
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %eax
	testl	%eax, %eax
	jle	.L24
	leaq	16(%rsp), %r14
	xorl	%ebp, %ebp
	movq	%r14, %r12
	.p2align 4,,10
	.p2align 3
.L25:
	movq	%r12, %rsi
	movq	%r13, %rdi
	xorl	%eax, %eax
	addl	$1, %ebp
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %eax
	addq	$4, %r12
	cmpl	%ebp, %eax
	jg	.L25
	testl	%eax, %eax
	jle	.L24
	leal	-1(%rax), %esi
	cmpl	$2, %esi
	jbe	.L34
	movl	%eax, %edx
	pxor	%xmm0, %xmm0
	shrl	$2, %edx
	subl	$1, %edx
	salq	$4, %rdx
	leaq	16(%r14,%rdx), %rcx
	movq	%r14, %rdx
	.p2align 4,,10
	.p2align 3
.L27:
	movdqa	%xmm0, %xmm1
	addq	$16, %rdx
	pcmpgtd	-16(%rdx), %xmm1
	pand	%xmm1, %xmm0
	pandn	-16(%rdx), %xmm1
	por	%xmm1, %xmm0
	cmpq	%rcx, %rdx
	jne	.L27
	movdqa	%xmm0, %xmm2
	movl	%eax, %edx
	psrldq	$8, %xmm2
	andl	$-4, %edx
	movdqa	%xmm2, %xmm1
	pcmpgtd	%xmm0, %xmm1
	pand	%xmm1, %xmm2
	pandn	%xmm0, %xmm1
	movdqa	%xmm1, %xmm0
	por	%xmm2, %xmm0
	movdqa	%xmm0, %xmm2
	psrldq	$4, %xmm2
	movdqa	%xmm2, %xmm1
	pcmpgtd	%xmm0, %xmm1
	pand	%xmm1, %xmm2
	pandn	%xmm0, %xmm1
	por	%xmm2, %xmm1
	movd	%xmm1, %edi
	testb	$3, %al
	je	.L28
.L26:
	movslq	%edx, %rcx
	leaq	0(,%rcx,4), %r8
	movl	16(%rsp,%rcx,4), %ecx
	cmpl	%ecx, %edi
	cmovl	%ecx, %edi
	leal	1(%rdx), %ecx
	cmpl	%ecx, %eax
	jle	.L28
	movl	20(%rsp,%r8), %ecx
	cmpl	%ecx, %edi
	cmovl	%ecx, %edi
	addl	$2, %edx
	cmpl	%edx, %eax
	jle	.L28
	movl	24(%rsp,%r8), %eax
	cmpl	%eax, %edi
	cmovl	%eax, %edi
.L28:
	movl	%edi, %r10d
	leaq	4(%r14), %rcx
	movl	$500000000, %r8d
	sarl	%r10d
	leaq	(%rcx,%rsi,4), %r9
	jmp	.L31
	.p2align 4,,10
	.p2align 3
.L44:
	addq	$4, %rcx
.L31:
	movl	(%r14), %esi
	movl	%esi, %edx
	subl	%r10d, %edx
	movl	%edx, %eax
	negl	%eax
	cmovs	%edx, %eax
	cmpl	%r8d, %eax
	jge	.L29
	cmpl	%esi, %edi
	setne	%dl
	testb	%dl, %dl
	cmovne	%esi, %ebx
	cmovne	%eax, %r8d
.L29:
	movq	%rcx, %r14
	cmpq	%rcx, %r9
	jne	.L44
.L32:
	cmpl	%ebx, %edi
	movl	%ebx, %ecx
	leaq	.LC1(%rip), %rsi
	cmovge	%edi, %ebx
	cmovle	%edi, %ecx
	xorl	%eax, %eax
	movl	$1, %edi
	movl	%ebx, %edx
	call	__printf_chk@PLT
	movq	400024(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L45
	addq	$400032, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 48
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
.L24:
	.cfi_restore_state
	xorl	%edi, %edi
	jmp	.L32
.L34:
	xorl	%edi, %edi
	xorl	%edx, %edx
	jmp	.L26
.L45:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE25:
	.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	max
	.type	max, @function
max:
.LFB23:
	.cfi_startproc
	endbr64
	movl	%esi, %edx
	testl	%esi, %esi
	jle	.L7
	leal	-1(%rsi), %eax
	cmpl	$2, %eax
	jbe	.L8
	movl	%esi, %ecx
	movq	%rdi, %rax
	pxor	%xmm2, %xmm2
	shrl	$2, %ecx
	subl	$1, %ecx
	salq	$4, %rcx
	leaq	16(%rdi,%rcx), %rcx
	.p2align 4,,10
	.p2align 3
.L4:
	movdqu	(%rax), %xmm0
	addq	$16, %rax
	movdqa	%xmm0, %xmm1
	pcmpgtd	%xmm2, %xmm1
	pand	%xmm1, %xmm0
	pandn	%xmm2, %xmm1
	movdqa	%xmm1, %xmm2
	por	%xmm0, %xmm2
	cmpq	%rcx, %rax
	jne	.L4
	movdqa	%xmm2, %xmm0
	movl	%edx, %ecx
	psrldq	$8, %xmm0
	andl	$-4, %ecx
	movdqa	%xmm0, %xmm1
	pcmpgtd	%xmm2, %xmm1
	pand	%xmm1, %xmm0
	pandn	%xmm2, %xmm1
	por	%xmm0, %xmm1
	movdqa	%xmm1, %xmm2
	psrldq	$4, %xmm2
	movdqa	%xmm2, %xmm0
	pcmpgtd	%xmm1, %xmm0
	pand	%xmm0, %xmm2
	pandn	%xmm1, %xmm0
	por	%xmm2, %xmm0
	movd	%xmm0, %eax
	testb	$3, %dl
	je	.L11
.L3:
	movslq	%ecx, %rsi
	leaq	0(,%rsi,4), %r8
	movl	(%rdi,%rsi,4), %esi
	cmpl	%esi, %eax
	cmovl	%esi, %eax
	leal	1(%rcx), %esi
	cmpl	%esi, %edx
	jle	.L1
	movl	4(%rdi,%r8), %esi
	cmpl	%esi, %eax
	cmovl	%esi, %eax
	addl	$2, %ecx
	cmpl	%ecx, %edx
	jle	.L1
	movl	8(%rdi,%r8), %edx
	cmpl	%edx, %eax
	cmovl	%edx, %eax
	ret
	.p2align 4,,10
	.p2align 3
.L7:
	xorl	%eax, %eax
.L1:
	ret
	.p2align 4,,10
	.p2align 3
.L11:
	ret
.L8:
	xorl	%eax, %eax
	xorl	%ecx, %ecx
	jmp	.L3
	.cfi_endproc
.LFE23:
	.size	max, .-max
	.p2align 4
	.globl	check
	.type	check, @function
check:
.LFB24:
	.cfi_startproc
	endbr64
	movl	%esi, %r9d
	movl	%esi, %r10d
	shrl	$31, %r9d
	addl	%esi, %r9d
	sarl	%r9d
	testl	%edx, %edx
	jle	.L17
	leal	-1(%rdx), %eax
	xorl	%r8d, %r8d
	movl	$500000000, %esi
	leaq	4(%rdi,%rax,4), %r11
	.p2align 4,,10
	.p2align 3
.L16:
	movl	(%rdi), %ecx
	movl	%ecx, %edx
	subl	%r9d, %edx
	movl	%edx, %eax
	negl	%eax
	cmovs	%edx, %eax
	cmpl	%esi, %eax
	jge	.L14
	cmpl	%ecx, %r10d
	setne	%dl
	testb	%dl, %dl
	cmovne	%ecx, %r8d
	cmovne	%eax, %esi
.L14:
	addq	$4, %rdi
	cmpq	%rdi, %r11
	jne	.L16
	movl	%r8d, %eax
	ret
	.p2align 4,,10
	.p2align 3
.L17:
	xorl	%r8d, %r8d
	movl	%r8d, %eax
	ret
	.cfi_endproc
.LFE24:
	.size	check, .-check
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d"
.LC1:
	.string	"%d %d"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB25:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	leaq	-397312(%rsp), %r11
	.cfi_def_cfa 11, 397360
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$2720, %rsp
	.cfi_def_cfa_offset 400080
	leaq	.LC0(%rip), %r13
	movq	%r13, %rdi
	movq	%fs:40, %rax
	movq	%rax, 400024(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rsi
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %eax
	testl	%eax, %eax
	jle	.L24
	leaq	16(%rsp), %r14
	xorl	%ebp, %ebp
	movq	%r14, %r12
	.p2align 4,,10
	.p2align 3
.L25:
	movq	%r12, %rsi
	movq	%r13, %rdi
	xorl	%eax, %eax
	addl	$1, %ebp
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %eax
	addq	$4, %r12
	cmpl	%ebp, %eax
	jg	.L25
	testl	%eax, %eax
	jle	.L24
	leal	-1(%rax), %esi
	cmpl	$2, %esi
	jbe	.L34
	movl	%eax, %edx
	pxor	%xmm0, %xmm0
	shrl	$2, %edx
	subl	$1, %edx
	salq	$4, %rdx
	leaq	16(%r14,%rdx), %rcx
	movq	%r14, %rdx
	.p2align 4,,10
	.p2align 3
.L27:
	movdqa	%xmm0, %xmm1
	addq	$16, %rdx
	pcmpgtd	-16(%rdx), %xmm1
	pand	%xmm1, %xmm0
	pandn	-16(%rdx), %xmm1
	por	%xmm1, %xmm0
	cmpq	%rcx, %rdx
	jne	.L27
	movdqa	%xmm0, %xmm2
	movl	%eax, %edx
	psrldq	$8, %xmm2
	andl	$-4, %edx
	movdqa	%xmm2, %xmm1
	pcmpgtd	%xmm0, %xmm1
	pand	%xmm1, %xmm2
	pandn	%xmm0, %xmm1
	movdqa	%xmm1, %xmm0
	por	%xmm2, %xmm0
	movdqa	%xmm0, %xmm2
	psrldq	$4, %xmm2
	movdqa	%xmm2, %xmm1
	pcmpgtd	%xmm0, %xmm1
	pand	%xmm1, %xmm2
	pandn	%xmm0, %xmm1
	por	%xmm2, %xmm1
	movd	%xmm1, %edi
	testb	$3, %al
	je	.L28
.L26:
	movslq	%edx, %rcx
	leaq	0(,%rcx,4), %r8
	movl	16(%rsp,%rcx,4), %ecx
	cmpl	%ecx, %edi
	cmovl	%ecx, %edi
	leal	1(%rdx), %ecx
	cmpl	%ecx, %eax
	jle	.L28
	movl	20(%rsp,%r8), %ecx
	cmpl	%ecx, %edi
	cmovl	%ecx, %edi
	addl	$2, %edx
	cmpl	%edx, %eax
	jle	.L28
	movl	24(%rsp,%r8), %eax
	cmpl	%eax, %edi
	cmovl	%eax, %edi
.L28:
	movl	%edi, %r10d
	leaq	4(%r14), %rcx
	movl	$500000000, %r8d
	sarl	%r10d
	leaq	(%rcx,%rsi,4), %r9
	jmp	.L31
	.p2align 4,,10
	.p2align 3
.L44:
	addq	$4, %rcx
.L31:
	movl	(%r14), %esi
	movl	%esi, %edx
	subl	%r10d, %edx
	movl	%edx, %eax
	negl	%eax
	cmovs	%edx, %eax
	cmpl	%r8d, %eax
	jge	.L29
	cmpl	%esi, %edi
	setne	%dl
	testb	%dl, %dl
	cmovne	%esi, %ebx
	cmovne	%eax, %r8d
.L29:
	movq	%rcx, %r14
	cmpq	%rcx, %r9
	jne	.L44
.L32:
	cmpl	%ebx, %edi
	movl	%ebx, %ecx
	leaq	.LC1(%rip), %rsi
	cmovge	%edi, %ebx
	cmovle	%edi, %ecx
	xorl	%eax, %eax
	movl	$1, %edi
	movl	%ebx, %edx
	call	__printf_chk@PLT
	movq	400024(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L45
	addq	$400032, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 48
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
.L24:
	.cfi_restore_state
	xorl	%edi, %edi
	jmp	.L32
.L34:
	xorl	%edi, %edi
	xorl	%edx, %edx
	jmp	.L26
.L45:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE25:
	.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<math.h>
#define LEN 100000

int max(int arr[], int n){
	int i;
	int m=0;
	for(i=0;i<n;i++){
		if(m<arr[i]){
			m = arr[i];
		}
	}
	return m;
}

int check(int arr[], int m, int n){
	int c;
	int i;
	int a=500000000;
	int p;
	c = m / 2;
	for(i=0;i<n;i++){
		if(a>abs(arr[i]-c)&&arr[i]!=m){
			a = abs(arr[i]-c);
			p = arr[i];
		}
	}
	return p;
}

int main(void){
	int n;
	int arr[LEN];
	int i;
	int m1;
	int m2;
	scanf("%d", &n);
	for(i=0;i<n;i++){
		scanf("%d", &arr[i]);
	}
	m1 = max(arr, n);
	m2 = check(arr, m1, n);
	printf("%d %d", ((m1>m2)?m1:m2), ((m1>m2)?m2:m1));
	return 0;
}
5
6 9 1 2 11
 5
6 9 1 2 20
 5
3 9 4 2 11
 2
010 0
 5
6 9 1 2 16
 5
10 9 1 4 20
 2
001 0
 5
6 9 1 2 0
 5
3 9 4 0 9
 2
101 0

11 6 20 9 11 4 10 0 16 9 20 10 1 0 9 6 9 4 101 0
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<math.h>
#define LEN 100000

int max(int arr[], int n){
	int i;
	int m=0;
	for(i=0;i<n;i++){
		if(m<arr[i]){
			m = arr[i];
		}
	}
	return m;
}

int check(int arr[], int m, int n){
	int c;
	int i;
	int a=500000000;
	int p;
	c = m / 2;
	for(i=0;i<n;i++){
		if(a>abs(arr[i]-c)&&arr[i]!=m){
			a = abs(arr[i]-c);
			p = arr[i];
		}
	}
	return p;
}

int main(void){
	int n;
	int arr[LEN];
	int i;
	int m1;
	int m2;
	scanf("%d", &n);
	for(i=0;i<n;i++){
		scanf("%d", &arr[i]);
	}
	m1 = max(arr, n);
	m2 = check(arr, m1, n);
	printf("%d %d", ((m1>m2)?m1:m2), ((m1>m2)?m2:m1));
	return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	max
	.type	max, @function
max:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -24(%rbp)
	movl	%esi, -28(%rbp)
	movl	$0, -4(%rbp)
	movl	$0, -8(%rbp)
	jmp	.L2
.L4:
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	cmpl	%eax, -4(%rbp)
	jge	.L3
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, -4(%rbp)
.L3:
	addl	$1, -8(%rbp)
.L2:
	movl	-8(%rbp), %eax
	cmpl	-28(%rbp), %eax
	jl	.L4
	movl	-4(%rbp), %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	max, .-max
	.globl	check
	.type	check, @function
check:
.LFB1:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -24(%rbp)
	movl	%esi, -28(%rbp)
	movl	%edx, -32(%rbp)
	movl	$500000000, -12(%rbp)
	movl	-28(%rbp), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	movl	%eax, -4(%rbp)
	movl	$0, -16(%rbp)
	jmp	.L7
.L9:
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	subl	-4(%rbp), %eax
	movl	%eax, %edx
	negl	%edx
	cmovns	%edx, %eax
	cmpl	%eax, -12(%rbp)
	jle	.L8
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	cmpl	%eax, -28(%rbp)
	je	.L8
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	subl	-4(%rbp), %eax
	movl	%eax, %edx
	negl	%edx
	cmovns	%edx, %eax
	movl	%eax, -12(%rbp)
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, -8(%rbp)
.L8:
	addl	$1, -16(%rbp)
.L7:
	movl	-16(%rbp), %eax
	cmpl	-32(%rbp), %eax
	jl	.L9
	movl	-8(%rbp), %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.size	check, .-check
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d %d"
	.text
	.globl	main
	.type	main, @function
main:
.LFB2:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	leaq	-397312(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$2720, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-400032(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -400028(%rbp)
	jmp	.L12
.L13:
	leaq	-400016(%rbp), %rdx
	movl	-400028(%rbp), %eax
	cltq
	salq	$2, %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -400028(%rbp)
.L12:
	movl	-400032(%rbp), %eax
	cmpl	%eax, -400028(%rbp)
	jl	.L13
	movl	-400032(%rbp), %edx
	leaq	-400016(%rbp), %rax
	movl	%edx, %esi
	movq	%rax, %rdi
	call	max
	movl	%eax, -400024(%rbp)
	movl	-400032(%rbp), %edx
	movl	-400024(%rbp), %ecx
	leaq	-400016(%rbp), %rax
	movl	%ecx, %esi
	movq	%rax, %rdi
	call	check
	movl	%eax, -400020(%rbp)
	movl	-400024(%rbp), %edx
	movl	-400020(%rbp), %eax
	cmpl	%eax, %edx
	cmovle	%edx, %eax
	movl	%eax, %ecx
	movl	-400020(%rbp), %edx
	movl	-400024(%rbp), %eax
	cmpl	%eax, %edx
	cmovge	%edx, %eax
	movl	%ecx, %edx
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L15
	call	__stack_chk_fail@PLT
.L15:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE2:
	.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:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -24(%rbp)
	movl	%esi, -28(%rbp)
	movl	$0, -4(%rbp)
	movl	$0, -8(%rbp)
	jmp	.L2
.L4:
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	cmpl	%eax, -4(%rbp)
	jge	.L3
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, -4(%rbp)
.L3:
	addl	$1, -8(%rbp)
.L2:
	movl	-8(%rbp), %eax
	cmpl	-28(%rbp), %eax
	jl	.L4
	movl	-4(%rbp), %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	max, .-max
	.globl	check
	.type	check, @function
check:
.LFB1:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -24(%rbp)
	movl	%esi, -28(%rbp)
	movl	%edx, -32(%rbp)
	movl	$500000000, -12(%rbp)
	movl	-28(%rbp), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	movl	%eax, -4(%rbp)
	movl	$0, -16(%rbp)
	jmp	.L7
.L9:
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	subl	-4(%rbp), %eax
	movl	%eax, %edx
	negl	%edx
	cmovns	%edx, %eax
	cmpl	%eax, -12(%rbp)
	jle	.L8
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	cmpl	%eax, -28(%rbp)
	je	.L8
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	subl	-4(%rbp), %eax
	movl	%eax, %edx
	negl	%edx
	cmovns	%edx, %eax
	movl	%eax, -12(%rbp)
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, -8(%rbp)
.L8:
	addl	$1, -16(%rbp)
.L7:
	movl	-16(%rbp), %eax
	cmpl	-32(%rbp), %eax
	jl	.L9
	movl	-8(%rbp), %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.size	check, .-check
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d %d"
	.text
	.globl	main
	.type	main, @function
main:
.LFB2:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	leaq	-397312(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$2720, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-400032(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -400028(%rbp)
	jmp	.L12
.L13:
	leaq	-400016(%rbp), %rdx
	movl	-400028(%rbp), %eax
	cltq
	salq	$2, %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -400028(%rbp)
.L12:
	movl	-400032(%rbp), %eax
	cmpl	%eax, -400028(%rbp)
	jl	.L13
	movl	-400032(%rbp), %edx
	leaq	-400016(%rbp), %rax
	movl	%edx, %esi
	movq	%rax, %rdi
	call	max
	movl	%eax, -400024(%rbp)
	movl	-400032(%rbp), %edx
	movl	-400024(%rbp), %ecx
	leaq	-400016(%rbp), %rax
	movl	%ecx, %esi
	movq	%rax, %rdi
	call	check
	movl	%eax, -400020(%rbp)
	movl	-400024(%rbp), %edx
	movl	-400020(%rbp), %eax
	cmpl	%eax, %edx
	cmovle	%edx, %eax
	movl	%eax, %ecx
	movl	-400020(%rbp), %edx
	movl	-400024(%rbp), %eax
	cmpl	%eax, %edx
	cmovge	%edx, %eax
	movl	%ecx, %edx
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L15
	call	__stack_chk_fail@PLT
.L15:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE2:
	.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:
