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

```c
#include <stdio.h>
int A[101],n,sum;
void bs(int key,int left,int right){
    if(left > right)
        return;
    int mid;
    mid=(left+right)/2;
    sum++;
    if(key == A[mid])
        return;
    if(key > A[mid])
        left=mid+1;
    else
        right=mid-1;
    bs(key,left,right);
}
int main(void){
    int n,k,i;
    for(;sum=0,scanf("%d",&n),n;){
        for(i=0;i<n;i++){
            scanf("%d",&A[i]);
        }
        scanf("%d",&k);
        bs(k,0,n-1);
        printf("%d\n",sum);
    }
    return 0;
}```

Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.p2align 4
	.globl	bs
	.type	bs, @function
bs:
.LFB23:
	.cfi_startproc
	endbr64
	cmpl	%edx, %esi
	jg	.L1
	movl	sum(%rip), %eax
	leaq	A(%rip), %r9
	leal	1(%rax), %ecx
	.p2align 4,,10
	.p2align 3
.L3:
	leal	(%rsi,%rdx), %r8d
	movl	%ecx, %r10d
	movl	%r8d, %eax
	shrl	$31, %eax
	addl	%r8d, %eax
	sarl	%eax
	movslq	%eax, %r8
	cmpl	%edi, (%r9,%r8,4)
	je	.L4
	jge	.L5
	leal	1(%rax), %esi
	addl	$1, %ecx
	cmpl	%edx, %esi
	jle	.L3
.L6:
	movl	%r10d, sum(%rip)
	ret
	.p2align 4,,10
	.p2align 3
.L5:
	leal	-1(%rax), %edx
	addl	$1, %ecx
	cmpl	%esi, %edx
	jge	.L3
	jmp	.L6
	.p2align 4,,10
	.p2align 3
.L4:
	movl	%ecx, sum(%rip)
.L1:
	ret
	.cfi_endproc
.LFE23:
	.size	bs, .-bs
	.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:
