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>

int compare(const void *a, const void *b) {
    if( *(long long*)a - *(long long*)b < 0 )
        return -1;
    if( *(long long*)a - *(long long*)b > 0 )
        return 1;
    return 0;
}

int main (void)
{
    long long N, A[(int)1e5];
    long long i, ans = 0, bsb, sbs;

    scanf("%lld", &N);

    for (i = 0; i < N; i++) {
        scanf("%lld", &A[i]);
    }

    qsort(A, N, sizeof(long long), compare);

    if (N % 2) {
        for (i = 0; i < ((N - 3) / 2); i++) ans += -2 * A[i];
        sbs  = -1 * A[i]; bsb  = -2 * A[i++];
        sbs += -1 * A[i]; bsb +=  1 * A[i++];
        sbs +=  2 * A[i]; bsb +=  1 * A[i++];
        ans += (sbs > bsb) ? sbs : bsb;
        for (;i < N; i++) ans += 2 * A[i];
    } else {
        for (i = 0; i < ((N - 2) / 2); i++) ans += -2 * A[i];
        ans += -1 * A[i++];
        ans +=  1 * A[i++];
        for (;i < N; i++) ans += (2 * A[i]);
    }

    printf("%lld\n", ans);

    return 0;
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	compare
	.type	compare, @function
compare:
.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), %rdx
	movq	-16(%rbp), %rax
	movq	(%rax), %rcx
	movq	%rdx, %rax
	subq	%rcx, %rax
	testq	%rax, %rax
	jns	.L2
	movl	$-1, %eax
	jmp	.L3
.L2:
	movq	-8(%rbp), %rax
	movq	(%rax), %rdx
	movq	-16(%rbp), %rax
	movq	(%rax), %rcx
	movq	%rdx, %rax
	subq	%rcx, %rax
	testq	%rax, %rax
	jle	.L4
	movl	$1, %eax
	jmp	.L3
.L4:
	movl	$0, %eax
.L3:
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	compare, .-compare
	.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
	leaq	-798720(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$1344, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movq	$0, -800040(%rbp)
	leaq	-800056(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	$0, -800048(%rbp)
	jmp	.L6
.L7:
	leaq	-800016(%rbp), %rdx
	movq	-800048(%rbp), %rax
	salq	$3, %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addq	$1, -800048(%rbp)
.L6:
	movq	-800056(%rbp), %rax
	cmpq	%rax, -800048(%rbp)
	jl	.L7
	movq	-800056(%rbp), %rax
	movq	%rax, %rsi
	leaq	-800016(%rbp), %rax
	leaq	compare(%rip), %rdx
	movq	%rdx, %rcx
	movl	$8, %edx
	movq	%rax, %rdi
	call	qsort@PLT
	movq	-800056(%rbp), %rax
	andl	$1, %eax
	testq	%rax, %rax
	je	.L8
	movq	$0, -800048(%rbp)
	jmp	.L9
.L10:
	movq	-800048(%rbp), %rax
	movq	-800016(%rbp,%rax,8), %rdx
	movl	$0, %eax
	subq	%rdx, %rax
	addq	%rax, %rax
	addq	%rax, -800040(%rbp)
	addq	$1, -800048(%rbp)
.L9:
	movq	-800056(%rbp), %rax
	subq	$3, %rax
	movq	%rax, %rdx
	shrq	$63, %rdx
	addq	%rdx, %rax
	sarq	%rax
	cmpq	%rax, -800048(%rbp)
	jl	.L10
	movq	-800048(%rbp), %rax
	movq	-800016(%rbp,%rax,8), %rax
	negq	%rax
	movq	%rax, -800032(%rbp)
	movq	-800048(%rbp), %rax
	leaq	1(%rax), %rdx
	movq	%rdx, -800048(%rbp)
	movq	-800016(%rbp,%rax,8), %rdx
	movl	$0, %eax
	subq	%rdx, %rax
	addq	%rax, %rax
	movq	%rax, -800024(%rbp)
	movq	-800048(%rbp), %rax
	movq	-800016(%rbp,%rax,8), %rax
	subq	%rax, -800032(%rbp)
	movq	-800048(%rbp), %rax
	leaq	1(%rax), %rdx
	movq	%rdx, -800048(%rbp)
	movq	-800016(%rbp,%rax,8), %rax
	addq	%rax, -800024(%rbp)
	movq	-800048(%rbp), %rax
	movq	-800016(%rbp,%rax,8), %rax
	addq	%rax, %rax
	addq	%rax, -800032(%rbp)
	movq	-800048(%rbp), %rax
	leaq	1(%rax), %rdx
	movq	%rdx, -800048(%rbp)
	movq	-800016(%rbp,%rax,8), %rax
	addq	%rax, -800024(%rbp)
	movq	-800024(%rbp), %rdx
	movq	-800032(%rbp), %rax
	cmpq	%rax, %rdx
	cmovge	%rdx, %rax
	addq	%rax, -800040(%rbp)
	jmp	.L11
.L12:
	movq	-800048(%rbp), %rax
	movq	-800016(%rbp,%rax,8), %rax
	addq	%rax, %rax
	addq	%rax, -800040(%rbp)
	addq	$1, -800048(%rbp)
.L11:
	movq	-800056(%rbp), %rax
	cmpq	%rax, -800048(%rbp)
	jl	.L12
	jmp	.L13
.L8:
	movq	$0, -800048(%rbp)
	jmp	.L14
.L15:
	movq	-800048(%rbp), %rax
	movq	-800016(%rbp,%rax,8), %rdx
	movl	$0, %eax
	subq	%rdx, %rax
	addq	%rax, %rax
	addq	%rax, -800040(%rbp)
	addq	$1, -800048(%rbp)
.L14:
	movq	-800056(%rbp), %rax
	subq	$2, %rax
	movq	%rax, %rdx
	shrq	$63, %rdx
	addq	%rdx, %rax
	sarq	%rax
	cmpq	%rax, -800048(%rbp)
	jl	.L15
	movq	-800048(%rbp), %rax
	leaq	1(%rax), %rdx
	movq	%rdx, -800048(%rbp)
	movq	-800016(%rbp,%rax,8), %rax
	negq	%rax
	addq	%rax, -800040(%rbp)
	movq	-800048(%rbp), %rax
	leaq	1(%rax), %rdx
	movq	%rdx, -800048(%rbp)
	movq	-800016(%rbp,%rax,8), %rax
	addq	%rax, -800040(%rbp)
	jmp	.L16
.L17:
	movq	-800048(%rbp), %rax
	movq	-800016(%rbp,%rax,8), %rax
	addq	%rax, %rax
	addq	%rax, -800040(%rbp)
	addq	$1, -800048(%rbp)
.L16:
	movq	-800056(%rbp), %rax
	cmpq	%rax, -800048(%rbp)
	jl	.L17
.L13:
	movq	-800040(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	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
.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
	.type	compare, @function
compare:
.LFB39:
	.cfi_startproc
	endbr64
	movq	(%rsi), %rdx
	movl	$-1, %eax
	cmpq	%rdx, (%rdi)
	js	.L1
	setne	%al
	movzbl	%al, %eax
.L1:
	ret
	.cfi_endproc
.LFE39:
	.size	compare, .-compare
	.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	%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), %r13
	xorl	%ebx, %ebx
	movq	%r13, %rdi
	movq	%fs:40, %rax
	movq	%rax, 800024(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rsi
	leaq	16(%rsp), %r12
	movq	%r12, %rbp
	call	__isoc99_scanf@PLT
	movq	8(%rsp), %rsi
	testq	%rsi, %rsi
	jle	.L6
	.p2align 4,,10
	.p2align 3
.L7:
	movq	%rbp, %rsi
	movq	%r13, %rdi
	xorl	%eax, %eax
	addq	$1, %rbx
	call	__isoc99_scanf@PLT
	movq	8(%rsp), %rsi
	addq	$8, %rbp
	cmpq	%rbx, %rsi
	jg	.L7
.L6:
	movq	%r12, %rdi
	leaq	compare(%rip), %rcx
	movl	$8, %edx
	call	qsort@PLT
	movq	8(%rsp), %rdi
	testb	$1, %dil
	jne	.L8
	leaq	-2(%rdi), %rax
	movl	$2, %ecx
	cqto
	idivq	%rcx
	xorl	%edx, %edx
	xorl	%ecx, %ecx
	cmpq	$3, %rdi
	jle	.L28
	.p2align 4,,10
	.p2align 3
.L9:
	movq	(%r12,%rcx,8), %rsi
	addq	$1, %rcx
	negq	%rsi
	leaq	(%rdx,%rsi,2), %rdx
	cmpq	%rax, %rcx
	jl	.L9
	testq	%rax, %rax
	movl	$1, %ecx
	cmovle	%rcx, %rax
.L10:
	subq	16(%rsp,%rax,8), %rdx
	addq	24(%rsp,%rax,8), %rdx
	addq	$2, %rax
	cmpq	%rax, %rdi
	jle	.L13
	leaq	(%r12,%rax,8), %rax
	leaq	(%r12,%rdi,8), %rsi
	.p2align 4,,10
	.p2align 3
.L15:
	movq	(%rax), %rcx
	addq	$8, %rax
	leaq	(%rdx,%rcx,2), %rdx
	cmpq	%rax, %rsi
	jne	.L15
.L13:
	xorl	%eax, %eax
	leaq	.LC1(%rip), %rsi
	movl	$1, %edi
	call	__printf_chk@PLT
	movq	800024(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L29
	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
.L8:
	.cfi_restore_state
	leaq	-3(%rdi), %rax
	movl	$2, %ecx
	xorl	%esi, %esi
	cqto
	idivq	%rcx
	cmpq	$4, %rdi
	jle	.L18
	xorl	%edx, %edx
	.p2align 4,,10
	.p2align 3
.L12:
	movq	(%r12,%rdx,8), %rcx
	addq	$1, %rdx
	negq	%rcx
	leaq	(%rsi,%rcx,2), %rsi
	cmpq	%rax, %rdx
	jl	.L12
	testq	%rax, %rax
	movl	$1, %edx
	cmovle	%rdx, %rax
.L11:
	movq	16(%rsp,%rax,8), %rdx
	movq	32(%rsp,%rax,8), %rcx
	movq	%rdx, %r9
	imulq	$-2, %rdx, %rdx
	addq	24(%rsp,%rax,8), %rdx
	negq	%r9
	movq	%rdx, %r8
	leaq	(%rcx,%rcx), %rdx
	subq	24(%rsp,%rax,8), %r9
	addq	%r9, %rdx
	addq	%r8, %rcx
	cmpq	%rcx, %rdx
	cmovl	%rcx, %rdx
	addq	$3, %rax
	addq	%rsi, %rdx
	cmpq	%rax, %rdi
	jle	.L13
	leaq	(%r12,%rax,8), %rax
	leaq	(%r12,%rdi,8), %rsi
	.p2align 4,,10
	.p2align 3
.L14:
	movq	(%rax), %rcx
	addq	$8, %rax
	leaq	(%rdx,%rcx,2), %rdx
	cmpq	%rax, %rsi
	jne	.L14
	jmp	.L13
.L28:
	xorl	%eax, %eax
	jmp	.L10
.L18:
	xorl	%eax, %eax
	jmp	.L11
.L29:
	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
	.type	compare, @function
compare:
.LFB39:
	.cfi_startproc
	endbr64
	movq	(%rsi), %rdx
	movl	$-1, %eax
	cmpq	%rdx, (%rdi)
	js	.L1
	setne	%al
	movzbl	%al, %eax
.L1:
	ret
	.cfi_endproc
.LFE39:
	.size	compare, .-compare
	.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	%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), %r13
	xorl	%ebx, %ebx
	movq	%r13, %rdi
	movq	%fs:40, %rax
	movq	%rax, 800024(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rsi
	leaq	16(%rsp), %r12
	movq	%r12, %rbp
	call	__isoc99_scanf@PLT
	movq	8(%rsp), %rsi
	testq	%rsi, %rsi
	jle	.L6
	.p2align 4,,10
	.p2align 3
.L7:
	movq	%rbp, %rsi
	movq	%r13, %rdi
	xorl	%eax, %eax
	addq	$1, %rbx
	call	__isoc99_scanf@PLT
	movq	8(%rsp), %rsi
	addq	$8, %rbp
	cmpq	%rbx, %rsi
	jg	.L7
.L6:
	movq	%r12, %rdi
	leaq	compare(%rip), %rcx
	movl	$8, %edx
	call	qsort@PLT
	movq	8(%rsp), %rdi
	testb	$1, %dil
	jne	.L8
	leaq	-2(%rdi), %rax
	movl	$2, %ecx
	cqto
	idivq	%rcx
	xorl	%edx, %edx
	xorl	%ecx, %ecx
	cmpq	$3, %rdi
	jle	.L28
	.p2align 4,,10
	.p2align 3
.L9:
	movq	(%r12,%rcx,8), %rsi
	addq	$1, %rcx
	negq	%rsi
	leaq	(%rdx,%rsi,2), %rdx
	cmpq	%rax, %rcx
	jl	.L9
	testq	%rax, %rax
	movl	$1, %ecx
	cmovle	%rcx, %rax
.L10:
	subq	16(%rsp,%rax,8), %rdx
	addq	24(%rsp,%rax,8), %rdx
	addq	$2, %rax
	cmpq	%rax, %rdi
	jle	.L13
	leaq	(%r12,%rax,8), %rax
	leaq	(%r12,%rdi,8), %rsi
	.p2align 4,,10
	.p2align 3
.L15:
	movq	(%rax), %rcx
	addq	$8, %rax
	leaq	(%rdx,%rcx,2), %rdx
	cmpq	%rax, %rsi
	jne	.L15
.L13:
	xorl	%eax, %eax
	leaq	.LC1(%rip), %rsi
	movl	$1, %edi
	call	__printf_chk@PLT
	movq	800024(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L29
	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
.L8:
	.cfi_restore_state
	leaq	-3(%rdi), %rax
	movl	$2, %ecx
	xorl	%esi, %esi
	cqto
	idivq	%rcx
	cmpq	$4, %rdi
	jle	.L18
	xorl	%edx, %edx
	.p2align 4,,10
	.p2align 3
.L12:
	movq	(%r12,%rdx,8), %rcx
	addq	$1, %rdx
	negq	%rcx
	leaq	(%rsi,%rcx,2), %rsi
	cmpq	%rax, %rdx
	jl	.L12
	testq	%rax, %rax
	movl	$1, %edx
	cmovle	%rdx, %rax
.L11:
	movq	16(%rsp,%rax,8), %rdx
	movq	32(%rsp,%rax,8), %rcx
	movq	%rdx, %r9
	imulq	$-2, %rdx, %rdx
	addq	24(%rsp,%rax,8), %rdx
	negq	%r9
	movq	%rdx, %r8
	leaq	(%rcx,%rcx), %rdx
	subq	24(%rsp,%rax,8), %r9
	addq	%r9, %rdx
	addq	%r8, %rcx
	cmpq	%rcx, %rdx
	cmovl	%rcx, %rdx
	addq	$3, %rax
	addq	%rsi, %rdx
	cmpq	%rax, %rdi
	jle	.L13
	leaq	(%r12,%rax,8), %rax
	leaq	(%r12,%rdi,8), %rsi
	.p2align 4,,10
	.p2align 3
.L14:
	movq	(%rax), %rcx
	addq	$8, %rax
	leaq	(%rdx,%rcx,2), %rdx
	cmpq	%rax, %rsi
	jne	.L14
	jmp	.L13
.L28:
	xorl	%eax, %eax
	jmp	.L10
.L18:
	xorl	%eax, %eax
	jmp	.L11
.L29:
	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>

int compare(const void *a, const void *b) {
    if( *(long long*)a - *(long long*)b < 0 )
        return -1;
    if( *(long long*)a - *(long long*)b > 0 )
        return 1;
    return 0;
}

int main (void)
{
    long long N, A[(int)1e5];
    long long i, ans = 0, bsb, sbs;

    scanf("%lld", &N);

    for (i = 0; i < N; i++) {
        scanf("%lld", &A[i]);
    }

    qsort(A, N, sizeof(long long), compare);

    if (N % 2) {
        for (i = 0; i < ((N - 3) / 2); i++) ans += -2 * A[i];
        sbs  = -1 * A[i]; bsb  = -2 * A[i++];
        sbs += -1 * A[i]; bsb +=  1 * A[i++];
        sbs +=  2 * A[i]; bsb +=  1 * A[i++];
        ans += (sbs > bsb) ? sbs : bsb;
        for (;i < N; i++) ans += 2 * A[i];
    } else {
        for (i = 0; i < ((N - 2) / 2); i++) ans += -2 * A[i];
        ans += -1 * A[i++];
        ans +=  1 * A[i++];
        for (;i < N; i++) ans += (2 * A[i]);
    }

    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>

int compare(const void *a, const void *b) {
    if( *(long long*)a - *(long long*)b < 0 )
        return -1;
    if( *(long long*)a - *(long long*)b > 0 )
        return 1;
    return 0;
}

int main (void)
{
    long long N, A[(int)1e5];
    long long i, ans = 0, bsb, sbs;

    scanf("%lld", &N);

    for (i = 0; i < N; i++) {
        scanf("%lld", &A[i]);
    }

    qsort(A, N, sizeof(long long), compare);

    if (N % 2) {
        for (i = 0; i < ((N - 3) / 2); i++) ans += -2 * A[i];
        sbs  = -1 * A[i]; bsb  = -2 * A[i++];
        sbs += -1 * A[i]; bsb +=  1 * A[i++];
        sbs +=  2 * A[i]; bsb +=  1 * A[i++];
        ans += (sbs > bsb) ? sbs : bsb;
        for (;i < N; i++) ans += 2 * A[i];
    } else {
        for (i = 0; i < ((N - 2) / 2); i++) ans += -2 * A[i];
        ans += -1 * A[i++];
        ans +=  1 * A[i++];
        for (;i < N; i++) ans += (2 * A[i]);
    }

    printf("%lld\n", ans);

    return 0;
}
```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	compare
	.type	compare, @function
compare:
.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), %rdx
	movq	-16(%rbp), %rax
	movq	(%rax), %rcx
	movq	%rdx, %rax
	subq	%rcx, %rax
	testq	%rax, %rax
	jns	.L2
	movl	$-1, %eax
	jmp	.L3
.L2:
	movq	-8(%rbp), %rax
	movq	(%rax), %rdx
	movq	-16(%rbp), %rax
	movq	(%rax), %rcx
	movq	%rdx, %rax
	subq	%rcx, %rax
	testq	%rax, %rax
	jle	.L4
	movl	$1, %eax
	jmp	.L3
.L4:
	movl	$0, %eax
.L3:
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	compare, .-compare
	.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
	leaq	-798720(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$1344, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movq	$0, -800040(%rbp)
	leaq	-800056(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	$0, -800048(%rbp)
	jmp	.L6
.L7:
	leaq	-800016(%rbp), %rdx
	movq	-800048(%rbp), %rax
	salq	$3, %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addq	$1, -800048(%rbp)
.L6:
	movq	-800056(%rbp), %rax
	cmpq	%rax, -800048(%rbp)
	jl	.L7
	movq	-800056(%rbp), %rax
	movq	%rax, %rsi
	leaq	-800016(%rbp), %rax
	leaq	compare(%rip), %rdx
	movq	%rdx, %rcx
	movl	$8, %edx
	movq	%rax, %rdi
	call	qsort@PLT
	movq	-800056(%rbp), %rax
	andl	$1, %eax
	testq	%rax, %rax
	je	.L8
	movq	$0, -800048(%rbp)
	jmp	.L9
.L10:
	movq	-800048(%rbp), %rax
	movq	-800016(%rbp,%rax,8), %rdx
	movl	$0, %eax
	subq	%rdx, %rax
	addq	%rax, %rax
	addq	%rax, -800040(%rbp)
	addq	$1, -800048(%rbp)
.L9:
	movq	-800056(%rbp), %rax
	subq	$3, %rax
	movq	%rax, %rdx
	shrq	$63, %rdx
	addq	%rdx, %rax
	sarq	%rax
	cmpq	%rax, -800048(%rbp)
	jl	.L10
	movq	-800048(%rbp), %rax
	movq	-800016(%rbp,%rax,8), %rax
	negq	%rax
	movq	%rax, -800032(%rbp)
	movq	-800048(%rbp), %rax
	leaq	1(%rax), %rdx
	movq	%rdx, -800048(%rbp)
	movq	-800016(%rbp,%rax,8), %rdx
	movl	$0, %eax
	subq	%rdx, %rax
	addq	%rax, %rax
	movq	%rax, -800024(%rbp)
	movq	-800048(%rbp), %rax
	movq	-800016(%rbp,%rax,8), %rax
	subq	%rax, -800032(%rbp)
	movq	-800048(%rbp), %rax
	leaq	1(%rax), %rdx
	movq	%rdx, -800048(%rbp)
	movq	-800016(%rbp,%rax,8), %rax
	addq	%rax, -800024(%rbp)
	movq	-800048(%rbp), %rax
	movq	-800016(%rbp,%rax,8), %rax
	addq	%rax, %rax
	addq	%rax, -800032(%rbp)
	movq	-800048(%rbp), %rax
	leaq	1(%rax), %rdx
	movq	%rdx, -800048(%rbp)
	movq	-800016(%rbp,%rax,8), %rax
	addq	%rax, -800024(%rbp)
	movq	-800024(%rbp), %rdx
	movq	-800032(%rbp), %rax
	cmpq	%rax, %rdx
	cmovge	%rdx, %rax
	addq	%rax, -800040(%rbp)
	jmp	.L11
.L12:
	movq	-800048(%rbp), %rax
	movq	-800016(%rbp,%rax,8), %rax
	addq	%rax, %rax
	addq	%rax, -800040(%rbp)
	addq	$1, -800048(%rbp)
.L11:
	movq	-800056(%rbp), %rax
	cmpq	%rax, -800048(%rbp)
	jl	.L12
	jmp	.L13
.L8:
	movq	$0, -800048(%rbp)
	jmp	.L14
.L15:
	movq	-800048(%rbp), %rax
	movq	-800016(%rbp,%rax,8), %rdx
	movl	$0, %eax
	subq	%rdx, %rax
	addq	%rax, %rax
	addq	%rax, -800040(%rbp)
	addq	$1, -800048(%rbp)
.L14:
	movq	-800056(%rbp), %rax
	subq	$2, %rax
	movq	%rax, %rdx
	shrq	$63, %rdx
	addq	%rdx, %rax
	sarq	%rax
	cmpq	%rax, -800048(%rbp)
	jl	.L15
	movq	-800048(%rbp), %rax
	leaq	1(%rax), %rdx
	movq	%rdx, -800048(%rbp)
	movq	-800016(%rbp,%rax,8), %rax
	negq	%rax
	addq	%rax, -800040(%rbp)
	movq	-800048(%rbp), %rax
	leaq	1(%rax), %rdx
	movq	%rdx, -800048(%rbp)
	movq	-800016(%rbp,%rax,8), %rax
	addq	%rax, -800040(%rbp)
	jmp	.L16
.L17:
	movq	-800048(%rbp), %rax
	movq	-800016(%rbp,%rax,8), %rax
	addq	%rax, %rax
	addq	%rax, -800040(%rbp)
	addq	$1, -800048(%rbp)
.L16:
	movq	-800056(%rbp), %rax
	cmpq	%rax, -800048(%rbp)
	jl	.L17
.L13:
	movq	-800040(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	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
.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
	.type	compare, @function
compare:
.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), %rdx
	movq	-16(%rbp), %rax
	movq	(%rax), %rcx
	movq	%rdx, %rax
	subq	%rcx, %rax
	testq	%rax, %rax
	jns	.L2
	movl	$-1, %eax
	jmp	.L3
.L2:
	movq	-8(%rbp), %rax
	movq	(%rax), %rdx
	movq	-16(%rbp), %rax
	movq	(%rax), %rcx
	movq	%rdx, %rax
	subq	%rcx, %rax
	testq	%rax, %rax
	jle	.L4
	movl	$1, %eax
	jmp	.L3
.L4:
	movl	$0, %eax
.L3:
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	compare, .-compare
	.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
	leaq	-798720(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$1344, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movq	$0, -800040(%rbp)
	leaq	-800056(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	$0, -800048(%rbp)
	jmp	.L6
.L7:
	leaq	-800016(%rbp), %rdx
	movq	-800048(%rbp), %rax
	salq	$3, %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addq	$1, -800048(%rbp)
.L6:
	movq	-800056(%rbp), %rax
	cmpq	%rax, -800048(%rbp)
	jl	.L7
	movq	-800056(%rbp), %rax
	movq	%rax, %rsi
	leaq	-800016(%rbp), %rax
	leaq	compare(%rip), %rdx
	movq	%rdx, %rcx
	movl	$8, %edx
	movq	%rax, %rdi
	call	qsort@PLT
	movq	-800056(%rbp), %rax
	andl	$1, %eax
	testq	%rax, %rax
	je	.L8
	movq	$0, -800048(%rbp)
	jmp	.L9
.L10:
	movq	-800048(%rbp), %rax
	movq	-800016(%rbp,%rax,8), %rdx
	movl	$0, %eax
	subq	%rdx, %rax
	addq	%rax, %rax
	addq	%rax, -800040(%rbp)
	addq	$1, -800048(%rbp)
.L9:
	movq	-800056(%rbp), %rax
	subq	$3, %rax
	movq	%rax, %rdx
	shrq	$63, %rdx
	addq	%rdx, %rax
	sarq	%rax
	cmpq	%rax, -800048(%rbp)
	jl	.L10
	movq	-800048(%rbp), %rax
	movq	-800016(%rbp,%rax,8), %rax
	negq	%rax
	movq	%rax, -800032(%rbp)
	movq	-800048(%rbp), %rax
	leaq	1(%rax), %rdx
	movq	%rdx, -800048(%rbp)
	movq	-800016(%rbp,%rax,8), %rdx
	movl	$0, %eax
	subq	%rdx, %rax
	addq	%rax, %rax
	movq	%rax, -800024(%rbp)
	movq	-800048(%rbp), %rax
	movq	-800016(%rbp,%rax,8), %rax
	subq	%rax, -800032(%rbp)
	movq	-800048(%rbp), %rax
	leaq	1(%rax), %rdx
	movq	%rdx, -800048(%rbp)
	movq	-800016(%rbp,%rax,8), %rax
	addq	%rax, -800024(%rbp)
	movq	-800048(%rbp), %rax
	movq	-800016(%rbp,%rax,8), %rax
	addq	%rax, %rax
	addq	%rax, -800032(%rbp)
	movq	-800048(%rbp), %rax
	leaq	1(%rax), %rdx
	movq	%rdx, -800048(%rbp)
	movq	-800016(%rbp,%rax,8), %rax
	addq	%rax, -800024(%rbp)
	movq	-800024(%rbp), %rdx
	movq	-800032(%rbp), %rax
	cmpq	%rax, %rdx
	cmovge	%rdx, %rax
	addq	%rax, -800040(%rbp)
	jmp	.L11
.L12:
	movq	-800048(%rbp), %rax
	movq	-800016(%rbp,%rax,8), %rax
	addq	%rax, %rax
	addq	%rax, -800040(%rbp)
	addq	$1, -800048(%rbp)
.L11:
	movq	-800056(%rbp), %rax
	cmpq	%rax, -800048(%rbp)
	jl	.L12
	jmp	.L13
.L8:
	movq	$0, -800048(%rbp)
	jmp	.L14
.L15:
	movq	-800048(%rbp), %rax
	movq	-800016(%rbp,%rax,8), %rdx
	movl	$0, %eax
	subq	%rdx, %rax
	addq	%rax, %rax
	addq	%rax, -800040(%rbp)
	addq	$1, -800048(%rbp)
.L14:
	movq	-800056(%rbp), %rax
	subq	$2, %rax
	movq	%rax, %rdx
	shrq	$63, %rdx
	addq	%rdx, %rax
	sarq	%rax
	cmpq	%rax, -800048(%rbp)
	jl	.L15
	movq	-800048(%rbp), %rax
	leaq	1(%rax), %rdx
	movq	%rdx, -800048(%rbp)
	movq	-800016(%rbp,%rax,8), %rax
	negq	%rax
	addq	%rax, -800040(%rbp)
	movq	-800048(%rbp), %rax
	leaq	1(%rax), %rdx
	movq	%rdx, -800048(%rbp)
	movq	-800016(%rbp,%rax,8), %rax
	addq	%rax, -800040(%rbp)
	jmp	.L16
.L17:
	movq	-800048(%rbp), %rax
	movq	-800016(%rbp,%rax,8), %rax
	addq	%rax, %rax
	addq	%rax, -800040(%rbp)
	addq	$1, -800048(%rbp)
.L16:
	movq	-800056(%rbp), %rax
	cmpq	%rax, -800048(%rbp)
	jl	.L17
.L13:
	movq	-800040(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	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
.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:
