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

```c
// AOJ 2028: Gather on the Clock
// 2017.11.03 bal4u@uu

#include <stdio.h>
#include <string.h>

int a[102];
int dp[102][102];

int main()
{
	int t, n, i, j, k, v, ans;
	
	scanf("%d", &t); while (t--) {
		scanf("%d", &n);
		for (i = 0; i < n; i++) scanf("%d", a+i);
		memset(dp, 0, sizeof(dp));

		for (k = 1; k < n; k++) for (i = 0; i < n; i++) for (j = 0; j < k; j++) {
			int x = i+j+1;
			if (x >= n) x -= n;
			v = a[x] - a[i]; if (v < 0) v = -v;
			v += dp[x][k-j-1] + dp[i][j];
			if (v > dp[i][k]) dp[i][k] = v;
		}

		for (ans = 0, i = 0; i < n; i++) if (dp[i][n-1] > ans) ans = dp[i][n-1];
		printf("%d\n",ans);
	}
	return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	a
	.bss
	.align 32
	.type	a, @object
	.size	a, 408
a:
	.zero	408
	.globl	dp
	.align 32
	.type	dp, @object
	.size	dp, 41616
dp:
	.zero	41616
	.section	.rodata
.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
	subq	$48, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-40(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	jmp	.L2
.L17:
	leaq	-36(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -32(%rbp)
	jmp	.L3
.L4:
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -32(%rbp)
.L3:
	movl	-36(%rbp), %eax
	cmpl	%eax, -32(%rbp)
	jl	.L4
	movl	$41616, %edx
	movl	$0, %esi
	leaq	dp(%rip), %rax
	movq	%rax, %rdi
	call	memset@PLT
	movl	$1, -24(%rbp)
	jmp	.L5
.L13:
	movl	$0, -32(%rbp)
	jmp	.L6
.L12:
	movl	$0, -28(%rbp)
	jmp	.L7
.L11:
	movl	-32(%rbp), %edx
	movl	-28(%rbp), %eax
	addl	%edx, %eax
	addl	$1, %eax
	movl	%eax, -12(%rbp)
	movl	-36(%rbp), %eax
	cmpl	%eax, -12(%rbp)
	jl	.L8
	movl	-36(%rbp), %eax
	subl	%eax, -12(%rbp)
.L8:
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	-32(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	a(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	subl	%edx, %eax
	movl	%eax, -20(%rbp)
	cmpl	$0, -20(%rbp)
	jns	.L9
	negl	-20(%rbp)
.L9:
	movl	-24(%rbp), %eax
	subl	-28(%rbp), %eax
	subl	$1, %eax
	movslq	%eax, %rdx
	movl	-12(%rbp), %eax
	cltq
	imulq	$102, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	dp(%rip), %rax
	movl	(%rdx,%rax), %ecx
	movl	-28(%rbp), %eax
	movslq	%eax, %rdx
	movl	-32(%rbp), %eax
	cltq
	imulq	$102, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	dp(%rip), %rax
	movl	(%rdx,%rax), %eax
	addl	%ecx, %eax
	addl	%eax, -20(%rbp)
	movl	-24(%rbp), %eax
	movslq	%eax, %rdx
	movl	-32(%rbp), %eax
	cltq
	imulq	$102, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	dp(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	%eax, -20(%rbp)
	jle	.L10
	movl	-24(%rbp), %eax
	movslq	%eax, %rdx
	movl	-32(%rbp), %eax
	cltq
	imulq	$102, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rcx
	leaq	dp(%rip), %rdx
	movl	-20(%rbp), %eax
	movl	%eax, (%rcx,%rdx)
.L10:
	addl	$1, -28(%rbp)
.L7:
	movl	-28(%rbp), %eax
	cmpl	-24(%rbp), %eax
	jl	.L11
	addl	$1, -32(%rbp)
.L6:
	movl	-36(%rbp), %eax
	cmpl	%eax, -32(%rbp)
	jl	.L12
	addl	$1, -24(%rbp)
.L5:
	movl	-36(%rbp), %eax
	cmpl	%eax, -24(%rbp)
	jl	.L13
	movl	$0, -16(%rbp)
	movl	$0, -32(%rbp)
	jmp	.L14
.L16:
	movl	-36(%rbp), %eax
	subl	$1, %eax
	movslq	%eax, %rdx
	movl	-32(%rbp), %eax
	cltq
	imulq	$102, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	dp(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	%eax, -16(%rbp)
	jge	.L15
	movl	-36(%rbp), %eax
	subl	$1, %eax
	movslq	%eax, %rdx
	movl	-32(%rbp), %eax
	cltq
	imulq	$102, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	dp(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, -16(%rbp)
.L15:
	addl	$1, -32(%rbp)
.L14:
	movl	-36(%rbp), %eax
	cmpl	%eax, -32(%rbp)
	jl	.L16
	movl	-16(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
.L2:
	movl	-40(%rbp), %eax
	leal	-1(%rax), %edx
	movl	%edx, -40(%rbp)
	testl	%eax, %eax
	jne	.L17
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L19
	call	__stack_chk_fail@PLT
.L19:
	leave
	.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"
.LC1:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB35:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	.LC0(%rip), %rdi
	leaq	a(%rip), %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	leaq	dp(%rip), %r14
	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	$72, %rsp
	.cfi_def_cfa_offset 128
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	leaq	48(%rsp), %rsi
	leaq	52(%rsp), %rbx
	call	__isoc99_scanf@PLT
	movl	48(%rsp), %eax
	movq	%rbx, 40(%rsp)
	leal	-1(%rax), %edx
	movl	%edx, 48(%rsp)
	testl	%eax, %eax
	je	.L17
.L2:
	movq	40(%rsp), %rsi
	leaq	.LC0(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	52(%rsp), %r13d
	testl	%r13d, %r13d
	jle	.L3
	leaq	a(%rip), %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
	movl	52(%rsp), %r13d
	addq	$4, %rbp
	cmpl	%ebx, %r13d
	jg	.L4
	xorl	%esi, %esi
	movl	$41616, %edx
	movq	%r14, %rdi
	call	memset@PLT
	cmpl	$1, %r13d
	jle	.L5
	leaq	4+dp(%rip), %rax
	movl	$1, %r11d
	xorl	%r10d, %r10d
	movq	$-4, 8(%rsp)
	movq	%rax, 24(%rsp)
	movslq	%r13d, %rax
	movq	24(%rsp), %rbp
	movq	%rax, 16(%rsp)
	movl	%r11d, %eax
	subl	%r13d, %eax
	movl	%eax, 32(%rsp)
	.p2align 4,,10
	.p2align 3
.L6:
	leal	1(%r11), %eax
	xorl	%r12d, %r12d
	movl	%eax, 36(%rsp)
	movl	%eax, %ebx
	.p2align 4,,10
	.p2align 3
.L14:
	movq	8(%rsp), %rax
	movl	(%r15,%r12,4), %r9d
	leal	1(%r12), %ecx
	leaq	0(%rbp,%rax), %r8
	movl	32(%rsp), %eax
	leal	(%rax,%r12), %edi
	.p2align 4,,10
	.p2align 3
.L10:
	cmpl	%ecx, %r13d
	movl	%edi, %eax
	movl	%r9d, %esi
	cmovg	%ecx, %eax
	cltq
	movl	(%r15,%rax,4), %edx
	subl	%edx, %esi
	subl	%r9d, %edx
	cmovs	%esi, %edx
	imulq	$102, %rax, %rax
	movl	%r11d, %esi
	subl	%ecx, %esi
	movslq	%esi, %rsi
	addq	%rax, %rsi
	movl	(%r8), %eax
	addl	(%r14,%rsi,4), %eax
	addl	%edx, %eax
	cmpl	%r10d, %eax
	jle	.L9
	movl	%eax, 0(%rbp)
	movl	%eax, %r10d
.L9:
	addl	$1, %ecx
	addq	$4, %r8
	addl	$1, %edi
	cmpl	%ebx, %ecx
	jne	.L10
	addq	$1, %r12
	addq	$408, %rbp
	addl	$1, %ebx
	addl	$1, %r11d
	cmpq	16(%rsp), %r12
	je	.L11
	movl	0(%rbp), %r10d
	jmp	.L14
	.p2align 4,,10
	.p2align 3
.L11:
	movl	36(%rsp), %r11d
	addq	$4, 24(%rsp)
	subq	$4, 8(%rsp)
	cmpl	%r11d, %r13d
	je	.L15
	movq	24(%rsp), %rax
	movl	(%rax), %r10d
	movq	%rax, %rbp
	jmp	.L6
.L15:
	leal	-1(%r13), %eax
	xorl	%edx, %edx
	cltq
	leaq	(%r14,%rax,4), %rcx
	xorl	%eax, %eax
	.p2align 4,,10
	.p2align 3
.L13:
	movl	(%rcx), %esi
	cmpl	%esi, %edx
	cmovl	%esi, %edx
	addl	$1, %eax
	addq	$408, %rcx
	cmpl	%eax, %r13d
	jg	.L13
.L16:
	leaq	.LC1(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	48(%rsp), %eax
	leal	-1(%rax), %edx
	movl	%edx, 48(%rsp)
	testl	%eax, %eax
	jne	.L2
.L17:
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L32
	addq	$72, %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
.L3:
	.cfi_restore_state
	movl	$41616, %edx
	xorl	%esi, %esi
	movq	%r14, %rdi
	call	memset@PLT
.L5:
	cmpl	$1, %r13d
	je	.L15
	xorl	%edx, %edx
	jmp	.L16
.L32:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE35:
	.size	main, .-main
	.globl	dp
	.bss
	.align 32
	.type	dp, @object
	.size	dp, 41616
dp:
	.zero	41616
	.globl	a
	.align 32
	.type	a, @object
	.size	a, 408
a:
	.zero	408
	.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:
.LFB35:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	.LC0(%rip), %rdi
	leaq	a(%rip), %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	leaq	dp(%rip), %r14
	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	$72, %rsp
	.cfi_def_cfa_offset 128
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	leaq	48(%rsp), %rsi
	leaq	52(%rsp), %rbx
	call	__isoc99_scanf@PLT
	movl	48(%rsp), %eax
	movq	%rbx, 40(%rsp)
	leal	-1(%rax), %edx
	movl	%edx, 48(%rsp)
	testl	%eax, %eax
	je	.L17
.L2:
	movq	40(%rsp), %rsi
	leaq	.LC0(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	52(%rsp), %r13d
	testl	%r13d, %r13d
	jle	.L3
	leaq	a(%rip), %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
	movl	52(%rsp), %r13d
	addq	$4, %rbp
	cmpl	%ebx, %r13d
	jg	.L4
	xorl	%esi, %esi
	movl	$41616, %edx
	movq	%r14, %rdi
	call	memset@PLT
	cmpl	$1, %r13d
	jle	.L5
	leaq	4+dp(%rip), %rax
	movl	$1, %r11d
	xorl	%r10d, %r10d
	movq	$-4, 8(%rsp)
	movq	%rax, 24(%rsp)
	movslq	%r13d, %rax
	movq	24(%rsp), %rbp
	movq	%rax, 16(%rsp)
	movl	%r11d, %eax
	subl	%r13d, %eax
	movl	%eax, 32(%rsp)
	.p2align 4,,10
	.p2align 3
.L6:
	leal	1(%r11), %eax
	xorl	%r12d, %r12d
	movl	%eax, 36(%rsp)
	movl	%eax, %ebx
	.p2align 4,,10
	.p2align 3
.L14:
	movq	8(%rsp), %rax
	movl	(%r15,%r12,4), %r9d
	leal	1(%r12), %ecx
	leaq	0(%rbp,%rax), %r8
	movl	32(%rsp), %eax
	leal	(%rax,%r12), %edi
	.p2align 4,,10
	.p2align 3
.L10:
	cmpl	%ecx, %r13d
	movl	%edi, %eax
	movl	%r9d, %esi
	cmovg	%ecx, %eax
	cltq
	movl	(%r15,%rax,4), %edx
	subl	%edx, %esi
	subl	%r9d, %edx
	cmovs	%esi, %edx
	imulq	$102, %rax, %rax
	movl	%r11d, %esi
	subl	%ecx, %esi
	movslq	%esi, %rsi
	addq	%rax, %rsi
	movl	(%r8), %eax
	addl	(%r14,%rsi,4), %eax
	addl	%edx, %eax
	cmpl	%r10d, %eax
	jle	.L9
	movl	%eax, 0(%rbp)
	movl	%eax, %r10d
.L9:
	addl	$1, %ecx
	addq	$4, %r8
	addl	$1, %edi
	cmpl	%ebx, %ecx
	jne	.L10
	addq	$1, %r12
	addq	$408, %rbp
	addl	$1, %ebx
	addl	$1, %r11d
	cmpq	16(%rsp), %r12
	je	.L11
	movl	0(%rbp), %r10d
	jmp	.L14
	.p2align 4,,10
	.p2align 3
.L11:
	movl	36(%rsp), %r11d
	addq	$4, 24(%rsp)
	subq	$4, 8(%rsp)
	cmpl	%r11d, %r13d
	je	.L15
	movq	24(%rsp), %rax
	movl	(%rax), %r10d
	movq	%rax, %rbp
	jmp	.L6
.L15:
	leal	-1(%r13), %eax
	xorl	%edx, %edx
	cltq
	leaq	(%r14,%rax,4), %rcx
	xorl	%eax, %eax
	.p2align 4,,10
	.p2align 3
.L13:
	movl	(%rcx), %esi
	cmpl	%esi, %edx
	cmovl	%esi, %edx
	addl	$1, %eax
	addq	$408, %rcx
	cmpl	%eax, %r13d
	jg	.L13
.L16:
	leaq	.LC1(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	48(%rsp), %eax
	leal	-1(%rax), %edx
	movl	%edx, 48(%rsp)
	testl	%eax, %eax
	jne	.L2
.L17:
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L32
	addq	$72, %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
.L3:
	.cfi_restore_state
	movl	$41616, %edx
	xorl	%esi, %esi
	movq	%r14, %rdi
	call	memset@PLT
.L5:
	cmpl	$1, %r13d
	je	.L15
	xorl	%edx, %edx
	jmp	.L16
.L32:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE35:
	.size	main, .-main
	.globl	dp
	.bss
	.align 32
	.type	dp, @object
	.size	dp, 41616
dp:
	.zero	41616
	.globl	a
	.align 32
	.type	a, @object
	.size	a, 408
a:
	.zero	408
	.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:

// AOJ 2028: Gather on the Clock
// 2017.11.03 bal4u@uu

#include <stdio.h>
#include <string.h>

int a[102];
int dp[102][102];

int main()
{
	int t, n, i, j, k, v, ans;
	
	scanf("%d", &t); while (t--) {
		scanf("%d", &n);
		for (i = 0; i < n; i++) scanf("%d", a+i);
		memset(dp, 0, sizeof(dp));

		for (k = 1; k < n; k++) for (i = 0; i < n; i++) for (j = 0; j < k; j++) {
			int x = i+j+1;
			if (x >= n) x -= n;
			v = a[x] - a[i]; if (v < 0) v = -v;
			v += dp[x][k-j-1] + dp[i][j];
			if (v > dp[i][k]) dp[i][k] = v;
		}

		for (ans = 0, i = 0; i < n; i++) if (dp[i][n-1] > ans) ans = dp[i][n-1];
		printf("%d\n",ans);
	}
	return 0;
}
2
4 1 1 2 3
6 1 8 0 3 5 9
 2
4 1 1 2 3
6 1 8 0 3 1 9
 2
4 1 1 2 3
6 1 8 0 3 0 9
 2
4 1 1 2 3
4 1 8 0 3 0 9
 2
0 0 1 2 3
6 1 8 0 3 5 9
 2
4 1 1 2 3
6 1 8 0 3 1 5
 2
4 1 1 2 3
6 1 8 -1 3 0 9
 2
4 1 1 2 3
4 1 8 0 6 -1 9
 2
4 1 1 2 3
3 1 2 0 3 5 9
 2
4 1 1 2 3
6 1 8 -1 3 1 5

5
34
 5
38
 5
39
 5
20
 0
0
 5
31
 5
40
 5
21
 5
3
 5
32

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

```c
// AOJ 2028: Gather on the Clock
// 2017.11.03 bal4u@uu

#include <stdio.h>
#include <string.h>

int a[102];
int dp[102][102];

int main()
{
	int t, n, i, j, k, v, ans;
	
	scanf("%d", &t); while (t--) {
		scanf("%d", &n);
		for (i = 0; i < n; i++) scanf("%d", a+i);
		memset(dp, 0, sizeof(dp));

		for (k = 1; k < n; k++) for (i = 0; i < n; i++) for (j = 0; j < k; j++) {
			int x = i+j+1;
			if (x >= n) x -= n;
			v = a[x] - a[i]; if (v < 0) v = -v;
			v += dp[x][k-j-1] + dp[i][j];
			if (v > dp[i][k]) dp[i][k] = v;
		}

		for (ans = 0, i = 0; i < n; i++) if (dp[i][n-1] > ans) ans = dp[i][n-1];
		printf("%d\n",ans);
	}
	return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	a
	.bss
	.align 32
	.type	a, @object
	.size	a, 408
a:
	.zero	408
	.globl	dp
	.align 32
	.type	dp, @object
	.size	dp, 41616
dp:
	.zero	41616
	.section	.rodata
.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
	subq	$48, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-40(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	jmp	.L2
.L17:
	leaq	-36(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -32(%rbp)
	jmp	.L3
.L4:
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -32(%rbp)
.L3:
	movl	-36(%rbp), %eax
	cmpl	%eax, -32(%rbp)
	jl	.L4
	movl	$41616, %edx
	movl	$0, %esi
	leaq	dp(%rip), %rax
	movq	%rax, %rdi
	call	memset@PLT
	movl	$1, -24(%rbp)
	jmp	.L5
.L13:
	movl	$0, -32(%rbp)
	jmp	.L6
.L12:
	movl	$0, -28(%rbp)
	jmp	.L7
.L11:
	movl	-32(%rbp), %edx
	movl	-28(%rbp), %eax
	addl	%edx, %eax
	addl	$1, %eax
	movl	%eax, -12(%rbp)
	movl	-36(%rbp), %eax
	cmpl	%eax, -12(%rbp)
	jl	.L8
	movl	-36(%rbp), %eax
	subl	%eax, -12(%rbp)
.L8:
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	-32(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	a(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	subl	%edx, %eax
	movl	%eax, -20(%rbp)
	cmpl	$0, -20(%rbp)
	jns	.L9
	negl	-20(%rbp)
.L9:
	movl	-24(%rbp), %eax
	subl	-28(%rbp), %eax
	subl	$1, %eax
	movslq	%eax, %rdx
	movl	-12(%rbp), %eax
	cltq
	imulq	$102, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	dp(%rip), %rax
	movl	(%rdx,%rax), %ecx
	movl	-28(%rbp), %eax
	movslq	%eax, %rdx
	movl	-32(%rbp), %eax
	cltq
	imulq	$102, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	dp(%rip), %rax
	movl	(%rdx,%rax), %eax
	addl	%ecx, %eax
	addl	%eax, -20(%rbp)
	movl	-24(%rbp), %eax
	movslq	%eax, %rdx
	movl	-32(%rbp), %eax
	cltq
	imulq	$102, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	dp(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	%eax, -20(%rbp)
	jle	.L10
	movl	-24(%rbp), %eax
	movslq	%eax, %rdx
	movl	-32(%rbp), %eax
	cltq
	imulq	$102, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rcx
	leaq	dp(%rip), %rdx
	movl	-20(%rbp), %eax
	movl	%eax, (%rcx,%rdx)
.L10:
	addl	$1, -28(%rbp)
.L7:
	movl	-28(%rbp), %eax
	cmpl	-24(%rbp), %eax
	jl	.L11
	addl	$1, -32(%rbp)
.L6:
	movl	-36(%rbp), %eax
	cmpl	%eax, -32(%rbp)
	jl	.L12
	addl	$1, -24(%rbp)
.L5:
	movl	-36(%rbp), %eax
	cmpl	%eax, -24(%rbp)
	jl	.L13
	movl	$0, -16(%rbp)
	movl	$0, -32(%rbp)
	jmp	.L14
.L16:
	movl	-36(%rbp), %eax
	subl	$1, %eax
	movslq	%eax, %rdx
	movl	-32(%rbp), %eax
	cltq
	imulq	$102, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	dp(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	%eax, -16(%rbp)
	jge	.L15
	movl	-36(%rbp), %eax
	subl	$1, %eax
	movslq	%eax, %rdx
	movl	-32(%rbp), %eax
	cltq
	imulq	$102, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	dp(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, -16(%rbp)
.L15:
	addl	$1, -32(%rbp)
.L14:
	movl	-36(%rbp), %eax
	cmpl	%eax, -32(%rbp)
	jl	.L16
	movl	-16(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
.L2:
	movl	-40(%rbp), %eax
	leal	-1(%rax), %edx
	movl	%edx, -40(%rbp)
	testl	%eax, %eax
	jne	.L17
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L19
	call	__stack_chk_fail@PLT
.L19:
	leave
	.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
	.globl	a
	.bss
	.align 32
	.type	a, @object
	.size	a, 408
a:
	.zero	408
	.globl	dp
	.align 32
	.type	dp, @object
	.size	dp, 41616
dp:
	.zero	41616
	.section	.rodata
.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
	subq	$48, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-40(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	jmp	.L2
.L17:
	leaq	-36(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -32(%rbp)
	jmp	.L3
.L4:
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -32(%rbp)
.L3:
	movl	-36(%rbp), %eax
	cmpl	%eax, -32(%rbp)
	jl	.L4
	movl	$41616, %edx
	movl	$0, %esi
	leaq	dp(%rip), %rax
	movq	%rax, %rdi
	call	memset@PLT
	movl	$1, -24(%rbp)
	jmp	.L5
.L13:
	movl	$0, -32(%rbp)
	jmp	.L6
.L12:
	movl	$0, -28(%rbp)
	jmp	.L7
.L11:
	movl	-32(%rbp), %edx
	movl	-28(%rbp), %eax
	addl	%edx, %eax
	addl	$1, %eax
	movl	%eax, -12(%rbp)
	movl	-36(%rbp), %eax
	cmpl	%eax, -12(%rbp)
	jl	.L8
	movl	-36(%rbp), %eax
	subl	%eax, -12(%rbp)
.L8:
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	a(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	-32(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	a(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	subl	%edx, %eax
	movl	%eax, -20(%rbp)
	cmpl	$0, -20(%rbp)
	jns	.L9
	negl	-20(%rbp)
.L9:
	movl	-24(%rbp), %eax
	subl	-28(%rbp), %eax
	subl	$1, %eax
	movslq	%eax, %rdx
	movl	-12(%rbp), %eax
	cltq
	imulq	$102, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	dp(%rip), %rax
	movl	(%rdx,%rax), %ecx
	movl	-28(%rbp), %eax
	movslq	%eax, %rdx
	movl	-32(%rbp), %eax
	cltq
	imulq	$102, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	dp(%rip), %rax
	movl	(%rdx,%rax), %eax
	addl	%ecx, %eax
	addl	%eax, -20(%rbp)
	movl	-24(%rbp), %eax
	movslq	%eax, %rdx
	movl	-32(%rbp), %eax
	cltq
	imulq	$102, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	dp(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	%eax, -20(%rbp)
	jle	.L10
	movl	-24(%rbp), %eax
	movslq	%eax, %rdx
	movl	-32(%rbp), %eax
	cltq
	imulq	$102, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rcx
	leaq	dp(%rip), %rdx
	movl	-20(%rbp), %eax
	movl	%eax, (%rcx,%rdx)
.L10:
	addl	$1, -28(%rbp)
.L7:
	movl	-28(%rbp), %eax
	cmpl	-24(%rbp), %eax
	jl	.L11
	addl	$1, -32(%rbp)
.L6:
	movl	-36(%rbp), %eax
	cmpl	%eax, -32(%rbp)
	jl	.L12
	addl	$1, -24(%rbp)
.L5:
	movl	-36(%rbp), %eax
	cmpl	%eax, -24(%rbp)
	jl	.L13
	movl	$0, -16(%rbp)
	movl	$0, -32(%rbp)
	jmp	.L14
.L16:
	movl	-36(%rbp), %eax
	subl	$1, %eax
	movslq	%eax, %rdx
	movl	-32(%rbp), %eax
	cltq
	imulq	$102, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	dp(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	%eax, -16(%rbp)
	jge	.L15
	movl	-36(%rbp), %eax
	subl	$1, %eax
	movslq	%eax, %rdx
	movl	-32(%rbp), %eax
	cltq
	imulq	$102, %rax, %rax
	addq	%rdx, %rax
	leaq	0(,%rax,4), %rdx
	leaq	dp(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, -16(%rbp)
.L15:
	addl	$1, -32(%rbp)
.L14:
	movl	-36(%rbp), %eax
	cmpl	%eax, -32(%rbp)
	jl	.L16
	movl	-16(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
.L2:
	movl	-40(%rbp), %eax
	leal	-1(%rax), %edx
	movl	%edx, -40(%rbp)
	testl	%eax, %eax
	jne	.L17
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L19
	call	__stack_chk_fail@PLT
.L19:
	leave
	.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:
