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 max(a,b) ((a)>(b)?(a):(b))

int compare_int(const void *a,const void *b){
	return *(long long*)a-*(long long*)b;
}

int main(){
	int n,i;
	long long a[100000],ans=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%lld",&a[i]);
	qsort(a,n,sizeof(long long),compare_int);
	if(n%2==0){
		for(i=0;i<n;i++){
			if(i<n/2){
				if(i==n/2-1)ans-=a[i];
				else ans-=2*a[i];
			}
			else{
				if(i==n/2)ans+=a[i];
				else ans+=2*a[i];
			}
		}
	}else{
		long long ans2=0;
		for(i=0;i<n;i++){
			if(i<n/2){
				ans-=2*a[i];
			}
			else{
				if(i<=n/2+1)ans+=a[i];
				else ans+=2*a[i];
			}
		}
		for(i=0;i<n;i++){
			if(i<=n/2){
				if(i>=n/2-1)ans2-=a[i];
				else ans2-=2*a[i];
			}
			else{
				ans2+=2*a[i];
			}
		}
		ans=max(ans,ans2);
	}
	printf("%lld\n",ans);
	return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	compare_int
	.type	compare_int, @function
compare_int:
.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	%rsi, -16(%rbp)
	movq	-8(%rbp), %rax
	movq	(%rax), %rax
	movl	%eax, %edx
	movq	-16(%rbp), %rax
	movq	(%rax), %rax
	movl	%eax, %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	compare_int, .-compare_int
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%lld"
.LC2:
	.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
	leaq	-798720(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$1328, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movq	$0, -800032(%rbp)
	leaq	-800040(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -800036(%rbp)
	jmp	.L4
.L5:
	leaq	-800016(%rbp), %rdx
	movl	-800036(%rbp), %eax
	cltq
	salq	$3, %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -800036(%rbp)
.L4:
	movl	-800040(%rbp), %eax
	cmpl	%eax, -800036(%rbp)
	jl	.L5
	movl	-800040(%rbp), %eax
	movslq	%eax, %rsi
	leaq	-800016(%rbp), %rax
	leaq	compare_int(%rip), %rdx
	movq	%rdx, %rcx
	movl	$8, %edx
	movq	%rax, %rdi
	call	qsort@PLT
	movl	-800040(%rbp), %eax
	andl	$1, %eax
	testl	%eax, %eax
	jne	.L6
	movl	$0, -800036(%rbp)
	jmp	.L7
.L12:
	movl	-800040(%rbp), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	cmpl	%eax, -800036(%rbp)
	jge	.L8
	movl	-800040(%rbp), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	subl	$1, %eax
	cmpl	%eax, -800036(%rbp)
	jne	.L9
	movl	-800036(%rbp), %eax
	cltq
	movq	-800016(%rbp,%rax,8), %rax
	subq	%rax, -800032(%rbp)
	jmp	.L10
.L9:
	movl	-800036(%rbp), %eax
	cltq
	movq	-800016(%rbp,%rax,8), %rax
	addq	%rax, %rax
	subq	%rax, -800032(%rbp)
	jmp	.L10
.L8:
	movl	-800040(%rbp), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	cmpl	%eax, -800036(%rbp)
	jne	.L11
	movl	-800036(%rbp), %eax
	cltq
	movq	-800016(%rbp,%rax,8), %rax
	addq	%rax, -800032(%rbp)
	jmp	.L10
.L11:
	movl	-800036(%rbp), %eax
	cltq
	movq	-800016(%rbp,%rax,8), %rax
	addq	%rax, %rax
	addq	%rax, -800032(%rbp)
.L10:
	addl	$1, -800036(%rbp)
.L7:
	movl	-800040(%rbp), %eax
	cmpl	%eax, -800036(%rbp)
	jl	.L12
	jmp	.L13
.L6:
	movq	$0, -800024(%rbp)
	movl	$0, -800036(%rbp)
	jmp	.L14
.L18:
	movl	-800040(%rbp), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	cmpl	%eax, -800036(%rbp)
	jge	.L15
	movl	-800036(%rbp), %eax
	cltq
	movq	-800016(%rbp,%rax,8), %rax
	addq	%rax, %rax
	subq	%rax, -800032(%rbp)
	jmp	.L16
.L15:
	movl	-800040(%rbp), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	addl	$1, %eax
	cmpl	%eax, -800036(%rbp)
	jg	.L17
	movl	-800036(%rbp), %eax
	cltq
	movq	-800016(%rbp,%rax,8), %rax
	addq	%rax, -800032(%rbp)
	jmp	.L16
.L17:
	movl	-800036(%rbp), %eax
	cltq
	movq	-800016(%rbp,%rax,8), %rax
	addq	%rax, %rax
	addq	%rax, -800032(%rbp)
.L16:
	addl	$1, -800036(%rbp)
.L14:
	movl	-800040(%rbp), %eax
	cmpl	%eax, -800036(%rbp)
	jl	.L18
	movl	$0, -800036(%rbp)
	jmp	.L19
.L23:
	movl	-800040(%rbp), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	cmpl	%eax, -800036(%rbp)
	jg	.L20
	movl	-800040(%rbp), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	subl	$1, %eax
	cmpl	%eax, -800036(%rbp)
	jl	.L21
	movl	-800036(%rbp), %eax
	cltq
	movq	-800016(%rbp,%rax,8), %rax
	subq	%rax, -800024(%rbp)
	jmp	.L22
.L21:
	movl	-800036(%rbp), %eax
	cltq
	movq	-800016(%rbp,%rax,8), %rax
	addq	%rax, %rax
	subq	%rax, -800024(%rbp)
	jmp	.L22
.L20:
	movl	-800036(%rbp), %eax
	cltq
	movq	-800016(%rbp,%rax,8), %rax
	addq	%rax, %rax
	addq	%rax, -800024(%rbp)
.L22:
	addl	$1, -800036(%rbp)
.L19:
	movl	-800040(%rbp), %eax
	cmpl	%eax, -800036(%rbp)
	jl	.L23
	movq	-800032(%rbp), %rdx
	movq	-800024(%rbp), %rax
	cmpq	%rax, %rdx
	cmovge	%rdx, %rax
	movq	%rax, -800032(%rbp)
.L13:
	movq	-800032(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L25
	call	__stack_chk_fail@PLT
.L25:
	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	compare_int
	.type	compare_int, @function
compare_int:
.LFB39:
	.cfi_startproc
	endbr64
	movq	(%rdi), %rax
	subl	(%rsi), %eax
	ret
	.cfi_endproc
.LFE39:
	.size	compare_int, .-compare_int
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d"
.LC1:
	.string	"%lld"
.LC2:
	.string	"%lld\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB40:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	leaq	-798720(%rsp), %r11
	.cfi_def_cfa 11, 798760
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$1320, %rsp
	.cfi_def_cfa_offset 800080
	leaq	.LC0(%rip), %rdi
	xorl	%ebx, %ebx
	leaq	.LC1(%rip), %r13
	movq	%fs:40, %rax
	movq	%rax, 800024(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rsi
	leaq	16(%rsp), %rbp
	movq	%rbp, %r12
	call	__isoc99_scanf@PLT
	movslq	12(%rsp), %rsi
	testl	%esi, %esi
	jle	.L4
	.p2align 4,,10
	.p2align 3
.L5:
	movq	%r12, %rsi
	movq	%r13, %rdi
	xorl	%eax, %eax
	addl	$1, %ebx
	call	__isoc99_scanf@PLT
	movslq	12(%rsp), %rsi
	addq	$8, %r12
	cmpl	%ebx, %esi
	jg	.L5
.L4:
	leaq	compare_int(%rip), %rcx
	movl	$8, %edx
	movq	%rbp, %rdi
	call	qsort@PLT
	movl	12(%rsp), %esi
	testb	$1, %sil
	je	.L6
	xorl	%ecx, %ecx
	xorl	%edx, %edx
	testl	%esi, %esi
	jle	.L8
	movl	%esi, %r10d
	movl	$0, %eax
	movl	$0, %ecx
	sarl	%r10d
	leal	1(%r10), %r8d
	je	.L19
	cmpl	%r10d, %esi
	movl	%r10d, %r9d
	movq	%rbp, %rdi
	cmovle	%esi, %r9d
	.p2align 4,,10
	.p2align 3
.L20:
	movq	(%rdi), %rbx
	addl	$1, %eax
	addq	$8, %rdi
	leaq	(%rbx,%rbx), %rdx
	subq	%rdx, %rcx
	cmpl	%r9d, %eax
	jl	.L20
	cmpl	%eax, %esi
	jle	.L25
.L19:
	cltq
	.p2align 4,,10
	.p2align 3
.L24:
	movq	0(%rbp,%rax,8), %rdx
	leaq	(%rcx,%rdx,2), %rdi
	addq	%rcx, %rdx
	cmpl	%eax, %r8d
	movq	%rdi, %rcx
	cmovge	%rdx, %rcx
	addq	$1, %rax
	cmpl	%eax, %esi
	jg	.L24
.L25:
	leal	-1(%rsi), %r11d
	leal	-1(%r10), %ebx
	movq	%rbp, %rdi
	cmpl	%r10d, %r11d
	cmovg	%r10d, %r11d
	xorl	%edx, %edx
	xorl	%eax, %eax
	.p2align 4,,10
	.p2align 3
.L29:
	movq	(%rdi), %r8
	movq	%rdx, %r9
	leaq	(%r8,%r8), %r10
	subq	%r8, %rdx
	subq	%r10, %r9
	cmpl	%eax, %ebx
	cmovg	%r9, %rdx
	addl	$1, %eax
	addq	$8, %rdi
	cmpl	%eax, %r11d
	jge	.L29
	movslq	%eax, %rdi
	cmpl	%eax, %esi
	jle	.L8
	.p2align 4,,10
	.p2align 3
.L31:
	movq	0(%rbp,%rdi,8), %rax
	addq	$1, %rdi
	leaq	(%rdx,%rax,2), %rdx
	cmpl	%edi, %esi
	jg	.L31
.L8:
	cmpq	%rdx, %rcx
	cmovge	%rcx, %rdx
.L9:
	xorl	%eax, %eax
	leaq	.LC2(%rip), %rsi
	movl	$1, %edi
	call	__printf_chk@PLT
	movq	800024(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L52
	addq	$800040, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 40
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
.L6:
	.cfi_restore_state
	testl	%esi, %esi
	jle	.L34
	movl	%esi, %r8d
	movl	$0, %eax
	movl	$0, %edx
	sarl	%r8d
	leal	-1(%r8), %r9d
	je	.L10
	cmpl	%r8d, %esi
	movl	%r8d, %r10d
	movq	%rbp, %rdi
	cmovle	%esi, %r10d
	.p2align 4,,10
	.p2align 3
.L11:
	movq	(%rdi), %rcx
	cmpl	%eax, %r9d
	je	.L12
	addq	%rcx, %rcx
	addl	$1, %eax
	addq	$8, %rdi
	subq	%rcx, %rdx
	cmpl	%eax, %r10d
	jg	.L11
.L14:
	cmpl	%eax, %esi
	jle	.L9
.L10:
	cltq
	.p2align 4,,10
	.p2align 3
.L17:
	movq	0(%rbp,%rax,8), %rcx
	leaq	(%rdx,%rcx,2), %rdi
	addq	%rcx, %rdx
	cmpl	%eax, %r8d
	cmovne	%rdi, %rdx
	addq	$1, %rax
	cmpl	%eax, %esi
	jg	.L17
	jmp	.L9
	.p2align 4,,10
	.p2align 3
.L12:
	leal	1(%r9), %eax
	subq	%rcx, %rdx
	addq	$8, %rdi
	cmpl	%eax, %r10d
	jg	.L11
	jmp	.L14
.L34:
	xorl	%edx, %edx
	jmp	.L9
.L52:
	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	compare_int
	.type	compare_int, @function
compare_int:
.LFB39:
	.cfi_startproc
	endbr64
	movq	(%rdi), %rax
	subl	(%rsi), %eax
	ret
	.cfi_endproc
.LFE39:
	.size	compare_int, .-compare_int
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d"
.LC1:
	.string	"%lld"
.LC2:
	.string	"%lld\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB40:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	leaq	-798720(%rsp), %r11
	.cfi_def_cfa 11, 798760
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$1320, %rsp
	.cfi_def_cfa_offset 800080
	leaq	.LC0(%rip), %rdi
	xorl	%ebx, %ebx
	leaq	.LC1(%rip), %r13
	movq	%fs:40, %rax
	movq	%rax, 800024(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rsi
	leaq	16(%rsp), %rbp
	movq	%rbp, %r12
	call	__isoc99_scanf@PLT
	movslq	12(%rsp), %rsi
	testl	%esi, %esi
	jle	.L4
	.p2align 4,,10
	.p2align 3
.L5:
	movq	%r12, %rsi
	movq	%r13, %rdi
	xorl	%eax, %eax
	addl	$1, %ebx
	call	__isoc99_scanf@PLT
	movslq	12(%rsp), %rsi
	addq	$8, %r12
	cmpl	%ebx, %esi
	jg	.L5
.L4:
	leaq	compare_int(%rip), %rcx
	movl	$8, %edx
	movq	%rbp, %rdi
	call	qsort@PLT
	movl	12(%rsp), %esi
	testb	$1, %sil
	je	.L6
	xorl	%ecx, %ecx
	xorl	%edx, %edx
	testl	%esi, %esi
	jle	.L8
	movl	%esi, %r10d
	movl	$0, %eax
	movl	$0, %ecx
	sarl	%r10d
	leal	1(%r10), %r8d
	je	.L19
	cmpl	%r10d, %esi
	movl	%r10d, %r9d
	movq	%rbp, %rdi
	cmovle	%esi, %r9d
	.p2align 4,,10
	.p2align 3
.L20:
	movq	(%rdi), %rbx
	addl	$1, %eax
	addq	$8, %rdi
	leaq	(%rbx,%rbx), %rdx
	subq	%rdx, %rcx
	cmpl	%r9d, %eax
	jl	.L20
	cmpl	%eax, %esi
	jle	.L25
.L19:
	cltq
	.p2align 4,,10
	.p2align 3
.L24:
	movq	0(%rbp,%rax,8), %rdx
	leaq	(%rcx,%rdx,2), %rdi
	addq	%rcx, %rdx
	cmpl	%eax, %r8d
	movq	%rdi, %rcx
	cmovge	%rdx, %rcx
	addq	$1, %rax
	cmpl	%eax, %esi
	jg	.L24
.L25:
	leal	-1(%rsi), %r11d
	leal	-1(%r10), %ebx
	movq	%rbp, %rdi
	cmpl	%r10d, %r11d
	cmovg	%r10d, %r11d
	xorl	%edx, %edx
	xorl	%eax, %eax
	.p2align 4,,10
	.p2align 3
.L29:
	movq	(%rdi), %r8
	movq	%rdx, %r9
	leaq	(%r8,%r8), %r10
	subq	%r8, %rdx
	subq	%r10, %r9
	cmpl	%eax, %ebx
	cmovg	%r9, %rdx
	addl	$1, %eax
	addq	$8, %rdi
	cmpl	%eax, %r11d
	jge	.L29
	movslq	%eax, %rdi
	cmpl	%eax, %esi
	jle	.L8
	.p2align 4,,10
	.p2align 3
.L31:
	movq	0(%rbp,%rdi,8), %rax
	addq	$1, %rdi
	leaq	(%rdx,%rax,2), %rdx
	cmpl	%edi, %esi
	jg	.L31
.L8:
	cmpq	%rdx, %rcx
	cmovge	%rcx, %rdx
.L9:
	xorl	%eax, %eax
	leaq	.LC2(%rip), %rsi
	movl	$1, %edi
	call	__printf_chk@PLT
	movq	800024(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L52
	addq	$800040, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 40
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
.L6:
	.cfi_restore_state
	testl	%esi, %esi
	jle	.L34
	movl	%esi, %r8d
	movl	$0, %eax
	movl	$0, %edx
	sarl	%r8d
	leal	-1(%r8), %r9d
	je	.L10
	cmpl	%r8d, %esi
	movl	%r8d, %r10d
	movq	%rbp, %rdi
	cmovle	%esi, %r10d
	.p2align 4,,10
	.p2align 3
.L11:
	movq	(%rdi), %rcx
	cmpl	%eax, %r9d
	je	.L12
	addq	%rcx, %rcx
	addl	$1, %eax
	addq	$8, %rdi
	subq	%rcx, %rdx
	cmpl	%eax, %r10d
	jg	.L11
.L14:
	cmpl	%eax, %esi
	jle	.L9
.L10:
	cltq
	.p2align 4,,10
	.p2align 3
.L17:
	movq	0(%rbp,%rax,8), %rcx
	leaq	(%rdx,%rcx,2), %rdi
	addq	%rcx, %rdx
	cmpl	%eax, %r8d
	cmovne	%rdi, %rdx
	addq	$1, %rax
	cmpl	%eax, %esi
	jg	.L17
	jmp	.L9
	.p2align 4,,10
	.p2align 3
.L12:
	leal	1(%r9), %eax
	subq	%rcx, %rdx
	addq	$8, %rdi
	cmpl	%eax, %r10d
	jg	.L11
	jmp	.L14
.L34:
	xorl	%edx, %edx
	jmp	.L9
.L52:
	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 max(a,b) ((a)>(b)?(a):(b))

int compare_int(const void *a,const void *b){
	return *(long long*)a-*(long long*)b;
}

int main(){
	int n,i;
	long long a[100000],ans=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%lld",&a[i]);
	qsort(a,n,sizeof(long long),compare_int);
	if(n%2==0){
		for(i=0;i<n;i++){
			if(i<n/2){
				if(i==n/2-1)ans-=a[i];
				else ans-=2*a[i];
			}
			else{
				if(i==n/2)ans+=a[i];
				else ans+=2*a[i];
			}
		}
	}else{
		long long ans2=0;
		for(i=0;i<n;i++){
			if(i<n/2){
				ans-=2*a[i];
			}
			else{
				if(i<=n/2+1)ans+=a[i];
				else ans+=2*a[i];
			}
		}
		for(i=0;i<n;i++){
			if(i<=n/2){
				if(i>=n/2-1)ans2-=a[i];
				else ans2-=2*a[i];
			}
			else{
				ans2+=2*a[i];
			}
		}
		ans=max(ans,ans2);
	}
	printf("%lld\n",ans);
	return 0;
}
3
5
6
1
 6
6
1
4
1
5
9
 5
6
8
1
1
3
 3
5
3
1
 6
6
1
4
1
1
9
 5
6
4
1
1
3
 3
0
3
1
 6
6
1
7
1
1
9
 5
6
4
1
2
3
 3
0
0
1

9
 27
 22
 6
 29
 15
 5
 33
 13
 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>

#define max(a,b) ((a)>(b)?(a):(b))

int compare_int(const void *a,const void *b){
	return *(long long*)a-*(long long*)b;
}

int main(){
	int n,i;
	long long a[100000],ans=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%lld",&a[i]);
	qsort(a,n,sizeof(long long),compare_int);
	if(n%2==0){
		for(i=0;i<n;i++){
			if(i<n/2){
				if(i==n/2-1)ans-=a[i];
				else ans-=2*a[i];
			}
			else{
				if(i==n/2)ans+=a[i];
				else ans+=2*a[i];
			}
		}
	}else{
		long long ans2=0;
		for(i=0;i<n;i++){
			if(i<n/2){
				ans-=2*a[i];
			}
			else{
				if(i<=n/2+1)ans+=a[i];
				else ans+=2*a[i];
			}
		}
		for(i=0;i<n;i++){
			if(i<=n/2){
				if(i>=n/2-1)ans2-=a[i];
				else ans2-=2*a[i];
			}
			else{
				ans2+=2*a[i];
			}
		}
		ans=max(ans,ans2);
	}
	printf("%lld\n",ans);
	return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	compare_int
	.type	compare_int, @function
compare_int:
.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	%rsi, -16(%rbp)
	movq	-8(%rbp), %rax
	movq	(%rax), %rax
	movl	%eax, %edx
	movq	-16(%rbp), %rax
	movq	(%rax), %rax
	movl	%eax, %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	compare_int, .-compare_int
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%lld"
.LC2:
	.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
	leaq	-798720(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$1328, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movq	$0, -800032(%rbp)
	leaq	-800040(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -800036(%rbp)
	jmp	.L4
.L5:
	leaq	-800016(%rbp), %rdx
	movl	-800036(%rbp), %eax
	cltq
	salq	$3, %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -800036(%rbp)
.L4:
	movl	-800040(%rbp), %eax
	cmpl	%eax, -800036(%rbp)
	jl	.L5
	movl	-800040(%rbp), %eax
	movslq	%eax, %rsi
	leaq	-800016(%rbp), %rax
	leaq	compare_int(%rip), %rdx
	movq	%rdx, %rcx
	movl	$8, %edx
	movq	%rax, %rdi
	call	qsort@PLT
	movl	-800040(%rbp), %eax
	andl	$1, %eax
	testl	%eax, %eax
	jne	.L6
	movl	$0, -800036(%rbp)
	jmp	.L7
.L12:
	movl	-800040(%rbp), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	cmpl	%eax, -800036(%rbp)
	jge	.L8
	movl	-800040(%rbp), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	subl	$1, %eax
	cmpl	%eax, -800036(%rbp)
	jne	.L9
	movl	-800036(%rbp), %eax
	cltq
	movq	-800016(%rbp,%rax,8), %rax
	subq	%rax, -800032(%rbp)
	jmp	.L10
.L9:
	movl	-800036(%rbp), %eax
	cltq
	movq	-800016(%rbp,%rax,8), %rax
	addq	%rax, %rax
	subq	%rax, -800032(%rbp)
	jmp	.L10
.L8:
	movl	-800040(%rbp), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	cmpl	%eax, -800036(%rbp)
	jne	.L11
	movl	-800036(%rbp), %eax
	cltq
	movq	-800016(%rbp,%rax,8), %rax
	addq	%rax, -800032(%rbp)
	jmp	.L10
.L11:
	movl	-800036(%rbp), %eax
	cltq
	movq	-800016(%rbp,%rax,8), %rax
	addq	%rax, %rax
	addq	%rax, -800032(%rbp)
.L10:
	addl	$1, -800036(%rbp)
.L7:
	movl	-800040(%rbp), %eax
	cmpl	%eax, -800036(%rbp)
	jl	.L12
	jmp	.L13
.L6:
	movq	$0, -800024(%rbp)
	movl	$0, -800036(%rbp)
	jmp	.L14
.L18:
	movl	-800040(%rbp), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	cmpl	%eax, -800036(%rbp)
	jge	.L15
	movl	-800036(%rbp), %eax
	cltq
	movq	-800016(%rbp,%rax,8), %rax
	addq	%rax, %rax
	subq	%rax, -800032(%rbp)
	jmp	.L16
.L15:
	movl	-800040(%rbp), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	addl	$1, %eax
	cmpl	%eax, -800036(%rbp)
	jg	.L17
	movl	-800036(%rbp), %eax
	cltq
	movq	-800016(%rbp,%rax,8), %rax
	addq	%rax, -800032(%rbp)
	jmp	.L16
.L17:
	movl	-800036(%rbp), %eax
	cltq
	movq	-800016(%rbp,%rax,8), %rax
	addq	%rax, %rax
	addq	%rax, -800032(%rbp)
.L16:
	addl	$1, -800036(%rbp)
.L14:
	movl	-800040(%rbp), %eax
	cmpl	%eax, -800036(%rbp)
	jl	.L18
	movl	$0, -800036(%rbp)
	jmp	.L19
.L23:
	movl	-800040(%rbp), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	cmpl	%eax, -800036(%rbp)
	jg	.L20
	movl	-800040(%rbp), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	subl	$1, %eax
	cmpl	%eax, -800036(%rbp)
	jl	.L21
	movl	-800036(%rbp), %eax
	cltq
	movq	-800016(%rbp,%rax,8), %rax
	subq	%rax, -800024(%rbp)
	jmp	.L22
.L21:
	movl	-800036(%rbp), %eax
	cltq
	movq	-800016(%rbp,%rax,8), %rax
	addq	%rax, %rax
	subq	%rax, -800024(%rbp)
	jmp	.L22
.L20:
	movl	-800036(%rbp), %eax
	cltq
	movq	-800016(%rbp,%rax,8), %rax
	addq	%rax, %rax
	addq	%rax, -800024(%rbp)
.L22:
	addl	$1, -800036(%rbp)
.L19:
	movl	-800040(%rbp), %eax
	cmpl	%eax, -800036(%rbp)
	jl	.L23
	movq	-800032(%rbp), %rdx
	movq	-800024(%rbp), %rax
	cmpq	%rax, %rdx
	cmovge	%rdx, %rax
	movq	%rax, -800032(%rbp)
.L13:
	movq	-800032(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L25
	call	__stack_chk_fail@PLT
.L25:
	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	compare_int
	.type	compare_int, @function
compare_int:
.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	%rsi, -16(%rbp)
	movq	-8(%rbp), %rax
	movq	(%rax), %rax
	movl	%eax, %edx
	movq	-16(%rbp), %rax
	movq	(%rax), %rax
	movl	%eax, %ecx
	movl	%edx, %eax
	subl	%ecx, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	compare_int, .-compare_int
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%lld"
.LC2:
	.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
	leaq	-798720(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$1328, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movq	$0, -800032(%rbp)
	leaq	-800040(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -800036(%rbp)
	jmp	.L4
.L5:
	leaq	-800016(%rbp), %rdx
	movl	-800036(%rbp), %eax
	cltq
	salq	$3, %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -800036(%rbp)
.L4:
	movl	-800040(%rbp), %eax
	cmpl	%eax, -800036(%rbp)
	jl	.L5
	movl	-800040(%rbp), %eax
	movslq	%eax, %rsi
	leaq	-800016(%rbp), %rax
	leaq	compare_int(%rip), %rdx
	movq	%rdx, %rcx
	movl	$8, %edx
	movq	%rax, %rdi
	call	qsort@PLT
	movl	-800040(%rbp), %eax
	andl	$1, %eax
	testl	%eax, %eax
	jne	.L6
	movl	$0, -800036(%rbp)
	jmp	.L7
.L12:
	movl	-800040(%rbp), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	cmpl	%eax, -800036(%rbp)
	jge	.L8
	movl	-800040(%rbp), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	subl	$1, %eax
	cmpl	%eax, -800036(%rbp)
	jne	.L9
	movl	-800036(%rbp), %eax
	cltq
	movq	-800016(%rbp,%rax,8), %rax
	subq	%rax, -800032(%rbp)
	jmp	.L10
.L9:
	movl	-800036(%rbp), %eax
	cltq
	movq	-800016(%rbp,%rax,8), %rax
	addq	%rax, %rax
	subq	%rax, -800032(%rbp)
	jmp	.L10
.L8:
	movl	-800040(%rbp), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	cmpl	%eax, -800036(%rbp)
	jne	.L11
	movl	-800036(%rbp), %eax
	cltq
	movq	-800016(%rbp,%rax,8), %rax
	addq	%rax, -800032(%rbp)
	jmp	.L10
.L11:
	movl	-800036(%rbp), %eax
	cltq
	movq	-800016(%rbp,%rax,8), %rax
	addq	%rax, %rax
	addq	%rax, -800032(%rbp)
.L10:
	addl	$1, -800036(%rbp)
.L7:
	movl	-800040(%rbp), %eax
	cmpl	%eax, -800036(%rbp)
	jl	.L12
	jmp	.L13
.L6:
	movq	$0, -800024(%rbp)
	movl	$0, -800036(%rbp)
	jmp	.L14
.L18:
	movl	-800040(%rbp), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	cmpl	%eax, -800036(%rbp)
	jge	.L15
	movl	-800036(%rbp), %eax
	cltq
	movq	-800016(%rbp,%rax,8), %rax
	addq	%rax, %rax
	subq	%rax, -800032(%rbp)
	jmp	.L16
.L15:
	movl	-800040(%rbp), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	addl	$1, %eax
	cmpl	%eax, -800036(%rbp)
	jg	.L17
	movl	-800036(%rbp), %eax
	cltq
	movq	-800016(%rbp,%rax,8), %rax
	addq	%rax, -800032(%rbp)
	jmp	.L16
.L17:
	movl	-800036(%rbp), %eax
	cltq
	movq	-800016(%rbp,%rax,8), %rax
	addq	%rax, %rax
	addq	%rax, -800032(%rbp)
.L16:
	addl	$1, -800036(%rbp)
.L14:
	movl	-800040(%rbp), %eax
	cmpl	%eax, -800036(%rbp)
	jl	.L18
	movl	$0, -800036(%rbp)
	jmp	.L19
.L23:
	movl	-800040(%rbp), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	cmpl	%eax, -800036(%rbp)
	jg	.L20
	movl	-800040(%rbp), %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	subl	$1, %eax
	cmpl	%eax, -800036(%rbp)
	jl	.L21
	movl	-800036(%rbp), %eax
	cltq
	movq	-800016(%rbp,%rax,8), %rax
	subq	%rax, -800024(%rbp)
	jmp	.L22
.L21:
	movl	-800036(%rbp), %eax
	cltq
	movq	-800016(%rbp,%rax,8), %rax
	addq	%rax, %rax
	subq	%rax, -800024(%rbp)
	jmp	.L22
.L20:
	movl	-800036(%rbp), %eax
	cltq
	movq	-800016(%rbp,%rax,8), %rax
	addq	%rax, %rax
	addq	%rax, -800024(%rbp)
.L22:
	addl	$1, -800036(%rbp)
.L19:
	movl	-800040(%rbp), %eax
	cmpl	%eax, -800036(%rbp)
	jl	.L23
	movq	-800032(%rbp), %rdx
	movq	-800024(%rbp), %rax
	cmpq	%rax, %rdx
	cmovge	%rdx, %rax
	movq	%rax, -800032(%rbp)
.L13:
	movq	-800032(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC2(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L25
	call	__stack_chk_fail@PLT
.L25:
	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:
