Given the following C code and unoptimized assembly code, your task is to generate highly optimized x86-64 assembly code.
C Code:

```c
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define ALLOC(size,type) ((type*)calloc((size),sizeof(type)))

#define POS(l, r) ((l) * (n + 1) + (r))

void run (void) {
  for (;;) {
    i32 n;
    scanf ("%" SCNi32, &n);
    if (n == 0) break;
    i32 *a = ALLOC (n, i32);
    for (i32 i = 0; i < n; ++i) {
      scanf ("%" SCNi32, a + i);
    }
    i32 *dp = ALLOC ((n + 1) * (n + 1), i32);
    for (i32 len = 2; len <= n; ++len) {
      for (i32 l = 0; l <= n - len; ++l) {
        i32 r = l + len;
        i32 max = 0;
        for (i32 m = l + 1; m < r; ++m) {
          max = MAX (max, dp[POS(l, m)] + dp[POS(m, r)]);
        }
        for (i32 m = l + 1; m < r; ++m) {
          if (dp[POS(l + 1, m)] == m - l - 1 && ABS (a[l] - a[m]) <= 1) {
            max = MAX (max, m + 1 - l + dp[POS(m + 1, r)]);
          }
        }
        dp[POS(l, r)] = max;
      }
    }
    printf ("%" PRIi32 "\n", dp[POS(0, n)]);
  }
}

int main (void) {
  run();
  return 0;
}

```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%i"
.LC1:
	.string	"%i\n"
	.text
	.globl	run
	.type	run, @function
run:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$64, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
.L14:
	leaq	-56(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-56(%rbp), %eax
	testl	%eax, %eax
	je	.L17
	movl	-56(%rbp), %eax
	cltq
	movl	$4, %esi
	movq	%rax, %rdi
	call	calloc@PLT
	movq	%rax, -24(%rbp)
	movl	$0, -52(%rbp)
	jmp	.L3
.L4:
	movl	-52(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -52(%rbp)
.L3:
	movl	-56(%rbp), %eax
	cmpl	%eax, -52(%rbp)
	jl	.L4
	movl	-56(%rbp), %eax
	leal	1(%rax), %edx
	movl	-56(%rbp), %eax
	addl	$1, %eax
	imull	%edx, %eax
	cltq
	movl	$4, %esi
	movq	%rax, %rdi
	call	calloc@PLT
	movq	%rax, -16(%rbp)
	movl	$2, -48(%rbp)
	jmp	.L5
.L13:
	movl	$0, -44(%rbp)
	jmp	.L6
.L12:
	movl	-44(%rbp), %edx
	movl	-48(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, -28(%rbp)
	movl	$0, -40(%rbp)
	movl	-44(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -36(%rbp)
	jmp	.L7
.L8:
	movl	-56(%rbp), %eax
	addl	$1, %eax
	imull	-44(%rbp), %eax
	movl	%eax, %edx
	movl	-36(%rbp), %eax
	addl	%edx, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-56(%rbp), %eax
	addl	$1, %eax
	imull	-36(%rbp), %eax
	movl	%eax, %ecx
	movl	-28(%rbp), %eax
	addl	%ecx, %eax
	cltq
	leaq	0(,%rax,4), %rcx
	movq	-16(%rbp), %rax
	addq	%rcx, %rax
	movl	(%rax), %eax
	addl	%eax, %edx
	movl	-40(%rbp), %eax
	cmpl	%edx, %eax
	cmovl	%edx, %eax
	movl	%eax, -40(%rbp)
	addl	$1, -36(%rbp)
.L7:
	movl	-36(%rbp), %eax
	cmpl	-28(%rbp), %eax
	jl	.L8
	movl	-44(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -32(%rbp)
	jmp	.L9
.L11:
	movl	-44(%rbp), %eax
	leal	1(%rax), %edx
	movl	-56(%rbp), %eax
	addl	$1, %eax
	imull	%eax, %edx
	movl	-32(%rbp), %eax
	addl	%edx, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-32(%rbp), %eax
	subl	-44(%rbp), %eax
	subl	$1, %eax
	cmpl	%eax, %edx
	jne	.L10
	movl	-44(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	-32(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	movq	-24(%rbp), %rdx
	addq	%rcx, %rdx
	movl	(%rdx), %edx
	subl	%edx, %eax
	cmpl	$-1, %eax
	jl	.L10
	movl	-44(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	-32(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	movq	-24(%rbp), %rdx
	addq	%rcx, %rdx
	movl	(%rdx), %edx
	subl	%edx, %eax
	cmpl	$1, %eax
	jg	.L10
	movl	-32(%rbp), %eax
	addl	$1, %eax
	subl	-44(%rbp), %eax
	movl	%eax, %ecx
	movl	-32(%rbp), %eax
	leal	1(%rax), %edx
	movl	-56(%rbp), %eax
	addl	$1, %eax
	imull	%eax, %edx
	movl	-28(%rbp), %eax
	addl	%edx, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	leal	(%rcx,%rax), %edx
	movl	-40(%rbp), %eax
	cmpl	%edx, %eax
	cmovl	%edx, %eax
	movl	%eax, -40(%rbp)
.L10:
	addl	$1, -32(%rbp)
.L9:
	movl	-32(%rbp), %eax
	cmpl	-28(%rbp), %eax
	jl	.L11
	movl	-56(%rbp), %eax
	addl	$1, %eax
	imull	-44(%rbp), %eax
	movl	%eax, %edx
	movl	-28(%rbp), %eax
	addl	%edx, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rax, %rdx
	movl	-40(%rbp), %eax
	movl	%eax, (%rdx)
	addl	$1, -44(%rbp)
.L6:
	movl	-56(%rbp), %eax
	subl	-48(%rbp), %eax
	cmpl	%eax, -44(%rbp)
	jle	.L12
	addl	$1, -48(%rbp)
.L5:
	movl	-56(%rbp), %eax
	cmpl	%eax, -48(%rbp)
	jle	.L13
	movl	-56(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	jmp	.L14
.L17:
	nop
	movq	-8(%rbp), %rax
	subq	%fs:40, %rax
	je	.L15
	call	__stack_chk_fail@PLT
.L15:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	run, .-run
	.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
	call	run
	movl	$0, %eax
	popq	%rbp
	.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
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%i"
.LC1:
	.string	"%i\n"
	.text
	.p2align 4
	.globl	run
	.type	run, @function
run:
.LFB39:
	.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
	subq	$104, %rsp
	.cfi_def_cfa_offset 160
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
	leaq	84(%rsp), %rax
	movq	%rax, 72(%rsp)
.L11:
	movq	72(%rsp), %rsi
	leaq	.LC0(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	84(%rsp), %ebx
	movl	%ebx, 56(%rsp)
	testl	%ebx, %ebx
	je	.L1
	movslq	%ebx, %rax
	movl	$4, %esi
	movq	%rax, %rdi
	movq	%rax, 64(%rsp)
	call	calloc@PLT
	movq	%rax, %r12
	testl	%ebx, %ebx
	jle	.L3
	movq	%rax, %rbp
	xorl	%ebx, %ebx
	.p2align 4,,10
	.p2align 3
.L4:
	movq	%rbp, %rsi
	leaq	.LC0(%rip), %rdi
	xorl	%eax, %eax
	addl	$1, %ebx
	call	__isoc99_scanf@PLT
	movslq	84(%rsp), %rax
	addq	$4, %rbp
	cmpl	%ebx, %eax
	jg	.L4
	movl	%eax, 56(%rsp)
	movq	%rax, 64(%rsp)
.L3:
	movl	56(%rsp), %r14d
	movl	$4, %esi
	leal	1(%r14), %ebx
	movl	%ebx, %edi
	imull	%ebx, %edi
	movslq	%edi, %rdi
	call	calloc@PLT
	movq	%rax, %r15
	cmpl	$1, %r14d
	jle	.L5
	leal	-2(%r14), %eax
	movl	%eax, 36(%rsp)
	movslq	%ebx, %rax
	leaq	8(,%rax,4), %rdx
	negq	%rax
	salq	$2, %rax
	leaq	(%r15,%rdx), %rsi
	leaq	-8(%rdx), %r11
	subq	$4, %rdx
	movq	%rax, 24(%rsp)
	leal	2(%r14), %eax
	movq	%rsi, 40(%rsp)
	leaq	(%r15,%r11), %rsi
	movl	%eax, 32(%rsp)
	leal	2(%r14,%r14,2), %eax
	movq	%rsi, 48(%rsp)
	movq	%rdx, 16(%rsp)
	movl	%eax, 60(%rsp)
	.p2align 4,,10
	.p2align 3
.L10:
	movl	36(%rsp), %eax
	movl	56(%rsp), %edi
	movq	%r15, %r10
	movl	$1, %ebp
	movl	60(%rsp), %r14d
	movq	40(%rsp), %r13
	subl	%eax, %edi
	movq	48(%rsp), %r9
	subl	%eax, %r14d
	addl	$2, %eax
	movq	%rax, 8(%rsp)
	.p2align 4,,10
	.p2align 3
.L9:
	movq	%r13, %rsi
	movq	%rbp, %rcx
	xorl	%edx, %edx
	.p2align 4,,10
	.p2align 3
.L6:
	movl	(%r10,%rcx,4), %eax
	addl	(%rsi), %eax
	cmpl	%eax, %edx
	cmovl	%eax, %edx
	addq	$1, %rcx
	addq	%r11, %rsi
	cmpl	%ecx, %edi
	jg	.L6
	movl	%r14d, %esi
	movq	%rbp, %rax
	xorl	%ecx, %ecx
	jmp	.L8
	.p2align 4,,10
	.p2align 3
.L7:
	addq	$1, %rax
	addl	$1, %ecx
	addl	%ebx, %esi
	cmpl	%eax, %edi
	jle	.L20
.L8:
	cmpl	(%r9,%rax,4), %ecx
	jne	.L7
	movl	-4(%r12,%rbp,4), %r8d
	subl	(%r12,%rax,4), %r8d
	addl	$1, %r8d
	cmpl	$2, %r8d
	ja	.L7
	movslq	%esi, %r8
	movl	(%r15,%r8,4), %r8d
	leal	2(%rcx,%r8), %r8d
	cmpl	%r8d, %edx
	cmovl	%r8d, %edx
	addq	$1, %rax
	addl	$1, %ecx
	addl	%ebx, %esi
	cmpl	%eax, %edi
	jg	.L8
	.p2align 4,,10
	.p2align 3
.L20:
	movq	24(%rsp), %rax
	addl	$1, %edi
	addq	$1, %rbp
	addq	%r11, %r9
	addl	32(%rsp), %r14d
	addq	%r11, %r10
	movl	%edx, 0(%r13,%rax)
	addq	16(%rsp), %r13
	cmpq	8(%rsp), %rbp
	jne	.L9
	subl	$1, 36(%rsp)
	movl	36(%rsp), %eax
	addq	$4, 40(%rsp)
	cmpl	$-1, %eax
	jne	.L10
.L5:
	movq	64(%rsp), %rax
	leaq	.LC1(%rip), %rsi
	movl	$1, %edi
	movl	(%r15,%rax,4), %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L11
.L1:
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L21
	addq	$104, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	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
.L21:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE39:
	.size	run, .-run
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB40:
	.cfi_startproc
	endbr64
	subq	$8, %rsp
	.cfi_def_cfa_offset 16
	call	run
	xorl	%eax, %eax
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
	ret
	.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
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%i"
.LC1:
	.string	"%i\n"
	.text
	.p2align 4
	.globl	run
	.type	run, @function
run:
.LFB39:
	.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
	subq	$104, %rsp
	.cfi_def_cfa_offset 160
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
	leaq	84(%rsp), %rax
	movq	%rax, 72(%rsp)
.L11:
	movq	72(%rsp), %rsi
	leaq	.LC0(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	84(%rsp), %ebx
	movl	%ebx, 56(%rsp)
	testl	%ebx, %ebx
	je	.L1
	movslq	%ebx, %rax
	movl	$4, %esi
	movq	%rax, %rdi
	movq	%rax, 64(%rsp)
	call	calloc@PLT
	movq	%rax, %r12
	testl	%ebx, %ebx
	jle	.L3
	movq	%rax, %rbp
	xorl	%ebx, %ebx
	.p2align 4,,10
	.p2align 3
.L4:
	movq	%rbp, %rsi
	leaq	.LC0(%rip), %rdi
	xorl	%eax, %eax
	addl	$1, %ebx
	call	__isoc99_scanf@PLT
	movslq	84(%rsp), %rax
	addq	$4, %rbp
	cmpl	%ebx, %eax
	jg	.L4
	movl	%eax, 56(%rsp)
	movq	%rax, 64(%rsp)
.L3:
	movl	56(%rsp), %r14d
	movl	$4, %esi
	leal	1(%r14), %ebx
	movl	%ebx, %edi
	imull	%ebx, %edi
	movslq	%edi, %rdi
	call	calloc@PLT
	movq	%rax, %r15
	cmpl	$1, %r14d
	jle	.L5
	leal	-2(%r14), %eax
	movl	%eax, 36(%rsp)
	movslq	%ebx, %rax
	leaq	8(,%rax,4), %rdx
	negq	%rax
	salq	$2, %rax
	leaq	(%r15,%rdx), %rsi
	leaq	-8(%rdx), %r11
	subq	$4, %rdx
	movq	%rax, 24(%rsp)
	leal	2(%r14), %eax
	movq	%rsi, 40(%rsp)
	leaq	(%r15,%r11), %rsi
	movl	%eax, 32(%rsp)
	leal	2(%r14,%r14,2), %eax
	movq	%rsi, 48(%rsp)
	movq	%rdx, 16(%rsp)
	movl	%eax, 60(%rsp)
	.p2align 4,,10
	.p2align 3
.L10:
	movl	36(%rsp), %eax
	movl	56(%rsp), %edi
	movq	%r15, %r10
	movl	$1, %ebp
	movl	60(%rsp), %r14d
	movq	40(%rsp), %r13
	subl	%eax, %edi
	movq	48(%rsp), %r9
	subl	%eax, %r14d
	addl	$2, %eax
	movq	%rax, 8(%rsp)
	.p2align 4,,10
	.p2align 3
.L9:
	movq	%r13, %rsi
	movq	%rbp, %rcx
	xorl	%edx, %edx
	.p2align 4,,10
	.p2align 3
.L6:
	movl	(%r10,%rcx,4), %eax
	addl	(%rsi), %eax
	cmpl	%eax, %edx
	cmovl	%eax, %edx
	addq	$1, %rcx
	addq	%r11, %rsi
	cmpl	%ecx, %edi
	jg	.L6
	movl	%r14d, %esi
	movq	%rbp, %rax
	xorl	%ecx, %ecx
	jmp	.L8
	.p2align 4,,10
	.p2align 3
.L7:
	addq	$1, %rax
	addl	$1, %ecx
	addl	%ebx, %esi
	cmpl	%eax, %edi
	jle	.L20
.L8:
	cmpl	(%r9,%rax,4), %ecx
	jne	.L7
	movl	-4(%r12,%rbp,4), %r8d
	subl	(%r12,%rax,4), %r8d
	addl	$1, %r8d
	cmpl	$2, %r8d
	ja	.L7
	movslq	%esi, %r8
	movl	(%r15,%r8,4), %r8d
	leal	2(%rcx,%r8), %r8d
	cmpl	%r8d, %edx
	cmovl	%r8d, %edx
	addq	$1, %rax
	addl	$1, %ecx
	addl	%ebx, %esi
	cmpl	%eax, %edi
	jg	.L8
	.p2align 4,,10
	.p2align 3
.L20:
	movq	24(%rsp), %rax
	addl	$1, %edi
	addq	$1, %rbp
	addq	%r11, %r9
	addl	32(%rsp), %r14d
	addq	%r11, %r10
	movl	%edx, 0(%r13,%rax)
	addq	16(%rsp), %r13
	cmpq	8(%rsp), %rbp
	jne	.L9
	subl	$1, 36(%rsp)
	movl	36(%rsp), %eax
	addq	$4, 40(%rsp)
	cmpl	$-1, %eax
	jne	.L10
.L5:
	movq	64(%rsp), %rax
	leaq	.LC1(%rip), %rsi
	movl	$1, %edi
	movl	(%r15,%rax,4), %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L11
.L1:
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L21
	addq	$104, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	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
.L21:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE39:
	.size	run, .-run
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB40:
	.cfi_startproc
	endbr64
	subq	$8, %rsp
	.cfi_def_cfa_offset 16
	call	run
	xorl	%eax, %eax
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
	ret
	.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>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define ALLOC(size,type) ((type*)calloc((size),sizeof(type)))

#define POS(l, r) ((l) * (n + 1) + (r))

void run (void) {
  for (;;) {
    i32 n;
    scanf ("%" SCNi32, &n);
    if (n == 0) break;
    i32 *a = ALLOC (n, i32);
    for (i32 i = 0; i < n; ++i) {
      scanf ("%" SCNi32, a + i);
    }
    i32 *dp = ALLOC ((n + 1) * (n + 1), i32);
    for (i32 len = 2; len <= n; ++len) {
      for (i32 l = 0; l <= n - len; ++l) {
        i32 r = l + len;
        i32 max = 0;
        for (i32 m = l + 1; m < r; ++m) {
          max = MAX (max, dp[POS(l, m)] + dp[POS(m, r)]);
        }
        for (i32 m = l + 1; m < r; ++m) {
          if (dp[POS(l + 1, m)] == m - l - 1 && ABS (a[l] - a[m]) <= 1) {
            max = MAX (max, m + 1 - l + dp[POS(m + 1, r)]);
          }
        }
        dp[POS(l, r)] = max;
      }
    }
    printf ("%" PRIi32 "\n", dp[POS(0, n)]);
  }
}

int main (void) {
  run();
  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>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define ALLOC(size,type) ((type*)calloc((size),sizeof(type)))

#define POS(l, r) ((l) * (n + 1) + (r))

void run (void) {
  for (;;) {
    i32 n;
    scanf ("%" SCNi32, &n);
    if (n == 0) break;
    i32 *a = ALLOC (n, i32);
    for (i32 i = 0; i < n; ++i) {
      scanf ("%" SCNi32, a + i);
    }
    i32 *dp = ALLOC ((n + 1) * (n + 1), i32);
    for (i32 len = 2; len <= n; ++len) {
      for (i32 l = 0; l <= n - len; ++l) {
        i32 r = l + len;
        i32 max = 0;
        for (i32 m = l + 1; m < r; ++m) {
          max = MAX (max, dp[POS(l, m)] + dp[POS(m, r)]);
        }
        for (i32 m = l + 1; m < r; ++m) {
          if (dp[POS(l + 1, m)] == m - l - 1 && ABS (a[l] - a[m]) <= 1) {
            max = MAX (max, m + 1 - l + dp[POS(m + 1, r)]);
          }
        }
        dp[POS(l, r)] = max;
      }
    }
    printf ("%" PRIi32 "\n", dp[POS(0, n)]);
  }
}

int main (void) {
  run();
  return 0;
}

```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%i"
.LC1:
	.string	"%i\n"
	.text
	.globl	run
	.type	run, @function
run:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$64, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
.L14:
	leaq	-56(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-56(%rbp), %eax
	testl	%eax, %eax
	je	.L17
	movl	-56(%rbp), %eax
	cltq
	movl	$4, %esi
	movq	%rax, %rdi
	call	calloc@PLT
	movq	%rax, -24(%rbp)
	movl	$0, -52(%rbp)
	jmp	.L3
.L4:
	movl	-52(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -52(%rbp)
.L3:
	movl	-56(%rbp), %eax
	cmpl	%eax, -52(%rbp)
	jl	.L4
	movl	-56(%rbp), %eax
	leal	1(%rax), %edx
	movl	-56(%rbp), %eax
	addl	$1, %eax
	imull	%edx, %eax
	cltq
	movl	$4, %esi
	movq	%rax, %rdi
	call	calloc@PLT
	movq	%rax, -16(%rbp)
	movl	$2, -48(%rbp)
	jmp	.L5
.L13:
	movl	$0, -44(%rbp)
	jmp	.L6
.L12:
	movl	-44(%rbp), %edx
	movl	-48(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, -28(%rbp)
	movl	$0, -40(%rbp)
	movl	-44(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -36(%rbp)
	jmp	.L7
.L8:
	movl	-56(%rbp), %eax
	addl	$1, %eax
	imull	-44(%rbp), %eax
	movl	%eax, %edx
	movl	-36(%rbp), %eax
	addl	%edx, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-56(%rbp), %eax
	addl	$1, %eax
	imull	-36(%rbp), %eax
	movl	%eax, %ecx
	movl	-28(%rbp), %eax
	addl	%ecx, %eax
	cltq
	leaq	0(,%rax,4), %rcx
	movq	-16(%rbp), %rax
	addq	%rcx, %rax
	movl	(%rax), %eax
	addl	%eax, %edx
	movl	-40(%rbp), %eax
	cmpl	%edx, %eax
	cmovl	%edx, %eax
	movl	%eax, -40(%rbp)
	addl	$1, -36(%rbp)
.L7:
	movl	-36(%rbp), %eax
	cmpl	-28(%rbp), %eax
	jl	.L8
	movl	-44(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -32(%rbp)
	jmp	.L9
.L11:
	movl	-44(%rbp), %eax
	leal	1(%rax), %edx
	movl	-56(%rbp), %eax
	addl	$1, %eax
	imull	%eax, %edx
	movl	-32(%rbp), %eax
	addl	%edx, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-32(%rbp), %eax
	subl	-44(%rbp), %eax
	subl	$1, %eax
	cmpl	%eax, %edx
	jne	.L10
	movl	-44(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	-32(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	movq	-24(%rbp), %rdx
	addq	%rcx, %rdx
	movl	(%rdx), %edx
	subl	%edx, %eax
	cmpl	$-1, %eax
	jl	.L10
	movl	-44(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	-32(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	movq	-24(%rbp), %rdx
	addq	%rcx, %rdx
	movl	(%rdx), %edx
	subl	%edx, %eax
	cmpl	$1, %eax
	jg	.L10
	movl	-32(%rbp), %eax
	addl	$1, %eax
	subl	-44(%rbp), %eax
	movl	%eax, %ecx
	movl	-32(%rbp), %eax
	leal	1(%rax), %edx
	movl	-56(%rbp), %eax
	addl	$1, %eax
	imull	%eax, %edx
	movl	-28(%rbp), %eax
	addl	%edx, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	leal	(%rcx,%rax), %edx
	movl	-40(%rbp), %eax
	cmpl	%edx, %eax
	cmovl	%edx, %eax
	movl	%eax, -40(%rbp)
.L10:
	addl	$1, -32(%rbp)
.L9:
	movl	-32(%rbp), %eax
	cmpl	-28(%rbp), %eax
	jl	.L11
	movl	-56(%rbp), %eax
	addl	$1, %eax
	imull	-44(%rbp), %eax
	movl	%eax, %edx
	movl	-28(%rbp), %eax
	addl	%edx, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rax, %rdx
	movl	-40(%rbp), %eax
	movl	%eax, (%rdx)
	addl	$1, -44(%rbp)
.L6:
	movl	-56(%rbp), %eax
	subl	-48(%rbp), %eax
	cmpl	%eax, -44(%rbp)
	jle	.L12
	addl	$1, -48(%rbp)
.L5:
	movl	-56(%rbp), %eax
	cmpl	%eax, -48(%rbp)
	jle	.L13
	movl	-56(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	jmp	.L14
.L17:
	nop
	movq	-8(%rbp), %rax
	subq	%fs:40, %rax
	je	.L15
	call	__stack_chk_fail@PLT
.L15:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	run, .-run
	.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
	call	run
	movl	$0, %eax
	popq	%rbp
	.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
	.section	.rodata
.LC0:
	.string	"%i"
.LC1:
	.string	"%i\n"
	.text
	.globl	run
	.type	run, @function
run:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$64, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
.L14:
	leaq	-56(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-56(%rbp), %eax
	testl	%eax, %eax
	je	.L17
	movl	-56(%rbp), %eax
	cltq
	movl	$4, %esi
	movq	%rax, %rdi
	call	calloc@PLT
	movq	%rax, -24(%rbp)
	movl	$0, -52(%rbp)
	jmp	.L3
.L4:
	movl	-52(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -52(%rbp)
.L3:
	movl	-56(%rbp), %eax
	cmpl	%eax, -52(%rbp)
	jl	.L4
	movl	-56(%rbp), %eax
	leal	1(%rax), %edx
	movl	-56(%rbp), %eax
	addl	$1, %eax
	imull	%edx, %eax
	cltq
	movl	$4, %esi
	movq	%rax, %rdi
	call	calloc@PLT
	movq	%rax, -16(%rbp)
	movl	$2, -48(%rbp)
	jmp	.L5
.L13:
	movl	$0, -44(%rbp)
	jmp	.L6
.L12:
	movl	-44(%rbp), %edx
	movl	-48(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, -28(%rbp)
	movl	$0, -40(%rbp)
	movl	-44(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -36(%rbp)
	jmp	.L7
.L8:
	movl	-56(%rbp), %eax
	addl	$1, %eax
	imull	-44(%rbp), %eax
	movl	%eax, %edx
	movl	-36(%rbp), %eax
	addl	%edx, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-56(%rbp), %eax
	addl	$1, %eax
	imull	-36(%rbp), %eax
	movl	%eax, %ecx
	movl	-28(%rbp), %eax
	addl	%ecx, %eax
	cltq
	leaq	0(,%rax,4), %rcx
	movq	-16(%rbp), %rax
	addq	%rcx, %rax
	movl	(%rax), %eax
	addl	%eax, %edx
	movl	-40(%rbp), %eax
	cmpl	%edx, %eax
	cmovl	%edx, %eax
	movl	%eax, -40(%rbp)
	addl	$1, -36(%rbp)
.L7:
	movl	-36(%rbp), %eax
	cmpl	-28(%rbp), %eax
	jl	.L8
	movl	-44(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -32(%rbp)
	jmp	.L9
.L11:
	movl	-44(%rbp), %eax
	leal	1(%rax), %edx
	movl	-56(%rbp), %eax
	addl	$1, %eax
	imull	%eax, %edx
	movl	-32(%rbp), %eax
	addl	%edx, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-32(%rbp), %eax
	subl	-44(%rbp), %eax
	subl	$1, %eax
	cmpl	%eax, %edx
	jne	.L10
	movl	-44(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	-32(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	movq	-24(%rbp), %rdx
	addq	%rcx, %rdx
	movl	(%rdx), %edx
	subl	%edx, %eax
	cmpl	$-1, %eax
	jl	.L10
	movl	-44(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	-32(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	movq	-24(%rbp), %rdx
	addq	%rcx, %rdx
	movl	(%rdx), %edx
	subl	%edx, %eax
	cmpl	$1, %eax
	jg	.L10
	movl	-32(%rbp), %eax
	addl	$1, %eax
	subl	-44(%rbp), %eax
	movl	%eax, %ecx
	movl	-32(%rbp), %eax
	leal	1(%rax), %edx
	movl	-56(%rbp), %eax
	addl	$1, %eax
	imull	%eax, %edx
	movl	-28(%rbp), %eax
	addl	%edx, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	leal	(%rcx,%rax), %edx
	movl	-40(%rbp), %eax
	cmpl	%edx, %eax
	cmovl	%edx, %eax
	movl	%eax, -40(%rbp)
.L10:
	addl	$1, -32(%rbp)
.L9:
	movl	-32(%rbp), %eax
	cmpl	-28(%rbp), %eax
	jl	.L11
	movl	-56(%rbp), %eax
	addl	$1, %eax
	imull	-44(%rbp), %eax
	movl	%eax, %edx
	movl	-28(%rbp), %eax
	addl	%edx, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rax, %rdx
	movl	-40(%rbp), %eax
	movl	%eax, (%rdx)
	addl	$1, -44(%rbp)
.L6:
	movl	-56(%rbp), %eax
	subl	-48(%rbp), %eax
	cmpl	%eax, -44(%rbp)
	jle	.L12
	addl	$1, -48(%rbp)
.L5:
	movl	-56(%rbp), %eax
	cmpl	%eax, -48(%rbp)
	jle	.L13
	movl	-56(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	jmp	.L14
.L17:
	nop
	movq	-8(%rbp), %rax
	subq	%fs:40, %rax
	je	.L15
	call	__stack_chk_fail@PLT
.L15:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	run, .-run
	.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
	call	run
	movl	$0, %eax
	popq	%rbp
	.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:
