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>
int main(){
  int n,a=0,b=0,d[100010],i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&d[i]);
    if(a<d[i])a=d[i];
  }
  for(i=0;i<n;i++){
    if(abs(a/2-d[i])<abs(a/2-b))b=d[i];
  }
  printf("%d %d\n",a,b);
  return 0;
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d %d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB6:
	.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	$2752, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -400060(%rbp)
	movl	$0, -400056(%rbp)
	leaq	-400064(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -400052(%rbp)
	jmp	.L2
.L4:
	leaq	-400048(%rbp), %rdx
	movl	-400052(%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
	movl	-400052(%rbp), %eax
	cltq
	movl	-400048(%rbp,%rax,4), %eax
	cmpl	%eax, -400060(%rbp)
	jge	.L3
	movl	-400052(%rbp), %eax
	cltq
	movl	-400048(%rbp,%rax,4), %eax
	movl	%eax, -400060(%rbp)
.L3:
	addl	$1, -400052(%rbp)
.L2:
	movl	-400064(%rbp), %eax
	cmpl	%eax, -400052(%rbp)
	jl	.L4
	movl	$0, -400052(%rbp)
	jmp	.L5
.L7:
	movl	-400060(%rbp), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	movl	%eax, %ecx
	movl	-400052(%rbp), %eax
	cltq
	movl	-400048(%rbp,%rax,4), %edx
	movl	%ecx, %eax
	subl	%edx, %eax
	movl	%eax, %edx
	negl	%edx
	cmovs	%eax, %edx
	movl	-400060(%rbp), %eax
	movl	%eax, %ecx
	shrl	$31, %ecx
	addl	%ecx, %eax
	sarl	%eax
	subl	-400056(%rbp), %eax
	movl	%eax, %ecx
	negl	%ecx
	cmovns	%ecx, %eax
	cmpl	%eax, %edx
	jge	.L6
	movl	-400052(%rbp), %eax
	cltq
	movl	-400048(%rbp,%rax,4), %eax
	movl	%eax, -400056(%rbp)
.L6:
	addl	$1, -400052(%rbp)
.L5:
	movl	-400064(%rbp), %eax
	cmpl	%eax, -400052(%rbp)
	jl	.L7
	movl	-400056(%rbp), %edx
	movl	-400060(%rbp), %eax
	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	.L9
	call	__stack_chk_fail@PLT
.L9:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.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
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d"
.LC1:
	.string	"%d %d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB39:
	.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	$2752, %rsp
	.cfi_def_cfa_offset 400112
	leaq	.LC0(%rip), %r13
	movq	%r13, %rdi
	movq	%fs:40, %rax
	movq	%rax, 400056(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rsi
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %eax
	testl	%eax, %eax
	jle	.L7
	xorl	%ebp, %ebp
	xorl	%r12d, %r12d
	leaq	16(%rsp), %r14
	.p2align 4,,10
	.p2align 3
.L3:
	leaq	(%r14,%rbp,4), %rsi
	xorl	%eax, %eax
	movq	%r13, %rdi
	movq	%r14, %rbx
	call	__isoc99_scanf@PLT
	movl	(%r14,%rbp,4), %eax
	cmpl	%eax, %r12d
	cmovl	%eax, %r12d
	movl	12(%rsp), %eax
	addq	$1, %rbp
	cmpl	%ebp, %eax
	jg	.L3
	testl	%eax, %eax
	jle	.L8
	movl	%r12d, %edi
	subl	$1, %eax
	xorl	%r8d, %r8d
	sarl	%edi
	leaq	20(%rsp,%rax,4), %r9
	.p2align 4,,10
	.p2align 3
.L5:
	movl	(%rbx), %esi
	movl	%edi, %eax
	movl	%edi, %ecx
	subl	%esi, %eax
	movl	%eax, %edx
	negl	%edx
	cmovs	%eax, %edx
	subl	%r8d, %ecx
	movl	%ecx, %eax
	negl	%eax
	cmovs	%ecx, %eax
	cmpl	%eax, %edx
	cmovl	%esi, %r8d
	addq	$4, %rbx
	cmpq	%r9, %rbx
	jne	.L5
.L2:
	xorl	%eax, %eax
	movl	%r8d, %ecx
	movl	%r12d, %edx
	movl	$1, %edi
	leaq	.LC1(%rip), %rsi
	call	__printf_chk@PLT
	movq	400056(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L14
	addq	$400064, %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
.L7:
	.cfi_restore_state
	xorl	%r12d, %r12d
	xorl	%r8d, %r8d
	jmp	.L2
.L8:
	xorl	%r8d, %r8d
	jmp	.L2
.L14:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE39:
	.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
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d"
.LC1:
	.string	"%d %d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB39:
	.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	$2752, %rsp
	.cfi_def_cfa_offset 400112
	leaq	.LC0(%rip), %r13
	movq	%r13, %rdi
	movq	%fs:40, %rax
	movq	%rax, 400056(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rsi
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %eax
	testl	%eax, %eax
	jle	.L7
	xorl	%ebp, %ebp
	xorl	%r12d, %r12d
	leaq	16(%rsp), %r14
	.p2align 4,,10
	.p2align 3
.L3:
	leaq	(%r14,%rbp,4), %rsi
	xorl	%eax, %eax
	movq	%r13, %rdi
	movq	%r14, %rbx
	call	__isoc99_scanf@PLT
	movl	(%r14,%rbp,4), %eax
	cmpl	%eax, %r12d
	cmovl	%eax, %r12d
	movl	12(%rsp), %eax
	addq	$1, %rbp
	cmpl	%ebp, %eax
	jg	.L3
	testl	%eax, %eax
	jle	.L8
	movl	%r12d, %edi
	subl	$1, %eax
	xorl	%r8d, %r8d
	sarl	%edi
	leaq	20(%rsp,%rax,4), %r9
	.p2align 4,,10
	.p2align 3
.L5:
	movl	(%rbx), %esi
	movl	%edi, %eax
	movl	%edi, %ecx
	subl	%esi, %eax
	movl	%eax, %edx
	negl	%edx
	cmovs	%eax, %edx
	subl	%r8d, %ecx
	movl	%ecx, %eax
	negl	%eax
	cmovs	%ecx, %eax
	cmpl	%eax, %edx
	cmovl	%esi, %r8d
	addq	$4, %rbx
	cmpq	%r9, %rbx
	jne	.L5
.L2:
	xorl	%eax, %eax
	movl	%r8d, %ecx
	movl	%r12d, %edx
	movl	$1, %edi
	leaq	.LC1(%rip), %rsi
	call	__printf_chk@PLT
	movq	400056(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L14
	addq	$400064, %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
.L7:
	.cfi_restore_state
	xorl	%r12d, %r12d
	xorl	%r8d, %r8d
	jmp	.L2
.L8:
	xorl	%r8d, %r8d
	jmp	.L2
.L14:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE39:
	.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>
int main(){
  int n,a=0,b=0,d[100010],i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&d[i]);
    if(a<d[i])a=d[i];
  }
  for(i=0;i<n;i++){
    if(abs(a/2-d[i])<abs(a/2-b))b=d[i];
  }
  printf("%d %d\n",a,b);
  return 0;
}

5
6 9 4 2 11

11 6

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>
int main(){
  int n,a=0,b=0,d[100010],i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&d[i]);
    if(a<d[i])a=d[i];
  }
  for(i=0;i<n;i++){
    if(abs(a/2-d[i])<abs(a/2-b))b=d[i];
  }
  printf("%d %d\n",a,b);
  return 0;
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d %d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB6:
	.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	$2752, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -400060(%rbp)
	movl	$0, -400056(%rbp)
	leaq	-400064(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -400052(%rbp)
	jmp	.L2
.L4:
	leaq	-400048(%rbp), %rdx
	movl	-400052(%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
	movl	-400052(%rbp), %eax
	cltq
	movl	-400048(%rbp,%rax,4), %eax
	cmpl	%eax, -400060(%rbp)
	jge	.L3
	movl	-400052(%rbp), %eax
	cltq
	movl	-400048(%rbp,%rax,4), %eax
	movl	%eax, -400060(%rbp)
.L3:
	addl	$1, -400052(%rbp)
.L2:
	movl	-400064(%rbp), %eax
	cmpl	%eax, -400052(%rbp)
	jl	.L4
	movl	$0, -400052(%rbp)
	jmp	.L5
.L7:
	movl	-400060(%rbp), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	movl	%eax, %ecx
	movl	-400052(%rbp), %eax
	cltq
	movl	-400048(%rbp,%rax,4), %edx
	movl	%ecx, %eax
	subl	%edx, %eax
	movl	%eax, %edx
	negl	%edx
	cmovs	%eax, %edx
	movl	-400060(%rbp), %eax
	movl	%eax, %ecx
	shrl	$31, %ecx
	addl	%ecx, %eax
	sarl	%eax
	subl	-400056(%rbp), %eax
	movl	%eax, %ecx
	negl	%ecx
	cmovns	%ecx, %eax
	cmpl	%eax, %edx
	jge	.L6
	movl	-400052(%rbp), %eax
	cltq
	movl	-400048(%rbp,%rax,4), %eax
	movl	%eax, -400056(%rbp)
.L6:
	addl	$1, -400052(%rbp)
.L5:
	movl	-400064(%rbp), %eax
	cmpl	%eax, -400052(%rbp)
	jl	.L7
	movl	-400056(%rbp), %edx
	movl	-400060(%rbp), %eax
	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	.L9
	call	__stack_chk_fail@PLT
.L9:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.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
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d %d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB6:
	.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	$2752, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -400060(%rbp)
	movl	$0, -400056(%rbp)
	leaq	-400064(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -400052(%rbp)
	jmp	.L2
.L4:
	leaq	-400048(%rbp), %rdx
	movl	-400052(%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
	movl	-400052(%rbp), %eax
	cltq
	movl	-400048(%rbp,%rax,4), %eax
	cmpl	%eax, -400060(%rbp)
	jge	.L3
	movl	-400052(%rbp), %eax
	cltq
	movl	-400048(%rbp,%rax,4), %eax
	movl	%eax, -400060(%rbp)
.L3:
	addl	$1, -400052(%rbp)
.L2:
	movl	-400064(%rbp), %eax
	cmpl	%eax, -400052(%rbp)
	jl	.L4
	movl	$0, -400052(%rbp)
	jmp	.L5
.L7:
	movl	-400060(%rbp), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	movl	%eax, %ecx
	movl	-400052(%rbp), %eax
	cltq
	movl	-400048(%rbp,%rax,4), %edx
	movl	%ecx, %eax
	subl	%edx, %eax
	movl	%eax, %edx
	negl	%edx
	cmovs	%eax, %edx
	movl	-400060(%rbp), %eax
	movl	%eax, %ecx
	shrl	$31, %ecx
	addl	%ecx, %eax
	sarl	%eax
	subl	-400056(%rbp), %eax
	movl	%eax, %ecx
	negl	%ecx
	cmovns	%ecx, %eax
	cmpl	%eax, %edx
	jge	.L6
	movl	-400052(%rbp), %eax
	cltq
	movl	-400048(%rbp,%rax,4), %eax
	movl	%eax, -400056(%rbp)
.L6:
	addl	$1, -400052(%rbp)
.L5:
	movl	-400064(%rbp), %eax
	cmpl	%eax, -400052(%rbp)
	jl	.L7
	movl	-400056(%rbp), %edx
	movl	-400060(%rbp), %eax
	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	.L9
	call	__stack_chk_fail@PLT
.L9:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.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:
