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>
main(){
  while(1){
  int a,n[100],i,key,l=0,r,mid,c=0;
    scanf("%d",&a);
    if(a==0) break;
    for(i=0;i<=a;i++){
      scanf("%d",&n[i]);
    }
    key=n[a];
    r=a-1; 
    while(l<=r){
      mid=(l+r)/2;
      c++;
      if(n[mid]==key) break;
      else if(n[mid]<key) l=mid+1;
      else r=mid-1;
    }
    printf("%d\n",c);
  } 
  return 0; 
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$448, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
.L11:
	movl	$0, -436(%rbp)
	movl	$0, -428(%rbp)
	leaq	-444(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-444(%rbp), %eax
	testl	%eax, %eax
	jne	.L2
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L12
	jmp	.L13
.L2:
	movl	$0, -440(%rbp)
	jmp	.L4
.L5:
	leaq	-416(%rbp), %rdx
	movl	-440(%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, -440(%rbp)
.L4:
	movl	-444(%rbp), %eax
	cmpl	%eax, -440(%rbp)
	jle	.L5
	movl	-444(%rbp), %eax
	cltq
	movl	-416(%rbp,%rax,4), %eax
	movl	%eax, -424(%rbp)
	movl	-444(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -432(%rbp)
	jmp	.L6
.L10:
	movl	-436(%rbp), %edx
	movl	-432(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	movl	%eax, -420(%rbp)
	addl	$1, -428(%rbp)
	movl	-420(%rbp), %eax
	cltq
	movl	-416(%rbp,%rax,4), %eax
	cmpl	%eax, -424(%rbp)
	je	.L14
	movl	-420(%rbp), %eax
	cltq
	movl	-416(%rbp,%rax,4), %eax
	cmpl	%eax, -424(%rbp)
	jle	.L9
	movl	-420(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -436(%rbp)
	jmp	.L6
.L9:
	movl	-420(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -432(%rbp)
.L6:
	movl	-436(%rbp), %eax
	cmpl	-432(%rbp), %eax
	jle	.L10
	jmp	.L8
.L14:
	nop
.L8:
	movl	-428(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	jmp	.L11
.L13:
	call	__stack_chk_fail@PLT
.L12:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.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\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.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
	leaq	.LC1(%rip), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	leaq	.LC0(%rip), %rbx
	subq	$432, %rsp
	.cfi_def_cfa_offset 480
	movq	%fs:40, %rax
	movq	%rax, 424(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rbp
	.p2align 4,,10
	.p2align 3
.L9:
	movq	%rbp, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %eax
	testl	%eax, %eax
	je	.L2
	js	.L3
	leaq	16(%rsp), %r14
	xorl	%r13d, %r13d
	.p2align 4,,10
	.p2align 3
.L4:
	movq	%r14, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	addl	$1, %r13d
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %eax
	addq	$4, %r14
	cmpl	%r13d, %eax
	jge	.L4
.L3:
	movslq	%eax, %rdx
	xorl	%r8d, %r8d
	movl	16(%rsp,%rdx,4), %edi
	subl	$1, %eax
	js	.L5
	xorl	%ecx, %ecx
	.p2align 4,,10
	.p2align 3
.L8:
	leal	(%rcx,%rax), %edx
	addl	$1, %r8d
	sarl	%edx
	movslq	%edx, %rsi
	cmpl	%edi, 16(%rsp,%rsi,4)
	je	.L5
	jge	.L6
	leal	1(%rdx), %ecx
	cmpl	%eax, %ecx
	jle	.L8
.L5:
	movl	%r8d, %edx
	movq	%r12, %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L9
	.p2align 4,,10
	.p2align 3
.L6:
	leal	-1(%rdx), %eax
	cmpl	%ecx, %eax
	jge	.L8
	jmp	.L5
	.p2align 4,,10
	.p2align 3
.L2:
	movq	424(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L15
	addq	$432, %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
.L15:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE23:
	.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\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.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
	leaq	.LC1(%rip), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	leaq	.LC0(%rip), %rbx
	subq	$432, %rsp
	.cfi_def_cfa_offset 480
	movq	%fs:40, %rax
	movq	%rax, 424(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rbp
	.p2align 4,,10
	.p2align 3
.L9:
	movq	%rbp, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %eax
	testl	%eax, %eax
	je	.L2
	js	.L3
	leaq	16(%rsp), %r14
	xorl	%r13d, %r13d
	.p2align 4,,10
	.p2align 3
.L4:
	movq	%r14, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	addl	$1, %r13d
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %eax
	addq	$4, %r14
	cmpl	%r13d, %eax
	jge	.L4
.L3:
	movslq	%eax, %rdx
	xorl	%r8d, %r8d
	movl	16(%rsp,%rdx,4), %edi
	subl	$1, %eax
	js	.L5
	xorl	%ecx, %ecx
	.p2align 4,,10
	.p2align 3
.L8:
	leal	(%rcx,%rax), %edx
	addl	$1, %r8d
	sarl	%edx
	movslq	%edx, %rsi
	cmpl	%edi, 16(%rsp,%rsi,4)
	je	.L5
	jge	.L6
	leal	1(%rdx), %ecx
	cmpl	%eax, %ecx
	jle	.L8
.L5:
	movl	%r8d, %edx
	movq	%r12, %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L9
	.p2align 4,,10
	.p2align 3
.L6:
	leal	-1(%rdx), %eax
	cmpl	%ecx, %eax
	jge	.L8
	jmp	.L5
	.p2align 4,,10
	.p2align 3
.L2:
	movq	424(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L15
	addq	$432, %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
.L15:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE23:
	.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>
main(){
  while(1){
  int a,n[100],i,key,l=0,r,mid,c=0;
    scanf("%d",&a);
    if(a==0) break;
    for(i=0;i<=a;i++){
      scanf("%d",&n[i]);
    }
    key=n[a];
    r=a-1; 
    while(l<=r){
      mid=(l+r)/2;
      c++;
      if(n[mid]==key) break;
      else if(n[mid]<key) l=mid+1;
      else r=mid-1;
    }
    printf("%d\n",c);
  } 
  return 0; 
}
7
11
15
0
36
51
61
86
51
4
1
2
3
5
4
0
 7
11
15
0
42
51
61
86
51
4
1
2
4
5
4
0
 7
11
8
-2
53
51
17
109
42
4
1
0
3
1
0
0
 7
11
15
0
42
51
61
86
61
4
1
2
4
5
4
0
 7
11
8
-2
53
51
1
109
42
0
1
0
3
1
0
0
 7
0
15
0
42
51
61
48
61
0
1
3
4
5
4
0
 7
11
15
0
42
51
61
86
51
4
1
2
3
5
4
0
 7
11
20
0
42
51
61
86
51
4
1
2
4
5
4
0
 7
11
20
0
42
51
61
86
51
4
1
1
4
5
4
0
 7
11
15
23
36
51
61
86
51
4
1
2
3
7
4
0

3
3
 3
2
 3
1
 2
2
 3
 2
 3
3
 3
2
 3
2
 3
3

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>
main(){
  while(1){
  int a,n[100],i,key,l=0,r,mid,c=0;
    scanf("%d",&a);
    if(a==0) break;
    for(i=0;i<=a;i++){
      scanf("%d",&n[i]);
    }
    key=n[a];
    r=a-1; 
    while(l<=r){
      mid=(l+r)/2;
      c++;
      if(n[mid]==key) break;
      else if(n[mid]<key) l=mid+1;
      else r=mid-1;
    }
    printf("%d\n",c);
  } 
  return 0; 
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$448, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
.L11:
	movl	$0, -436(%rbp)
	movl	$0, -428(%rbp)
	leaq	-444(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-444(%rbp), %eax
	testl	%eax, %eax
	jne	.L2
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L12
	jmp	.L13
.L2:
	movl	$0, -440(%rbp)
	jmp	.L4
.L5:
	leaq	-416(%rbp), %rdx
	movl	-440(%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, -440(%rbp)
.L4:
	movl	-444(%rbp), %eax
	cmpl	%eax, -440(%rbp)
	jle	.L5
	movl	-444(%rbp), %eax
	cltq
	movl	-416(%rbp,%rax,4), %eax
	movl	%eax, -424(%rbp)
	movl	-444(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -432(%rbp)
	jmp	.L6
.L10:
	movl	-436(%rbp), %edx
	movl	-432(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	movl	%eax, -420(%rbp)
	addl	$1, -428(%rbp)
	movl	-420(%rbp), %eax
	cltq
	movl	-416(%rbp,%rax,4), %eax
	cmpl	%eax, -424(%rbp)
	je	.L14
	movl	-420(%rbp), %eax
	cltq
	movl	-416(%rbp,%rax,4), %eax
	cmpl	%eax, -424(%rbp)
	jle	.L9
	movl	-420(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -436(%rbp)
	jmp	.L6
.L9:
	movl	-420(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -432(%rbp)
.L6:
	movl	-436(%rbp), %eax
	cmpl	-432(%rbp), %eax
	jle	.L10
	jmp	.L8
.L14:
	nop
.L8:
	movl	-428(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	jmp	.L11
.L13:
	call	__stack_chk_fail@PLT
.L12:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.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\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$448, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
.L11:
	movl	$0, -436(%rbp)
	movl	$0, -428(%rbp)
	leaq	-444(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-444(%rbp), %eax
	testl	%eax, %eax
	jne	.L2
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L12
	jmp	.L13
.L2:
	movl	$0, -440(%rbp)
	jmp	.L4
.L5:
	leaq	-416(%rbp), %rdx
	movl	-440(%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, -440(%rbp)
.L4:
	movl	-444(%rbp), %eax
	cmpl	%eax, -440(%rbp)
	jle	.L5
	movl	-444(%rbp), %eax
	cltq
	movl	-416(%rbp,%rax,4), %eax
	movl	%eax, -424(%rbp)
	movl	-444(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -432(%rbp)
	jmp	.L6
.L10:
	movl	-436(%rbp), %edx
	movl	-432(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	movl	%eax, -420(%rbp)
	addl	$1, -428(%rbp)
	movl	-420(%rbp), %eax
	cltq
	movl	-416(%rbp,%rax,4), %eax
	cmpl	%eax, -424(%rbp)
	je	.L14
	movl	-420(%rbp), %eax
	cltq
	movl	-416(%rbp,%rax,4), %eax
	cmpl	%eax, -424(%rbp)
	jle	.L9
	movl	-420(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -436(%rbp)
	jmp	.L6
.L9:
	movl	-420(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -432(%rbp)
.L6:
	movl	-436(%rbp), %eax
	cmpl	-432(%rbp), %eax
	jle	.L10
	jmp	.L8
.L14:
	nop
.L8:
	movl	-428(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	jmp	.L11
.L13:
	call	__stack_chk_fail@PLT
.L12:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.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:
