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>
#define int long long

int ABS(int a){
	return a >= 0 ? a : -a;
}

signed main(){
	int N, i;
	scanf("%lld", &N);
	int *A = (int *)malloc(sizeof(int) * (N + 2));
	int *S = (int *)malloc(sizeof(int) * (N + 2));
	int *T = (int *)malloc(sizeof(int) * (N + 2));
	A[0] = 0;
	A[N + 1] = 0;
	for(i = 1; i <= N; i++){
		scanf("%lld", &A[i]);
	}
	S[0] = 0;
	for(i = 1; i <= N; i++){
		S[i] = S[i - 1] + ABS(A[i] - A[i - 1]);
	}
	T[N + 1] = 0;
	for(i = N; i > 0; i--){
		T[i] = T[i + 1] + ABS(A[i] - A[i + 1]);
	}
/*	for(i = 1; i <= N; i++){
		printf("S[%lld] = %lld\n", i, S[i]);
	}
	for(i = 1; i <= N; i++){
		printf("T[%lld] = %lld\n", i, T[i]);
	}
*/	for(i = 1; i <= N; i++){
		printf("%lld\n", S[i - 1] + ABS(A[i - 1] - A[i + 1]) + T[i + 1]);
	}
	return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	ABS
	.type	ABS, @function
ABS:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -8(%rbp)
	movq	-8(%rbp), %rax
	movq	%rax, %rdx
	negq	%rdx
	cmovns	%rdx, %rax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	ABS, .-ABS
	.section	.rodata
.LC0:
	.string	"%lld"
.LC1:
	.string	"%lld\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
	subq	$56, %rsp
	.cfi_offset 3, -24
	movq	%fs:40, %rax
	movq	%rax, -24(%rbp)
	xorl	%eax, %eax
	leaq	-64(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	-64(%rbp), %rax
	addq	$2, %rax
	salq	$3, %rax
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -48(%rbp)
	movq	-64(%rbp), %rax
	addq	$2, %rax
	salq	$3, %rax
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -40(%rbp)
	movq	-64(%rbp), %rax
	addq	$2, %rax
	salq	$3, %rax
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -32(%rbp)
	movq	-48(%rbp), %rax
	movq	$0, (%rax)
	movq	-64(%rbp), %rax
	addq	$1, %rax
	leaq	0(,%rax,8), %rdx
	movq	-48(%rbp), %rax
	addq	%rdx, %rax
	movq	$0, (%rax)
	movq	$1, -56(%rbp)
	jmp	.L4
.L5:
	movq	-56(%rbp), %rax
	leaq	0(,%rax,8), %rdx
	movq	-48(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addq	$1, -56(%rbp)
.L4:
	movq	-64(%rbp), %rax
	cmpq	%rax, -56(%rbp)
	jle	.L5
	movq	-40(%rbp), %rax
	movq	$0, (%rax)
	movq	$1, -56(%rbp)
	jmp	.L6
.L7:
	movq	-56(%rbp), %rax
	salq	$3, %rax
	leaq	-8(%rax), %rdx
	movq	-40(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rbx
	movq	-56(%rbp), %rax
	leaq	0(,%rax,8), %rdx
	movq	-48(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rax
	movq	-56(%rbp), %rdx
	salq	$3, %rdx
	leaq	-8(%rdx), %rcx
	movq	-48(%rbp), %rdx
	addq	%rcx, %rdx
	movq	(%rdx), %rdx
	subq	%rdx, %rax
	movq	%rax, %rdi
	call	ABS
	movq	%rax, %rdx
	movq	-56(%rbp), %rax
	leaq	0(,%rax,8), %rcx
	movq	-40(%rbp), %rax
	addq	%rcx, %rax
	addq	%rbx, %rdx
	movq	%rdx, (%rax)
	addq	$1, -56(%rbp)
.L6:
	movq	-64(%rbp), %rax
	cmpq	%rax, -56(%rbp)
	jle	.L7
	movq	-64(%rbp), %rax
	addq	$1, %rax
	leaq	0(,%rax,8), %rdx
	movq	-32(%rbp), %rax
	addq	%rdx, %rax
	movq	$0, (%rax)
	movq	-64(%rbp), %rax
	movq	%rax, -56(%rbp)
	jmp	.L8
.L9:
	movq	-56(%rbp), %rax
	addq	$1, %rax
	leaq	0(,%rax,8), %rdx
	movq	-32(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rbx
	movq	-56(%rbp), %rax
	leaq	0(,%rax,8), %rdx
	movq	-48(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rax
	movq	-56(%rbp), %rdx
	addq	$1, %rdx
	leaq	0(,%rdx,8), %rcx
	movq	-48(%rbp), %rdx
	addq	%rcx, %rdx
	movq	(%rdx), %rdx
	subq	%rdx, %rax
	movq	%rax, %rdi
	call	ABS
	movq	%rax, %rdx
	movq	-56(%rbp), %rax
	leaq	0(,%rax,8), %rcx
	movq	-32(%rbp), %rax
	addq	%rcx, %rax
	addq	%rbx, %rdx
	movq	%rdx, (%rax)
	subq	$1, -56(%rbp)
.L8:
	cmpq	$0, -56(%rbp)
	jg	.L9
	movq	$1, -56(%rbp)
	jmp	.L10
.L11:
	movq	-56(%rbp), %rax
	salq	$3, %rax
	leaq	-8(%rax), %rdx
	movq	-40(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rbx
	movq	-56(%rbp), %rax
	salq	$3, %rax
	leaq	-8(%rax), %rdx
	movq	-48(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rax
	movq	-56(%rbp), %rdx
	addq	$1, %rdx
	leaq	0(,%rdx,8), %rcx
	movq	-48(%rbp), %rdx
	addq	%rcx, %rdx
	movq	(%rdx), %rdx
	subq	%rdx, %rax
	movq	%rax, %rdi
	call	ABS
	leaq	(%rbx,%rax), %rdx
	movq	-56(%rbp), %rax
	addq	$1, %rax
	leaq	0(,%rax,8), %rcx
	movq	-32(%rbp), %rax
	addq	%rcx, %rax
	movq	(%rax), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	addq	$1, -56(%rbp)
.L10:
	movq	-64(%rbp), %rax
	cmpq	%rax, -56(%rbp)
	jle	.L11
	movl	$0, %eax
	movq	-24(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L13
	call	__stack_chk_fail@PLT
.L13:
	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	ABS
	.type	ABS, @function
ABS:
.LFB39:
	.cfi_startproc
	endbr64
	movq	%rdi, %rax
	negq	%rax
	cmovs	%rdi, %rax
	ret
	.cfi_endproc
.LFE39:
	.size	ABS, .-ABS
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%lld"
.LC1:
	.string	"%lld\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
	leaq	.LC0(%rip), %rdi
	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	$24, %rsp
	.cfi_def_cfa_offset 80
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %rsi
	call	__isoc99_scanf@PLT
	movq	(%rsp), %rbx
	leaq	16(,%rbx,8), %r14
	movq	%r14, %rdi
	call	malloc@PLT
	movq	%r14, %rdi
	movq	%rax, %r13
	call	malloc@PLT
	movq	%r14, %rdi
	movq	%rax, %r12
	call	malloc@PLT
	movq	$0, 0(%r13)
	movq	$0, -8(%r13,%r14)
	movq	%rax, %rbp
	testq	%rbx, %rbx
	jle	.L4
	leaq	8(%r13), %r15
	movl	$1, %r14d
	.p2align 4,,10
	.p2align 3
.L5:
	movq	%r15, %rsi
	leaq	.LC0(%rip), %rdi
	xorl	%eax, %eax
	addq	$1, %r14
	call	__isoc99_scanf@PLT
	movq	(%rsp), %rbx
	addq	$8, %r15
	cmpq	%r14, %rbx
	jge	.L5
	movq	$0, (%r12)
	testq	%rbx, %rbx
	jle	.L6
	cmpq	$2, %rbx
	jle	.L19
	leaq	-3(%rbx), %rax
	movq	0(%r13), %rsi
	xorl	%ecx, %ecx
	movl	$1, %edx
	andq	$-2, %rax
	addq	$3, %rax
.L8:
	movq	0(%r13,%rdx,8), %r9
	movq	%r9, %rdi
	subq	%rsi, %rdi
	movq	%rdi, %rsi
	negq	%rsi
	cmovs	%rdi, %rsi
	addq	%rsi, %rcx
	movq	8(%r13,%rdx,8), %rsi
	movq	%rcx, (%r12,%rdx,8)
	movq	%rsi, %r8
	subq	%r9, %r8
	movq	%r8, %rdi
	negq	%rdi
	cmovs	%r8, %rdi
	addq	%rdi, %rcx
	movq	%rcx, 8(%r12,%rdx,8)
	addq	$2, %rdx
	cmpq	%rax, %rdx
	jne	.L8
	.p2align 4,,10
	.p2align 3
.L9:
	movq	0(%r13,%rax,8), %rcx
	subq	-8(%r13,%rax,8), %rcx
	movq	%rcx, %rdx
	negq	%rdx
	cmovs	%rcx, %rdx
	addq	-8(%r12,%rax,8), %rdx
	movq	%rdx, (%r12,%rax,8)
	addq	$1, %rax
	cmpq	%rax, %rbx
	jge	.L9
	leaq	1(%rbx), %rax
	movq	$0, 0(%rbp,%rax,8)
	leaq	-8(,%rax,8), %rax
	leaq	0(%r13,%rax), %rdx
	addq	%rbp, %rax
	cmpq	$2, %rbx
	jle	.L11
	movq	8(%rdx), %rsi
	leaq	-2(%rbx), %rcx
	leaq	-3(%rbx), %rdx
	movq	8(%rax), %rax
	andq	$-2, %rdx
	movq	%rcx, %r8
	subq	%rdx, %r8
	jmp	.L13
	.p2align 4,,10
	.p2align 3
.L29:
	subq	$2, %rcx
.L13:
	movq	0(%r13,%rbx,8), %r9
	movq	%r9, %rdi
	subq	%rsi, %rdi
	movq	-8(%r13,%rbx,8), %rsi
	movq	%rdi, %rdx
	negq	%rdx
	cmovs	%rdi, %rdx
	movq	%rsi, %rdi
	subq	%r9, %rdi
	addq	%rdx, %rax
	movq	%rdi, %rdx
	negq	%rdx
	movq	%rax, 0(%rbp,%rbx,8)
	cmovs	%rdi, %rdx
	addq	%rdx, %rax
	movq	%rax, -8(%rbp,%rbx,8)
	movq	%rcx, %rbx
	cmpq	%rcx, %r8
	jne	.L29
	.p2align 4,,10
	.p2align 3
.L11:
	movq	0(%r13,%rbx,8), %rdx
	subq	8(%r13,%rbx,8), %rdx
	movq	%rdx, %rax
	negq	%rax
	cmovs	%rdx, %rax
	addq	8(%rbp,%rbx,8), %rax
	movq	%rax, 0(%rbp,%rbx,8)
	subq	$1, %rbx
	jne	.L11
.L12:
	movl	$1, %r14d
	leaq	.LC1(%rip), %rbx
	.p2align 4,,10
	.p2align 3
.L15:
	movq	-8(%r13,%r14,8), %rax
	subq	8(%r13,%r14,8), %rax
	movq	%rbx, %rsi
	movl	$1, %edi
	movq	%rax, %rdx
	negq	%rdx
	cmovs	%rax, %rdx
	xorl	%eax, %eax
	addq	-8(%r12,%r14,8), %rdx
	addq	8(%rbp,%r14,8), %rdx
	call	__printf_chk@PLT
	addq	$1, %r14
	cmpq	%r14, (%rsp)
	jge	.L15
.L16:
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L30
	addq	$24, %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
.L4:
	.cfi_restore_state
	movq	$0, (%r12)
.L6:
	movq	$0, 8(%rbp,%rbx,8)
	cmpq	$0, (%rsp)
	jle	.L16
	jmp	.L12
.L19:
	movl	$1, %eax
	jmp	.L9
.L30:
	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	ABS
	.type	ABS, @function
ABS:
.LFB39:
	.cfi_startproc
	endbr64
	movq	%rdi, %rax
	negq	%rax
	cmovs	%rdi, %rax
	ret
	.cfi_endproc
.LFE39:
	.size	ABS, .-ABS
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%lld"
.LC1:
	.string	"%lld\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
	leaq	.LC0(%rip), %rdi
	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	$24, %rsp
	.cfi_def_cfa_offset 80
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %rsi
	call	__isoc99_scanf@PLT
	movq	(%rsp), %rbx
	leaq	16(,%rbx,8), %r14
	movq	%r14, %rdi
	call	malloc@PLT
	movq	%r14, %rdi
	movq	%rax, %r13
	call	malloc@PLT
	movq	%r14, %rdi
	movq	%rax, %r12
	call	malloc@PLT
	movq	$0, 0(%r13)
	movq	$0, -8(%r13,%r14)
	movq	%rax, %rbp
	testq	%rbx, %rbx
	jle	.L4
	leaq	8(%r13), %r15
	movl	$1, %r14d
	.p2align 4,,10
	.p2align 3
.L5:
	movq	%r15, %rsi
	leaq	.LC0(%rip), %rdi
	xorl	%eax, %eax
	addq	$1, %r14
	call	__isoc99_scanf@PLT
	movq	(%rsp), %rbx
	addq	$8, %r15
	cmpq	%r14, %rbx
	jge	.L5
	movq	$0, (%r12)
	testq	%rbx, %rbx
	jle	.L6
	cmpq	$2, %rbx
	jle	.L19
	leaq	-3(%rbx), %rax
	movq	0(%r13), %rsi
	xorl	%ecx, %ecx
	movl	$1, %edx
	andq	$-2, %rax
	addq	$3, %rax
.L8:
	movq	0(%r13,%rdx,8), %r9
	movq	%r9, %rdi
	subq	%rsi, %rdi
	movq	%rdi, %rsi
	negq	%rsi
	cmovs	%rdi, %rsi
	addq	%rsi, %rcx
	movq	8(%r13,%rdx,8), %rsi
	movq	%rcx, (%r12,%rdx,8)
	movq	%rsi, %r8
	subq	%r9, %r8
	movq	%r8, %rdi
	negq	%rdi
	cmovs	%r8, %rdi
	addq	%rdi, %rcx
	movq	%rcx, 8(%r12,%rdx,8)
	addq	$2, %rdx
	cmpq	%rax, %rdx
	jne	.L8
	.p2align 4,,10
	.p2align 3
.L9:
	movq	0(%r13,%rax,8), %rcx
	subq	-8(%r13,%rax,8), %rcx
	movq	%rcx, %rdx
	negq	%rdx
	cmovs	%rcx, %rdx
	addq	-8(%r12,%rax,8), %rdx
	movq	%rdx, (%r12,%rax,8)
	addq	$1, %rax
	cmpq	%rax, %rbx
	jge	.L9
	leaq	1(%rbx), %rax
	movq	$0, 0(%rbp,%rax,8)
	leaq	-8(,%rax,8), %rax
	leaq	0(%r13,%rax), %rdx
	addq	%rbp, %rax
	cmpq	$2, %rbx
	jle	.L11
	movq	8(%rdx), %rsi
	leaq	-2(%rbx), %rcx
	leaq	-3(%rbx), %rdx
	movq	8(%rax), %rax
	andq	$-2, %rdx
	movq	%rcx, %r8
	subq	%rdx, %r8
	jmp	.L13
	.p2align 4,,10
	.p2align 3
.L29:
	subq	$2, %rcx
.L13:
	movq	0(%r13,%rbx,8), %r9
	movq	%r9, %rdi
	subq	%rsi, %rdi
	movq	-8(%r13,%rbx,8), %rsi
	movq	%rdi, %rdx
	negq	%rdx
	cmovs	%rdi, %rdx
	movq	%rsi, %rdi
	subq	%r9, %rdi
	addq	%rdx, %rax
	movq	%rdi, %rdx
	negq	%rdx
	movq	%rax, 0(%rbp,%rbx,8)
	cmovs	%rdi, %rdx
	addq	%rdx, %rax
	movq	%rax, -8(%rbp,%rbx,8)
	movq	%rcx, %rbx
	cmpq	%rcx, %r8
	jne	.L29
	.p2align 4,,10
	.p2align 3
.L11:
	movq	0(%r13,%rbx,8), %rdx
	subq	8(%r13,%rbx,8), %rdx
	movq	%rdx, %rax
	negq	%rax
	cmovs	%rdx, %rax
	addq	8(%rbp,%rbx,8), %rax
	movq	%rax, 0(%rbp,%rbx,8)
	subq	$1, %rbx
	jne	.L11
.L12:
	movl	$1, %r14d
	leaq	.LC1(%rip), %rbx
	.p2align 4,,10
	.p2align 3
.L15:
	movq	-8(%r13,%r14,8), %rax
	subq	8(%r13,%r14,8), %rax
	movq	%rbx, %rsi
	movl	$1, %edi
	movq	%rax, %rdx
	negq	%rdx
	cmovs	%rax, %rdx
	xorl	%eax, %eax
	addq	-8(%r12,%r14,8), %rdx
	addq	8(%rbp,%r14,8), %rdx
	call	__printf_chk@PLT
	addq	$1, %r14
	cmpq	%r14, (%rsp)
	jge	.L15
.L16:
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L30
	addq	$24, %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
.L4:
	.cfi_restore_state
	movq	$0, (%r12)
.L6:
	movq	$0, 8(%rbp,%rbx,8)
	cmpq	$0, (%rsp)
	jle	.L16
	jmp	.L12
.L19:
	movl	$1, %eax
	jmp	.L9
.L30:
	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>
#define int long long

int ABS(int a){
	return a >= 0 ? a : -a;
}

signed main(){
	int N, i;
	scanf("%lld", &N);
	int *A = (int *)malloc(sizeof(int) * (N + 2));
	int *S = (int *)malloc(sizeof(int) * (N + 2));
	int *T = (int *)malloc(sizeof(int) * (N + 2));
	A[0] = 0;
	A[N + 1] = 0;
	for(i = 1; i <= N; i++){
		scanf("%lld", &A[i]);
	}
	S[0] = 0;
	for(i = 1; i <= N; i++){
		S[i] = S[i - 1] + ABS(A[i] - A[i - 1]);
	}
	T[N + 1] = 0;
	for(i = N; i > 0; i--){
		T[i] = T[i + 1] + ABS(A[i] - A[i + 1]);
	}
/*	for(i = 1; i <= N; i++){
		printf("S[%lld] = %lld\n", i, S[i]);
	}
	for(i = 1; i <= N; i++){
		printf("T[%lld] = %lld\n", i, T[i]);
	}
*/	for(i = 1; i <= N; i++){
		printf("%lld\n", S[i - 1] + ABS(A[i - 1] - A[i + 1]) + T[i + 1]);
	}
	return 0;
}
6
-679 -3431 -3258 3095 -3291 -4462
 5
1 1 0 2 0
 3
2 5 -1
 6
-679 -3431 -3258 3095 -3291 -2101
 5
1 0 0 2 0
 3
2 5 -2
 6
-679 -3431 -3258 3095 -4122 -2101
 5
1 0 0 2 1
 3
3 5 -2
 6
-679 -52 -3258 3095 -4122 -2101

21976
21630
21976
9270
21976
19634
 6
6
4
2
6
 12
6
10
 19634
19288
19634
6928
17254
19634
 4
6
6
2
6
 14
8
10
 21296
20950
21296
8590
17254
21296
 4
6
6
4
6
 14
10
10
 20950
20950
15792
9498
18162
22204

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>
#define int long long

int ABS(int a){
	return a >= 0 ? a : -a;
}

signed main(){
	int N, i;
	scanf("%lld", &N);
	int *A = (int *)malloc(sizeof(int) * (N + 2));
	int *S = (int *)malloc(sizeof(int) * (N + 2));
	int *T = (int *)malloc(sizeof(int) * (N + 2));
	A[0] = 0;
	A[N + 1] = 0;
	for(i = 1; i <= N; i++){
		scanf("%lld", &A[i]);
	}
	S[0] = 0;
	for(i = 1; i <= N; i++){
		S[i] = S[i - 1] + ABS(A[i] - A[i - 1]);
	}
	T[N + 1] = 0;
	for(i = N; i > 0; i--){
		T[i] = T[i + 1] + ABS(A[i] - A[i + 1]);
	}
/*	for(i = 1; i <= N; i++){
		printf("S[%lld] = %lld\n", i, S[i]);
	}
	for(i = 1; i <= N; i++){
		printf("T[%lld] = %lld\n", i, T[i]);
	}
*/	for(i = 1; i <= N; i++){
		printf("%lld\n", S[i - 1] + ABS(A[i - 1] - A[i + 1]) + T[i + 1]);
	}
	return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	ABS
	.type	ABS, @function
ABS:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -8(%rbp)
	movq	-8(%rbp), %rax
	movq	%rax, %rdx
	negq	%rdx
	cmovns	%rdx, %rax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	ABS, .-ABS
	.section	.rodata
.LC0:
	.string	"%lld"
.LC1:
	.string	"%lld\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
	subq	$56, %rsp
	.cfi_offset 3, -24
	movq	%fs:40, %rax
	movq	%rax, -24(%rbp)
	xorl	%eax, %eax
	leaq	-64(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	-64(%rbp), %rax
	addq	$2, %rax
	salq	$3, %rax
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -48(%rbp)
	movq	-64(%rbp), %rax
	addq	$2, %rax
	salq	$3, %rax
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -40(%rbp)
	movq	-64(%rbp), %rax
	addq	$2, %rax
	salq	$3, %rax
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -32(%rbp)
	movq	-48(%rbp), %rax
	movq	$0, (%rax)
	movq	-64(%rbp), %rax
	addq	$1, %rax
	leaq	0(,%rax,8), %rdx
	movq	-48(%rbp), %rax
	addq	%rdx, %rax
	movq	$0, (%rax)
	movq	$1, -56(%rbp)
	jmp	.L4
.L5:
	movq	-56(%rbp), %rax
	leaq	0(,%rax,8), %rdx
	movq	-48(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addq	$1, -56(%rbp)
.L4:
	movq	-64(%rbp), %rax
	cmpq	%rax, -56(%rbp)
	jle	.L5
	movq	-40(%rbp), %rax
	movq	$0, (%rax)
	movq	$1, -56(%rbp)
	jmp	.L6
.L7:
	movq	-56(%rbp), %rax
	salq	$3, %rax
	leaq	-8(%rax), %rdx
	movq	-40(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rbx
	movq	-56(%rbp), %rax
	leaq	0(,%rax,8), %rdx
	movq	-48(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rax
	movq	-56(%rbp), %rdx
	salq	$3, %rdx
	leaq	-8(%rdx), %rcx
	movq	-48(%rbp), %rdx
	addq	%rcx, %rdx
	movq	(%rdx), %rdx
	subq	%rdx, %rax
	movq	%rax, %rdi
	call	ABS
	movq	%rax, %rdx
	movq	-56(%rbp), %rax
	leaq	0(,%rax,8), %rcx
	movq	-40(%rbp), %rax
	addq	%rcx, %rax
	addq	%rbx, %rdx
	movq	%rdx, (%rax)
	addq	$1, -56(%rbp)
.L6:
	movq	-64(%rbp), %rax
	cmpq	%rax, -56(%rbp)
	jle	.L7
	movq	-64(%rbp), %rax
	addq	$1, %rax
	leaq	0(,%rax,8), %rdx
	movq	-32(%rbp), %rax
	addq	%rdx, %rax
	movq	$0, (%rax)
	movq	-64(%rbp), %rax
	movq	%rax, -56(%rbp)
	jmp	.L8
.L9:
	movq	-56(%rbp), %rax
	addq	$1, %rax
	leaq	0(,%rax,8), %rdx
	movq	-32(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rbx
	movq	-56(%rbp), %rax
	leaq	0(,%rax,8), %rdx
	movq	-48(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rax
	movq	-56(%rbp), %rdx
	addq	$1, %rdx
	leaq	0(,%rdx,8), %rcx
	movq	-48(%rbp), %rdx
	addq	%rcx, %rdx
	movq	(%rdx), %rdx
	subq	%rdx, %rax
	movq	%rax, %rdi
	call	ABS
	movq	%rax, %rdx
	movq	-56(%rbp), %rax
	leaq	0(,%rax,8), %rcx
	movq	-32(%rbp), %rax
	addq	%rcx, %rax
	addq	%rbx, %rdx
	movq	%rdx, (%rax)
	subq	$1, -56(%rbp)
.L8:
	cmpq	$0, -56(%rbp)
	jg	.L9
	movq	$1, -56(%rbp)
	jmp	.L10
.L11:
	movq	-56(%rbp), %rax
	salq	$3, %rax
	leaq	-8(%rax), %rdx
	movq	-40(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rbx
	movq	-56(%rbp), %rax
	salq	$3, %rax
	leaq	-8(%rax), %rdx
	movq	-48(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rax
	movq	-56(%rbp), %rdx
	addq	$1, %rdx
	leaq	0(,%rdx,8), %rcx
	movq	-48(%rbp), %rdx
	addq	%rcx, %rdx
	movq	(%rdx), %rdx
	subq	%rdx, %rax
	movq	%rax, %rdi
	call	ABS
	leaq	(%rbx,%rax), %rdx
	movq	-56(%rbp), %rax
	addq	$1, %rax
	leaq	0(,%rax,8), %rcx
	movq	-32(%rbp), %rax
	addq	%rcx, %rax
	movq	(%rax), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	addq	$1, -56(%rbp)
.L10:
	movq	-64(%rbp), %rax
	cmpq	%rax, -56(%rbp)
	jle	.L11
	movl	$0, %eax
	movq	-24(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L13
	call	__stack_chk_fail@PLT
.L13:
	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	ABS
	.type	ABS, @function
ABS:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movq	%rdi, -8(%rbp)
	movq	-8(%rbp), %rax
	movq	%rax, %rdx
	negq	%rdx
	cmovns	%rdx, %rax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	ABS, .-ABS
	.section	.rodata
.LC0:
	.string	"%lld"
.LC1:
	.string	"%lld\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
	subq	$56, %rsp
	.cfi_offset 3, -24
	movq	%fs:40, %rax
	movq	%rax, -24(%rbp)
	xorl	%eax, %eax
	leaq	-64(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	-64(%rbp), %rax
	addq	$2, %rax
	salq	$3, %rax
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -48(%rbp)
	movq	-64(%rbp), %rax
	addq	$2, %rax
	salq	$3, %rax
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -40(%rbp)
	movq	-64(%rbp), %rax
	addq	$2, %rax
	salq	$3, %rax
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -32(%rbp)
	movq	-48(%rbp), %rax
	movq	$0, (%rax)
	movq	-64(%rbp), %rax
	addq	$1, %rax
	leaq	0(,%rax,8), %rdx
	movq	-48(%rbp), %rax
	addq	%rdx, %rax
	movq	$0, (%rax)
	movq	$1, -56(%rbp)
	jmp	.L4
.L5:
	movq	-56(%rbp), %rax
	leaq	0(,%rax,8), %rdx
	movq	-48(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addq	$1, -56(%rbp)
.L4:
	movq	-64(%rbp), %rax
	cmpq	%rax, -56(%rbp)
	jle	.L5
	movq	-40(%rbp), %rax
	movq	$0, (%rax)
	movq	$1, -56(%rbp)
	jmp	.L6
.L7:
	movq	-56(%rbp), %rax
	salq	$3, %rax
	leaq	-8(%rax), %rdx
	movq	-40(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rbx
	movq	-56(%rbp), %rax
	leaq	0(,%rax,8), %rdx
	movq	-48(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rax
	movq	-56(%rbp), %rdx
	salq	$3, %rdx
	leaq	-8(%rdx), %rcx
	movq	-48(%rbp), %rdx
	addq	%rcx, %rdx
	movq	(%rdx), %rdx
	subq	%rdx, %rax
	movq	%rax, %rdi
	call	ABS
	movq	%rax, %rdx
	movq	-56(%rbp), %rax
	leaq	0(,%rax,8), %rcx
	movq	-40(%rbp), %rax
	addq	%rcx, %rax
	addq	%rbx, %rdx
	movq	%rdx, (%rax)
	addq	$1, -56(%rbp)
.L6:
	movq	-64(%rbp), %rax
	cmpq	%rax, -56(%rbp)
	jle	.L7
	movq	-64(%rbp), %rax
	addq	$1, %rax
	leaq	0(,%rax,8), %rdx
	movq	-32(%rbp), %rax
	addq	%rdx, %rax
	movq	$0, (%rax)
	movq	-64(%rbp), %rax
	movq	%rax, -56(%rbp)
	jmp	.L8
.L9:
	movq	-56(%rbp), %rax
	addq	$1, %rax
	leaq	0(,%rax,8), %rdx
	movq	-32(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rbx
	movq	-56(%rbp), %rax
	leaq	0(,%rax,8), %rdx
	movq	-48(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rax
	movq	-56(%rbp), %rdx
	addq	$1, %rdx
	leaq	0(,%rdx,8), %rcx
	movq	-48(%rbp), %rdx
	addq	%rcx, %rdx
	movq	(%rdx), %rdx
	subq	%rdx, %rax
	movq	%rax, %rdi
	call	ABS
	movq	%rax, %rdx
	movq	-56(%rbp), %rax
	leaq	0(,%rax,8), %rcx
	movq	-32(%rbp), %rax
	addq	%rcx, %rax
	addq	%rbx, %rdx
	movq	%rdx, (%rax)
	subq	$1, -56(%rbp)
.L8:
	cmpq	$0, -56(%rbp)
	jg	.L9
	movq	$1, -56(%rbp)
	jmp	.L10
.L11:
	movq	-56(%rbp), %rax
	salq	$3, %rax
	leaq	-8(%rax), %rdx
	movq	-40(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rbx
	movq	-56(%rbp), %rax
	salq	$3, %rax
	leaq	-8(%rax), %rdx
	movq	-48(%rbp), %rax
	addq	%rdx, %rax
	movq	(%rax), %rax
	movq	-56(%rbp), %rdx
	addq	$1, %rdx
	leaq	0(,%rdx,8), %rcx
	movq	-48(%rbp), %rdx
	addq	%rcx, %rdx
	movq	(%rdx), %rdx
	subq	%rdx, %rax
	movq	%rax, %rdi
	call	ABS
	leaq	(%rbx,%rax), %rdx
	movq	-56(%rbp), %rax
	addq	$1, %rax
	leaq	0(,%rax,8), %rcx
	movq	-32(%rbp), %rax
	addq	%rcx, %rax
	movq	(%rax), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	addq	$1, -56(%rbp)
.L10:
	movq	-64(%rbp), %rax
	cmpq	%rax, -56(%rbp)
	jle	.L11
	movl	$0, %eax
	movq	-24(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L13
	call	__stack_chk_fail@PLT
.L13:
	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:
