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>

 
static const int MAX = 500;
static const int INFTY = (1<<21);
 
main(){
  int n, i, j, e, sum=0;
  int M[MAX][MAX];
  int d[MAX],p[MAX],v[MAX];
  int a,point=0;
  
   
   
 
  scanf("%d", &n);
   
  for ( i = 0; i< n; i++ ){
    for ( j = 0; j < n; j++ ){
      scanf("%d", &e);
      M[i][j] = (e==-1)?INFTY:e;
    }
  }
 
  for(i = 0; i < n; i++){
    v[i] = 0;
    d[i] = INFTY;
    p[i] = -1;
  }
   
  d[0] = 0;
   
  while(1){
    a = -1;
    point = INFTY;
     
    for(i = 0; i < n; i++){
 
      if(d[i] < point && !v[i]){
      a = i;
      point = d[i];
      }
    }
     
    if(a == -1){
      break;
    }
     
    v[a] = 1;
   
    for(j = 0; j < n; j++){
      
      if(M[a][j] < d[j] && !v[j]){
    p[j] = a;
    d[j] = M[a][j];
      }
    }
  }
   
   
  //   sum = 0;
   
  for(i = 0; i < n; i++){
    if(p[i] != -1){
      sum += M[i][p[i]];
    }
  }
   
  printf("%d\n",sum);
   
  return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
	.align 4
	.type	MAX, @object
	.size	MAX, 4
MAX:
	.long	500
	.align 4
	.type	INFTY, @object
	.size	INFTY, 4
INFTY:
	.long	2097152
.LC0:
	.string	"%d"
.LC1:
	.string	"%d\n"
	.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
	pushq	%r14
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	subq	$208, %rsp
	.cfi_offset 14, -24
	.cfi_offset 13, -32
	.cfi_offset 12, -40
	.cfi_offset 3, -48
	movq	%fs:40, %rax
	movq	%rax, -40(%rbp)
	xorl	%eax, %eax
	movq	%rsp, %rax
	movq	%rax, %r14
	movl	$0, -124(%rbp)
	movl	$500, %eax
	cltq
	subq	$1, %rax
	movq	%rax, -112(%rbp)
	movl	$500, %eax
	cltq
	movq	%rax, %rcx
	movl	$0, %ebx
	movl	$500, %eax
	cltq
	leaq	0(,%rax,4), %rbx
	movl	$500, %eax
	cltq
	subq	$1, %rax
	movq	%rax, -104(%rbp)
	movl	$500, %eax
	cltq
	movq	%rax, %r8
	movl	$0, %r9d
	movl	$500, %eax
	cltq
	movq	%rax, %rsi
	movl	$0, %edi
	movq	%r9, %rdx
	imulq	%rsi, %rdx
	movq	%rdi, %rax
	imulq	%r8, %rax
	leaq	(%rdx,%rax), %rcx
	movq	%r8, %rax
	mulq	%rsi
	addq	%rdx, %rcx
	movq	%rcx, %rdx
	movl	$500, %eax
	cltq
	movq	%rax, %r12
	movl	$0, %r13d
	movl	$500, %eax
	cltq
	movq	%rax, %r10
	movl	$0, %r11d
	movq	%r13, %rdx
	imulq	%r10, %rdx
	movq	%r11, %rax
	imulq	%r12, %rax
	leaq	(%rdx,%rax), %rcx
	movq	%r12, %rax
	mulq	%r10
	addq	%rdx, %rcx
	movq	%rcx, %rdx
	movl	$500, %eax
	movslq	%eax, %rdx
	movl	$500, %eax
	cltq
	imulq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	movl	$16, %eax
	subq	$1, %rax
	addq	%rdx, %rax
	movl	$16, %edi
	movl	$0, %edx
	divq	%rdi
	imulq	$16, %rax, %rdx
	movq	%rdx, %rax
	andq	$-4096, %rax
	movq	%rsp, %rcx
	subq	%rax, %rcx
.L2:
	cmpq	%rcx, %rsp
	je	.L3
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L2
.L3:
	movq	%rdx, %rax
	andl	$4095, %eax
	subq	%rax, %rsp
	movq	%rdx, %rax
	andl	$4095, %eax
	testq	%rax, %rax
	je	.L4
	movq	%rdx, %rax
	andl	$4095, %eax
	subq	$8, %rax
	addq	%rsp, %rax
	orq	$0, (%rax)
.L4:
	movq	%rsp, %rax
	addq	$3, %rax
	shrq	$2, %rax
	salq	$2, %rax
	movq	%rax, -96(%rbp)
	movl	$500, %eax
	cltq
	subq	$1, %rax
	movq	%rax, -88(%rbp)
	movl	$500, %eax
	cltq
	movq	%rax, -160(%rbp)
	movq	$0, -152(%rbp)
	movl	$500, %eax
	cltq
	movq	%rax, -176(%rbp)
	movq	$0, -168(%rbp)
	movl	$500, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movl	$16, %eax
	subq	$1, %rax
	addq	%rdx, %rax
	movl	$16, %edi
	movl	$0, %edx
	divq	%rdi
	imulq	$16, %rax, %rax
	movq	%rax, %rcx
	andq	$-4096, %rcx
	movq	%rsp, %rdx
	subq	%rcx, %rdx
.L5:
	cmpq	%rdx, %rsp
	je	.L6
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L5
.L6:
	movq	%rax, %rdx
	andl	$4095, %edx
	subq	%rdx, %rsp
	movq	%rax, %rdx
	andl	$4095, %edx
	testq	%rdx, %rdx
	je	.L7
	andl	$4095, %eax
	subq	$8, %rax
	addq	%rsp, %rax
	orq	$0, (%rax)
.L7:
	movq	%rsp, %rax
	addq	$3, %rax
	shrq	$2, %rax
	salq	$2, %rax
	movq	%rax, -80(%rbp)
	movl	$500, %eax
	cltq
	subq	$1, %rax
	movq	%rax, -72(%rbp)
	movl	$500, %eax
	cltq
	movq	%rax, -192(%rbp)
	movq	$0, -184(%rbp)
	movl	$500, %eax
	cltq
	movq	%rax, -208(%rbp)
	movq	$0, -200(%rbp)
	movl	$500, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movl	$16, %eax
	subq	$1, %rax
	addq	%rdx, %rax
	movl	$16, %edi
	movl	$0, %edx
	divq	%rdi
	imulq	$16, %rax, %rax
	movq	%rax, %rcx
	andq	$-4096, %rcx
	movq	%rsp, %rdx
	subq	%rcx, %rdx
.L8:
	cmpq	%rdx, %rsp
	je	.L9
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L8
.L9:
	movq	%rax, %rdx
	andl	$4095, %edx
	subq	%rdx, %rsp
	movq	%rax, %rdx
	andl	$4095, %edx
	testq	%rdx, %rdx
	je	.L10
	andl	$4095, %eax
	subq	$8, %rax
	addq	%rsp, %rax
	orq	$0, (%rax)
.L10:
	movq	%rsp, %rax
	addq	$3, %rax
	shrq	$2, %rax
	salq	$2, %rax
	movq	%rax, -64(%rbp)
	movl	$500, %eax
	cltq
	subq	$1, %rax
	movq	%rax, -56(%rbp)
	movl	$500, %eax
	cltq
	movq	%rax, -224(%rbp)
	movq	$0, -216(%rbp)
	movl	$500, %eax
	cltq
	movq	%rax, -240(%rbp)
	movq	$0, -232(%rbp)
	movl	$500, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movl	$16, %eax
	subq	$1, %rax
	addq	%rdx, %rax
	movl	$16, %edi
	movl	$0, %edx
	divq	%rdi
	imulq	$16, %rax, %rax
	movq	%rax, %rcx
	andq	$-4096, %rcx
	movq	%rsp, %rdx
	subq	%rcx, %rdx
.L11:
	cmpq	%rdx, %rsp
	je	.L12
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L11
.L12:
	movq	%rax, %rdx
	andl	$4095, %edx
	subq	%rdx, %rsp
	movq	%rax, %rdx
	andl	$4095, %edx
	testq	%rdx, %rdx
	je	.L13
	andl	$4095, %eax
	subq	$8, %rax
	addq	%rsp, %rax
	orq	$0, (%rax)
.L13:
	movq	%rsp, %rax
	addq	$3, %rax
	shrq	$2, %rax
	salq	$2, %rax
	movq	%rax, -48(%rbp)
	movl	$0, -116(%rbp)
	leaq	-140(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -132(%rbp)
	jmp	.L14
.L19:
	movl	$0, -128(%rbp)
	jmp	.L15
.L18:
	leaq	-136(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-136(%rbp), %eax
	cmpl	$-1, %eax
	jne	.L16
	movl	$2097152, %eax
	jmp	.L17
.L16:
	movl	-136(%rbp), %eax
.L17:
	movq	%rbx, %rsi
	shrq	$2, %rsi
	movq	-96(%rbp), %rdx
	movl	-128(%rbp), %ecx
	movslq	%ecx, %rdi
	movl	-132(%rbp), %ecx
	movslq	%ecx, %rcx
	imulq	%rsi, %rcx
	addq	%rdi, %rcx
	movl	%eax, (%rdx,%rcx,4)
	addl	$1, -128(%rbp)
.L15:
	movl	-140(%rbp), %eax
	cmpl	%eax, -128(%rbp)
	jl	.L18
	addl	$1, -132(%rbp)
.L14:
	movl	-140(%rbp), %eax
	cmpl	%eax, -132(%rbp)
	jl	.L19
	movl	$0, -132(%rbp)
	jmp	.L20
.L21:
	movq	-48(%rbp), %rax
	movl	-132(%rbp), %edx
	movslq	%edx, %rdx
	movl	$0, (%rax,%rdx,4)
	movl	$2097152, %ecx
	movq	-80(%rbp), %rax
	movl	-132(%rbp), %edx
	movslq	%edx, %rdx
	movl	%ecx, (%rax,%rdx,4)
	movq	-64(%rbp), %rax
	movl	-132(%rbp), %edx
	movslq	%edx, %rdx
	movl	$-1, (%rax,%rdx,4)
	addl	$1, -132(%rbp)
.L20:
	movl	-140(%rbp), %eax
	cmpl	%eax, -132(%rbp)
	jl	.L21
	movq	-80(%rbp), %rax
	movl	$0, (%rax)
.L30:
	movl	$-1, -120(%rbp)
	movl	$2097152, -116(%rbp)
	movl	$0, -132(%rbp)
	jmp	.L22
.L24:
	movq	-80(%rbp), %rax
	movl	-132(%rbp), %edx
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %eax
	cmpl	%eax, -116(%rbp)
	jle	.L23
	movq	-48(%rbp), %rax
	movl	-132(%rbp), %edx
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %eax
	testl	%eax, %eax
	jne	.L23
	movl	-132(%rbp), %eax
	movl	%eax, -120(%rbp)
	movq	-80(%rbp), %rax
	movl	-132(%rbp), %edx
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %eax
	movl	%eax, -116(%rbp)
.L23:
	addl	$1, -132(%rbp)
.L22:
	movl	-140(%rbp), %eax
	cmpl	%eax, -132(%rbp)
	jl	.L24
	cmpl	$-1, -120(%rbp)
	je	.L37
	movq	-48(%rbp), %rax
	movl	-120(%rbp), %edx
	movslq	%edx, %rdx
	movl	$1, (%rax,%rdx,4)
	movl	$0, -128(%rbp)
	jmp	.L27
.L29:
	movq	%rbx, %rcx
	shrq	$2, %rcx
	movq	-96(%rbp), %rax
	movl	-128(%rbp), %edx
	movslq	%edx, %rsi
	movl	-120(%rbp), %edx
	movslq	%edx, %rdx
	imulq	%rcx, %rdx
	addq	%rsi, %rdx
	movl	(%rax,%rdx,4), %ecx
	movq	-80(%rbp), %rax
	movl	-128(%rbp), %edx
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %eax
	cmpl	%eax, %ecx
	jge	.L28
	movq	-48(%rbp), %rax
	movl	-128(%rbp), %edx
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %eax
	testl	%eax, %eax
	jne	.L28
	movq	-64(%rbp), %rax
	movl	-128(%rbp), %edx
	movslq	%edx, %rdx
	movl	-120(%rbp), %ecx
	movl	%ecx, (%rax,%rdx,4)
	movq	%rbx, %rcx
	shrq	$2, %rcx
	movq	-96(%rbp), %rax
	movl	-128(%rbp), %edx
	movslq	%edx, %rsi
	movl	-120(%rbp), %edx
	movslq	%edx, %rdx
	imulq	%rcx, %rdx
	addq	%rsi, %rdx
	movl	(%rax,%rdx,4), %ecx
	movq	-80(%rbp), %rax
	movl	-128(%rbp), %edx
	movslq	%edx, %rdx
	movl	%ecx, (%rax,%rdx,4)
.L28:
	addl	$1, -128(%rbp)
.L27:
	movl	-140(%rbp), %eax
	cmpl	%eax, -128(%rbp)
	jl	.L29
	jmp	.L30
.L37:
	nop
	movl	$0, -132(%rbp)
	jmp	.L31
.L33:
	movq	-64(%rbp), %rax
	movl	-132(%rbp), %edx
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %eax
	cmpl	$-1, %eax
	je	.L32
	movq	%rbx, %rcx
	shrq	$2, %rcx
	movq	-64(%rbp), %rax
	movl	-132(%rbp), %edx
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %edx
	movq	-96(%rbp), %rax
	movslq	%edx, %rsi
	movl	-132(%rbp), %edx
	movslq	%edx, %rdx
	imulq	%rcx, %rdx
	addq	%rsi, %rdx
	movl	(%rax,%rdx,4), %eax
	addl	%eax, -124(%rbp)
.L32:
	addl	$1, -132(%rbp)
.L31:
	movl	-140(%rbp), %eax
	cmpl	%eax, -132(%rbp)
	jl	.L33
	movl	-124(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	%r14, %rsp
	movq	-40(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L35
	call	__stack_chk_fail@PLT
.L35:
	leaq	-32(%rbp), %rsp
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%rbp
	.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
.LC0:
	.string	"%d"
.LC2:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%r15
	pushq	%r14
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	subq	$72, %rsp
	.cfi_offset 15, -24
	.cfi_offset 14, -32
	.cfi_offset 13, -40
	.cfi_offset 12, -48
	.cfi_offset 3, -56
	movq	%fs:40, %rax
	movq	%rax, -56(%rbp)
	xorl	%eax, %eax
	leaq	-999424(%rsp), %rax
	cmpq	%rax, %rsp
	je	.L3
.L50:
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	cmpq	%rax, %rsp
	jne	.L50
.L3:
	subq	$576, %rsp
	orq	$0, 568(%rsp)
	movq	%rsp, -96(%rbp)
	movq	%rsp, %rax
.L5:
	cmpq	%rax, %rsp
	je	.L6
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L5
.L6:
	subq	$2000, %rsp
	orq	$0, 1992(%rsp)
	leaq	3(%rsp), %rcx
	movq	%rcx, %rax
	andq	$-4, %rcx
	shrq	$2, %rax
	movq	%rcx, %r15
	movq	%rax, -104(%rbp)
	movq	%rsp, %rax
.L8:
	cmpq	%rax, %rsp
	je	.L9
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L8
.L9:
	subq	$2000, %rsp
	orq	$0, 1992(%rsp)
	movq	%rsp, -80(%rbp)
	movq	%rsp, %rax
.L11:
	cmpq	%rax, %rsp
	je	.L12
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L11
.L12:
	subq	$2000, %rsp
	orq	$0, 1992(%rsp)
	leaq	.LC0(%rip), %r14
	xorl	%eax, %eax
	movq	%r14, %rdi
	leaq	-64(%rbp), %rsi
	movq	%rsp, %r12
	call	__isoc99_scanf@PLT
	movl	-64(%rbp), %r8d
	testl	%r8d, %r8d
	jle	.L15
	movq	-96(%rbp), %rax
	movl	$0, -84(%rbp)
	leaq	-60(%rbp), %r13
	movq	%rax, -72(%rbp)
	.p2align 4,,10
	.p2align 3
.L31:
	xorl	%ebx, %ebx
	.p2align 4,,10
	.p2align 3
.L19:
	movq	%r13, %rsi
	movq	%r14, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	-60(%rbp), %eax
	cmpl	$-1, %eax
	je	.L16
	movq	-72(%rbp), %rcx
	movl	-64(%rbp), %r8d
	movl	%eax, (%rcx,%rbx,4)
	addq	$1, %rbx
	cmpl	%ebx, %r8d
	jg	.L19
	addl	$1, -84(%rbp)
	movl	-84(%rbp), %eax
	cmpl	%eax, %r8d
	jle	.L51
.L32:
	addq	$2000, -72(%rbp)
	jmp	.L31
	.p2align 4,,10
	.p2align 3
.L16:
	movq	-72(%rbp), %rax
	movl	-64(%rbp), %r8d
	movl	$2097152, (%rax,%rbx,4)
	addq	$1, %rbx
	cmpl	%ebx, %r8d
	jg	.L19
	addl	$1, -84(%rbp)
	movl	-84(%rbp), %eax
	cmpl	%eax, %r8d
	jg	.L32
.L51:
	testl	%r8d, %r8d
	jle	.L15
	movl	%r8d, %r13d
	xorl	%esi, %esi
	movq	%r12, %rdi
	movl	%r8d, -72(%rbp)
	salq	$2, %r13
	movq	%r13, %rdx
	call	memset@PLT
	movl	-72(%rbp), %r8d
	leal	-1(%r8), %eax
	cmpl	$2, %eax
	jbe	.L35
	movl	%r8d, %edx
	movdqa	.LC1(%rip), %xmm0
	movq	%r15, %rax
	shrl	$2, %edx
	subl	$1, %edx
	salq	$4, %rdx
	leaq	16(%r15,%rdx), %rdx
	.p2align 4,,10
	.p2align 3
.L21:
	movups	%xmm0, (%rax)
	addq	$16, %rax
	cmpq	%rdx, %rax
	jne	.L21
	movl	%r8d, %eax
	andl	$-4, %eax
	testb	$3, %r8b
	je	.L22
.L20:
	movslq	%eax, %rdx
	leal	1(%rax), %esi
	leaq	(%r15,%rdx,4), %rdx
	movl	$2097152, (%rdx)
	cmpl	%esi, %r8d
	jle	.L22
	addl	$2, %eax
	movl	$2097152, 4(%rdx)
	cmpl	%eax, %r8d
	jle	.L22
	movl	$2097152, 8(%rdx)
.L22:
	movq	-80(%rbp), %rdi
	movq	%r13, %rdx
	movl	$255, %esi
	movl	%r8d, -72(%rbp)
	call	memset@PLT
	movl	-72(%rbp), %r8d
.L15:
	movq	-104(%rbp), %rax
	movslq	%r8d, %rdi
	movl	$0, 0(,%rax,4)
	testl	%r8d, %r8d
	jle	.L36
	.p2align 4,,10
	.p2align 3
.L52:
	xorl	%eax, %eax
	movl	$2097152, %esi
	movl	$-1, %r9d
	.p2align 4,,10
	.p2align 3
.L25:
	movl	(%r15,%rax,4), %edx
	cmpl	%esi, %edx
	jge	.L24
	movl	(%r12,%rax,4), %r10d
	testl	%r10d, %r10d
	cmove	%edx, %esi
	cmove	%eax, %r9d
.L24:
	addq	$1, %rax
	cmpq	%rdi, %rax
	jne	.L25
	cmpl	$-1, %r9d
	je	.L38
	movslq	%r9d, %rsi
	xorl	%eax, %eax
	movl	$1, (%r12,%rsi,4)
	imulq	$2000, %rsi, %rsi
	addq	-96(%rbp), %rsi
	.p2align 4,,10
	.p2align 3
.L28:
	movl	(%rsi,%rax,4), %edx
	cmpl	(%r15,%rax,4), %edx
	jge	.L27
	movl	(%r12,%rax,4), %ecx
	testl	%ecx, %ecx
	jne	.L27
	movq	-80(%rbp), %rcx
	movl	%edx, (%r15,%rax,4)
	movl	%r9d, (%rcx,%rax,4)
.L27:
	addq	$1, %rax
	cmpq	%rdi, %rax
	jne	.L28
	testl	%r8d, %r8d
	jg	.L52
.L36:
	xorl	%r8d, %r8d
.L23:
	xorl	%eax, %eax
	movl	%r8d, %edx
	movl	$1, %edi
	leaq	.LC2(%rip), %rsi
	call	__printf_chk@PLT
	movq	-56(%rbp), %rax
	subq	%fs:40, %rax
	jne	.L53
	leaq	-40(%rbp), %rsp
	xorl	%eax, %eax
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_remember_state
	.cfi_def_cfa 7, 8
	ret
.L38:
	.cfi_restore_state
	xorl	%eax, %eax
	xorl	%r8d, %r8d
	.p2align 4,,10
	.p2align 3
.L26:
	movq	-80(%rbp), %rcx
	movslq	(%rcx,%rax,4), %rdx
	cmpl	$-1, %edx
	je	.L30
	movslq	%eax, %rcx
	imulq	$500, %rcx, %rcx
	addq	%rcx, %rdx
	movq	-96(%rbp), %rcx
	addl	(%rcx,%rdx,4), %r8d
.L30:
	addq	$1, %rax
	cmpq	%rdi, %rax
	jne	.L26
	jmp	.L23
.L35:
	xorl	%eax, %eax
	jmp	.L20
.L53:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE23:
	.size	main, .-main
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC1:
	.long	2097152
	.long	2097152
	.long	2097152
	.long	2097152
	.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"
.LC2:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%r15
	pushq	%r14
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	subq	$72, %rsp
	.cfi_offset 15, -24
	.cfi_offset 14, -32
	.cfi_offset 13, -40
	.cfi_offset 12, -48
	.cfi_offset 3, -56
	movq	%fs:40, %rax
	movq	%rax, -56(%rbp)
	xorl	%eax, %eax
	leaq	-999424(%rsp), %rax
	cmpq	%rax, %rsp
	je	.L3
.L50:
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	cmpq	%rax, %rsp
	jne	.L50
.L3:
	subq	$576, %rsp
	orq	$0, 568(%rsp)
	movq	%rsp, -96(%rbp)
	movq	%rsp, %rax
.L5:
	cmpq	%rax, %rsp
	je	.L6
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L5
.L6:
	subq	$2000, %rsp
	orq	$0, 1992(%rsp)
	leaq	3(%rsp), %rcx
	movq	%rcx, %rax
	andq	$-4, %rcx
	shrq	$2, %rax
	movq	%rcx, %r15
	movq	%rax, -104(%rbp)
	movq	%rsp, %rax
.L8:
	cmpq	%rax, %rsp
	je	.L9
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L8
.L9:
	subq	$2000, %rsp
	orq	$0, 1992(%rsp)
	movq	%rsp, -80(%rbp)
	movq	%rsp, %rax
.L11:
	cmpq	%rax, %rsp
	je	.L12
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L11
.L12:
	subq	$2000, %rsp
	orq	$0, 1992(%rsp)
	leaq	.LC0(%rip), %r14
	xorl	%eax, %eax
	movq	%r14, %rdi
	leaq	-64(%rbp), %rsi
	movq	%rsp, %r12
	call	__isoc99_scanf@PLT
	movl	-64(%rbp), %r8d
	testl	%r8d, %r8d
	jle	.L15
	movq	-96(%rbp), %rax
	movl	$0, -84(%rbp)
	leaq	-60(%rbp), %r13
	movq	%rax, -72(%rbp)
	.p2align 4,,10
	.p2align 3
.L31:
	xorl	%ebx, %ebx
	.p2align 4,,10
	.p2align 3
.L19:
	movq	%r13, %rsi
	movq	%r14, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	-60(%rbp), %eax
	cmpl	$-1, %eax
	je	.L16
	movq	-72(%rbp), %rcx
	movl	-64(%rbp), %r8d
	movl	%eax, (%rcx,%rbx,4)
	addq	$1, %rbx
	cmpl	%ebx, %r8d
	jg	.L19
	addl	$1, -84(%rbp)
	movl	-84(%rbp), %eax
	cmpl	%eax, %r8d
	jle	.L51
.L32:
	addq	$2000, -72(%rbp)
	jmp	.L31
	.p2align 4,,10
	.p2align 3
.L16:
	movq	-72(%rbp), %rax
	movl	-64(%rbp), %r8d
	movl	$2097152, (%rax,%rbx,4)
	addq	$1, %rbx
	cmpl	%ebx, %r8d
	jg	.L19
	addl	$1, -84(%rbp)
	movl	-84(%rbp), %eax
	cmpl	%eax, %r8d
	jg	.L32
.L51:
	testl	%r8d, %r8d
	jle	.L15
	movl	%r8d, %r13d
	xorl	%esi, %esi
	movq	%r12, %rdi
	movl	%r8d, -72(%rbp)
	salq	$2, %r13
	movq	%r13, %rdx
	call	memset@PLT
	movl	-72(%rbp), %r8d
	leal	-1(%r8), %eax
	cmpl	$2, %eax
	jbe	.L35
	movl	%r8d, %edx
	movdqa	.LC1(%rip), %xmm0
	movq	%r15, %rax
	shrl	$2, %edx
	subl	$1, %edx
	salq	$4, %rdx
	leaq	16(%r15,%rdx), %rdx
	.p2align 4,,10
	.p2align 3
.L21:
	movups	%xmm0, (%rax)
	addq	$16, %rax
	cmpq	%rdx, %rax
	jne	.L21
	movl	%r8d, %eax
	andl	$-4, %eax
	testb	$3, %r8b
	je	.L22
.L20:
	movslq	%eax, %rdx
	leal	1(%rax), %esi
	leaq	(%r15,%rdx,4), %rdx
	movl	$2097152, (%rdx)
	cmpl	%esi, %r8d
	jle	.L22
	addl	$2, %eax
	movl	$2097152, 4(%rdx)
	cmpl	%eax, %r8d
	jle	.L22
	movl	$2097152, 8(%rdx)
.L22:
	movq	-80(%rbp), %rdi
	movq	%r13, %rdx
	movl	$255, %esi
	movl	%r8d, -72(%rbp)
	call	memset@PLT
	movl	-72(%rbp), %r8d
.L15:
	movq	-104(%rbp), %rax
	movslq	%r8d, %rdi
	movl	$0, 0(,%rax,4)
	testl	%r8d, %r8d
	jle	.L36
	.p2align 4,,10
	.p2align 3
.L52:
	xorl	%eax, %eax
	movl	$2097152, %esi
	movl	$-1, %r9d
	.p2align 4,,10
	.p2align 3
.L25:
	movl	(%r15,%rax,4), %edx
	cmpl	%esi, %edx
	jge	.L24
	movl	(%r12,%rax,4), %r10d
	testl	%r10d, %r10d
	cmove	%edx, %esi
	cmove	%eax, %r9d
.L24:
	addq	$1, %rax
	cmpq	%rdi, %rax
	jne	.L25
	cmpl	$-1, %r9d
	je	.L38
	movslq	%r9d, %rsi
	xorl	%eax, %eax
	movl	$1, (%r12,%rsi,4)
	imulq	$2000, %rsi, %rsi
	addq	-96(%rbp), %rsi
	.p2align 4,,10
	.p2align 3
.L28:
	movl	(%rsi,%rax,4), %edx
	cmpl	(%r15,%rax,4), %edx
	jge	.L27
	movl	(%r12,%rax,4), %ecx
	testl	%ecx, %ecx
	jne	.L27
	movq	-80(%rbp), %rcx
	movl	%edx, (%r15,%rax,4)
	movl	%r9d, (%rcx,%rax,4)
.L27:
	addq	$1, %rax
	cmpq	%rdi, %rax
	jne	.L28
	testl	%r8d, %r8d
	jg	.L52
.L36:
	xorl	%r8d, %r8d
.L23:
	xorl	%eax, %eax
	movl	%r8d, %edx
	movl	$1, %edi
	leaq	.LC2(%rip), %rsi
	call	__printf_chk@PLT
	movq	-56(%rbp), %rax
	subq	%fs:40, %rax
	jne	.L53
	leaq	-40(%rbp), %rsp
	xorl	%eax, %eax
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_remember_state
	.cfi_def_cfa 7, 8
	ret
.L38:
	.cfi_restore_state
	xorl	%eax, %eax
	xorl	%r8d, %r8d
	.p2align 4,,10
	.p2align 3
.L26:
	movq	-80(%rbp), %rcx
	movslq	(%rcx,%rax,4), %rdx
	cmpl	$-1, %edx
	je	.L30
	movslq	%eax, %rcx
	imulq	$500, %rcx, %rcx
	addq	%rcx, %rdx
	movq	-96(%rbp), %rcx
	addl	(%rcx,%rdx,4), %r8d
.L30:
	addq	$1, %rax
	cmpq	%rdi, %rax
	jne	.L26
	jmp	.L23
.L35:
	xorl	%eax, %eax
	jmp	.L20
.L53:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE23:
	.size	main, .-main
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC1:
	.long	2097152
	.long	2097152
	.long	2097152
	.long	2097152
	.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>

 
static const int MAX = 500;
static const int INFTY = (1<<21);
 
main(){
  int n, i, j, e, sum=0;
  int M[MAX][MAX];
  int d[MAX],p[MAX],v[MAX];
  int a,point=0;
  
   
   
 
  scanf("%d", &n);
   
  for ( i = 0; i< n; i++ ){
    for ( j = 0; j < n; j++ ){
      scanf("%d", &e);
      M[i][j] = (e==-1)?INFTY:e;
    }
  }
 
  for(i = 0; i < n; i++){
    v[i] = 0;
    d[i] = INFTY;
    p[i] = -1;
  }
   
  d[0] = 0;
   
  while(1){
    a = -1;
    point = INFTY;
     
    for(i = 0; i < n; i++){
 
      if(d[i] < point && !v[i]){
      a = i;
      point = d[i];
      }
    }
     
    if(a == -1){
      break;
    }
     
    v[a] = 1;
   
    for(j = 0; j < n; j++){
      
      if(M[a][j] < d[j] && !v[j]){
    p[j] = a;
    d[j] = M[a][j];
      }
    }
  }
   
   
  //   sum = 0;
   
  for(i = 0; i < n; i++){
    if(p[i] != -1){
      sum += M[i][p[i]];
    }
  }
   
  printf("%d\n",sum);
   
  return 0;
}
5
 -1 2 3 1 -1
 2 -1 -1 4 -1
 3 -1 -1 1 1
 1 4 1 -1 3
 -1 -1 1 3 -1

5

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>

 
static const int MAX = 500;
static const int INFTY = (1<<21);
 
main(){
  int n, i, j, e, sum=0;
  int M[MAX][MAX];
  int d[MAX],p[MAX],v[MAX];
  int a,point=0;
  
   
   
 
  scanf("%d", &n);
   
  for ( i = 0; i< n; i++ ){
    for ( j = 0; j < n; j++ ){
      scanf("%d", &e);
      M[i][j] = (e==-1)?INFTY:e;
    }
  }
 
  for(i = 0; i < n; i++){
    v[i] = 0;
    d[i] = INFTY;
    p[i] = -1;
  }
   
  d[0] = 0;
   
  while(1){
    a = -1;
    point = INFTY;
     
    for(i = 0; i < n; i++){
 
      if(d[i] < point && !v[i]){
      a = i;
      point = d[i];
      }
    }
     
    if(a == -1){
      break;
    }
     
    v[a] = 1;
   
    for(j = 0; j < n; j++){
      
      if(M[a][j] < d[j] && !v[j]){
    p[j] = a;
    d[j] = M[a][j];
      }
    }
  }
   
   
  //   sum = 0;
   
  for(i = 0; i < n; i++){
    if(p[i] != -1){
      sum += M[i][p[i]];
    }
  }
   
  printf("%d\n",sum);
   
  return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
	.align 4
	.type	MAX, @object
	.size	MAX, 4
MAX:
	.long	500
	.align 4
	.type	INFTY, @object
	.size	INFTY, 4
INFTY:
	.long	2097152
.LC0:
	.string	"%d"
.LC1:
	.string	"%d\n"
	.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
	pushq	%r14
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	subq	$208, %rsp
	.cfi_offset 14, -24
	.cfi_offset 13, -32
	.cfi_offset 12, -40
	.cfi_offset 3, -48
	movq	%fs:40, %rax
	movq	%rax, -40(%rbp)
	xorl	%eax, %eax
	movq	%rsp, %rax
	movq	%rax, %r14
	movl	$0, -124(%rbp)
	movl	$500, %eax
	cltq
	subq	$1, %rax
	movq	%rax, -112(%rbp)
	movl	$500, %eax
	cltq
	movq	%rax, %rcx
	movl	$0, %ebx
	movl	$500, %eax
	cltq
	leaq	0(,%rax,4), %rbx
	movl	$500, %eax
	cltq
	subq	$1, %rax
	movq	%rax, -104(%rbp)
	movl	$500, %eax
	cltq
	movq	%rax, %r8
	movl	$0, %r9d
	movl	$500, %eax
	cltq
	movq	%rax, %rsi
	movl	$0, %edi
	movq	%r9, %rdx
	imulq	%rsi, %rdx
	movq	%rdi, %rax
	imulq	%r8, %rax
	leaq	(%rdx,%rax), %rcx
	movq	%r8, %rax
	mulq	%rsi
	addq	%rdx, %rcx
	movq	%rcx, %rdx
	movl	$500, %eax
	cltq
	movq	%rax, %r12
	movl	$0, %r13d
	movl	$500, %eax
	cltq
	movq	%rax, %r10
	movl	$0, %r11d
	movq	%r13, %rdx
	imulq	%r10, %rdx
	movq	%r11, %rax
	imulq	%r12, %rax
	leaq	(%rdx,%rax), %rcx
	movq	%r12, %rax
	mulq	%r10
	addq	%rdx, %rcx
	movq	%rcx, %rdx
	movl	$500, %eax
	movslq	%eax, %rdx
	movl	$500, %eax
	cltq
	imulq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	movl	$16, %eax
	subq	$1, %rax
	addq	%rdx, %rax
	movl	$16, %edi
	movl	$0, %edx
	divq	%rdi
	imulq	$16, %rax, %rdx
	movq	%rdx, %rax
	andq	$-4096, %rax
	movq	%rsp, %rcx
	subq	%rax, %rcx
.L2:
	cmpq	%rcx, %rsp
	je	.L3
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L2
.L3:
	movq	%rdx, %rax
	andl	$4095, %eax
	subq	%rax, %rsp
	movq	%rdx, %rax
	andl	$4095, %eax
	testq	%rax, %rax
	je	.L4
	movq	%rdx, %rax
	andl	$4095, %eax
	subq	$8, %rax
	addq	%rsp, %rax
	orq	$0, (%rax)
.L4:
	movq	%rsp, %rax
	addq	$3, %rax
	shrq	$2, %rax
	salq	$2, %rax
	movq	%rax, -96(%rbp)
	movl	$500, %eax
	cltq
	subq	$1, %rax
	movq	%rax, -88(%rbp)
	movl	$500, %eax
	cltq
	movq	%rax, -160(%rbp)
	movq	$0, -152(%rbp)
	movl	$500, %eax
	cltq
	movq	%rax, -176(%rbp)
	movq	$0, -168(%rbp)
	movl	$500, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movl	$16, %eax
	subq	$1, %rax
	addq	%rdx, %rax
	movl	$16, %edi
	movl	$0, %edx
	divq	%rdi
	imulq	$16, %rax, %rax
	movq	%rax, %rcx
	andq	$-4096, %rcx
	movq	%rsp, %rdx
	subq	%rcx, %rdx
.L5:
	cmpq	%rdx, %rsp
	je	.L6
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L5
.L6:
	movq	%rax, %rdx
	andl	$4095, %edx
	subq	%rdx, %rsp
	movq	%rax, %rdx
	andl	$4095, %edx
	testq	%rdx, %rdx
	je	.L7
	andl	$4095, %eax
	subq	$8, %rax
	addq	%rsp, %rax
	orq	$0, (%rax)
.L7:
	movq	%rsp, %rax
	addq	$3, %rax
	shrq	$2, %rax
	salq	$2, %rax
	movq	%rax, -80(%rbp)
	movl	$500, %eax
	cltq
	subq	$1, %rax
	movq	%rax, -72(%rbp)
	movl	$500, %eax
	cltq
	movq	%rax, -192(%rbp)
	movq	$0, -184(%rbp)
	movl	$500, %eax
	cltq
	movq	%rax, -208(%rbp)
	movq	$0, -200(%rbp)
	movl	$500, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movl	$16, %eax
	subq	$1, %rax
	addq	%rdx, %rax
	movl	$16, %edi
	movl	$0, %edx
	divq	%rdi
	imulq	$16, %rax, %rax
	movq	%rax, %rcx
	andq	$-4096, %rcx
	movq	%rsp, %rdx
	subq	%rcx, %rdx
.L8:
	cmpq	%rdx, %rsp
	je	.L9
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L8
.L9:
	movq	%rax, %rdx
	andl	$4095, %edx
	subq	%rdx, %rsp
	movq	%rax, %rdx
	andl	$4095, %edx
	testq	%rdx, %rdx
	je	.L10
	andl	$4095, %eax
	subq	$8, %rax
	addq	%rsp, %rax
	orq	$0, (%rax)
.L10:
	movq	%rsp, %rax
	addq	$3, %rax
	shrq	$2, %rax
	salq	$2, %rax
	movq	%rax, -64(%rbp)
	movl	$500, %eax
	cltq
	subq	$1, %rax
	movq	%rax, -56(%rbp)
	movl	$500, %eax
	cltq
	movq	%rax, -224(%rbp)
	movq	$0, -216(%rbp)
	movl	$500, %eax
	cltq
	movq	%rax, -240(%rbp)
	movq	$0, -232(%rbp)
	movl	$500, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movl	$16, %eax
	subq	$1, %rax
	addq	%rdx, %rax
	movl	$16, %edi
	movl	$0, %edx
	divq	%rdi
	imulq	$16, %rax, %rax
	movq	%rax, %rcx
	andq	$-4096, %rcx
	movq	%rsp, %rdx
	subq	%rcx, %rdx
.L11:
	cmpq	%rdx, %rsp
	je	.L12
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L11
.L12:
	movq	%rax, %rdx
	andl	$4095, %edx
	subq	%rdx, %rsp
	movq	%rax, %rdx
	andl	$4095, %edx
	testq	%rdx, %rdx
	je	.L13
	andl	$4095, %eax
	subq	$8, %rax
	addq	%rsp, %rax
	orq	$0, (%rax)
.L13:
	movq	%rsp, %rax
	addq	$3, %rax
	shrq	$2, %rax
	salq	$2, %rax
	movq	%rax, -48(%rbp)
	movl	$0, -116(%rbp)
	leaq	-140(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -132(%rbp)
	jmp	.L14
.L19:
	movl	$0, -128(%rbp)
	jmp	.L15
.L18:
	leaq	-136(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-136(%rbp), %eax
	cmpl	$-1, %eax
	jne	.L16
	movl	$2097152, %eax
	jmp	.L17
.L16:
	movl	-136(%rbp), %eax
.L17:
	movq	%rbx, %rsi
	shrq	$2, %rsi
	movq	-96(%rbp), %rdx
	movl	-128(%rbp), %ecx
	movslq	%ecx, %rdi
	movl	-132(%rbp), %ecx
	movslq	%ecx, %rcx
	imulq	%rsi, %rcx
	addq	%rdi, %rcx
	movl	%eax, (%rdx,%rcx,4)
	addl	$1, -128(%rbp)
.L15:
	movl	-140(%rbp), %eax
	cmpl	%eax, -128(%rbp)
	jl	.L18
	addl	$1, -132(%rbp)
.L14:
	movl	-140(%rbp), %eax
	cmpl	%eax, -132(%rbp)
	jl	.L19
	movl	$0, -132(%rbp)
	jmp	.L20
.L21:
	movq	-48(%rbp), %rax
	movl	-132(%rbp), %edx
	movslq	%edx, %rdx
	movl	$0, (%rax,%rdx,4)
	movl	$2097152, %ecx
	movq	-80(%rbp), %rax
	movl	-132(%rbp), %edx
	movslq	%edx, %rdx
	movl	%ecx, (%rax,%rdx,4)
	movq	-64(%rbp), %rax
	movl	-132(%rbp), %edx
	movslq	%edx, %rdx
	movl	$-1, (%rax,%rdx,4)
	addl	$1, -132(%rbp)
.L20:
	movl	-140(%rbp), %eax
	cmpl	%eax, -132(%rbp)
	jl	.L21
	movq	-80(%rbp), %rax
	movl	$0, (%rax)
.L30:
	movl	$-1, -120(%rbp)
	movl	$2097152, -116(%rbp)
	movl	$0, -132(%rbp)
	jmp	.L22
.L24:
	movq	-80(%rbp), %rax
	movl	-132(%rbp), %edx
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %eax
	cmpl	%eax, -116(%rbp)
	jle	.L23
	movq	-48(%rbp), %rax
	movl	-132(%rbp), %edx
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %eax
	testl	%eax, %eax
	jne	.L23
	movl	-132(%rbp), %eax
	movl	%eax, -120(%rbp)
	movq	-80(%rbp), %rax
	movl	-132(%rbp), %edx
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %eax
	movl	%eax, -116(%rbp)
.L23:
	addl	$1, -132(%rbp)
.L22:
	movl	-140(%rbp), %eax
	cmpl	%eax, -132(%rbp)
	jl	.L24
	cmpl	$-1, -120(%rbp)
	je	.L37
	movq	-48(%rbp), %rax
	movl	-120(%rbp), %edx
	movslq	%edx, %rdx
	movl	$1, (%rax,%rdx,4)
	movl	$0, -128(%rbp)
	jmp	.L27
.L29:
	movq	%rbx, %rcx
	shrq	$2, %rcx
	movq	-96(%rbp), %rax
	movl	-128(%rbp), %edx
	movslq	%edx, %rsi
	movl	-120(%rbp), %edx
	movslq	%edx, %rdx
	imulq	%rcx, %rdx
	addq	%rsi, %rdx
	movl	(%rax,%rdx,4), %ecx
	movq	-80(%rbp), %rax
	movl	-128(%rbp), %edx
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %eax
	cmpl	%eax, %ecx
	jge	.L28
	movq	-48(%rbp), %rax
	movl	-128(%rbp), %edx
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %eax
	testl	%eax, %eax
	jne	.L28
	movq	-64(%rbp), %rax
	movl	-128(%rbp), %edx
	movslq	%edx, %rdx
	movl	-120(%rbp), %ecx
	movl	%ecx, (%rax,%rdx,4)
	movq	%rbx, %rcx
	shrq	$2, %rcx
	movq	-96(%rbp), %rax
	movl	-128(%rbp), %edx
	movslq	%edx, %rsi
	movl	-120(%rbp), %edx
	movslq	%edx, %rdx
	imulq	%rcx, %rdx
	addq	%rsi, %rdx
	movl	(%rax,%rdx,4), %ecx
	movq	-80(%rbp), %rax
	movl	-128(%rbp), %edx
	movslq	%edx, %rdx
	movl	%ecx, (%rax,%rdx,4)
.L28:
	addl	$1, -128(%rbp)
.L27:
	movl	-140(%rbp), %eax
	cmpl	%eax, -128(%rbp)
	jl	.L29
	jmp	.L30
.L37:
	nop
	movl	$0, -132(%rbp)
	jmp	.L31
.L33:
	movq	-64(%rbp), %rax
	movl	-132(%rbp), %edx
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %eax
	cmpl	$-1, %eax
	je	.L32
	movq	%rbx, %rcx
	shrq	$2, %rcx
	movq	-64(%rbp), %rax
	movl	-132(%rbp), %edx
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %edx
	movq	-96(%rbp), %rax
	movslq	%edx, %rsi
	movl	-132(%rbp), %edx
	movslq	%edx, %rdx
	imulq	%rcx, %rdx
	addq	%rsi, %rdx
	movl	(%rax,%rdx,4), %eax
	addl	%eax, -124(%rbp)
.L32:
	addl	$1, -132(%rbp)
.L31:
	movl	-140(%rbp), %eax
	cmpl	%eax, -132(%rbp)
	jl	.L33
	movl	-124(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	%r14, %rsp
	movq	-40(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L35
	call	__stack_chk_fail@PLT
.L35:
	leaq	-32(%rbp), %rsp
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%rbp
	.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
	.section	.rodata
	.align 4
	.type	MAX, @object
	.size	MAX, 4
MAX:
	.long	500
	.align 4
	.type	INFTY, @object
	.size	INFTY, 4
INFTY:
	.long	2097152
.LC0:
	.string	"%d"
.LC1:
	.string	"%d\n"
	.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
	pushq	%r14
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	subq	$208, %rsp
	.cfi_offset 14, -24
	.cfi_offset 13, -32
	.cfi_offset 12, -40
	.cfi_offset 3, -48
	movq	%fs:40, %rax
	movq	%rax, -40(%rbp)
	xorl	%eax, %eax
	movq	%rsp, %rax
	movq	%rax, %r14
	movl	$0, -124(%rbp)
	movl	$500, %eax
	cltq
	subq	$1, %rax
	movq	%rax, -112(%rbp)
	movl	$500, %eax
	cltq
	movq	%rax, %rcx
	movl	$0, %ebx
	movl	$500, %eax
	cltq
	leaq	0(,%rax,4), %rbx
	movl	$500, %eax
	cltq
	subq	$1, %rax
	movq	%rax, -104(%rbp)
	movl	$500, %eax
	cltq
	movq	%rax, %r8
	movl	$0, %r9d
	movl	$500, %eax
	cltq
	movq	%rax, %rsi
	movl	$0, %edi
	movq	%r9, %rdx
	imulq	%rsi, %rdx
	movq	%rdi, %rax
	imulq	%r8, %rax
	leaq	(%rdx,%rax), %rcx
	movq	%r8, %rax
	mulq	%rsi
	addq	%rdx, %rcx
	movq	%rcx, %rdx
	movl	$500, %eax
	cltq
	movq	%rax, %r12
	movl	$0, %r13d
	movl	$500, %eax
	cltq
	movq	%rax, %r10
	movl	$0, %r11d
	movq	%r13, %rdx
	imulq	%r10, %rdx
	movq	%r11, %rax
	imulq	%r12, %rax
	leaq	(%rdx,%rax), %rcx
	movq	%r12, %rax
	mulq	%r10
	addq	%rdx, %rcx
	movq	%rcx, %rdx
	movl	$500, %eax
	movslq	%eax, %rdx
	movl	$500, %eax
	cltq
	imulq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	movl	$16, %eax
	subq	$1, %rax
	addq	%rdx, %rax
	movl	$16, %edi
	movl	$0, %edx
	divq	%rdi
	imulq	$16, %rax, %rdx
	movq	%rdx, %rax
	andq	$-4096, %rax
	movq	%rsp, %rcx
	subq	%rax, %rcx
.L2:
	cmpq	%rcx, %rsp
	je	.L3
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L2
.L3:
	movq	%rdx, %rax
	andl	$4095, %eax
	subq	%rax, %rsp
	movq	%rdx, %rax
	andl	$4095, %eax
	testq	%rax, %rax
	je	.L4
	movq	%rdx, %rax
	andl	$4095, %eax
	subq	$8, %rax
	addq	%rsp, %rax
	orq	$0, (%rax)
.L4:
	movq	%rsp, %rax
	addq	$3, %rax
	shrq	$2, %rax
	salq	$2, %rax
	movq	%rax, -96(%rbp)
	movl	$500, %eax
	cltq
	subq	$1, %rax
	movq	%rax, -88(%rbp)
	movl	$500, %eax
	cltq
	movq	%rax, -160(%rbp)
	movq	$0, -152(%rbp)
	movl	$500, %eax
	cltq
	movq	%rax, -176(%rbp)
	movq	$0, -168(%rbp)
	movl	$500, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movl	$16, %eax
	subq	$1, %rax
	addq	%rdx, %rax
	movl	$16, %edi
	movl	$0, %edx
	divq	%rdi
	imulq	$16, %rax, %rax
	movq	%rax, %rcx
	andq	$-4096, %rcx
	movq	%rsp, %rdx
	subq	%rcx, %rdx
.L5:
	cmpq	%rdx, %rsp
	je	.L6
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L5
.L6:
	movq	%rax, %rdx
	andl	$4095, %edx
	subq	%rdx, %rsp
	movq	%rax, %rdx
	andl	$4095, %edx
	testq	%rdx, %rdx
	je	.L7
	andl	$4095, %eax
	subq	$8, %rax
	addq	%rsp, %rax
	orq	$0, (%rax)
.L7:
	movq	%rsp, %rax
	addq	$3, %rax
	shrq	$2, %rax
	salq	$2, %rax
	movq	%rax, -80(%rbp)
	movl	$500, %eax
	cltq
	subq	$1, %rax
	movq	%rax, -72(%rbp)
	movl	$500, %eax
	cltq
	movq	%rax, -192(%rbp)
	movq	$0, -184(%rbp)
	movl	$500, %eax
	cltq
	movq	%rax, -208(%rbp)
	movq	$0, -200(%rbp)
	movl	$500, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movl	$16, %eax
	subq	$1, %rax
	addq	%rdx, %rax
	movl	$16, %edi
	movl	$0, %edx
	divq	%rdi
	imulq	$16, %rax, %rax
	movq	%rax, %rcx
	andq	$-4096, %rcx
	movq	%rsp, %rdx
	subq	%rcx, %rdx
.L8:
	cmpq	%rdx, %rsp
	je	.L9
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L8
.L9:
	movq	%rax, %rdx
	andl	$4095, %edx
	subq	%rdx, %rsp
	movq	%rax, %rdx
	andl	$4095, %edx
	testq	%rdx, %rdx
	je	.L10
	andl	$4095, %eax
	subq	$8, %rax
	addq	%rsp, %rax
	orq	$0, (%rax)
.L10:
	movq	%rsp, %rax
	addq	$3, %rax
	shrq	$2, %rax
	salq	$2, %rax
	movq	%rax, -64(%rbp)
	movl	$500, %eax
	cltq
	subq	$1, %rax
	movq	%rax, -56(%rbp)
	movl	$500, %eax
	cltq
	movq	%rax, -224(%rbp)
	movq	$0, -216(%rbp)
	movl	$500, %eax
	cltq
	movq	%rax, -240(%rbp)
	movq	$0, -232(%rbp)
	movl	$500, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movl	$16, %eax
	subq	$1, %rax
	addq	%rdx, %rax
	movl	$16, %edi
	movl	$0, %edx
	divq	%rdi
	imulq	$16, %rax, %rax
	movq	%rax, %rcx
	andq	$-4096, %rcx
	movq	%rsp, %rdx
	subq	%rcx, %rdx
.L11:
	cmpq	%rdx, %rsp
	je	.L12
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L11
.L12:
	movq	%rax, %rdx
	andl	$4095, %edx
	subq	%rdx, %rsp
	movq	%rax, %rdx
	andl	$4095, %edx
	testq	%rdx, %rdx
	je	.L13
	andl	$4095, %eax
	subq	$8, %rax
	addq	%rsp, %rax
	orq	$0, (%rax)
.L13:
	movq	%rsp, %rax
	addq	$3, %rax
	shrq	$2, %rax
	salq	$2, %rax
	movq	%rax, -48(%rbp)
	movl	$0, -116(%rbp)
	leaq	-140(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -132(%rbp)
	jmp	.L14
.L19:
	movl	$0, -128(%rbp)
	jmp	.L15
.L18:
	leaq	-136(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-136(%rbp), %eax
	cmpl	$-1, %eax
	jne	.L16
	movl	$2097152, %eax
	jmp	.L17
.L16:
	movl	-136(%rbp), %eax
.L17:
	movq	%rbx, %rsi
	shrq	$2, %rsi
	movq	-96(%rbp), %rdx
	movl	-128(%rbp), %ecx
	movslq	%ecx, %rdi
	movl	-132(%rbp), %ecx
	movslq	%ecx, %rcx
	imulq	%rsi, %rcx
	addq	%rdi, %rcx
	movl	%eax, (%rdx,%rcx,4)
	addl	$1, -128(%rbp)
.L15:
	movl	-140(%rbp), %eax
	cmpl	%eax, -128(%rbp)
	jl	.L18
	addl	$1, -132(%rbp)
.L14:
	movl	-140(%rbp), %eax
	cmpl	%eax, -132(%rbp)
	jl	.L19
	movl	$0, -132(%rbp)
	jmp	.L20
.L21:
	movq	-48(%rbp), %rax
	movl	-132(%rbp), %edx
	movslq	%edx, %rdx
	movl	$0, (%rax,%rdx,4)
	movl	$2097152, %ecx
	movq	-80(%rbp), %rax
	movl	-132(%rbp), %edx
	movslq	%edx, %rdx
	movl	%ecx, (%rax,%rdx,4)
	movq	-64(%rbp), %rax
	movl	-132(%rbp), %edx
	movslq	%edx, %rdx
	movl	$-1, (%rax,%rdx,4)
	addl	$1, -132(%rbp)
.L20:
	movl	-140(%rbp), %eax
	cmpl	%eax, -132(%rbp)
	jl	.L21
	movq	-80(%rbp), %rax
	movl	$0, (%rax)
.L30:
	movl	$-1, -120(%rbp)
	movl	$2097152, -116(%rbp)
	movl	$0, -132(%rbp)
	jmp	.L22
.L24:
	movq	-80(%rbp), %rax
	movl	-132(%rbp), %edx
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %eax
	cmpl	%eax, -116(%rbp)
	jle	.L23
	movq	-48(%rbp), %rax
	movl	-132(%rbp), %edx
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %eax
	testl	%eax, %eax
	jne	.L23
	movl	-132(%rbp), %eax
	movl	%eax, -120(%rbp)
	movq	-80(%rbp), %rax
	movl	-132(%rbp), %edx
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %eax
	movl	%eax, -116(%rbp)
.L23:
	addl	$1, -132(%rbp)
.L22:
	movl	-140(%rbp), %eax
	cmpl	%eax, -132(%rbp)
	jl	.L24
	cmpl	$-1, -120(%rbp)
	je	.L37
	movq	-48(%rbp), %rax
	movl	-120(%rbp), %edx
	movslq	%edx, %rdx
	movl	$1, (%rax,%rdx,4)
	movl	$0, -128(%rbp)
	jmp	.L27
.L29:
	movq	%rbx, %rcx
	shrq	$2, %rcx
	movq	-96(%rbp), %rax
	movl	-128(%rbp), %edx
	movslq	%edx, %rsi
	movl	-120(%rbp), %edx
	movslq	%edx, %rdx
	imulq	%rcx, %rdx
	addq	%rsi, %rdx
	movl	(%rax,%rdx,4), %ecx
	movq	-80(%rbp), %rax
	movl	-128(%rbp), %edx
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %eax
	cmpl	%eax, %ecx
	jge	.L28
	movq	-48(%rbp), %rax
	movl	-128(%rbp), %edx
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %eax
	testl	%eax, %eax
	jne	.L28
	movq	-64(%rbp), %rax
	movl	-128(%rbp), %edx
	movslq	%edx, %rdx
	movl	-120(%rbp), %ecx
	movl	%ecx, (%rax,%rdx,4)
	movq	%rbx, %rcx
	shrq	$2, %rcx
	movq	-96(%rbp), %rax
	movl	-128(%rbp), %edx
	movslq	%edx, %rsi
	movl	-120(%rbp), %edx
	movslq	%edx, %rdx
	imulq	%rcx, %rdx
	addq	%rsi, %rdx
	movl	(%rax,%rdx,4), %ecx
	movq	-80(%rbp), %rax
	movl	-128(%rbp), %edx
	movslq	%edx, %rdx
	movl	%ecx, (%rax,%rdx,4)
.L28:
	addl	$1, -128(%rbp)
.L27:
	movl	-140(%rbp), %eax
	cmpl	%eax, -128(%rbp)
	jl	.L29
	jmp	.L30
.L37:
	nop
	movl	$0, -132(%rbp)
	jmp	.L31
.L33:
	movq	-64(%rbp), %rax
	movl	-132(%rbp), %edx
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %eax
	cmpl	$-1, %eax
	je	.L32
	movq	%rbx, %rcx
	shrq	$2, %rcx
	movq	-64(%rbp), %rax
	movl	-132(%rbp), %edx
	movslq	%edx, %rdx
	movl	(%rax,%rdx,4), %edx
	movq	-96(%rbp), %rax
	movslq	%edx, %rsi
	movl	-132(%rbp), %edx
	movslq	%edx, %rdx
	imulq	%rcx, %rdx
	addq	%rsi, %rdx
	movl	(%rax,%rdx,4), %eax
	addl	%eax, -124(%rbp)
.L32:
	addl	$1, -132(%rbp)
.L31:
	movl	-140(%rbp), %eax
	cmpl	%eax, -132(%rbp)
	jl	.L33
	movl	-124(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	%r14, %rsp
	movq	-40(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L35
	call	__stack_chk_fail@PLT
.L35:
	leaq	-32(%rbp), %rsp
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%rbp
	.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:
