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>
int MAX(int a,int b){return a<b?b:a;}
int main(){
  int n,m[1010],i,j,k,d[510][510]={};
  while(scanf("%d",&n),n){
    for(i=0;i<n;i++)scanf("%d",&m[i]);
    for(i=0;i<=n;i++){
      for(j=0;i+j<=n;j++){
	if(i<2)d[j][j+i]=0;
	else if(d[j+1][j+i-1]+2==i&&abs(m[j]-m[j+i-1])<2)d[j][j+i]=i;
	else{
d[j][j+i]=0;
	  for(k=j+1;k<i+j;k++)d[j][j+i]=MAX(d[j][j+i],d[j][k]+d[k][j+i]);
	}
      }
    }
    printf("%d\n",d[0][n]);
  }
  return 0;
}

```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	MAX
	.type	MAX, @function
MAX:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -4(%rbp)
	movl	%esi, -8(%rbp)
	movl	-4(%rbp), %edx
	movl	-8(%rbp), %eax
	cmpl	%eax, %edx
	cmovge	%edx, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	MAX, .-MAX
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%rbx
	leaq	-1044480(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$8, %rsp
	.cfi_offset 3, -24
	movq	%fs:40, %rax
	movq	%rax, -24(%rbp)
	xorl	%eax, %eax
	leaq	-1040432(%rbp), %rax
	movl	$1040400, %edx
	movl	$0, %esi
	movq	%rax, %rdi
	call	memset@PLT
	jmp	.L4
.L16:
	movl	$0, -1044492(%rbp)
	jmp	.L5
.L6:
	leaq	-1044480(%rbp), %rdx
	movl	-1044492(%rbp), %eax
	cltq
	salq	$2, %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -1044492(%rbp)
.L5:
	movl	-1044496(%rbp), %eax
	cmpl	%eax, -1044492(%rbp)
	jl	.L6
	movl	$0, -1044492(%rbp)
	jmp	.L7
.L15:
	movl	$0, -1044488(%rbp)
	jmp	.L8
.L14:
	cmpl	$1, -1044492(%rbp)
	jg	.L9
	movl	-1044488(%rbp), %edx
	movl	-1044492(%rbp), %eax
	addl	%edx, %eax
	movslq	%eax, %rcx
	movl	-1044488(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$8, %rax
	subq	%rdx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	movl	$0, -1040432(%rbp,%rax,4)
	jmp	.L10
.L9:
	movl	-1044488(%rbp), %eax
	addl	$1, %eax
	movl	-1044488(%rbp), %ecx
	movl	-1044492(%rbp), %edx
	addl	%ecx, %edx
	subl	$1, %edx
	movslq	%edx, %rcx
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$8, %rax
	subq	%rdx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	movl	-1040432(%rbp,%rax,4), %eax
	addl	$2, %eax
	cmpl	%eax, -1044492(%rbp)
	jne	.L11
	movl	-1044488(%rbp), %eax
	cltq
	movl	-1044480(%rbp,%rax,4), %edx
	movl	-1044488(%rbp), %ecx
	movl	-1044492(%rbp), %eax
	addl	%ecx, %eax
	subl	$1, %eax
	cltq
	movl	-1044480(%rbp,%rax,4), %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	cmpl	$-1, %eax
	jl	.L11
	movl	-1044488(%rbp), %eax
	cltq
	movl	-1044480(%rbp,%rax,4), %edx
	movl	-1044488(%rbp), %ecx
	movl	-1044492(%rbp), %eax
	addl	%ecx, %eax
	subl	$1, %eax
	cltq
	movl	-1044480(%rbp,%rax,4), %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	cmpl	$1, %eax
	jg	.L11
	movl	-1044488(%rbp), %edx
	movl	-1044492(%rbp), %eax
	addl	%edx, %eax
	movslq	%eax, %rcx
	movl	-1044488(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$8, %rax
	subq	%rdx, %rax
	addq	%rax, %rax
	leaq	(%rax,%rcx), %rdx
	movl	-1044492(%rbp), %eax
	movl	%eax, -1040432(%rbp,%rdx,4)
	jmp	.L10
.L11:
	movl	-1044488(%rbp), %edx
	movl	-1044492(%rbp), %eax
	addl	%edx, %eax
	movslq	%eax, %rcx
	movl	-1044488(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$8, %rax
	subq	%rdx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	movl	$0, -1040432(%rbp,%rax,4)
	movl	-1044488(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -1044484(%rbp)
	jmp	.L12
.L13:
	movl	-1044484(%rbp), %eax
	movslq	%eax, %rcx
	movl	-1044488(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$8, %rax
	subq	%rdx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	movl	-1040432(%rbp,%rax,4), %ecx
	movl	-1044488(%rbp), %edx
	movl	-1044492(%rbp), %eax
	addl	%edx, %eax
	movslq	%eax, %rsi
	movl	-1044484(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$8, %rax
	subq	%rdx, %rax
	addq	%rax, %rax
	addq	%rsi, %rax
	movl	-1040432(%rbp,%rax,4), %eax
	leal	(%rcx,%rax), %edx
	movl	-1044488(%rbp), %ecx
	movl	-1044492(%rbp), %eax
	addl	%ecx, %eax
	movslq	%eax, %rsi
	movl	-1044488(%rbp), %eax
	movslq	%eax, %rcx
	movq	%rcx, %rax
	salq	$8, %rax
	subq	%rcx, %rax
	addq	%rax, %rax
	addq	%rsi, %rax
	movl	-1040432(%rbp,%rax,4), %eax
	movl	-1044488(%rbp), %esi
	movl	-1044492(%rbp), %ecx
	leal	(%rsi,%rcx), %ebx
	movl	%edx, %esi
	movl	%eax, %edi
	call	MAX
	movl	%eax, %edx
	movslq	%ebx, %rsi
	movl	-1044488(%rbp), %eax
	movslq	%eax, %rcx
	movq	%rcx, %rax
	salq	$8, %rax
	subq	%rcx, %rax
	addq	%rax, %rax
	addq	%rsi, %rax
	movl	%edx, -1040432(%rbp,%rax,4)
	addl	$1, -1044484(%rbp)
.L12:
	movl	-1044492(%rbp), %edx
	movl	-1044488(%rbp), %eax
	addl	%edx, %eax
	cmpl	%eax, -1044484(%rbp)
	jl	.L13
.L10:
	addl	$1, -1044488(%rbp)
.L8:
	movl	-1044492(%rbp), %edx
	movl	-1044488(%rbp), %eax
	addl	%eax, %edx
	movl	-1044496(%rbp), %eax
	cmpl	%eax, %edx
	jle	.L14
	addl	$1, -1044492(%rbp)
.L7:
	movl	-1044496(%rbp), %eax
	cmpl	%eax, -1044492(%rbp)
	jle	.L15
	movl	-1044496(%rbp), %eax
	cltq
	movl	-1040432(%rbp,%rax,4), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
.L4:
	leaq	-1044496(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-1044496(%rbp), %eax
	testl	%eax, %eax
	jne	.L16
	movl	$0, %eax
	movq	-24(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L18
	call	__stack_chk_fail@PLT
.L18:
	movq	-8(%rbp), %rbx
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.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
	.p2align 4
	.globl	MAX
	.type	MAX, @function
MAX:
.LFB39:
	.cfi_startproc
	endbr64
	cmpl	%esi, %edi
	movl	%esi, %eax
	cmovge	%edi, %eax
	ret
	.cfi_endproc
.LFE39:
	.size	MAX, .-MAX
	.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:
.LFB40:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	leaq	-1044480(%rsp), %r11
	.cfi_def_cfa 11, 1044536
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$40, %rsp
	.cfi_def_cfa_offset 1044576
	movl	$1040400, %edx
	xorl	%esi, %esi
	leaq	.LC0(%rip), %r15
	movq	%fs:40, %rax
	movq	%rax, 1044504(%rsp)
	xorl	%eax, %eax
	leaq	4096(%rsp), %rax
	movq	%rax, %rdi
	movq	%rax, 16(%rsp)
	call	memset@PLT
	leaq	44(%rsp), %rax
	movq	%rax, 24(%rsp)
.L4:
	movq	24(%rsp), %rsi
	movq	%r15, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	44(%rsp), %ebp
	testl	%ebp, %ebp
	je	.L15
	leaq	48(%rsp), %r12
	movl	$0, %ebx
	jle	.L17
	.p2align 4,,10
	.p2align 3
.L5:
	movq	%r12, %rsi
	movq	%r15, %rdi
	xorl	%eax, %eax
	addl	$1, %ebx
	call	__isoc99_scanf@PLT
	movl	44(%rsp), %ebp
	addq	$4, %r12
	cmpl	%ebx, %ebp
	jg	.L5
.L17:
	movslq	%ebp, %rax
	leaq	6136(%rsp), %r14
	xorl	%ebx, %ebx
	movq	%rax, 8(%rsp)
	testl	%ebp, %ebp
	js	.L7
	.p2align 4,,10
	.p2align 3
.L14:
	movq	16(%rsp), %r8
	movl	%ebx, %r13d
	movl	%ebx, %r12d
	movq	%r14, %rdi
	movq	%rbx, %r9
	movl	$1, %r10d
	jmp	.L13
	.p2align 4,,10
	.p2align 3
.L32:
	movl	44(%rsp,%r10,4), %edx
	subl	48(%rsp,%rax,4), %edx
	movl	%edx, %eax
	addl	$1, %eax
	cmpl	$2, %eax
	ja	.L10
	movl	%r13d, -2040(%rdi)
.L9:
	addq	$1, %r9
	addq	$1, %r10
	addq	$2044, %rdi
	addq	$2040, %r8
	cmpl	%r9d, %ebp
	jl	.L30
.L13:
	cmpq	$1, %rbx
	jbe	.L31
	movslq	%r10d, %rcx
	leal	-1(%r9), %eax
	movq	%rcx, %rdx
	cltq
	salq	$8, %rdx
	subq	%rcx, %rdx
	leaq	(%rax,%rdx,2), %rdx
	movl	4096(%rsp,%rdx,4), %edx
	addl	$2, %edx
	cmpl	%r12d, %edx
	je	.L32
.L10:
	movl	%r9d, %r11d
	movq	%rdi, %rsi
	movq	%r10, %rcx
	xorl	%edx, %edx
	movl	$0, -2040(%rdi)
	cmpl	%r10d, %r9d
	jle	.L9
	.p2align 4,,10
	.p2align 3
.L11:
	movl	(%rsi), %eax
	addl	(%r8,%rcx,4), %eax
	cmpl	%eax, %edx
	cmovl	%eax, %edx
	addq	$1, %rcx
	addq	$2040, %rsi
	movl	%edx, -2040(%rdi)
	cmpl	%ecx, %r11d
	jg	.L11
	jmp	.L9
	.p2align 4,,10
	.p2align 3
.L31:
	movl	$0, -2040(%rdi)
	jmp	.L9
	.p2align 4,,10
	.p2align 3
.L30:
	leaq	1(%rbx), %rax
	addq	$4, %r14
	cmpq	8(%rsp), %rbx
	je	.L7
	movq	%rax, %rbx
	jmp	.L14
.L7:
	movq	8(%rsp), %rax
	leaq	.LC1(%rip), %rsi
	movl	$1, %edi
	movl	4096(%rsp,%rax,4), %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L4
.L15:
	movq	1044504(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L33
	addq	$1044520, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
.L33:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE40:
	.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
	.p2align 4
	.globl	MAX
	.type	MAX, @function
MAX:
.LFB39:
	.cfi_startproc
	endbr64
	cmpl	%esi, %edi
	movl	%esi, %eax
	cmovge	%edi, %eax
	ret
	.cfi_endproc
.LFE39:
	.size	MAX, .-MAX
	.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:
.LFB40:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	leaq	-1044480(%rsp), %r11
	.cfi_def_cfa 11, 1044536
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$40, %rsp
	.cfi_def_cfa_offset 1044576
	movl	$1040400, %edx
	xorl	%esi, %esi
	leaq	.LC0(%rip), %r15
	movq	%fs:40, %rax
	movq	%rax, 1044504(%rsp)
	xorl	%eax, %eax
	leaq	4096(%rsp), %rax
	movq	%rax, %rdi
	movq	%rax, 16(%rsp)
	call	memset@PLT
	leaq	44(%rsp), %rax
	movq	%rax, 24(%rsp)
.L4:
	movq	24(%rsp), %rsi
	movq	%r15, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	44(%rsp), %ebp
	testl	%ebp, %ebp
	je	.L15
	leaq	48(%rsp), %r12
	movl	$0, %ebx
	jle	.L17
	.p2align 4,,10
	.p2align 3
.L5:
	movq	%r12, %rsi
	movq	%r15, %rdi
	xorl	%eax, %eax
	addl	$1, %ebx
	call	__isoc99_scanf@PLT
	movl	44(%rsp), %ebp
	addq	$4, %r12
	cmpl	%ebx, %ebp
	jg	.L5
.L17:
	movslq	%ebp, %rax
	leaq	6136(%rsp), %r14
	xorl	%ebx, %ebx
	movq	%rax, 8(%rsp)
	testl	%ebp, %ebp
	js	.L7
	.p2align 4,,10
	.p2align 3
.L14:
	movq	16(%rsp), %r8
	movl	%ebx, %r13d
	movl	%ebx, %r12d
	movq	%r14, %rdi
	movq	%rbx, %r9
	movl	$1, %r10d
	jmp	.L13
	.p2align 4,,10
	.p2align 3
.L32:
	movl	44(%rsp,%r10,4), %edx
	subl	48(%rsp,%rax,4), %edx
	movl	%edx, %eax
	addl	$1, %eax
	cmpl	$2, %eax
	ja	.L10
	movl	%r13d, -2040(%rdi)
.L9:
	addq	$1, %r9
	addq	$1, %r10
	addq	$2044, %rdi
	addq	$2040, %r8
	cmpl	%r9d, %ebp
	jl	.L30
.L13:
	cmpq	$1, %rbx
	jbe	.L31
	movslq	%r10d, %rcx
	leal	-1(%r9), %eax
	movq	%rcx, %rdx
	cltq
	salq	$8, %rdx
	subq	%rcx, %rdx
	leaq	(%rax,%rdx,2), %rdx
	movl	4096(%rsp,%rdx,4), %edx
	addl	$2, %edx
	cmpl	%r12d, %edx
	je	.L32
.L10:
	movl	%r9d, %r11d
	movq	%rdi, %rsi
	movq	%r10, %rcx
	xorl	%edx, %edx
	movl	$0, -2040(%rdi)
	cmpl	%r10d, %r9d
	jle	.L9
	.p2align 4,,10
	.p2align 3
.L11:
	movl	(%rsi), %eax
	addl	(%r8,%rcx,4), %eax
	cmpl	%eax, %edx
	cmovl	%eax, %edx
	addq	$1, %rcx
	addq	$2040, %rsi
	movl	%edx, -2040(%rdi)
	cmpl	%ecx, %r11d
	jg	.L11
	jmp	.L9
	.p2align 4,,10
	.p2align 3
.L31:
	movl	$0, -2040(%rdi)
	jmp	.L9
	.p2align 4,,10
	.p2align 3
.L30:
	leaq	1(%rbx), %rax
	addq	$4, %r14
	cmpq	8(%rsp), %rbx
	je	.L7
	movq	%rax, %rbx
	jmp	.L14
.L7:
	movq	8(%rsp), %rax
	leaq	.LC1(%rip), %rsi
	movl	$1, %edi
	movl	4096(%rsp,%rax,4), %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L4
.L15:
	movq	1044504(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L33
	addq	$1044520, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
.L33:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE40:
	.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>
int MAX(int a,int b){return a<b?b:a;}
int main(){
  int n,m[1010],i,j,k,d[510][510]={};
  while(scanf("%d",&n),n){
    for(i=0;i<n;i++)scanf("%d",&m[i]);
    for(i=0;i<=n;i++){
      for(j=0;i+j<=n;j++){
	if(i<2)d[j][j+i]=0;
	else if(d[j+1][j+i-1]+2==i&&abs(m[j]-m[j+i-1])<2)d[j][j+i]=i;
	else{
d[j][j+i]=0;
	  for(k=j+1;k<i+j;k++)d[j][j+i]=MAX(d[j][j+i],d[j][k]+d[k][j+i]);
	}
      }
    }
    printf("%d\n",d[0][n]);
  }
  return 0;
}


4
1 2 3 4
4
1 2 3 1
5
5 1 2 3 6
14
8 7 1 4 3 5 4 1 6 8 10 4 6 5
5
1 3 5 2 3
0
 4
1 2 3 2
4
1 2 3 1
5
2 1 2 3 6
14
8 7 1 4 3 5 4 2 6 8 10 4 6 5
5
1 3 5 2 3
0
 4
1 0 3 2
4
1 2 3 1
5
2 1 2 3 6
14
8 7 1 4 3 5 4 2 6 8 10 4 1 5
5
1 3 5 2 3
0
 4
1 0 3 2
4
1 2 3 1
5
2 1 2 3 6
14
8 7 1 4 3 5 8 2 6 8 10 4 1 5
5
1 3 5 2 3
0
 4
1 2 3 4
4
1 2 3 1
5
5 0 2 3 6
14
8 7 1 4 3 5 4 1 6 8 10 4 6 5
5
1 3 5 1 3
0
 4
1 2 3 2
4
1 2 3 1
5
5 1 2 3 6
14
8 7 1 4 3 5 0 1 6 8 10 4 6 5
5
1 3 5 2 3
0
 4
1 0 3 2
4
1 2 3 1
5
2 1 2 3 6
14
8 7 1 4 3 5 8 2 6 8 10 1 1 5
5
1 3 5 2 3
0
 4
1 2 3 4
4
1 2 3 1
5
5 0 2 3 6
14
11 7 1 4 3 5 4 1 6 8 10 4 6 5
5
1 3 5 1 3
0
 4
1 0 3 2
4
1 2 3 1
5
2 1 2 3 6
14
8 7 1 4 3 5 4 2 11 8 10 4 6 5
5
1 3 5 0 3
0
 4
1 0 4 2
4
1 2 3 1
5
2 1 2 3 6
14
8 7 1 4 3 5 4 2 6 8 0 4 1 5
5
1 3 5 2 3
0

4
4
2
12
2
 4
4
4
12
2
 4
4
4
10
2
 4
4
4
4
2
 4
4
2
12
0
 4
4
2
10
2
 4
4
4
6
2
 4
4
2
10
0
 4
4
4
10
0
 2
4
4
10
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>
int MAX(int a,int b){return a<b?b:a;}
int main(){
  int n,m[1010],i,j,k,d[510][510]={};
  while(scanf("%d",&n),n){
    for(i=0;i<n;i++)scanf("%d",&m[i]);
    for(i=0;i<=n;i++){
      for(j=0;i+j<=n;j++){
	if(i<2)d[j][j+i]=0;
	else if(d[j+1][j+i-1]+2==i&&abs(m[j]-m[j+i-1])<2)d[j][j+i]=i;
	else{
d[j][j+i]=0;
	  for(k=j+1;k<i+j;k++)d[j][j+i]=MAX(d[j][j+i],d[j][k]+d[k][j+i]);
	}
      }
    }
    printf("%d\n",d[0][n]);
  }
  return 0;
}

```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	MAX
	.type	MAX, @function
MAX:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -4(%rbp)
	movl	%esi, -8(%rbp)
	movl	-4(%rbp), %edx
	movl	-8(%rbp), %eax
	cmpl	%eax, %edx
	cmovge	%edx, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	MAX, .-MAX
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%rbx
	leaq	-1044480(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$8, %rsp
	.cfi_offset 3, -24
	movq	%fs:40, %rax
	movq	%rax, -24(%rbp)
	xorl	%eax, %eax
	leaq	-1040432(%rbp), %rax
	movl	$1040400, %edx
	movl	$0, %esi
	movq	%rax, %rdi
	call	memset@PLT
	jmp	.L4
.L16:
	movl	$0, -1044492(%rbp)
	jmp	.L5
.L6:
	leaq	-1044480(%rbp), %rdx
	movl	-1044492(%rbp), %eax
	cltq
	salq	$2, %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -1044492(%rbp)
.L5:
	movl	-1044496(%rbp), %eax
	cmpl	%eax, -1044492(%rbp)
	jl	.L6
	movl	$0, -1044492(%rbp)
	jmp	.L7
.L15:
	movl	$0, -1044488(%rbp)
	jmp	.L8
.L14:
	cmpl	$1, -1044492(%rbp)
	jg	.L9
	movl	-1044488(%rbp), %edx
	movl	-1044492(%rbp), %eax
	addl	%edx, %eax
	movslq	%eax, %rcx
	movl	-1044488(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$8, %rax
	subq	%rdx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	movl	$0, -1040432(%rbp,%rax,4)
	jmp	.L10
.L9:
	movl	-1044488(%rbp), %eax
	addl	$1, %eax
	movl	-1044488(%rbp), %ecx
	movl	-1044492(%rbp), %edx
	addl	%ecx, %edx
	subl	$1, %edx
	movslq	%edx, %rcx
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$8, %rax
	subq	%rdx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	movl	-1040432(%rbp,%rax,4), %eax
	addl	$2, %eax
	cmpl	%eax, -1044492(%rbp)
	jne	.L11
	movl	-1044488(%rbp), %eax
	cltq
	movl	-1044480(%rbp,%rax,4), %edx
	movl	-1044488(%rbp), %ecx
	movl	-1044492(%rbp), %eax
	addl	%ecx, %eax
	subl	$1, %eax
	cltq
	movl	-1044480(%rbp,%rax,4), %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	cmpl	$-1, %eax
	jl	.L11
	movl	-1044488(%rbp), %eax
	cltq
	movl	-1044480(%rbp,%rax,4), %edx
	movl	-1044488(%rbp), %ecx
	movl	-1044492(%rbp), %eax
	addl	%ecx, %eax
	subl	$1, %eax
	cltq
	movl	-1044480(%rbp,%rax,4), %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	cmpl	$1, %eax
	jg	.L11
	movl	-1044488(%rbp), %edx
	movl	-1044492(%rbp), %eax
	addl	%edx, %eax
	movslq	%eax, %rcx
	movl	-1044488(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$8, %rax
	subq	%rdx, %rax
	addq	%rax, %rax
	leaq	(%rax,%rcx), %rdx
	movl	-1044492(%rbp), %eax
	movl	%eax, -1040432(%rbp,%rdx,4)
	jmp	.L10
.L11:
	movl	-1044488(%rbp), %edx
	movl	-1044492(%rbp), %eax
	addl	%edx, %eax
	movslq	%eax, %rcx
	movl	-1044488(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$8, %rax
	subq	%rdx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	movl	$0, -1040432(%rbp,%rax,4)
	movl	-1044488(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -1044484(%rbp)
	jmp	.L12
.L13:
	movl	-1044484(%rbp), %eax
	movslq	%eax, %rcx
	movl	-1044488(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$8, %rax
	subq	%rdx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	movl	-1040432(%rbp,%rax,4), %ecx
	movl	-1044488(%rbp), %edx
	movl	-1044492(%rbp), %eax
	addl	%edx, %eax
	movslq	%eax, %rsi
	movl	-1044484(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$8, %rax
	subq	%rdx, %rax
	addq	%rax, %rax
	addq	%rsi, %rax
	movl	-1040432(%rbp,%rax,4), %eax
	leal	(%rcx,%rax), %edx
	movl	-1044488(%rbp), %ecx
	movl	-1044492(%rbp), %eax
	addl	%ecx, %eax
	movslq	%eax, %rsi
	movl	-1044488(%rbp), %eax
	movslq	%eax, %rcx
	movq	%rcx, %rax
	salq	$8, %rax
	subq	%rcx, %rax
	addq	%rax, %rax
	addq	%rsi, %rax
	movl	-1040432(%rbp,%rax,4), %eax
	movl	-1044488(%rbp), %esi
	movl	-1044492(%rbp), %ecx
	leal	(%rsi,%rcx), %ebx
	movl	%edx, %esi
	movl	%eax, %edi
	call	MAX
	movl	%eax, %edx
	movslq	%ebx, %rsi
	movl	-1044488(%rbp), %eax
	movslq	%eax, %rcx
	movq	%rcx, %rax
	salq	$8, %rax
	subq	%rcx, %rax
	addq	%rax, %rax
	addq	%rsi, %rax
	movl	%edx, -1040432(%rbp,%rax,4)
	addl	$1, -1044484(%rbp)
.L12:
	movl	-1044492(%rbp), %edx
	movl	-1044488(%rbp), %eax
	addl	%edx, %eax
	cmpl	%eax, -1044484(%rbp)
	jl	.L13
.L10:
	addl	$1, -1044488(%rbp)
.L8:
	movl	-1044492(%rbp), %edx
	movl	-1044488(%rbp), %eax
	addl	%eax, %edx
	movl	-1044496(%rbp), %eax
	cmpl	%eax, %edx
	jle	.L14
	addl	$1, -1044492(%rbp)
.L7:
	movl	-1044496(%rbp), %eax
	cmpl	%eax, -1044492(%rbp)
	jle	.L15
	movl	-1044496(%rbp), %eax
	cltq
	movl	-1040432(%rbp,%rax,4), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
.L4:
	leaq	-1044496(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-1044496(%rbp), %eax
	testl	%eax, %eax
	jne	.L16
	movl	$0, %eax
	movq	-24(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L18
	call	__stack_chk_fail@PLT
.L18:
	movq	-8(%rbp), %rbx
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.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	MAX
	.type	MAX, @function
MAX:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -4(%rbp)
	movl	%esi, -8(%rbp)
	movl	-4(%rbp), %edx
	movl	-8(%rbp), %eax
	cmpl	%eax, %edx
	cmovge	%edx, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	MAX, .-MAX
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%rbx
	leaq	-1044480(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$8, %rsp
	.cfi_offset 3, -24
	movq	%fs:40, %rax
	movq	%rax, -24(%rbp)
	xorl	%eax, %eax
	leaq	-1040432(%rbp), %rax
	movl	$1040400, %edx
	movl	$0, %esi
	movq	%rax, %rdi
	call	memset@PLT
	jmp	.L4
.L16:
	movl	$0, -1044492(%rbp)
	jmp	.L5
.L6:
	leaq	-1044480(%rbp), %rdx
	movl	-1044492(%rbp), %eax
	cltq
	salq	$2, %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -1044492(%rbp)
.L5:
	movl	-1044496(%rbp), %eax
	cmpl	%eax, -1044492(%rbp)
	jl	.L6
	movl	$0, -1044492(%rbp)
	jmp	.L7
.L15:
	movl	$0, -1044488(%rbp)
	jmp	.L8
.L14:
	cmpl	$1, -1044492(%rbp)
	jg	.L9
	movl	-1044488(%rbp), %edx
	movl	-1044492(%rbp), %eax
	addl	%edx, %eax
	movslq	%eax, %rcx
	movl	-1044488(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$8, %rax
	subq	%rdx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	movl	$0, -1040432(%rbp,%rax,4)
	jmp	.L10
.L9:
	movl	-1044488(%rbp), %eax
	addl	$1, %eax
	movl	-1044488(%rbp), %ecx
	movl	-1044492(%rbp), %edx
	addl	%ecx, %edx
	subl	$1, %edx
	movslq	%edx, %rcx
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$8, %rax
	subq	%rdx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	movl	-1040432(%rbp,%rax,4), %eax
	addl	$2, %eax
	cmpl	%eax, -1044492(%rbp)
	jne	.L11
	movl	-1044488(%rbp), %eax
	cltq
	movl	-1044480(%rbp,%rax,4), %edx
	movl	-1044488(%rbp), %ecx
	movl	-1044492(%rbp), %eax
	addl	%ecx, %eax
	subl	$1, %eax
	cltq
	movl	-1044480(%rbp,%rax,4), %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	cmpl	$-1, %eax
	jl	.L11
	movl	-1044488(%rbp), %eax
	cltq
	movl	-1044480(%rbp,%rax,4), %edx
	movl	-1044488(%rbp), %ecx
	movl	-1044492(%rbp), %eax
	addl	%ecx, %eax
	subl	$1, %eax
	cltq
	movl	-1044480(%rbp,%rax,4), %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	cmpl	$1, %eax
	jg	.L11
	movl	-1044488(%rbp), %edx
	movl	-1044492(%rbp), %eax
	addl	%edx, %eax
	movslq	%eax, %rcx
	movl	-1044488(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$8, %rax
	subq	%rdx, %rax
	addq	%rax, %rax
	leaq	(%rax,%rcx), %rdx
	movl	-1044492(%rbp), %eax
	movl	%eax, -1040432(%rbp,%rdx,4)
	jmp	.L10
.L11:
	movl	-1044488(%rbp), %edx
	movl	-1044492(%rbp), %eax
	addl	%edx, %eax
	movslq	%eax, %rcx
	movl	-1044488(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$8, %rax
	subq	%rdx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	movl	$0, -1040432(%rbp,%rax,4)
	movl	-1044488(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -1044484(%rbp)
	jmp	.L12
.L13:
	movl	-1044484(%rbp), %eax
	movslq	%eax, %rcx
	movl	-1044488(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$8, %rax
	subq	%rdx, %rax
	addq	%rax, %rax
	addq	%rcx, %rax
	movl	-1040432(%rbp,%rax,4), %ecx
	movl	-1044488(%rbp), %edx
	movl	-1044492(%rbp), %eax
	addl	%edx, %eax
	movslq	%eax, %rsi
	movl	-1044484(%rbp), %eax
	movslq	%eax, %rdx
	movq	%rdx, %rax
	salq	$8, %rax
	subq	%rdx, %rax
	addq	%rax, %rax
	addq	%rsi, %rax
	movl	-1040432(%rbp,%rax,4), %eax
	leal	(%rcx,%rax), %edx
	movl	-1044488(%rbp), %ecx
	movl	-1044492(%rbp), %eax
	addl	%ecx, %eax
	movslq	%eax, %rsi
	movl	-1044488(%rbp), %eax
	movslq	%eax, %rcx
	movq	%rcx, %rax
	salq	$8, %rax
	subq	%rcx, %rax
	addq	%rax, %rax
	addq	%rsi, %rax
	movl	-1040432(%rbp,%rax,4), %eax
	movl	-1044488(%rbp), %esi
	movl	-1044492(%rbp), %ecx
	leal	(%rsi,%rcx), %ebx
	movl	%edx, %esi
	movl	%eax, %edi
	call	MAX
	movl	%eax, %edx
	movslq	%ebx, %rsi
	movl	-1044488(%rbp), %eax
	movslq	%eax, %rcx
	movq	%rcx, %rax
	salq	$8, %rax
	subq	%rcx, %rax
	addq	%rax, %rax
	addq	%rsi, %rax
	movl	%edx, -1040432(%rbp,%rax,4)
	addl	$1, -1044484(%rbp)
.L12:
	movl	-1044492(%rbp), %edx
	movl	-1044488(%rbp), %eax
	addl	%edx, %eax
	cmpl	%eax, -1044484(%rbp)
	jl	.L13
.L10:
	addl	$1, -1044488(%rbp)
.L8:
	movl	-1044492(%rbp), %edx
	movl	-1044488(%rbp), %eax
	addl	%eax, %edx
	movl	-1044496(%rbp), %eax
	cmpl	%eax, %edx
	jle	.L14
	addl	$1, -1044492(%rbp)
.L7:
	movl	-1044496(%rbp), %eax
	cmpl	%eax, -1044492(%rbp)
	jle	.L15
	movl	-1044496(%rbp), %eax
	cltq
	movl	-1040432(%rbp,%rax,4), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
.L4:
	leaq	-1044496(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-1044496(%rbp), %eax
	testl	%eax, %eax
	jne	.L16
	movl	$0, %eax
	movq	-24(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L18
	call	__stack_chk_fail@PLT
.L18:
	movq	-8(%rbp), %rbx
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.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:
