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>
#include<math.h>
#define M 32769

int main(void){

  int i,j;
  int n;
  char *a;
  int count;

  a = (char *)malloc(sizeof(char)*M);

  for(i=2;i<M;i++)a[i] = 1;
  a[0]=0;
  a[1]=0;

  i=2;
  while(i<M){
    for(j=2*i;j<M;j+=i)a[j] = 0;
    while(!a[++i]);
  }

  while(1){
    scanf("%d",&n);
    if(n==0)break;
    count = 0;

    for(i=1;i<=n/2;i++)if(a[i] && a[n-i])count++;

    printf("%d\n",count);
  }

  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:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$32, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$32769, %edi
	call	malloc@PLT
	movq	%rax, -16(%rbp)
	movl	$2, -28(%rbp)
	jmp	.L2
.L3:
	movl	-28(%rbp), %eax
	movslq	%eax, %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movb	$1, (%rax)
	addl	$1, -28(%rbp)
.L2:
	cmpl	$32768, -28(%rbp)
	jle	.L3
	movq	-16(%rbp), %rax
	movb	$0, (%rax)
	movq	-16(%rbp), %rax
	addq	$1, %rax
	movb	$0, (%rax)
	movl	$2, -28(%rbp)
	jmp	.L4
.L8:
	movl	-28(%rbp), %eax
	addl	%eax, %eax
	movl	%eax, -24(%rbp)
	jmp	.L5
.L6:
	movl	-24(%rbp), %eax
	movslq	%eax, %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movb	$0, (%rax)
	movl	-28(%rbp), %eax
	addl	%eax, -24(%rbp)
.L5:
	cmpl	$32768, -24(%rbp)
	jle	.L6
	nop
.L7:
	addl	$1, -28(%rbp)
	movl	-28(%rbp), %eax
	movslq	%eax, %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	testb	%al, %al
	je	.L7
.L4:
	cmpl	$32768, -28(%rbp)
	jle	.L8
.L14:
	leaq	-32(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-32(%rbp), %eax
	testl	%eax, %eax
	je	.L18
	movl	$0, -20(%rbp)
	movl	$1, -28(%rbp)
	jmp	.L11
.L13:
	movl	-28(%rbp), %eax
	movslq	%eax, %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	testb	%al, %al
	je	.L12
	movl	-32(%rbp), %eax
	subl	-28(%rbp), %eax
	movslq	%eax, %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	testb	%al, %al
	je	.L12
	addl	$1, -20(%rbp)
.L12:
	addl	$1, -28(%rbp)
.L11:
	movl	-32(%rbp), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	cmpl	%eax, -28(%rbp)
	jle	.L13
	movl	-20(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	jmp	.L14
.L18:
	nop
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L16
	call	__stack_chk_fail@PLT
.L16:
	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\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB39:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movl	$32769, %edi
	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
	subq	$24, %rsp
	.cfi_def_cfa_offset 64
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	call	malloc@PLT
	movl	$32767, %edx
	movl	$1, %esi
	leaq	2(%rax), %rdi
	movq	%rax, %rbx
	call	memset@PLT
	xorl	%eax, %eax
	movl	$2, %edx
	movw	%ax, (%rbx)
	.p2align 4,,10
	.p2align 3
.L5:
	leal	(%rdx,%rdx), %eax
	cmpl	$32768, %eax
	jg	.L2
	movslq	%edx, %rcx
	cltq
	.p2align 4,,10
	.p2align 3
.L3:
	movb	$0, (%rbx,%rax)
	addq	%rcx, %rax
	cmpl	$32768, %eax
	jle	.L3
.L2:
	addl	$1, %edx
	movslq	%edx, %rax
	.p2align 4,,10
	.p2align 3
.L4:
	movl	%eax, %edx
	addq	$1, %rax
	cmpb	$0, -1(%rbx,%rax)
	je	.L4
	cmpl	$32768, %edx
	jle	.L5
	leaq	4(%rsp), %r12
	leaq	.LC0(%rip), %rbp
	leaq	.LC1(%rip), %r13
	.p2align 4,,10
	.p2align 3
.L10:
	movq	%r12, %rsi
	movq	%rbp, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	4(%rsp), %esi
	testl	%esi, %esi
	je	.L6
	movl	%esi, %ecx
	shrl	$31, %ecx
	addl	%esi, %ecx
	sarl	%ecx
	cmpl	$1, %esi
	jle	.L12
	movl	$1, %eax
	xorl	%r8d, %r8d
	.p2align 4,,10
	.p2align 3
.L9:
	cmpb	$0, (%rbx,%rax)
	je	.L8
	movl	%esi, %edx
	subl	%eax, %edx
	movslq	%edx, %rdx
	cmpb	$1, (%rbx,%rdx)
	sbbl	$-1, %r8d
.L8:
	addq	$1, %rax
	cmpl	%eax, %ecx
	jge	.L9
.L7:
	movl	%r8d, %edx
	movq	%r13, %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L10
.L6:
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L19
	addq	$24, %rsp
	.cfi_remember_state
	.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
.L12:
	.cfi_restore_state
	xorl	%r8d, %r8d
	jmp	.L7
.L19:
	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\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB39:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movl	$32769, %edi
	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
	subq	$24, %rsp
	.cfi_def_cfa_offset 64
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	call	malloc@PLT
	movl	$32767, %edx
	movl	$1, %esi
	leaq	2(%rax), %rdi
	movq	%rax, %rbx
	call	memset@PLT
	xorl	%eax, %eax
	movl	$2, %edx
	movw	%ax, (%rbx)
	.p2align 4,,10
	.p2align 3
.L5:
	leal	(%rdx,%rdx), %eax
	cmpl	$32768, %eax
	jg	.L2
	movslq	%edx, %rcx
	cltq
	.p2align 4,,10
	.p2align 3
.L3:
	movb	$0, (%rbx,%rax)
	addq	%rcx, %rax
	cmpl	$32768, %eax
	jle	.L3
.L2:
	addl	$1, %edx
	movslq	%edx, %rax
	.p2align 4,,10
	.p2align 3
.L4:
	movl	%eax, %edx
	addq	$1, %rax
	cmpb	$0, -1(%rbx,%rax)
	je	.L4
	cmpl	$32768, %edx
	jle	.L5
	leaq	4(%rsp), %r12
	leaq	.LC0(%rip), %rbp
	leaq	.LC1(%rip), %r13
	.p2align 4,,10
	.p2align 3
.L10:
	movq	%r12, %rsi
	movq	%rbp, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	4(%rsp), %esi
	testl	%esi, %esi
	je	.L6
	movl	%esi, %ecx
	shrl	$31, %ecx
	addl	%esi, %ecx
	sarl	%ecx
	cmpl	$1, %esi
	jle	.L12
	movl	$1, %eax
	xorl	%r8d, %r8d
	.p2align 4,,10
	.p2align 3
.L9:
	cmpb	$0, (%rbx,%rax)
	je	.L8
	movl	%esi, %edx
	subl	%eax, %edx
	movslq	%edx, %rdx
	cmpb	$1, (%rbx,%rdx)
	sbbl	$-1, %r8d
.L8:
	addq	$1, %rax
	cmpl	%eax, %ecx
	jge	.L9
.L7:
	movl	%r8d, %edx
	movq	%r13, %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L10
.L6:
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L19
	addq	$24, %rsp
	.cfi_remember_state
	.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
.L12:
	.cfi_restore_state
	xorl	%r8d, %r8d
	jmp	.L7
.L19:
	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>
#include<math.h>
#define M 32769

int main(void){

  int i,j;
  int n;
  char *a;
  int count;

  a = (char *)malloc(sizeof(char)*M);

  for(i=2;i<M;i++)a[i] = 1;
  a[0]=0;
  a[1]=0;

  i=2;
  while(i<M){
    for(j=2*i;j<M;j+=i)a[j] = 0;
    while(!a[++i]);
  }

  while(1){
    scanf("%d",&n);
    if(n==0)break;
    count = 0;

    for(i=1;i<=n/2;i++)if(a[i] && a[n-i])count++;

    printf("%d\n",count);
  }

  return 0;
}
6
1
12
0
 6
10
8
0
 6
4
12
0
 6
1
3
0
 6
4
2
0
 6
0
2
0
 6
4
0
0
 6
2
14
0
 6
1
0
0
 6
16
0
0

1
0
1
 1
2
1
 1
1
1
 1
0
0
 1
1
0
 1
 1
1
 1
0
2
 1
0
 1
2

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>
#include<math.h>
#define M 32769

int main(void){

  int i,j;
  int n;
  char *a;
  int count;

  a = (char *)malloc(sizeof(char)*M);

  for(i=2;i<M;i++)a[i] = 1;
  a[0]=0;
  a[1]=0;

  i=2;
  while(i<M){
    for(j=2*i;j<M;j+=i)a[j] = 0;
    while(!a[++i]);
  }

  while(1){
    scanf("%d",&n);
    if(n==0)break;
    count = 0;

    for(i=1;i<=n/2;i++)if(a[i] && a[n-i])count++;

    printf("%d\n",count);
  }

  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:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$32, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$32769, %edi
	call	malloc@PLT
	movq	%rax, -16(%rbp)
	movl	$2, -28(%rbp)
	jmp	.L2
.L3:
	movl	-28(%rbp), %eax
	movslq	%eax, %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movb	$1, (%rax)
	addl	$1, -28(%rbp)
.L2:
	cmpl	$32768, -28(%rbp)
	jle	.L3
	movq	-16(%rbp), %rax
	movb	$0, (%rax)
	movq	-16(%rbp), %rax
	addq	$1, %rax
	movb	$0, (%rax)
	movl	$2, -28(%rbp)
	jmp	.L4
.L8:
	movl	-28(%rbp), %eax
	addl	%eax, %eax
	movl	%eax, -24(%rbp)
	jmp	.L5
.L6:
	movl	-24(%rbp), %eax
	movslq	%eax, %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movb	$0, (%rax)
	movl	-28(%rbp), %eax
	addl	%eax, -24(%rbp)
.L5:
	cmpl	$32768, -24(%rbp)
	jle	.L6
	nop
.L7:
	addl	$1, -28(%rbp)
	movl	-28(%rbp), %eax
	movslq	%eax, %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	testb	%al, %al
	je	.L7
.L4:
	cmpl	$32768, -28(%rbp)
	jle	.L8
.L14:
	leaq	-32(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-32(%rbp), %eax
	testl	%eax, %eax
	je	.L18
	movl	$0, -20(%rbp)
	movl	$1, -28(%rbp)
	jmp	.L11
.L13:
	movl	-28(%rbp), %eax
	movslq	%eax, %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	testb	%al, %al
	je	.L12
	movl	-32(%rbp), %eax
	subl	-28(%rbp), %eax
	movslq	%eax, %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	testb	%al, %al
	je	.L12
	addl	$1, -20(%rbp)
.L12:
	addl	$1, -28(%rbp)
.L11:
	movl	-32(%rbp), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	cmpl	%eax, -28(%rbp)
	jle	.L13
	movl	-20(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	jmp	.L14
.L18:
	nop
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L16
	call	__stack_chk_fail@PLT
.L16:
	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\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
	subq	$32, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$32769, %edi
	call	malloc@PLT
	movq	%rax, -16(%rbp)
	movl	$2, -28(%rbp)
	jmp	.L2
.L3:
	movl	-28(%rbp), %eax
	movslq	%eax, %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movb	$1, (%rax)
	addl	$1, -28(%rbp)
.L2:
	cmpl	$32768, -28(%rbp)
	jle	.L3
	movq	-16(%rbp), %rax
	movb	$0, (%rax)
	movq	-16(%rbp), %rax
	addq	$1, %rax
	movb	$0, (%rax)
	movl	$2, -28(%rbp)
	jmp	.L4
.L8:
	movl	-28(%rbp), %eax
	addl	%eax, %eax
	movl	%eax, -24(%rbp)
	jmp	.L5
.L6:
	movl	-24(%rbp), %eax
	movslq	%eax, %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movb	$0, (%rax)
	movl	-28(%rbp), %eax
	addl	%eax, -24(%rbp)
.L5:
	cmpl	$32768, -24(%rbp)
	jle	.L6
	nop
.L7:
	addl	$1, -28(%rbp)
	movl	-28(%rbp), %eax
	movslq	%eax, %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	testb	%al, %al
	je	.L7
.L4:
	cmpl	$32768, -28(%rbp)
	jle	.L8
.L14:
	leaq	-32(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-32(%rbp), %eax
	testl	%eax, %eax
	je	.L18
	movl	$0, -20(%rbp)
	movl	$1, -28(%rbp)
	jmp	.L11
.L13:
	movl	-28(%rbp), %eax
	movslq	%eax, %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	testb	%al, %al
	je	.L12
	movl	-32(%rbp), %eax
	subl	-28(%rbp), %eax
	movslq	%eax, %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movzbl	(%rax), %eax
	testb	%al, %al
	je	.L12
	addl	$1, -20(%rbp)
.L12:
	addl	$1, -28(%rbp)
.L11:
	movl	-32(%rbp), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	cmpl	%eax, -28(%rbp)
	jle	.L13
	movl	-20(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	jmp	.L14
.L18:
	nop
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L16
	call	__stack_chk_fail@PLT
.L16:
	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:
