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 sum(int m,int n)
{
    int a;
    a = (m+n-1) * (m+n) / 2 - (m-1) * m / 2 ;
    return a ;
}

int main()
{
  int i,j,a;
  int n[1001]={0};
  for(i=2;i<45;i++){
    for(j=1;;j++){
      if(sum(j,i)>1001){
    break;
      }
 n[sum(j,i)]++;
    }
  }

  while(scanf("%d",&a),a){
      printf("%d\n",n[a]);
  }
  return 0;
}```

Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.p2align 4
	.globl	sum
	.type	sum, @function
sum:
.LFB23:
	.cfi_startproc
	endbr64
	leal	(%rdi,%rsi), %eax
	leal	-1(%rdi), %edx
	imull	%edi, %edx
	leal	-1(%rax), %esi
	imull	%eax, %esi
	movl	%edx, %edi
	movl	%esi, %eax
	shrl	$31, %edi
	shrl	$31, %eax
	addl	%edx, %edi
	addl	%esi, %eax
	sarl	%edi
	sarl	%eax
	subl	%edi, %eax
	ret
	.cfi_endproc
.LFE23:
	.size	sum, .-sum
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d\n"
.LC1:
	.string	"%d"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB24:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movl	$500, %ecx
	movl	$2, %r8d
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	subq	$4032, %rsp
	.cfi_def_cfa_offset 4064
	movq	%fs:40, %rax
	movq	%rax, 4024(%rsp)
	xorl	%eax, %eax
	leaq	16(%rsp), %rdi
	rep stosq
	movl	$0, (%rdi)
	.p2align 4,,10
	.p2align 3
.L4:
	movl	%r8d, %ecx
	movl	%r8d, %edi
	addl	$1, %r8d
	movl	$1, %edx
	movl	%r8d, %eax
	leal	-1(%rcx), %r9d
	imull	%ecx, %eax
	sarl	%eax
	.p2align 4,,10
	.p2align 3
.L5:
	movl	%edx, %esi
	addl	$1, %edx
	cltq
	imull	%edx, %esi
	leal	(%rdi,%rdx), %ecx
	addl	$1, 16(%rsp,%rax,4)
	leal	(%r9,%rdx), %eax
	imull	%ecx, %eax
	movl	%esi, %ecx
	shrl	$31, %ecx
	addl	%esi, %ecx
	sarl	%eax
	sarl	%ecx
	subl	%ecx, %eax
	cmpl	$1001, %eax
	jle	.L5
	cmpl	$45, %r8d
	jne	.L4
	leaq	12(%rsp), %rbp
	leaq	.LC1(%rip), %rbx
	leaq	.LC0(%rip), %r12
	jmp	.L6
	.p2align 4,,10
	.p2align 3
.L7:
	movl	16(%rsp,%rax,4), %edx
	movq	%r12, %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L6:
	movq	%rbp, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movslq	12(%rsp), %rax
	testl	%eax, %eax
	jne	.L7
	movq	4024(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L12
	addq	$4032, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 32
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
.L12:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE24:
	.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.
Optimized Assembly Code:

user
```assembly
	.file	"temp.c"
	.text
	.p2align 4
	.globl	sum
	.type	sum, @function
sum:
.LFB23:
	.cfi_startproc
	endbr64
	leal	(%rdi,%rsi), %eax
	leal	-1(%rdi), %edx
	imull	%edi, %edx
	leal	-1(%rax), %esi
	imull	%eax, %esi
	movl	%edx, %edi
	movl	%esi, %eax
	shrl	$31, %edi
	shrl	$31, %eax
	addl	%edx, %edi
	addl	%esi, %eax
	sarl	%edi
	sarl	%eax
	subl	%edi, %eax
	ret
	.cfi_endproc
.LFE23:
	.size	sum, .-sum
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d\n"
.LC1:
	.string	"%d"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB24:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movl	$500, %ecx
	movl	$2, %r8d
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	subq	$4032, %rsp
	.cfi_def_cfa_offset 4064
	movq	%fs:40, %rax
	movq	%rax, 4024(%rsp)
	xorl	%eax, %eax
	leaq	16(%rsp), %rdi
	rep stosq
	movl	$0, (%rdi)
	.p2align 4,,10
	.p2align 3
.L4:
	movl	%r8d, %ecx
	movl	%r8d, %edi
	addl	$1, %r8d
	movl	$1, %edx
	movl	%r8d, %eax
	leal	-1(%rcx), %r9d
	imull	%ecx, %eax
	sarl	%eax
	.p2align 4,,10
	.p2align 3
.L5:
	movl	%edx, %esi
	addl	$1, %edx
	cltq
	imull	%edx, %esi
	leal	(%rdi,%rdx), %ecx
	addl	$1, 16(%rsp,%rax,4)
	leal	(%r9,%rdx), %eax
	imull	%ecx, %eax
	movl	%esi, %ecx
	shrl	$31, %ecx
	addl	%esi, %ecx
	sarl	%eax
	sarl	%ecx
	subl	%ecx, %eax
	cmpl	$1001, %eax
	jle	.L5
	cmpl	$45, %r8d
	jne	.L4
	leaq	12(%rsp), %rbp
	leaq	.LC1(%rip), %rbx
	leaq	.LC0(%rip), %r12
	jmp	.L6
	.p2align 4,,10
	.p2align 3
.L7:
	movl	16(%rsp,%rax,4), %edx
	movq	%r12, %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L6:
	movq	%rbp, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movslq	12(%rsp), %rax
	testl	%eax, %eax
	jne	.L7
	movq	4024(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L12
	addq	$4032, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 32
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
.L12:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE24:
	.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
```assembly
	.file	"temp.c"
	.text
	.p2align 4
	.globl	sum
	.type	sum, @function
sum:
.LFB23:
	.cfi_startproc
	endbr64
	leal	(%rdi,%rsi), %eax
	leal	-1(%rdi), %edx
	imull	%edi, %edx
	leal	-1(%rax), %esi
	imull	%eax, %esi
	movl	%edx, %edi
	movl	%esi, %eax
	shrl	$31, %edi
	shrl	$31, %eax
	addl	%edx, %edi
	addl	%esi, %eax
	sarl	%edi
	sarl	%eax
	subl	%edi, %eax
	ret
	.cfi_endproc
.LFE23:
	.size	sum, .-sum
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d\n"
.LC1:
	.string	"%d"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB24:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movl	$500, %ecx
	movl	$2, %r8d
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	subq	$4032, %rsp
	.cfi_def_cfa_offset 4064
	movq	%fs:40, %rax
	movq	%rax, 4024(%rsp)
	xorl	%eax, %eax
	leaq	16(%rsp), %rdi
	rep stosq
	movl	$0, (%rdi)
	.p2align 4,,10
	.p2align 3
.L4:
	movl	%r8d, %ecx
	movl	%r8d, %edi
	addl	$1, %r8d
	movl	$1, %edx
	movl	%r8d, %eax
	leal	-1(%rcx), %r9d
	imull	%ecx, %eax
	sarl	%eax
	.p2align 4,,10
	.p2align 3
.L5:
	movl	%edx, %esi
	addl	$1, %edx
	cltq
	imull	%edx, %esi
	leal	(%rdi,%rdx), %ecx
	addl	$1, 16(%rsp,%rax,4)
	leal	(%r9,%rdx), %eax
	imull	%ecx, %eax
	movl	%esi, %ecx
	shrl	$31, %ecx
	addl	%esi, %ecx
	sarl	%eax
	sarl	%ecx
	subl	%ecx, %eax
	cmpl	$1001, %eax
	jle	.L5
	cmpl	$45, %r8d
	jne	.L4
	leaq	12(%rsp), %rbp
	leaq	.LC1(%rip), %rbx
	leaq	.LC0(%rip), %r12
	jmp	.L6
	.p2align 4,,10
	.p2align 3
.L7:
	movl	16(%rsp,%rax,4), %edx
	movq	%r12, %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L6:
	movq	%rbp, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movslq	12(%rsp), %rax
	testl	%eax, %eax
	jne	.L7
	movq	4024(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L12
	addq	$4032, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 32
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
.L12:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE24:
	.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:
```
```c
#include<stdio.h>
 
int sum(int m,int n)
{
    int a;
    a = (m+n-1) * (m+n) / 2 - (m-1) * m / 2 ;
    return a ;
}

int main()
{
  int i,j,a;
  int n[1001]={0};
  for(i=2;i<45;i++){
    for(j=1;;j++){
      if(sum(j,i)>1001){
    break;
      }
 n[sum(j,i)]++;
    }
  }

  while(scanf("%d",&a),a){
      printf("%d\n",n[a]);
  }
  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 sum(int m,int n)
{
    int a;
    a = (m+n-1) * (m+n) / 2 - (m-1) * m / 2 ;
    return a ;
}

int main()
{
  int i,j,a;
  int n[1001]={0};
  for(i=2;i<45;i++){
    for(j=1;;j++){
      if(sum(j,i)>1001){
    break;
      }
 n[sum(j,i)]++;
    }
  }

  while(scanf("%d",&a),a){
      printf("%d\n",n[a]);
  }
  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:

9
256
0
 9
160
0
 9
213
0
 9
200
0
 9
135
0
 9
350
0
 9
0
-1
 9
162
0
 9
315
0
 9
225
0

2
0
 2
1
 2
3
 2
2
 2
7
 2
5
 2
 2
4
 2
11
 2
8

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 sum(int m,int n)
{
    int a;
    a = (m+n-1) * (m+n) / 2 - (m-1) * m / 2 ;
    return a ;
}

int main()
{
  int i,j,a;
  int n[1001]={0};
  for(i=2;i<45;i++){
    for(j=1;;j++){
      if(sum(j,i)>1001){
    break;
      }
 n[sum(j,i)]++;
    }
  }

  while(scanf("%d",&a),a){
      printf("%d\n",n[a]);
  }
  return 0;
}```

Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.p2align 4
	.globl	sum
	.type	sum, @function
sum:
.LFB23:
	.cfi_startproc
	endbr64
	leal	(%rdi,%rsi), %eax
	leal	-1(%rdi), %edx
	imull	%edi, %edx
	leal	-1(%rax), %esi
	imull	%eax, %esi
	movl	%edx, %edi
	movl	%esi, %eax
	shrl	$31, %edi
	shrl	$31, %eax
	addl	%edx, %edi
	addl	%esi, %eax
	sarl	%edi
	sarl	%eax
	subl	%edi, %eax
	ret
	.cfi_endproc
.LFE23:
	.size	sum, .-sum
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d\n"
.LC1:
	.string	"%d"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB24:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movl	$500, %ecx
	movl	$2, %r8d
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	subq	$4032, %rsp
	.cfi_def_cfa_offset 4064
	movq	%fs:40, %rax
	movq	%rax, 4024(%rsp)
	xorl	%eax, %eax
	leaq	16(%rsp), %rdi
	rep stosq
	movl	$0, (%rdi)
	.p2align 4,,10
	.p2align 3
.L4:
	movl	%r8d, %ecx
	movl	%r8d, %edi
	addl	$1, %r8d
	movl	$1, %edx
	movl	%r8d, %eax
	leal	-1(%rcx), %r9d
	imull	%ecx, %eax
	sarl	%eax
	.p2align 4,,10
	.p2align 3
.L5:
	movl	%edx, %esi
	addl	$1, %edx
	cltq
	imull	%edx, %esi
	leal	(%rdi,%rdx), %ecx
	addl	$1, 16(%rsp,%rax,4)
	leal	(%r9,%rdx), %eax
	imull	%ecx, %eax
	movl	%esi, %ecx
	shrl	$31, %ecx
	addl	%esi, %ecx
	sarl	%eax
	sarl	%ecx
	subl	%ecx, %eax
	cmpl	$1001, %eax
	jle	.L5
	cmpl	$45, %r8d
	jne	.L4
	leaq	12(%rsp), %rbp
	leaq	.LC1(%rip), %rbx
	leaq	.LC0(%rip), %r12
	jmp	.L6
	.p2align 4,,10
	.p2align 3
.L7:
	movl	16(%rsp,%rax,4), %edx
	movq	%r12, %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L6:
	movq	%rbp, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movslq	12(%rsp), %rax
	testl	%eax, %eax
	jne	.L7
	movq	4024(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L12
	addq	$4032, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 32
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
.L12:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE24:
	.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.
Optimized Assembly Code:

train
```assembly
	.file	"temp.c"
	.text
	.p2align 4
	.globl	sum
	.type	sum, @function
sum:
.LFB23:
	.cfi_startproc
	endbr64
	leal	(%rdi,%rsi), %eax
	leal	-1(%rdi), %edx
	imull	%edi, %edx
	leal	-1(%rax), %esi
	imull	%eax, %esi
	movl	%edx, %edi
	movl	%esi, %eax
	shrl	$31, %edi
	shrl	$31, %eax
	addl	%edx, %edi
	addl	%esi, %eax
	sarl	%edi
	sarl	%eax
	subl	%edi, %eax
	ret
	.cfi_endproc
.LFE23:
	.size	sum, .-sum
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d\n"
.LC1:
	.string	"%d"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB24:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movl	$500, %ecx
	movl	$2, %r8d
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	subq	$4032, %rsp
	.cfi_def_cfa_offset 4064
	movq	%fs:40, %rax
	movq	%rax, 4024(%rsp)
	xorl	%eax, %eax
	leaq	16(%rsp), %rdi
	rep stosq
	movl	$0, (%rdi)
	.p2align 4,,10
	.p2align 3
.L4:
	movl	%r8d, %ecx
	movl	%r8d, %edi
	addl	$1, %r8d
	movl	$1, %edx
	movl	%r8d, %eax
	leal	-1(%rcx), %r9d
	imull	%ecx, %eax
	sarl	%eax
	.p2align 4,,10
	.p2align 3
.L5:
	movl	%edx, %esi
	addl	$1, %edx
	cltq
	imull	%edx, %esi
	leal	(%rdi,%rdx), %ecx
	addl	$1, 16(%rsp,%rax,4)
	leal	(%r9,%rdx), %eax
	imull	%ecx, %eax
	movl	%esi, %ecx
	shrl	$31, %ecx
	addl	%esi, %ecx
	sarl	%eax
	sarl	%ecx
	subl	%ecx, %eax
	cmpl	$1001, %eax
	jle	.L5
	cmpl	$45, %r8d
	jne	.L4
	leaq	12(%rsp), %rbp
	leaq	.LC1(%rip), %rbx
	leaq	.LC0(%rip), %r12
	jmp	.L6
	.p2align 4,,10
	.p2align 3
.L7:
	movl	16(%rsp,%rax,4), %edx
	movq	%r12, %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L6:
	movq	%rbp, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movslq	12(%rsp), %rax
	testl	%eax, %eax
	jne	.L7
	movq	4024(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L12
	addq	$4032, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 32
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
.L12:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE24:
	.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:
```