.LFB24:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	leaq	A(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	leaq	.LC0(%rip), %rbx
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %r12
	leaq	4(%rsp), %r14
	.p2align 4,,10
	.p2align 3
.L10:
	movq	%r12, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	movl	$0, sum(%rip)
	call	__isoc99_scanf@PLT
	movl	(%rsp), %eax
	testl	%eax, %eax
	je	.L19
	leaq	A(%rip), %r13
	movl	$0, %r15d
	jle	.L21
	.p2align 4,,10
	.p2align 3
.L11:
	movq	%r13, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	addl	$1, %r15d
	call	__isoc99_scanf@PLT
	addq	$4, %r13
	cmpl	%r15d, (%rsp)
	jg	.L11
.L21:
	xorl	%eax, %eax
	movq	%r14, %rsi
	movq	%rbx, %rdi
	call	__isoc99_scanf@PLT
	movl	(%rsp), %ecx
	movl	4(%rsp), %r9d
	movl	sum(%rip), %r8d
	subl	$1, %ecx
	js	.L13
	movl	sum(%rip), %eax
	xorl	%esi, %esi
	leal	1(%rax), %edx
	.p2align 4,,10
	.p2align 3
.L14:
	leal	(%rsi,%rcx), %eax
	movl	%edx, %r8d
	sarl	%eax
	movslq	%eax, %rdi
	cmpl	0(%rbp,%rdi,4), %r9d
	je	.L15
	jle	.L16
	leal	1(%rax), %esi
	addl	$1, %edx
	cmpl	%ecx, %esi
	jle	.L14
.L15:
	movl	%r8d, sum(%rip)
.L13:
	movl	%r8d, %edx
	leaq	.LC1(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L10
	.p2align 4,,10
	.p2align 3
.L16:
	leal	-1(%rax), %ecx
	addl	$1, %edx
	cmpl	%esi, %ecx
	jge	.L14
	jmp	.L15
	.p2align 4,,10
	.p2align 3
.L19:
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L26
	addq	$24, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
.L26:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE24:
	.size	main, .-main
	.globl	sum
	.bss
	.align 4
	.type	sum, @object
	.size	sum, 4
sum:
	.zero	4
	.globl	n
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.globl	A
	.align 32
	.type	A, @object
	.size	A, 404
A:
	.zero	404
	.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.
Optimized Assembly Code:

user
```assembly
	.file	"temp.c"
	.text
	.p2align 4
	.globl	bs
	.type	bs, @function
bs:
.LFB23:
	.cfi_startproc
	endbr64
	cmpl	%edx, %esi
	jg	.L1
	movl	sum(%rip), %eax
	leaq	A(%rip), %r9
	leal	1(%rax), %ecx
	.p2align 4,,10
	.p2align 3
.L3:
	leal	(%rsi,%rdx), %r8d
	movl	%ecx, %r10d
	movl	%r8d, %eax
	shrl	$31, %eax
	addl	%r8d, %eax
	sarl	%eax
	movslq	%eax, %r8
	cmpl	%edi, (%r9,%r8,4)
	je	.L4
	jge	.L5
	leal	1(%rax), %esi
	addl	$1, %ecx
	cmpl	%edx, %esi
	jle	.L3
.L6:
	movl	%r10d, sum(%rip)
	ret
	.p2align 4,,10
	.p2align 3
.L5:
	leal	-1(%rax), %edx
	addl	$1, %ecx
	cmpl	%esi, %edx
	jge	.L3
	jmp	.L6
	.p2align 4,,10
	.p2align 3
.L4:
	movl	%ecx, sum(%rip)
.L1:
	ret
	.cfi_endproc
.LFE23:
	.size	bs, .-bs
	.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:
.LFB24:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	leaq	A(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	leaq	.LC0(%rip), %rbx
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %r12
	leaq	4(%rsp), %r14
	.p2align 4,,10
	.p2align 3
.L10:
	movq	%r12, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	movl	$0, sum(%rip)
	call	__isoc99_scanf@PLT
	movl	(%rsp), %eax
	testl	%eax, %eax
	je	.L19
	leaq	A(%rip), %r13
	movl	$0, %r15d
	jle	.L21
	.p2align 4,,10
	.p2align 3
.L11:
	movq	%r13, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	addl	$1, %r15d
	call	__isoc99_scanf@PLT
	addq	$4, %r13
	cmpl	%r15d, (%rsp)
	jg	.L11
.L21:
	xorl	%eax, %eax
	movq	%r14, %rsi
	movq	%rbx, %rdi
	call	__isoc99_scanf@PLT
	movl	(%rsp), %ecx
	movl	4(%rsp), %r9d
	movl	sum(%rip), %r8d
	subl	$1, %ecx
	js	.L13
	movl	sum(%rip), %eax
	xorl	%esi, %esi
	leal	1(%rax), %edx
	.p2align 4,,10
	.p2align 3
.L14:
	leal	(%rsi,%rcx), %eax
	movl	%edx, %r8d
	sarl	%eax
	movslq	%eax, %rdi
	cmpl	0(%rbp,%rdi,4), %r9d
	je	.L15
	jle	.L16
	leal	1(%rax), %esi
	addl	$1, %edx
	cmpl	%ecx, %esi
	jle	.L14
.L15:
	movl	%r8d, sum(%rip)
.L13:
	movl	%r8d, %edx
	leaq	.LC1(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L10
	.p2align 4,,10
	.p2align 3
.L16:
	leal	-1(%rax), %ecx
	addl	$1, %edx
	cmpl	%esi, %ecx
	jge	.L14
	jmp	.L15
	.p2align 4,,10
	.p2align 3
.L19:
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L26
	addq	$24, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
.L26:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE24:
	.size	main, .-main
	.globl	sum
	.bss
	.align 4
	.type	sum, @object
	.size	sum, 4
sum:
	.zero	4
	.globl	n
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.globl	A
	.align 32
	.type	A, @object
	.size	A, 404
A:
	.zero	404
	.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
```assembly
	.file	"temp.c"
	.text
	.p2align 4
	.globl	bs
	.type	bs, @function
bs:
.LFB23:
	.cfi_startproc
	endbr64
	cmpl	%edx, %esi
	jg	.L1
	movl	sum(%rip), %eax
	leaq	A(%rip), %r9
	leal	1(%rax), %ecx
	.p2align 4,,10
	.p2align 3
.L3:
	leal	(%rsi,%rdx), %r8d
	movl	%ecx, %r10d
	movl	%r8d, %eax
	shrl	$31, %eax
	addl	%r8d, %eax
	sarl	%eax
	movslq	%eax, %r8
	cmpl	%edi, (%r9,%r8,4)
	je	.L4
	jge	.L5
	leal	1(%rax), %esi
	addl	$1, %ecx
	cmpl	%edx, %esi
	jle	.L3
.L6:
	movl	%r10d, sum(%rip)
	ret
	.p2align 4,,10
	.p2align 3
.L5:
	leal	-1(%rax), %edx
	addl	$1, %ecx
	cmpl	%esi, %edx
	jge	.L3
	jmp	.L6
	.p2align 4,,10
	.p2align 3
.L4:
	movl	%ecx, sum(%rip)
.L1:
	ret
	.cfi_endproc
.LFE23:
	.size	bs, .-bs
	.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:
.LFB24:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	leaq	A(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	leaq	.LC0(%rip), %rbx
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %r12
	leaq	4(%rsp), %r14
	.p2align 4,,10
	.p2align 3
.L10:
	movq	%r12, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	movl	$0, sum(%rip)
	call	__isoc99_scanf@PLT
	movl	(%rsp), %eax
	testl	%eax, %eax
	je	.L19
	leaq	A(%rip), %r13
	movl	$0, %r15d
	jle	.L21
	.p2align 4,,10
	.p2align 3
.L11:
	movq	%r13, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	addl	$1, %r15d
	call	__isoc99_scanf@PLT
	addq	$4, %r13
	cmpl	%r15d, (%rsp)
	jg	.L11
.L21:
	xorl	%eax, %eax
	movq	%r14, %rsi
	movq	%rbx, %rdi
	call	__isoc99_scanf@PLT
	movl	(%rsp), %ecx
	movl	4(%rsp), %r9d
	movl	sum(%rip), %r8d
	subl	$1, %ecx
	js	.L13
	movl	sum(%rip), %eax
	xorl	%esi, %esi
	leal	1(%rax), %edx
	.p2align 4,,10
	.p2align 3
.L14:
	leal	(%rsi,%rcx), %eax
	movl	%edx, %r8d
	sarl	%eax
	movslq	%eax, %rdi
	cmpl	0(%rbp,%rdi,4), %r9d
	je	.L15
	jle	.L16
	leal	1(%rax), %esi
	addl	$1, %edx
	cmpl	%ecx, %esi
	jle	.L14
.L15:
	movl	%r8d, sum(%rip)
.L13:
	movl	%r8d, %edx
	leaq	.LC1(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L10
	.p2align 4,,10
	.p2align 3
.L16:
	leal	-1(%rax), %ecx
	addl	$1, %edx
	cmpl	%esi, %ecx
	jge	.L14
	jmp	.L15
	.p2align 4,,10
	.p2align 3
.L19:
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L26
	addq	$24, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
.L26:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE24:
	.size	main, .-main
	.globl	sum
	.bss
	.align 4
	.type	sum, @object
	.size	sum, 4
sum:
	.zero	4
	.globl	n
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.globl	A
	.align 32
	.type	A, @object
	.size	A, 404
A:
	.zero	404
	.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:
```
```c
#include <stdio.h>
int A[101],n,sum;
void bs(int key,int left,int right){
    if(left > right)
        return;
    int mid;
    mid=(left+right)/2;
    sum++;
    if(key == A[mid])
        return;
    if(key > A[mid])
        left=mid+1;
    else
        right=mid-1;
    bs(key,left,right);
}
int main(void){
    int n,k,i;
    for(;sum=0,scanf("%d",&n),n;){
        for(i=0;i<n;i++){
            scanf("%d",&A[i]);
        }
        scanf("%d",&k);
        bs(k,0,n-1);
        printf("%d\n",sum);
    }
    return 0;
}```
Given the following C code, your task is to generate highly optimized x86-64 assembly code.
C Code:

```c
#include <stdio.h>
int A[101],n,sum;
void bs(int key,int left,int right){
    if(left > right)
        return;
    int mid;
    mid=(left+right)/2;
    sum++;
    if(key == A[mid])
        return;
    if(key > A[mid])
        left=mid+1;
    else
        right=mid-1;
    bs(key,left,right);
}
int main(void){
    int n,k,i;
    for(;sum=0,scanf("%d",&n),n;){
        for(i=0;i<n;i++){
            scanf("%d",&A[i]);
        }
        scanf("%d",&k);
        bs(k,0,n-1);
        printf("%d\n",sum);
    }
    return 0;
}```

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.
Optimized Assembly Code:

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 assembly code, your task is to generate highly optimized x86-64 assembly code.
C Code:

```c
#include <stdio.h>
int A[101],n,sum;
void bs(int key,int left,int right){
    if(left > right)
        return;
    int mid;
    mid=(left+right)/2;
    sum++;
    if(key == A[mid])
        return;
    if(key > A[mid])
        left=mid+1;
    else
        right=mid-1;
    bs(key,left,right);
}
int main(void){
    int n,k,i;
    for(;sum=0,scanf("%d",&n),n;){
        for(i=0;i<n;i++){
            scanf("%d",&A[i]);
        }
        scanf("%d",&k);
        bs(k,0,n-1);
        printf("%d\n",sum);
    }
    return 0;
}```

Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.p2align 4
	.globl	bs
	.type	bs, @function
bs:
.LFB23:
	.cfi_startproc
	endbr64
	cmpl	%edx, %esi
	jg	.L1
	movl	sum(%rip), %eax
	leaq	A(%rip), %r9
	leal	1(%rax), %ecx
	.p2align 4,,10
	.p2align 3
.L3:
	leal	(%rsi,%rdx), %r8d
	movl	%ecx, %r10d
	movl	%r8d, %eax
	shrl	$31, %eax
	addl	%r8d, %eax
	sarl	%eax
	movslq	%eax, %r8
	cmpl	%edi, (%r9,%r8,4)
	je	.L4
	jge	.L5
	leal	1(%rax), %esi
	addl	$1, %ecx
	cmpl	%edx, %esi
	jle	.L3
.L6:
	movl	%r10d, sum(%rip)
	ret
	.p2align 4,,10
	.p2align 3
.L5:
	leal	-1(%rax), %edx
	addl	$1, %ecx
	cmpl	%esi, %edx
	jge	.L3
	jmp	.L6
	.p2align 4,,10
	.p2align 3
.L4:
	movl	%ecx, sum(%rip)
.L1:
	ret
	.cfi_endproc
.LFE23:
	.size	bs, .-bs
	.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:
.LFB24:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	leaq	A(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	leaq	.LC0(%rip), %rbx
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %r12
	leaq	4(%rsp), %r14
	.p2align 4,,10
	.p2align 3
.L10:
	movq	%r12, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	movl	$0, sum(%rip)
	call	__isoc99_scanf@PLT
	movl	(%rsp), %eax
	testl	%eax, %eax
	je	.L19
	leaq	A(%rip), %r13
	movl	$0, %r15d
	jle	.L21
	.p2align 4,,10
	.p2align 3
.L11:
	movq	%r13, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	addl	$1, %r15d
	call	__isoc99_scanf@PLT
	addq	$4, %r13
	cmpl	%r15d, (%rsp)
	jg	.L11
.L21:
	xorl	%eax, %eax
	movq	%r14, %rsi
	movq	%rbx, %rdi
	call	__isoc99_scanf@PLT
	movl	(%rsp), %ecx
	movl	4(%rsp), %r9d
	movl	sum(%rip), %r8d
	subl	$1, %ecx
	js	.L13
	movl	sum(%rip), %eax
	xorl	%esi, %esi
	leal	1(%rax), %edx
	.p2align 4,,10
	.p2align 3
.L14:
	leal	(%rsi,%rcx), %eax
	movl	%edx, %r8d
	sarl	%eax
	movslq	%eax, %rdi
	cmpl	0(%rbp,%rdi,4), %r9d
	je	.L15
	jle	.L16
	leal	1(%rax), %esi
	addl	$1, %edx
	cmpl	%ecx, %esi
	jle	.L14
.L15:
	movl	%r8d, sum(%rip)
.L13:
	movl	%r8d, %edx
	leaq	.LC1(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L10
	.p2align 4,,10
	.p2align 3
.L16:
	leal	-1(%rax), %ecx
	addl	$1, %edx
	cmpl	%esi, %ecx
	jge	.L14
	jmp	.L15
	.p2align 4,,10
	.p2align 3
.L19:
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L26
	addq	$24, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
.L26:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE24:
	.size	main, .-main
	.globl	sum
	.bss
	.align 4
	.type	sum, @object
	.size	sum, 4
sum:
	.zero	4
	.globl	n
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.globl	A
	.align 32
	.type	A, @object
	.size	A, 404
A:
	.zero	404
	.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.
Optimized Assembly Code:

train
```assembly
	.file	"temp.c"
	.text
	.p2align 4
	.globl	bs
	.type	bs, @function
bs:
.LFB23:
	.cfi_startproc
	endbr64
	cmpl	%edx, %esi
	jg	.L1
	movl	sum(%rip), %eax
	leaq	A(%rip), %r9
	leal	1(%rax), %ecx
	.p2align 4,,10
	.p2align 3
.L3:
	leal	(%rsi,%rdx), %r8d
	movl	%ecx, %r10d
	movl	%r8d, %eax
	shrl	$31, %eax
	addl	%r8d, %eax
	sarl	%eax
	movslq	%eax, %r8
	cmpl	%edi, (%r9,%r8,4)
	je	.L4
	jge	.L5
	leal	1(%rax), %esi
	addl	$1, %ecx
	cmpl	%edx, %esi
	jle	.L3
.L6:
	movl	%r10d, sum(%rip)
	ret
	.p2align 4,,10
	.p2align 3
.L5:
	leal	-1(%rax), %edx
	addl	$1, %ecx
	cmpl	%esi, %edx
	jge	.L3
	jmp	.L6
	.p2align 4,,10
	.p2align 3
.L4:
	movl	%ecx, sum(%rip)
.L1:
	ret
	.cfi_endproc
.LFE23:
	.size	bs, .-bs
	.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:
.LFB24:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	leaq	A(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	leaq	.LC0(%rip), %rbx
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %r12
	leaq	4(%rsp), %r14
	.p2align 4,,10
	.p2align 3
.L10:
	movq	%r12, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	movl	$0, sum(%rip)
	call	__isoc99_scanf@PLT
	movl	(%rsp), %eax
	testl	%eax, %eax
	je	.L19
	leaq	A(%rip), %r13
	movl	$0, %r15d
	jle	.L21
	.p2align 4,,10
	.p2align 3
.L11:
	movq	%r13, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	addl	$1, %r15d
	call	__isoc99_scanf@PLT
	addq	$4, %r13
	cmpl	%r15d, (%rsp)
	jg	.L11
.L21:
	xorl	%eax, %eax
	movq	%r14, %rsi
	movq	%rbx, %rdi
	call	__isoc99_scanf@PLT
	movl	(%rsp), %ecx
	movl	4(%rsp), %r9d
	movl	sum(%rip), %r8d
	subl	$1, %ecx
	js	.L13
	movl	sum(%rip), %eax
	xorl	%esi, %esi
	leal	1(%rax), %edx
	.p2align 4,,10
	.p2align 3
.L14:
	leal	(%rsi,%rcx), %eax
	movl	%edx, %r8d
	sarl	%eax
	movslq	%eax, %rdi
	cmpl	0(%rbp,%rdi,4), %r9d
	je	.L15
	jle	.L16
	leal	1(%rax), %esi
	addl	$1, %edx
	cmpl	%ecx, %esi
	jle	.L14
.L15:
	movl	%r8d, sum(%rip)
.L13:
	movl	%r8d, %edx
	leaq	.LC1(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L10
	.p2align 4,,10
	.p2align 3
.L16:
	leal	-1(%rax), %ecx
	addl	$1, %edx
	cmpl	%esi, %ecx
	jge	.L14
	jmp	.L15
	.p2align 4,,10
	.p2align 3
.L19:
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L26
	addq	$24, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
.L26:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE24:
	.size	main, .-main
	.globl	sum
	.bss
	.align 4
	.type	sum, @object
	.size	sum, 4
sum:
	.zero	4
	.globl	n
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.globl	A
	.align 32
	.type	A, @object
	.size	A, 404
A:
	.zero	404
	.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:
```