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<string.h>
#include<stdlib.h>
#define REP(i,n) for(int i=0; i<n; i++)
int dp[301][301];
int main(void){
    int n,w[300];
    int x;
    int dp[301][301];
    while(scanf("%d",&n),n){
        memset(dp,0,sizeof dp);
        if(n==0) break;
        for(int i=0;i<n;i++){
            scanf("%d",&x);
            w[i]=x;
        }
        for (int i=n-1; i>=0; i--) {
            dp[i][i] = 0;
            //dp[i][i+1] = 0;
            for (int j=i+1; j<n; j++) {
                if(j==i+1 && (abs(w[i] - w[j]) <= 1)) dp[i][j]=2;
                else if (/*i + 1 < j && */(abs(w[i] - w[j]) <= 1) && dp[i+1][j-1] == j-i-1)
                    dp[i][j] = j - i + 1;
                
                for (int k=j; k<n; k++)
                    if(dp[i][k]<dp[i][j-1] + dp[j][k])
                        dp[i][k]=dp[i][j-1] + dp[j][k];
            }
        }
        
        printf("%d\n", dp[0][n-1]);
        /*REP(i,n+1) {
            REP(j,n+1){
                printf("%d ",dp[i][j]);
            }
            printf("\n");
        }*/
    }
    return 0;
}

```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	dp
	.bss
	.align 32
	.type	dp, @object
	.size	dp, 362404
dp:
	.zero	362404
	.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
	leaq	-360448(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$3200, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	jmp	.L2
.L16:
	leaq	-362416(%rbp), %rax
	movl	$362404, %edx
	movl	$0, %esi
	movq	%rax, %rdi
	call	memset@PLT
	movl	-363640(%rbp), %eax
	testl	%eax, %eax
	je	.L19
	movl	$0, -363632(%rbp)
	jmp	.L5
.L6:
	leaq	-363636(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-363636(%rbp), %edx
	movl	-363632(%rbp), %eax
	cltq
	movl	%edx, -363616(%rbp,%rax,4)
	addl	$1, -363632(%rbp)
.L5:
	movl	-363640(%rbp), %eax
	cmpl	%eax, -363632(%rbp)
	jl	.L6
	movl	-363640(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -363628(%rbp)
	jmp	.L7
.L15:
	movl	-363628(%rbp), %eax
	cltq
	imulq	$1208, %rax, %rax
	addq	%rbp, %rax
	subq	$362416, %rax
	movl	$0, (%rax)
	movl	-363628(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -363624(%rbp)
	jmp	.L8
.L14:
	movl	-363628(%rbp), %eax
	addl	$1, %eax
	cmpl	%eax, -363624(%rbp)
	jne	.L9
	movl	-363628(%rbp), %eax
	cltq
	movl	-363616(%rbp,%rax,4), %edx
	movl	-363624(%rbp), %eax
	cltq
	movl	-363616(%rbp,%rax,4), %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	cmpl	$-1, %eax
	jl	.L9
	movl	-363628(%rbp), %eax
	cltq
	movl	-363616(%rbp,%rax,4), %edx
	movl	-363624(%rbp), %eax
	cltq
	movl	-363616(%rbp,%rax,4), %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	cmpl	$1, %eax
	jg	.L9
	movl	-363624(%rbp), %eax
	movslq	%eax, %rdx
	movl	-363628(%rbp), %eax
	cltq
	imulq	$301, %rax, %rax
	addq	%rdx, %rax
	movl	$2, -362416(%rbp,%rax,4)
	jmp	.L10
.L9:
	movl	-363628(%rbp), %eax
	cltq
	movl	-363616(%rbp,%rax,4), %edx
	movl	-363624(%rbp), %eax
	cltq
	movl	-363616(%rbp,%rax,4), %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	cmpl	$-1, %eax
	jl	.L10
	movl	-363628(%rbp), %eax
	cltq
	movl	-363616(%rbp,%rax,4), %edx
	movl	-363624(%rbp), %eax
	cltq
	movl	-363616(%rbp,%rax,4), %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	cmpl	$1, %eax
	jg	.L10
	movl	-363628(%rbp), %eax
	leal	1(%rax), %edx
	movl	-363624(%rbp), %eax
	subl	$1, %eax
	movslq	%eax, %rcx
	movslq	%edx, %rax
	imulq	$301, %rax, %rax
	addq	%rcx, %rax
	movl	-362416(%rbp,%rax,4), %edx
	movl	-363624(%rbp), %eax
	subl	-363628(%rbp), %eax
	subl	$1, %eax
	cmpl	%eax, %edx
	jne	.L10
	movl	-363624(%rbp), %eax
	subl	-363628(%rbp), %eax
	leal	1(%rax), %edx
	movl	-363624(%rbp), %eax
	movslq	%eax, %rcx
	movl	-363628(%rbp), %eax
	cltq
	imulq	$301, %rax, %rax
	addq	%rcx, %rax
	movl	%edx, -362416(%rbp,%rax,4)
.L10:
	movl	-363624(%rbp), %eax
	movl	%eax, -363620(%rbp)
	jmp	.L11
.L13:
	movl	-363620(%rbp), %eax
	movslq	%eax, %rdx
	movl	-363628(%rbp), %eax
	cltq
	imulq	$301, %rax, %rax
	addq	%rdx, %rax
	movl	-362416(%rbp,%rax,4), %eax
	movl	-363624(%rbp), %edx
	subl	$1, %edx
	movslq	%edx, %rcx
	movl	-363628(%rbp), %edx
	movslq	%edx, %rdx
	imulq	$301, %rdx, %rdx
	addq	%rcx, %rdx
	movl	-362416(%rbp,%rdx,4), %ecx
	movl	-363620(%rbp), %edx
	movslq	%edx, %rsi
	movl	-363624(%rbp), %edx
	movslq	%edx, %rdx
	imulq	$301, %rdx, %rdx
	addq	%rsi, %rdx
	movl	-362416(%rbp,%rdx,4), %edx
	addl	%ecx, %edx
	cmpl	%edx, %eax
	jge	.L12
	movl	-363624(%rbp), %eax
	subl	$1, %eax
	movslq	%eax, %rdx
	movl	-363628(%rbp), %eax
	cltq
	imulq	$301, %rax, %rax
	addq	%rdx, %rax
	movl	-362416(%rbp,%rax,4), %edx
	movl	-363620(%rbp), %eax
	movslq	%eax, %rcx
	movl	-363624(%rbp), %eax
	cltq
	imulq	$301, %rax, %rax
	addq	%rcx, %rax
	movl	-362416(%rbp,%rax,4), %eax
	addl	%eax, %edx
	movl	-363620(%rbp), %eax
	movslq	%eax, %rcx
	movl	-363628(%rbp), %eax
	cltq
	imulq	$301, %rax, %rax
	addq	%rcx, %rax
	movl	%edx, -362416(%rbp,%rax,4)
.L12:
	addl	$1, -363620(%rbp)
.L11:
	movl	-363640(%rbp), %eax
	cmpl	%eax, -363620(%rbp)
	jl	.L13
	addl	$1, -363624(%rbp)
.L8:
	movl	-363640(%rbp), %eax
	cmpl	%eax, -363624(%rbp)
	jl	.L14
	subl	$1, -363628(%rbp)
.L7:
	cmpl	$0, -363628(%rbp)
	jns	.L15
	movl	-363640(%rbp), %eax
	subl	$1, %eax
	cltq
	movl	-362416(%rbp,%rax,4), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
.L2:
	leaq	-363640(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-363640(%rbp), %eax
	testl	%eax, %eax
	jne	.L16
	jmp	.L4
.L19:
	nop
.L4:
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L18
	call	__stack_chk_fail@PLT
.L18:
	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:
.LFB51:
	.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	-360448(%rsp), %r11
	.cfi_def_cfa 11, 360504
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$3208, %rsp
	.cfi_def_cfa_offset 363712
	movq	%fs:40, %rax
	movq	%rax, 363640(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movq	%rax, 8(%rsp)
.L2:
	movq	8(%rsp), %rsi
	leaq	.LC0(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	24(%rsp), %ebx
	testl	%ebx, %ebx
	je	.L25
	leaq	1232(%rsp), %r12
	xorl	%esi, %esi
	movl	$362404, %edx
	movq	%r12, %rdi
	call	memset@PLT
	testl	%ebx, %ebx
	jle	.L3
	xorl	%ebp, %ebp
	leaq	28(%rsp), %r14
	leaq	32(%rsp), %r13
	.p2align 4,,10
	.p2align 3
.L4:
	movq	%r14, %rsi
	leaq	.LC0(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	28(%rsp), %eax
	movl	24(%rsp), %ebx
	movl	%eax, 0(%r13,%rbp,4)
	addq	$1, %rbp
	cmpl	%ebp, %ebx
	jg	.L4
.L3:
	movl	%ebx, %r15d
	subl	$1, %r15d
	js	.L26
	movslq	%ebx, %rax
	movl	%ebx, %r11d
	leaq	28(%rsp,%rax,4), %rbp
	movslq	%r15d, %rax
	movq	%rax, (%rsp)
	imulq	$-1204, %rax, %r8
	imulq	$1208, %rax, %rax
	leaq	4(%r12,%rax), %r13
	.p2align 4,,10
	.p2align 3
.L7:
	movl	$0, -4(%r13)
	cmpl	%ebx, %r11d
	jge	.L13
	movslq	%r11d, %rdi
	movl	0(%rbp), %r12d
	movq	%r13, %rsi
	movl	%r11d, %r9d
	imulq	$1204, %rdi, %rdi
	xorl	%r10d, %r10d
	leaq	1200(%r13), %r14
	.p2align 4,,10
	.p2align 3
.L12:
	movl	4(%rbp,%r10,4), %edx
	movl	%r12d, %eax
	subl	%edx, %eax
	addl	$1, %eax
	cmpl	%r9d, %r11d
	je	.L27
	cmpl	$2, %eax
	ja	.L10
	cmpl	%r10d, (%r14,%r10,4)
	jne	.L10
	leal	2(%r10), %eax
	movl	%eax, (%rsi)
	.p2align 4,,10
	.p2align 3
.L10:
	movq	%rsi, %rax
	movl	%r9d, %edx
	.p2align 4,,10
	.p2align 3
.L11:
	leaq	(%rax,%r8), %rcx
	movl	(%rcx,%rdi), %ecx
	addl	-4(%rsi), %ecx
	cmpl	%ecx, (%rax)
	jge	.L14
	movl	%ecx, (%rax)
.L14:
	addl	$1, %edx
	addq	$4, %rax
	cmpl	%ebx, %edx
	jl	.L11
	addl	$1, %r9d
	addq	$1, %r10
	addq	$1204, %rdi
	addq	$4, %rsi
	cmpl	%ebx, %r9d
	jl	.L12
.L13:
	subl	$1, %r15d
	subl	$1, %r11d
	subq	$4, %rbp
	addq	$1204, %r8
	subq	$1208, %r13
	cmpl	$-1, %r15d
	jne	.L7
.L8:
	movq	(%rsp), %rax
	leaq	.LC1(%rip), %rsi
	movl	$1, %edi
	movl	1232(%rsp,%rax,4), %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L2
	.p2align 4,,10
	.p2align 3
.L27:
	cmpl	$2, %eax
	ja	.L10
	movl	$2, (%rsi)
	jmp	.L10
.L26:
	movslq	%r15d, %rax
	movq	%rax, (%rsp)
	jmp	.L8
.L25:
	movq	363640(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L28
	addq	$363656, %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
.L28:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE51:
	.size	main, .-main
	.globl	dp
	.bss
	.align 32
	.type	dp, @object
	.size	dp, 362404
dp:
	.zero	362404
	.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:
.LFB51:
	.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	-360448(%rsp), %r11
	.cfi_def_cfa 11, 360504
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$3208, %rsp
	.cfi_def_cfa_offset 363712
	movq	%fs:40, %rax
	movq	%rax, 363640(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movq	%rax, 8(%rsp)
.L2:
	movq	8(%rsp), %rsi
	leaq	.LC0(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	24(%rsp), %ebx
	testl	%ebx, %ebx
	je	.L25
	leaq	1232(%rsp), %r12
	xorl	%esi, %esi
	movl	$362404, %edx
	movq	%r12, %rdi
	call	memset@PLT
	testl	%ebx, %ebx
	jle	.L3
	xorl	%ebp, %ebp
	leaq	28(%rsp), %r14
	leaq	32(%rsp), %r13
	.p2align 4,,10
	.p2align 3
.L4:
	movq	%r14, %rsi
	leaq	.LC0(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	28(%rsp), %eax
	movl	24(%rsp), %ebx
	movl	%eax, 0(%r13,%rbp,4)
	addq	$1, %rbp
	cmpl	%ebp, %ebx
	jg	.L4
.L3:
	movl	%ebx, %r15d
	subl	$1, %r15d
	js	.L26
	movslq	%ebx, %rax
	movl	%ebx, %r11d
	leaq	28(%rsp,%rax,4), %rbp
	movslq	%r15d, %rax
	movq	%rax, (%rsp)
	imulq	$-1204, %rax, %r8
	imulq	$1208, %rax, %rax
	leaq	4(%r12,%rax), %r13
	.p2align 4,,10
	.p2align 3
.L7:
	movl	$0, -4(%r13)
	cmpl	%ebx, %r11d
	jge	.L13
	movslq	%r11d, %rdi
	movl	0(%rbp), %r12d
	movq	%r13, %rsi
	movl	%r11d, %r9d
	imulq	$1204, %rdi, %rdi
	xorl	%r10d, %r10d
	leaq	1200(%r13), %r14
	.p2align 4,,10
	.p2align 3
.L12:
	movl	4(%rbp,%r10,4), %edx
	movl	%r12d, %eax
	subl	%edx, %eax
	addl	$1, %eax
	cmpl	%r9d, %r11d
	je	.L27
	cmpl	$2, %eax
	ja	.L10
	cmpl	%r10d, (%r14,%r10,4)
	jne	.L10
	leal	2(%r10), %eax
	movl	%eax, (%rsi)
	.p2align 4,,10
	.p2align 3
.L10:
	movq	%rsi, %rax
	movl	%r9d, %edx
	.p2align 4,,10
	.p2align 3
.L11:
	leaq	(%rax,%r8), %rcx
	movl	(%rcx,%rdi), %ecx
	addl	-4(%rsi), %ecx
	cmpl	%ecx, (%rax)
	jge	.L14
	movl	%ecx, (%rax)
.L14:
	addl	$1, %edx
	addq	$4, %rax
	cmpl	%ebx, %edx
	jl	.L11
	addl	$1, %r9d
	addq	$1, %r10
	addq	$1204, %rdi
	addq	$4, %rsi
	cmpl	%ebx, %r9d
	jl	.L12
.L13:
	subl	$1, %r15d
	subl	$1, %r11d
	subq	$4, %rbp
	addq	$1204, %r8
	subq	$1208, %r13
	cmpl	$-1, %r15d
	jne	.L7
.L8:
	movq	(%rsp), %rax
	leaq	.LC1(%rip), %rsi
	movl	$1, %edi
	movl	1232(%rsp,%rax,4), %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L2
	.p2align 4,,10
	.p2align 3
.L27:
	cmpl	$2, %eax
	ja	.L10
	movl	$2, (%rsi)
	jmp	.L10
.L26:
	movslq	%r15d, %rax
	movq	%rax, (%rsp)
	jmp	.L8
.L25:
	movq	363640(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L28
	addq	$363656, %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
.L28:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE51:
	.size	main, .-main
	.globl	dp
	.bss
	.align 32
	.type	dp, @object
	.size	dp, 362404
dp:
	.zero	362404
	.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<string.h>
#include<stdlib.h>
#define REP(i,n) for(int i=0; i<n; i++)
int dp[301][301];
int main(void){
    int n,w[300];
    int x;
    int dp[301][301];
    while(scanf("%d",&n),n){
        memset(dp,0,sizeof dp);
        if(n==0) break;
        for(int i=0;i<n;i++){
            scanf("%d",&x);
            w[i]=x;
        }
        for (int i=n-1; i>=0; i--) {
            dp[i][i] = 0;
            //dp[i][i+1] = 0;
            for (int j=i+1; j<n; j++) {
                if(j==i+1 && (abs(w[i] - w[j]) <= 1)) dp[i][j]=2;
                else if (/*i + 1 < j && */(abs(w[i] - w[j]) <= 1) && dp[i+1][j-1] == j-i-1)
                    dp[i][j] = j - i + 1;
                
                for (int k=j; k<n; k++)
                    if(dp[i][k]<dp[i][j-1] + dp[j][k])
                        dp[i][k]=dp[i][j-1] + dp[j][k];
            }
        }
        
        printf("%d\n", dp[0][n-1]);
        /*REP(i,n+1) {
            REP(j,n+1){
                printf("%d ",dp[i][j]);
            }
            printf("\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<string.h>
#include<stdlib.h>
#define REP(i,n) for(int i=0; i<n; i++)
int dp[301][301];
int main(void){
    int n,w[300];
    int x;
    int dp[301][301];
    while(scanf("%d",&n),n){
        memset(dp,0,sizeof dp);
        if(n==0) break;
        for(int i=0;i<n;i++){
            scanf("%d",&x);
            w[i]=x;
        }
        for (int i=n-1; i>=0; i--) {
            dp[i][i] = 0;
            //dp[i][i+1] = 0;
            for (int j=i+1; j<n; j++) {
                if(j==i+1 && (abs(w[i] - w[j]) <= 1)) dp[i][j]=2;
                else if (/*i + 1 < j && */(abs(w[i] - w[j]) <= 1) && dp[i+1][j-1] == j-i-1)
                    dp[i][j] = j - i + 1;
                
                for (int k=j; k<n; k++)
                    if(dp[i][k]<dp[i][j-1] + dp[j][k])
                        dp[i][k]=dp[i][j-1] + dp[j][k];
            }
        }
        
        printf("%d\n", dp[0][n-1]);
        /*REP(i,n+1) {
            REP(j,n+1){
                printf("%d ",dp[i][j]);
            }
            printf("\n");
        }*/
    }
    return 0;
}

```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	dp
	.bss
	.align 32
	.type	dp, @object
	.size	dp, 362404
dp:
	.zero	362404
	.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
	leaq	-360448(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$3200, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	jmp	.L2
.L16:
	leaq	-362416(%rbp), %rax
	movl	$362404, %edx
	movl	$0, %esi
	movq	%rax, %rdi
	call	memset@PLT
	movl	-363640(%rbp), %eax
	testl	%eax, %eax
	je	.L19
	movl	$0, -363632(%rbp)
	jmp	.L5
.L6:
	leaq	-363636(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-363636(%rbp), %edx
	movl	-363632(%rbp), %eax
	cltq
	movl	%edx, -363616(%rbp,%rax,4)
	addl	$1, -363632(%rbp)
.L5:
	movl	-363640(%rbp), %eax
	cmpl	%eax, -363632(%rbp)
	jl	.L6
	movl	-363640(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -363628(%rbp)
	jmp	.L7
.L15:
	movl	-363628(%rbp), %eax
	cltq
	imulq	$1208, %rax, %rax
	addq	%rbp, %rax
	subq	$362416, %rax
	movl	$0, (%rax)
	movl	-363628(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -363624(%rbp)
	jmp	.L8
.L14:
	movl	-363628(%rbp), %eax
	addl	$1, %eax
	cmpl	%eax, -363624(%rbp)
	jne	.L9
	movl	-363628(%rbp), %eax
	cltq
	movl	-363616(%rbp,%rax,4), %edx
	movl	-363624(%rbp), %eax
	cltq
	movl	-363616(%rbp,%rax,4), %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	cmpl	$-1, %eax
	jl	.L9
	movl	-363628(%rbp), %eax
	cltq
	movl	-363616(%rbp,%rax,4), %edx
	movl	-363624(%rbp), %eax
	cltq
	movl	-363616(%rbp,%rax,4), %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	cmpl	$1, %eax
	jg	.L9
	movl	-363624(%rbp), %eax
	movslq	%eax, %rdx
	movl	-363628(%rbp), %eax
	cltq
	imulq	$301, %rax, %rax
	addq	%rdx, %rax
	movl	$2, -362416(%rbp,%rax,4)
	jmp	.L10
.L9:
	movl	-363628(%rbp), %eax
	cltq
	movl	-363616(%rbp,%rax,4), %edx
	movl	-363624(%rbp), %eax
	cltq
	movl	-363616(%rbp,%rax,4), %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	cmpl	$-1, %eax
	jl	.L10
	movl	-363628(%rbp), %eax
	cltq
	movl	-363616(%rbp,%rax,4), %edx
	movl	-363624(%rbp), %eax
	cltq
	movl	-363616(%rbp,%rax,4), %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	cmpl	$1, %eax
	jg	.L10
	movl	-363628(%rbp), %eax
	leal	1(%rax), %edx
	movl	-363624(%rbp), %eax
	subl	$1, %eax
	movslq	%eax, %rcx
	movslq	%edx, %rax
	imulq	$301, %rax, %rax
	addq	%rcx, %rax
	movl	-362416(%rbp,%rax,4), %edx
	movl	-363624(%rbp), %eax
	subl	-363628(%rbp), %eax
	subl	$1, %eax
	cmpl	%eax, %edx
	jne	.L10
	movl	-363624(%rbp), %eax
	subl	-363628(%rbp), %eax
	leal	1(%rax), %edx
	movl	-363624(%rbp), %eax
	movslq	%eax, %rcx
	movl	-363628(%rbp), %eax
	cltq
	imulq	$301, %rax, %rax
	addq	%rcx, %rax
	movl	%edx, -362416(%rbp,%rax,4)
.L10:
	movl	-363624(%rbp), %eax
	movl	%eax, -363620(%rbp)
	jmp	.L11
.L13:
	movl	-363620(%rbp), %eax
	movslq	%eax, %rdx
	movl	-363628(%rbp), %eax
	cltq
	imulq	$301, %rax, %rax
	addq	%rdx, %rax
	movl	-362416(%rbp,%rax,4), %eax
	movl	-363624(%rbp), %edx
	subl	$1, %edx
	movslq	%edx, %rcx
	movl	-363628(%rbp), %edx
	movslq	%edx, %rdx
	imulq	$301, %rdx, %rdx
	addq	%rcx, %rdx
	movl	-362416(%rbp,%rdx,4), %ecx
	movl	-363620(%rbp), %edx
	movslq	%edx, %rsi
	movl	-363624(%rbp), %edx
	movslq	%edx, %rdx
	imulq	$301, %rdx, %rdx
	addq	%rsi, %rdx
	movl	-362416(%rbp,%rdx,4), %edx
	addl	%ecx, %edx
	cmpl	%edx, %eax
	jge	.L12
	movl	-363624(%rbp), %eax
	subl	$1, %eax
	movslq	%eax, %rdx
	movl	-363628(%rbp), %eax
	cltq
	imulq	$301, %rax, %rax
	addq	%rdx, %rax
	movl	-362416(%rbp,%rax,4), %edx
	movl	-363620(%rbp), %eax
	movslq	%eax, %rcx
	movl	-363624(%rbp), %eax
	cltq
	imulq	$301, %rax, %rax
	addq	%rcx, %rax
	movl	-362416(%rbp,%rax,4), %eax
	addl	%eax, %edx
	movl	-363620(%rbp), %eax
	movslq	%eax, %rcx
	movl	-363628(%rbp), %eax
	cltq
	imulq	$301, %rax, %rax
	addq	%rcx, %rax
	movl	%edx, -362416(%rbp,%rax,4)
.L12:
	addl	$1, -363620(%rbp)
.L11:
	movl	-363640(%rbp), %eax
	cmpl	%eax, -363620(%rbp)
	jl	.L13
	addl	$1, -363624(%rbp)
.L8:
	movl	-363640(%rbp), %eax
	cmpl	%eax, -363624(%rbp)
	jl	.L14
	subl	$1, -363628(%rbp)
.L7:
	cmpl	$0, -363628(%rbp)
	jns	.L15
	movl	-363640(%rbp), %eax
	subl	$1, %eax
	cltq
	movl	-362416(%rbp,%rax,4), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
.L2:
	leaq	-363640(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-363640(%rbp), %eax
	testl	%eax, %eax
	jne	.L16
	jmp	.L4
.L19:
	nop
.L4:
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L18
	call	__stack_chk_fail@PLT
.L18:
	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
	.globl	dp
	.bss
	.align 32
	.type	dp, @object
	.size	dp, 362404
dp:
	.zero	362404
	.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
	leaq	-360448(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$3200, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	jmp	.L2
.L16:
	leaq	-362416(%rbp), %rax
	movl	$362404, %edx
	movl	$0, %esi
	movq	%rax, %rdi
	call	memset@PLT
	movl	-363640(%rbp), %eax
	testl	%eax, %eax
	je	.L19
	movl	$0, -363632(%rbp)
	jmp	.L5
.L6:
	leaq	-363636(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-363636(%rbp), %edx
	movl	-363632(%rbp), %eax
	cltq
	movl	%edx, -363616(%rbp,%rax,4)
	addl	$1, -363632(%rbp)
.L5:
	movl	-363640(%rbp), %eax
	cmpl	%eax, -363632(%rbp)
	jl	.L6
	movl	-363640(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -363628(%rbp)
	jmp	.L7
.L15:
	movl	-363628(%rbp), %eax
	cltq
	imulq	$1208, %rax, %rax
	addq	%rbp, %rax
	subq	$362416, %rax
	movl	$0, (%rax)
	movl	-363628(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -363624(%rbp)
	jmp	.L8
.L14:
	movl	-363628(%rbp), %eax
	addl	$1, %eax
	cmpl	%eax, -363624(%rbp)
	jne	.L9
	movl	-363628(%rbp), %eax
	cltq
	movl	-363616(%rbp,%rax,4), %edx
	movl	-363624(%rbp), %eax
	cltq
	movl	-363616(%rbp,%rax,4), %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	cmpl	$-1, %eax
	jl	.L9
	movl	-363628(%rbp), %eax
	cltq
	movl	-363616(%rbp,%rax,4), %edx
	movl	-363624(%rbp), %eax
	cltq
	movl	-363616(%rbp,%rax,4), %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	cmpl	$1, %eax
	jg	.L9
	movl	-363624(%rbp), %eax
	movslq	%eax, %rdx
	movl	-363628(%rbp), %eax
	cltq
	imulq	$301, %rax, %rax
	addq	%rdx, %rax
	movl	$2, -362416(%rbp,%rax,4)
	jmp	.L10
.L9:
	movl	-363628(%rbp), %eax
	cltq
	movl	-363616(%rbp,%rax,4), %edx
	movl	-363624(%rbp), %eax
	cltq
	movl	-363616(%rbp,%rax,4), %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	cmpl	$-1, %eax
	jl	.L10
	movl	-363628(%rbp), %eax
	cltq
	movl	-363616(%rbp,%rax,4), %edx
	movl	-363624(%rbp), %eax
	cltq
	movl	-363616(%rbp,%rax,4), %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	cmpl	$1, %eax
	jg	.L10
	movl	-363628(%rbp), %eax
	leal	1(%rax), %edx
	movl	-363624(%rbp), %eax
	subl	$1, %eax
	movslq	%eax, %rcx
	movslq	%edx, %rax
	imulq	$301, %rax, %rax
	addq	%rcx, %rax
	movl	-362416(%rbp,%rax,4), %edx
	movl	-363624(%rbp), %eax
	subl	-363628(%rbp), %eax
	subl	$1, %eax
	cmpl	%eax, %edx
	jne	.L10
	movl	-363624(%rbp), %eax
	subl	-363628(%rbp), %eax
	leal	1(%rax), %edx
	movl	-363624(%rbp), %eax
	movslq	%eax, %rcx
	movl	-363628(%rbp), %eax
	cltq
	imulq	$301, %rax, %rax
	addq	%rcx, %rax
	movl	%edx, -362416(%rbp,%rax,4)
.L10:
	movl	-363624(%rbp), %eax
	movl	%eax, -363620(%rbp)
	jmp	.L11
.L13:
	movl	-363620(%rbp), %eax
	movslq	%eax, %rdx
	movl	-363628(%rbp), %eax
	cltq
	imulq	$301, %rax, %rax
	addq	%rdx, %rax
	movl	-362416(%rbp,%rax,4), %eax
	movl	-363624(%rbp), %edx
	subl	$1, %edx
	movslq	%edx, %rcx
	movl	-363628(%rbp), %edx
	movslq	%edx, %rdx
	imulq	$301, %rdx, %rdx
	addq	%rcx, %rdx
	movl	-362416(%rbp,%rdx,4), %ecx
	movl	-363620(%rbp), %edx
	movslq	%edx, %rsi
	movl	-363624(%rbp), %edx
	movslq	%edx, %rdx
	imulq	$301, %rdx, %rdx
	addq	%rsi, %rdx
	movl	-362416(%rbp,%rdx,4), %edx
	addl	%ecx, %edx
	cmpl	%edx, %eax
	jge	.L12
	movl	-363624(%rbp), %eax
	subl	$1, %eax
	movslq	%eax, %rdx
	movl	-363628(%rbp), %eax
	cltq
	imulq	$301, %rax, %rax
	addq	%rdx, %rax
	movl	-362416(%rbp,%rax,4), %edx
	movl	-363620(%rbp), %eax
	movslq	%eax, %rcx
	movl	-363624(%rbp), %eax
	cltq
	imulq	$301, %rax, %rax
	addq	%rcx, %rax
	movl	-362416(%rbp,%rax,4), %eax
	addl	%eax, %edx
	movl	-363620(%rbp), %eax
	movslq	%eax, %rcx
	movl	-363628(%rbp), %eax
	cltq
	imulq	$301, %rax, %rax
	addq	%rcx, %rax
	movl	%edx, -362416(%rbp,%rax,4)
.L12:
	addl	$1, -363620(%rbp)
.L11:
	movl	-363640(%rbp), %eax
	cmpl	%eax, -363620(%rbp)
	jl	.L13
	addl	$1, -363624(%rbp)
.L8:
	movl	-363640(%rbp), %eax
	cmpl	%eax, -363624(%rbp)
	jl	.L14
	subl	$1, -363628(%rbp)
.L7:
	cmpl	$0, -363628(%rbp)
	jns	.L15
	movl	-363640(%rbp), %eax
	subl	$1, %eax
	cltq
	movl	-362416(%rbp,%rax,4), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
.L2:
	leaq	-363640(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-363640(%rbp), %eax
	testl	%eax, %eax
	jne	.L16
	jmp	.L4
.L19:
	nop
.L4:
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L18
	call	__stack_chk_fail@PLT
.L18:
	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:
