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

```c
int p[10001];
main(i,j,r){
  p[0]=p[1]=1;
  for(i=2;i<10001;i++)
    if(!p[i])
      for(j=i*2;j<10001;j+=i)p[j]=1;
  for(;~scanf("%d",&j);printf("%d\n",r))
    for(r=0,i=2;i<=j;i++)
      if(!p[i]&&!p[j-i+1])r++;
  return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	p
	.bss
	.align 32
	.type	p, @object
	.size	p, 40004
p:
	.zero	40004
	.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	%edx, -12(%rbp)
	movl	$1, 4+p(%rip)
	movl	4+p(%rip), %eax
	movl	%eax, p(%rip)
	movl	$2, -4(%rbp)
	jmp	.L2
.L6:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	p(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	jne	.L3
	movl	-4(%rbp), %eax
	addl	%eax, %eax
	movl	%eax, -8(%rbp)
	jmp	.L4
.L5:
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	p(%rip), %rax
	movl	$1, (%rdx,%rax)
	movl	-8(%rbp), %edx
	movl	-4(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, -8(%rbp)
.L4:
	movl	-8(%rbp), %eax
	cmpl	$10000, %eax
	jle	.L5
.L3:
	addl	$1, -4(%rbp)
.L2:
	cmpl	$10000, -4(%rbp)
	jle	.L6
	jmp	.L7
.L11:
	movl	$0, -12(%rbp)
	movl	$2, -4(%rbp)
	jmp	.L8
.L10:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	p(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	jne	.L9
	movl	-8(%rbp), %eax
	subl	-4(%rbp), %eax
	addl	$1, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	p(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	jne	.L9
	addl	$1, -12(%rbp)
.L9:
	addl	$1, -4(%rbp)
.L8:
	movl	-8(%rbp), %eax
	cmpl	%eax, -4(%rbp)
	jle	.L10
	movl	-12(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
.L7:
	leaq	-8(%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, %eax
	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
.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
	movl	$4, %edi
	movl	$2, %ecx
	leaq	16+p(%rip), %r9
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	leaq	-16(%r9), %rbx
	subq	$24, %rsp
	.cfi_def_cfa_offset 64
	movq	.LC0(%rip), %rdx
	movl	%esi, 12(%rsp)
	movq	%rdx, p(%rip)
	xorl	%edx, %edx
	jmp	.L4
	.p2align 4,,10
	.p2align 3
.L2:
	addq	$1, %rcx
	addl	$2, %edi
	addq	$8, %r9
	cmpq	$10001, %rcx
	je	.L22
.L4:
	movl	(%rbx,%rcx,4), %r8d
	movl	%ecx, %esi
	testl	%r8d, %r8d
	jne	.L2
	movl	%edi, %eax
	cmpl	$10000, %edi
	ja	.L12
	leaq	0(,%rcx,4), %r8
	movq	%r9, %rdx
	.p2align 4,,10
	.p2align 3
.L3:
	addl	%esi, %eax
	movl	$1, (%rdx)
	addq	%r8, %rdx
	cmpl	$10000, %eax
	jle	.L3
.L12:
	movl	$1, %edx
	jmp	.L2
.L22:
	testb	%dl, %dl
	je	.L5
	movl	%eax, 12(%rsp)
.L5:
	leaq	12(%rsp), %r12
	leaq	.LC2(%rip), %rbp
	leaq	.LC1(%rip), %r13
	.p2align 4,,10
	.p2align 3
.L6:
	xorl	%eax, %eax
	movq	%r12, %rsi
	movq	%rbp, %rdi
	call	scanf@PLT
	cmpl	$-1, %eax
	je	.L9
	movl	12(%rsp), %ecx
	leaq	8+p(%rip), %rdx
	xorl	%esi, %esi
	leal	-1(%rcx), %eax
	cmpl	$1, %ecx
	jle	.L11
	.p2align 4,,10
	.p2align 3
.L8:
	movl	(%rdx), %ecx
	testl	%ecx, %ecx
	jne	.L7
	movslq	%eax, %rcx
	cmpl	$1, (%rbx,%rcx,4)
	adcl	$0, %esi
.L7:
	addq	$4, %rdx
	subl	$1, %eax
	jne	.L8
.L11:
	movq	%r13, %rdi
	xorl	%eax, %eax
	call	printf@PLT
	jmp	.L6
.L9:
	addq	$24, %rsp
	.cfi_def_cfa_offset 40
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE0:
	.size	main, .-main
	.globl	p
	.bss
	.align 32
	.type	p, @object
	.size	p, 40004
p:
	.zero	40004
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC0:
	.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
	movl	$4, %edi
	movl	$2, %ecx
	leaq	16+p(%rip), %r9
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	leaq	-16(%r9), %rbx
	subq	$24, %rsp
	.cfi_def_cfa_offset 64
	movq	.LC0(%rip), %rdx
	movl	%esi, 12(%rsp)
	movq	%rdx, p(%rip)
	xorl	%edx, %edx
	jmp	.L4
	.p2align 4,,10
	.p2align 3
.L2:
	addq	$1, %rcx
	addl	$2, %edi
	addq	$8, %r9
	cmpq	$10001, %rcx
	je	.L22
.L4:
	movl	(%rbx,%rcx,4), %r8d
	movl	%ecx, %esi
	testl	%r8d, %r8d
	jne	.L2
	movl	%edi, %eax
	cmpl	$10000, %edi
	ja	.L12
	leaq	0(,%rcx,4), %r8
	movq	%r9, %rdx
	.p2align 4,,10
	.p2align 3
.L3:
	addl	%esi, %eax
	movl	$1, (%rdx)
	addq	%r8, %rdx
	cmpl	$10000, %eax
	jle	.L3
.L12:
	movl	$1, %edx
	jmp	.L2
.L22:
	testb	%dl, %dl
	je	.L5
	movl	%eax, 12(%rsp)
.L5:
	leaq	12(%rsp), %r12
	leaq	.LC2(%rip), %rbp
	leaq	.LC1(%rip), %r13
	.p2align 4,,10
	.p2align 3
.L6:
	xorl	%eax, %eax
	movq	%r12, %rsi
	movq	%rbp, %rdi
	call	scanf@PLT
	cmpl	$-1, %eax
	je	.L9
	movl	12(%rsp), %ecx
	leaq	8+p(%rip), %rdx
	xorl	%esi, %esi
	leal	-1(%rcx), %eax
	cmpl	$1, %ecx
	jle	.L11
	.p2align 4,,10
	.p2align 3
.L8:
	movl	(%rdx), %ecx
	testl	%ecx, %ecx
	jne	.L7
	movslq	%eax, %rcx
	cmpl	$1, (%rbx,%rcx,4)
	adcl	$0, %esi
.L7:
	addq	$4, %rdx
	subl	$1, %eax
	jne	.L8
.L11:
	movq	%r13, %rdi
	xorl	%eax, %eax
	call	printf@PLT
	jmp	.L6
.L9:
	addq	$24, %rsp
	.cfi_def_cfa_offset 40
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE0:
	.size	main, .-main
	.globl	p
	.bss
	.align 32
	.type	p, @object
	.size	p, 40004
p:
	.zero	40004
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC0:
	.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:

int p[10001];
main(i,j,r){
  p[0]=p[1]=1;
  for(i=2;i<10001;i++)
    if(!p[i])
      for(j=i*2;j<10001;j+=i)p[j]=1;
  for(;~scanf("%d",&j);printf("%d\n",r))
    for(r=0,i=2;i<=j;i++)
      if(!p[i]&&!p[j-i+1])r++;
  return 0;
}
1
8
7
51
 1
10
7
51
 1
10
7
65
 1
12
7
115
 1
12
9
115
 1
12
9
15
 1
26
9
15
 1
26
11
15
 1
26
11
20
 1
27
11
20

0
2
2
6
 0
0
2
6
 0
0
2
12
 0
2
2
12
 0
2
3
12
 0
2
3
4
 0
0
3
4
 0
0
2
4
 0
0
2
2
 0
4
2
2

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

```c
int p[10001];
main(i,j,r){
  p[0]=p[1]=1;
  for(i=2;i<10001;i++)
    if(!p[i])
      for(j=i*2;j<10001;j+=i)p[j]=1;
  for(;~scanf("%d",&j);printf("%d\n",r))
    for(r=0,i=2;i<=j;i++)
      if(!p[i]&&!p[j-i+1])r++;
  return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	p
	.bss
	.align 32
	.type	p, @object
	.size	p, 40004
p:
	.zero	40004
	.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	%edx, -12(%rbp)
	movl	$1, 4+p(%rip)
	movl	4+p(%rip), %eax
	movl	%eax, p(%rip)
	movl	$2, -4(%rbp)
	jmp	.L2
.L6:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	p(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	jne	.L3
	movl	-4(%rbp), %eax
	addl	%eax, %eax
	movl	%eax, -8(%rbp)
	jmp	.L4
.L5:
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	p(%rip), %rax
	movl	$1, (%rdx,%rax)
	movl	-8(%rbp), %edx
	movl	-4(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, -8(%rbp)
.L4:
	movl	-8(%rbp), %eax
	cmpl	$10000, %eax
	jle	.L5
.L3:
	addl	$1, -4(%rbp)
.L2:
	cmpl	$10000, -4(%rbp)
	jle	.L6
	jmp	.L7
.L11:
	movl	$0, -12(%rbp)
	movl	$2, -4(%rbp)
	jmp	.L8
.L10:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	p(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	jne	.L9
	movl	-8(%rbp), %eax
	subl	-4(%rbp), %eax
	addl	$1, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	p(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	jne	.L9
	addl	$1, -12(%rbp)
.L9:
	addl	$1, -4(%rbp)
.L8:
	movl	-8(%rbp), %eax
	cmpl	%eax, -4(%rbp)
	jle	.L10
	movl	-12(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
.L7:
	leaq	-8(%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, %eax
	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
	.globl	p
	.bss
	.align 32
	.type	p, @object
	.size	p, 40004
p:
	.zero	40004
	.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	%edx, -12(%rbp)
	movl	$1, 4+p(%rip)
	movl	4+p(%rip), %eax
	movl	%eax, p(%rip)
	movl	$2, -4(%rbp)
	jmp	.L2
.L6:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	p(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	jne	.L3
	movl	-4(%rbp), %eax
	addl	%eax, %eax
	movl	%eax, -8(%rbp)
	jmp	.L4
.L5:
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	p(%rip), %rax
	movl	$1, (%rdx,%rax)
	movl	-8(%rbp), %edx
	movl	-4(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, -8(%rbp)
.L4:
	movl	-8(%rbp), %eax
	cmpl	$10000, %eax
	jle	.L5
.L3:
	addl	$1, -4(%rbp)
.L2:
	cmpl	$10000, -4(%rbp)
	jle	.L6
	jmp	.L7
.L11:
	movl	$0, -12(%rbp)
	movl	$2, -4(%rbp)
	jmp	.L8
.L10:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	p(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	jne	.L9
	movl	-8(%rbp), %eax
	subl	-4(%rbp), %eax
	addl	$1, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	p(%rip), %rax
	movl	(%rdx,%rax), %eax
	testl	%eax, %eax
	jne	.L9
	addl	$1, -12(%rbp)
.L9:
	addl	$1, -4(%rbp)
.L8:
	movl	-8(%rbp), %eax
	cmpl	%eax, -4(%rbp)
	jle	.L10
	movl	-12(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
.L7:
	leaq	-8(%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, %eax
	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:
