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

```c
A[2001],B[4001];main(a,b){
	for(a=0;a<1001;a++)for(b=0;b<1001;b++)A[a+b]++;
	for(a=0;a<2001;a++)for(b=0;b<2001;b++)B[a+b]+=A[a]*A[b];
	for(;~scanf("%d",&a);)printf("%d\n",B[a]);
exit(0);}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	A
	.bss
	.align 32
	.type	A, @object
	.size	A, 8004
A:
	.zero	8004
	.globl	B
	.align 32
	.type	B, @object
	.size	B, 16004
B:
	.zero	16004
	.section	.rodata
.LC0:
	.string	"%d\n"
.LC1:
	.string	"%d"
	.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	$16, %rsp
	movl	%edi, -4(%rbp)
	movl	%esi, -8(%rbp)
	movl	$0, -4(%rbp)
	jmp	.L2
.L5:
	movl	$0, -8(%rbp)
	jmp	.L3
.L4:
	movl	-4(%rbp), %edx
	movl	-8(%rbp), %eax
	addl	%edx, %eax
	movslq	%eax, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	A(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	leal	1(%rdx), %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	addl	$1, -8(%rbp)
.L3:
	cmpl	$1000, -8(%rbp)
	jle	.L4
	movl	-4(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -4(%rbp)
.L2:
	movl	-4(%rbp), %eax
	cmpl	$1000, %eax
	jle	.L5
	movl	$0, -4(%rbp)
	jmp	.L6
.L9:
	movl	$0, -8(%rbp)
	jmp	.L7
.L8:
	movl	-4(%rbp), %edx
	movl	-8(%rbp), %eax
	addl	%edx, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	B(%rip), %rax
	movl	(%rdx,%rax), %esi
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	A(%rip), %rax
	movl	(%rcx,%rax), %eax
	imull	%eax, %edx
	movl	-4(%rbp), %ecx
	movl	-8(%rbp), %eax
	addl	%ecx, %eax
	leal	(%rsi,%rdx), %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	B(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	addl	$1, -8(%rbp)
.L7:
	cmpl	$2000, -8(%rbp)
	jle	.L8
	movl	-4(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -4(%rbp)
.L6:
	movl	-4(%rbp), %eax
	cmpl	$2000, %eax
	jle	.L9
	jmp	.L10
.L11:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	B(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
.L10:
	leaq	-4(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	scanf@PLT
	cmpl	$-1, %eax
	jne	.L11
	movl	$0, %edi
	call	exit@PLT
	.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
.LC1:
	.string	"%d\n"
.LC2:
	.string	"%d"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	leaq	4000+A(%rip), %rax
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	leaq	-4000(%rax), %rcx
	leaq	4004(%rax), %rdi
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	movq	%rcx, %r8
	movq	%rcx, %rdx
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	subq	$24, %rsp
	.cfi_def_cfa_offset 64
	movdqa	.LC0(%rip), %xmm1
	.p2align 4,,10
	.p2align 3
.L3:
	movq	%rdx, %rsi
	.p2align 4,,10
	.p2align 3
.L2:
	movdqu	(%rsi), %xmm0
	addq	$16, %rsi
	paddd	%xmm1, %xmm0
	movups	%xmm0, -16(%rsi)
	cmpq	%rsi, %rax
	jne	.L2
	addl	$1, (%rax)
	addq	$4, %rax
	addq	$4, %rdx
	cmpq	%rax, %rdi
	jne	.L3
	leaq	B(%rip), %rbx
	movq	%rbx, %rax
	leaq	8004(%rbx), %rdi
	.p2align 4,,10
	.p2align 3
.L5:
	movl	(%rcx), %edx
	xorl	%esi, %esi
	movd	%edx, %xmm5
	pshufd	$0, %xmm5, %xmm2
	movdqa	%xmm2, %xmm3
	psrlq	$32, %xmm3
	.p2align 4,,10
	.p2align 3
.L4:
	movdqa	(%r8,%rsi), %xmm1
	movdqu	(%rax,%rsi), %xmm4
	movdqa	%xmm2, %xmm0
	pmuludq	(%r8,%rsi), %xmm0
	pshufd	$8, %xmm0, %xmm0
	psrlq	$32, %xmm1
	pmuludq	%xmm3, %xmm1
	pshufd	$8, %xmm1, %xmm1
	punpckldq	%xmm1, %xmm0
	paddd	%xmm4, %xmm0
	movups	%xmm0, (%rax,%rsi)
	addq	$16, %rsi
	cmpq	$8000, %rsi
	jne	.L4
	imull	8000+A(%rip), %edx
	addl	%edx, 8000(%rax)
	addq	$4, %rax
	addq	$4, %rcx
	cmpq	%rdi, %rax
	jne	.L5
	movl	$2001, 12(%rsp)
	leaq	12(%rsp), %r12
	leaq	.LC2(%rip), %rbp
	leaq	.LC1(%rip), %r13
	jmp	.L6
.L7:
	movslq	12(%rsp), %rax
	movq	%r13, %rdi
	movl	(%rbx,%rax,4), %esi
	xorl	%eax, %eax
	call	printf@PLT
.L6:
	xorl	%eax, %eax
	movq	%r12, %rsi
	movq	%rbp, %rdi
	call	scanf@PLT
	cmpl	$-1, %eax
	jne	.L7
	xorl	%edi, %edi
	call	exit@PLT
	.cfi_endproc
.LFE0:
	.size	main, .-main
	.globl	B
	.bss
	.align 32
	.type	B, @object
	.size	B, 16004
B:
	.zero	16004
	.globl	A
	.align 32
	.type	A, @object
	.size	A, 8004
A:
	.zero	8004
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC0:
	.long	1
	.long	1
	.long	1
	.long	1
	.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
.LC1:
	.string	"%d\n"
.LC2:
	.string	"%d"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	leaq	4000+A(%rip), %rax
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	leaq	-4000(%rax), %rcx
	leaq	4004(%rax), %rdi
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	movq	%rcx, %r8
	movq	%rcx, %rdx
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	subq	$24, %rsp
	.cfi_def_cfa_offset 64
	movdqa	.LC0(%rip), %xmm1
	.p2align 4,,10
	.p2align 3
.L3:
	movq	%rdx, %rsi
	.p2align 4,,10
	.p2align 3
.L2:
	movdqu	(%rsi), %xmm0
	addq	$16, %rsi
	paddd	%xmm1, %xmm0
	movups	%xmm0, -16(%rsi)
	cmpq	%rsi, %rax
	jne	.L2
	addl	$1, (%rax)
	addq	$4, %rax
	addq	$4, %rdx
	cmpq	%rax, %rdi
	jne	.L3
	leaq	B(%rip), %rbx
	movq	%rbx, %rax
	leaq	8004(%rbx), %rdi
	.p2align 4,,10
	.p2align 3
.L5:
	movl	(%rcx), %edx
	xorl	%esi, %esi
	movd	%edx, %xmm5
	pshufd	$0, %xmm5, %xmm2
	movdqa	%xmm2, %xmm3
	psrlq	$32, %xmm3
	.p2align 4,,10
	.p2align 3
.L4:
	movdqa	(%r8,%rsi), %xmm1
	movdqu	(%rax,%rsi), %xmm4
	movdqa	%xmm2, %xmm0
	pmuludq	(%r8,%rsi), %xmm0
	pshufd	$8, %xmm0, %xmm0
	psrlq	$32, %xmm1
	pmuludq	%xmm3, %xmm1
	pshufd	$8, %xmm1, %xmm1
	punpckldq	%xmm1, %xmm0
	paddd	%xmm4, %xmm0
	movups	%xmm0, (%rax,%rsi)
	addq	$16, %rsi
	cmpq	$8000, %rsi
	jne	.L4
	imull	8000+A(%rip), %edx
	addl	%edx, 8000(%rax)
	addq	$4, %rax
	addq	$4, %rcx
	cmpq	%rdi, %rax
	jne	.L5
	movl	$2001, 12(%rsp)
	leaq	12(%rsp), %r12
	leaq	.LC2(%rip), %rbp
	leaq	.LC1(%rip), %r13
	jmp	.L6
.L7:
	movslq	12(%rsp), %rax
	movq	%r13, %rdi
	movl	(%rbx,%rax,4), %esi
	xorl	%eax, %eax
	call	printf@PLT
.L6:
	xorl	%eax, %eax
	movq	%r12, %rsi
	movq	%rbp, %rdi
	call	scanf@PLT
	cmpl	$-1, %eax
	jne	.L7
	xorl	%edi, %edi
	call	exit@PLT
	.cfi_endproc
.LFE0:
	.size	main, .-main
	.globl	B
	.bss
	.align 32
	.type	B, @object
	.size	B, 16004
B:
	.zero	16004
	.globl	A
	.align 32
	.type	A, @object
	.size	A, 8004
A:
	.zero	8004
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC0:
	.long	1
	.long	1
	.long	1
	.long	1
	.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:

A[2001],B[4001];main(a,b){
	for(a=0;a<1001;a++)for(b=0;b<1001;b++)A[a+b]++;
	for(a=0;a<2001;a++)for(b=0;b<2001;b++)B[a+b]+=A[a]*A[b];
	for(;~scanf("%d",&a);)printf("%d\n",B[a]);
exit(0);}
2
0
35
 2
-1
35
 2
-1
24
 2
-1
43
 2
-1
72
 2
-1
81
 2
-1
61
 2
-1
82
 2
0
82
 2
-1
59

10
1
8436
 10
0
8436
 10
0
2925
 10
0
15180
 10
0
67525
 10
0
95284
 10
0
41664
 10
0
98770
 10
1
98770
 10
0
37820

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

```c
A[2001],B[4001];main(a,b){
	for(a=0;a<1001;a++)for(b=0;b<1001;b++)A[a+b]++;
	for(a=0;a<2001;a++)for(b=0;b<2001;b++)B[a+b]+=A[a]*A[b];
	for(;~scanf("%d",&a);)printf("%d\n",B[a]);
exit(0);}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	A
	.bss
	.align 32
	.type	A, @object
	.size	A, 8004
A:
	.zero	8004
	.globl	B
	.align 32
	.type	B, @object
	.size	B, 16004
B:
	.zero	16004
	.section	.rodata
.LC0:
	.string	"%d\n"
.LC1:
	.string	"%d"
	.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	$16, %rsp
	movl	%edi, -4(%rbp)
	movl	%esi, -8(%rbp)
	movl	$0, -4(%rbp)
	jmp	.L2
.L5:
	movl	$0, -8(%rbp)
	jmp	.L3
.L4:
	movl	-4(%rbp), %edx
	movl	-8(%rbp), %eax
	addl	%edx, %eax
	movslq	%eax, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	A(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	leal	1(%rdx), %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	addl	$1, -8(%rbp)
.L3:
	cmpl	$1000, -8(%rbp)
	jle	.L4
	movl	-4(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -4(%rbp)
.L2:
	movl	-4(%rbp), %eax
	cmpl	$1000, %eax
	jle	.L5
	movl	$0, -4(%rbp)
	jmp	.L6
.L9:
	movl	$0, -8(%rbp)
	jmp	.L7
.L8:
	movl	-4(%rbp), %edx
	movl	-8(%rbp), %eax
	addl	%edx, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	B(%rip), %rax
	movl	(%rdx,%rax), %esi
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	A(%rip), %rax
	movl	(%rcx,%rax), %eax
	imull	%eax, %edx
	movl	-4(%rbp), %ecx
	movl	-8(%rbp), %eax
	addl	%ecx, %eax
	leal	(%rsi,%rdx), %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	B(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	addl	$1, -8(%rbp)
.L7:
	cmpl	$2000, -8(%rbp)
	jle	.L8
	movl	-4(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -4(%rbp)
.L6:
	movl	-4(%rbp), %eax
	cmpl	$2000, %eax
	jle	.L9
	jmp	.L10
.L11:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	B(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
.L10:
	leaq	-4(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	scanf@PLT
	cmpl	$-1, %eax
	jne	.L11
	movl	$0, %edi
	call	exit@PLT
	.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
	.globl	A
	.bss
	.align 32
	.type	A, @object
	.size	A, 8004
A:
	.zero	8004
	.globl	B
	.align 32
	.type	B, @object
	.size	B, 16004
B:
	.zero	16004
	.section	.rodata
.LC0:
	.string	"%d\n"
.LC1:
	.string	"%d"
	.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	$16, %rsp
	movl	%edi, -4(%rbp)
	movl	%esi, -8(%rbp)
	movl	$0, -4(%rbp)
	jmp	.L2
.L5:
	movl	$0, -8(%rbp)
	jmp	.L3
.L4:
	movl	-4(%rbp), %edx
	movl	-8(%rbp), %eax
	addl	%edx, %eax
	movslq	%eax, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	A(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	leal	1(%rdx), %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	addl	$1, -8(%rbp)
.L3:
	cmpl	$1000, -8(%rbp)
	jle	.L4
	movl	-4(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -4(%rbp)
.L2:
	movl	-4(%rbp), %eax
	cmpl	$1000, %eax
	jle	.L5
	movl	$0, -4(%rbp)
	jmp	.L6
.L9:
	movl	$0, -8(%rbp)
	jmp	.L7
.L8:
	movl	-4(%rbp), %edx
	movl	-8(%rbp), %eax
	addl	%edx, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	B(%rip), %rax
	movl	(%rdx,%rax), %esi
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	A(%rip), %rax
	movl	(%rcx,%rax), %eax
	imull	%eax, %edx
	movl	-4(%rbp), %ecx
	movl	-8(%rbp), %eax
	addl	%ecx, %eax
	leal	(%rsi,%rdx), %ecx
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	B(%rip), %rax
	movl	%ecx, (%rdx,%rax)
	addl	$1, -8(%rbp)
.L7:
	cmpl	$2000, -8(%rbp)
	jle	.L8
	movl	-4(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -4(%rbp)
.L6:
	movl	-4(%rbp), %eax
	cmpl	$2000, %eax
	jle	.L9
	jmp	.L10
.L11:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	B(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
.L10:
	leaq	-4(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	scanf@PLT
	cmpl	$-1, %eax
	jne	.L11
	movl	$0, %edi
	call	exit@PLT
	.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:
