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 cmpnum(const void * n1, const void * n2) {
	if (*(long *)n1 > *(long *)n2)
	{
		return 1;
	}
	else if (*(long *)n1 < *(long *)n2)
	{
		return -1;
	}
	else
	{
		return 0;
	}
}

int main(void) {

  long n;
  scanf("%ld", &n);
  long a[n];
  for (long i = 0; i < n; i++) {
    scanf("%ld", &a[i]);
    a[i] -= i+1;
  }
  qsort(a, n, sizeof(long), cmpnum);
  long all = 0;
  for (long i = 1; i < n; i++) {
    all += a[i]-a[0];
  }
  long sadness = all;
  long min = all;
  long level = a[0];
  long width,height;
  for (long i = 0; i < n; i++) {
    if (a[i+1] == level) {
      continue;
    }
    width = i+1;
    if (n-width*2 <= 0) {
      break;
    }
    height = a[i+1]-a[i];
    if (height*(n-width*2) <= sadness) {
      level = a[i+1];
      sadness -= height*(n-width*2);
      min = sadness;
    } else {
      height = sadness/(n-width*2);
      level += height;
      sadness -= height*(n-width*2);
      if (sadness <= min) {
        min = sadness;
      }
      sadness = -(sadness-(n-width*2));
      if (sadness <= min) {
        min = sadness;
      }
      break;
    }
  }
  printf("%ld\n", min);

  return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	cmpnum
	.type	cmpnum, @function
cmpnum:
.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), %rax
	cmpq	%rax, %rdx
	jle	.L2
	movl	$1, %eax
	jmp	.L3
.L2:
	movq	-8(%rbp), %rax
	movq	(%rax), %rdx
	movq	-16(%rbp), %rax
	movq	(%rax), %rax
	cmpq	%rax, %rdx
	jge	.L4
	movl	$-1, %eax
	jmp	.L3
.L4:
	movl	$0, %eax
.L3:
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	cmpnum, .-cmpnum
	.section	.rodata
.LC0:
	.string	"%ld"
.LC1:
	.string	"%ld\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	%r15
	pushq	%r14
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	subq	$120, %rsp
	.cfi_offset 15, -24
	.cfi_offset 14, -32
	.cfi_offset 13, -40
	.cfi_offset 12, -48
	.cfi_offset 3, -56
	movq	%fs:40, %rax
	movq	%rax, -56(%rbp)
	xorl	%eax, %eax
	movq	%rsp, %rax
	movq	%rax, %rbx
	leaq	-152(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	-152(%rbp), %rax
	leaq	-1(%rax), %rdx
	movq	%rdx, -88(%rbp)
	movq	%rax, %rdx
	movq	%rdx, %r14
	movl	$0, %r15d
	movq	%rax, %rdx
	movq	%rdx, %r12
	movl	$0, %r13d
	leaq	0(,%rax,8), %rdx
	movl	$16, %eax
	subq	$1, %rax
	addq	%rdx, %rax
	movl	$16, %esi
	movl	$0, %edx
	divq	%rsi
	imulq	$16, %rax, %rax
	movq	%rax, %rcx
	andq	$-4096, %rcx
	movq	%rsp, %rdx
	subq	%rcx, %rdx
.L6:
	cmpq	%rdx, %rsp
	je	.L7
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L6
.L7:
	movq	%rax, %rdx
	andl	$4095, %edx
	subq	%rdx, %rsp
	movq	%rax, %rdx
	andl	$4095, %edx
	testq	%rdx, %rdx
	je	.L8
	andl	$4095, %eax
	subq	$8, %rax
	addq	%rsp, %rax
	orq	$0, (%rax)
.L8:
	movq	%rsp, %rax
	addq	$7, %rax
	shrq	$3, %rax
	salq	$3, %rax
	movq	%rax, -80(%rbp)
	movq	$0, -144(%rbp)
	jmp	.L9
.L10:
	movq	-144(%rbp), %rax
	leaq	0(,%rax,8), %rdx
	movq	-80(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	-80(%rbp), %rax
	movq	-144(%rbp), %rdx
	movq	(%rax,%rdx,8), %rax
	movq	-144(%rbp), %rdx
	addq	$1, %rdx
	subq	%rdx, %rax
	movq	%rax, %rcx
	movq	-80(%rbp), %rax
	movq	-144(%rbp), %rdx
	movq	%rcx, (%rax,%rdx,8)
	addq	$1, -144(%rbp)
.L9:
	movq	-152(%rbp), %rax
	cmpq	%rax, -144(%rbp)
	jl	.L10
	movq	-152(%rbp), %rax
	movq	%rax, %rsi
	movq	-80(%rbp), %rax
	leaq	cmpnum(%rip), %rdx
	movq	%rdx, %rcx
	movl	$8, %edx
	movq	%rax, %rdi
	call	qsort@PLT
	movq	$0, -136(%rbp)
	movq	$1, -128(%rbp)
	jmp	.L11
.L12:
	movq	-80(%rbp), %rax
	movq	-128(%rbp), %rdx
	movq	(%rax,%rdx,8), %rdx
	movq	-80(%rbp), %rax
	movq	(%rax), %rcx
	movq	%rdx, %rax
	subq	%rcx, %rax
	addq	%rax, -136(%rbp)
	addq	$1, -128(%rbp)
.L11:
	movq	-152(%rbp), %rax
	cmpq	%rax, -128(%rbp)
	jl	.L12
	movq	-136(%rbp), %rax
	movq	%rax, -120(%rbp)
	movq	-136(%rbp), %rax
	movq	%rax, -112(%rbp)
	movq	-80(%rbp), %rax
	movq	(%rax), %rax
	movq	%rax, -104(%rbp)
	movq	$0, -96(%rbp)
	jmp	.L13
.L21:
	movq	-96(%rbp), %rax
	leaq	1(%rax), %rdx
	movq	-80(%rbp), %rax
	movq	(%rax,%rdx,8), %rax
	cmpq	%rax, -104(%rbp)
	je	.L24
	movq	-96(%rbp), %rax
	addq	$1, %rax
	movq	%rax, -72(%rbp)
	movq	-152(%rbp), %rax
	movq	-72(%rbp), %rdx
	addq	%rdx, %rdx
	subq	%rdx, %rax
	testq	%rax, %rax
	jle	.L25
	movq	-96(%rbp), %rax
	leaq	1(%rax), %rdx
	movq	-80(%rbp), %rax
	movq	(%rax,%rdx,8), %rcx
	movq	-80(%rbp), %rax
	movq	-96(%rbp), %rdx
	movq	(%rax,%rdx,8), %rdx
	movq	%rcx, %rax
	subq	%rdx, %rax
	movq	%rax, -64(%rbp)
	movq	-152(%rbp), %rax
	movq	-72(%rbp), %rdx
	addq	%rdx, %rdx
	subq	%rdx, %rax
	imulq	-64(%rbp), %rax
	cmpq	%rax, -120(%rbp)
	jl	.L18
	movq	-96(%rbp), %rax
	leaq	1(%rax), %rdx
	movq	-80(%rbp), %rax
	movq	(%rax,%rdx,8), %rax
	movq	%rax, -104(%rbp)
	movq	-152(%rbp), %rax
	movq	-72(%rbp), %rdx
	addq	%rdx, %rdx
	subq	%rdx, %rax
	imulq	-64(%rbp), %rax
	subq	%rax, -120(%rbp)
	movq	-120(%rbp), %rax
	movq	%rax, -112(%rbp)
	jmp	.L15
.L18:
	movq	-152(%rbp), %rax
	movq	-72(%rbp), %rdx
	leaq	(%rdx,%rdx), %rcx
	subq	%rcx, %rax
	movq	%rax, %rdi
	movq	-120(%rbp), %rax
	cqto
	idivq	%rdi
	movq	%rax, -64(%rbp)
	movq	-64(%rbp), %rax
	addq	%rax, -104(%rbp)
	movq	-152(%rbp), %rax
	movq	-72(%rbp), %rdx
	addq	%rdx, %rdx
	subq	%rdx, %rax
	imulq	-64(%rbp), %rax
	subq	%rax, -120(%rbp)
	movq	-120(%rbp), %rax
	cmpq	-112(%rbp), %rax
	jg	.L19
	movq	-120(%rbp), %rax
	movq	%rax, -112(%rbp)
.L19:
	movq	-152(%rbp), %rax
	movq	-72(%rbp), %rdx
	addq	%rdx, %rdx
	subq	%rdx, %rax
	subq	-120(%rbp), %rax
	movq	%rax, -120(%rbp)
	movq	-120(%rbp), %rax
	cmpq	-112(%rbp), %rax
	jg	.L26
	movq	-120(%rbp), %rax
	movq	%rax, -112(%rbp)
	jmp	.L26
.L24:
	nop
.L15:
	addq	$1, -96(%rbp)
.L13:
	movq	-152(%rbp), %rax
	cmpq	%rax, -96(%rbp)
	jl	.L21
	jmp	.L17
.L25:
	nop
	jmp	.L17
.L26:
	nop
.L17:
	movq	-112(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	%rbx, %rsp
	movq	-56(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L23
	call	__stack_chk_fail@PLT
.L23:
	leaq	-40(%rbp), %rsp
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	main, .-main
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:
```

Only output the optimized assembly code. Do not include any other text. Do not write any comments in the assembly code. Wrap the assembly code in ```assembly``` tags.
user
	.file	"temp.c"
	.text
	.p2align 4
	.globl	cmpnum
	.type	cmpnum, @function
cmpnum:
.LFB39:
	.cfi_startproc
	endbr64
	movq	(%rsi), %rdx
	movl	$1, %eax
	cmpq	%rdx, (%rdi)
	jg	.L1
	setl	%al
	movzbl	%al, %eax
	negl	%eax
.L1:
	ret
	.cfi_endproc
.LFE39:
	.size	cmpnum, .-cmpnum
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%ld"
.LC1:
	.string	"%ld\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB40:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%r15
	pushq	%r14
	.cfi_offset 15, -24
	.cfi_offset 14, -32
	leaq	.LC0(%rip), %r14
	leaq	-64(%rbp), %rsi
	pushq	%r13
	movq	%r14, %rdi
	pushq	%r12
	pushq	%rbx
	subq	$24, %rsp
	.cfi_offset 13, -40
	.cfi_offset 12, -48
	.cfi_offset 3, -56
	movq	%fs:40, %rax
	movq	%rax, -56(%rbp)
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movq	-64(%rbp), %rsi
	movq	%rsp, %rcx
	leaq	15(,%rsi,8), %rax
	movq	%rax, %rdx
	andq	$-4096, %rax
	subq	%rax, %rcx
	andq	$-16, %rdx
	cmpq	%rcx, %rsp
	je	.L7
.L31:
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	cmpq	%rcx, %rsp
	jne	.L31
.L7:
	andl	$4095, %edx
	subq	%rdx, %rsp
	testq	%rdx, %rdx
	jne	.L32
.L8:
	leaq	7(%rsp), %r13
	movq	%r13, %r15
	andq	$-8, %r13
	shrq	$3, %r15
	testq	%rsi, %rsi
	jle	.L9
	movq	%r13, %rbx
	xorl	%r12d, %r12d
	.p2align 4,,10
	.p2align 3
.L10:
	movq	%rbx, %rsi
	movq	%r14, %rdi
	xorl	%eax, %eax
	addq	$1, %r12
	call	__isoc99_scanf@PLT
	movq	-64(%rbp), %rsi
	subq	%r12, (%rbx)
	addq	$8, %rbx
	cmpq	%rsi, %r12
	jl	.L10
.L9:
	movq	%r13, %rdi
	leaq	cmpnum(%rip), %rcx
	movl	$8, %edx
	call	qsort@PLT
	movq	-64(%rbp), %rdi
	cmpq	$1, %rdi
	jle	.L11
	movq	0(,%r15,8), %rdx
	leaq	-1(%rdi), %r9
	cmpq	$2, %rdi
	je	.L22
	movq	%r9, %rsi
	movq	%rdx, %xmm2
	pxor	%xmm1, %xmm1
	xorl	%eax, %eax
	shrq	%rsi
	punpcklqdq	%xmm2, %xmm2
	.p2align 4,,10
	.p2align 3
.L13:
	movq	%rax, %rcx
	addq	$1, %rax
	salq	$4, %rcx
	movdqu	8(%r13,%rcx), %xmm0
	psubq	%xmm2, %xmm0
	paddq	%xmm0, %xmm1
	cmpq	%rax, %rsi
	jne	.L13
	movdqa	%xmm1, %xmm0
	movq	%r9, %rax
	psrldq	$8, %xmm0
	orq	$1, %rax
	andl	$1, %r9d
	paddq	%xmm0, %xmm1
	movq	%xmm1, %r8
	je	.L15
.L12:
	movq	0(%r13,%rax,8), %rax
	subq	%rdx, %rax
	addq	%rax, %r8
.L15:
	leaq	-2(%rdi), %rcx
	xorl	%eax, %eax
	.p2align 4,,10
	.p2align 3
.L20:
	addq	$1, %rax
	movq	0(%r13,%rax,8), %rsi
	cmpq	%rdx, %rsi
	je	.L18
	testq	%rcx, %rcx
	jle	.L17
	movq	%rsi, %rdx
	subq	-8(%r13,%rax,8), %rdx
	imulq	%rcx, %rdx
	cmpq	%r8, %rdx
	jg	.L19
	subq	%rdx, %r8
	movq	%rsi, %rdx
.L18:
	subq	$2, %rcx
	cmpq	%rdi, %rax
	jl	.L20
.L17:
	xorl	%eax, %eax
	movq	%r8, %rdx
	movl	$1, %edi
	leaq	.LC1(%rip), %rsi
	call	__printf_chk@PLT
	movq	-56(%rbp), %rax
	subq	%fs:40, %rax
	jne	.L33
	leaq	-40(%rbp), %rsp
	xorl	%eax, %eax
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_remember_state
	.cfi_def_cfa 7, 8
	ret
.L19:
	.cfi_restore_state
	movq	%r8, %rax
	cqto
	idivq	%rcx
	cmpq	%r8, %rdx
	cmovle	%rdx, %r8
	subq	%rdx, %rcx
	cmpq	%rcx, %r8
	cmovg	%rcx, %r8
	jmp	.L17
.L32:
	orq	$0, -8(%rsp,%rdx)
	jmp	.L8
.L11:
	jne	.L23
	movq	0(,%r15,8), %rdx
	xorl	%r8d, %r8d
	jmp	.L15
.L22:
	movl	$1, %eax
	xorl	%r8d, %r8d
	jmp	.L12
.L23:
	xorl	%r8d, %r8d
	jmp	.L17
.L33:
	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	cmpnum
	.type	cmpnum, @function
cmpnum:
.LFB39:
	.cfi_startproc
	endbr64
	movq	(%rsi), %rdx
	movl	$1, %eax
	cmpq	%rdx, (%rdi)
	jg	.L1
	setl	%al
	movzbl	%al, %eax
	negl	%eax
.L1:
	ret
	.cfi_endproc
.LFE39:
	.size	cmpnum, .-cmpnum
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%ld"
.LC1:
	.string	"%ld\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB40:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%r15
	pushq	%r14
	.cfi_offset 15, -24
	.cfi_offset 14, -32
	leaq	.LC0(%rip), %r14
	leaq	-64(%rbp), %rsi
	pushq	%r13
	movq	%r14, %rdi
	pushq	%r12
	pushq	%rbx
	subq	$24, %rsp
	.cfi_offset 13, -40
	.cfi_offset 12, -48
	.cfi_offset 3, -56
	movq	%fs:40, %rax
	movq	%rax, -56(%rbp)
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movq	-64(%rbp), %rsi
	movq	%rsp, %rcx
	leaq	15(,%rsi,8), %rax
	movq	%rax, %rdx
	andq	$-4096, %rax
	subq	%rax, %rcx
	andq	$-16, %rdx
	cmpq	%rcx, %rsp
	je	.L7
.L31:
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	cmpq	%rcx, %rsp
	jne	.L31
.L7:
	andl	$4095, %edx
	subq	%rdx, %rsp
	testq	%rdx, %rdx
	jne	.L32
.L8:
	leaq	7(%rsp), %r13
	movq	%r13, %r15
	andq	$-8, %r13
	shrq	$3, %r15
	testq	%rsi, %rsi
	jle	.L9
	movq	%r13, %rbx
	xorl	%r12d, %r12d
	.p2align 4,,10
	.p2align 3
.L10:
	movq	%rbx, %rsi
	movq	%r14, %rdi
	xorl	%eax, %eax
	addq	$1, %r12
	call	__isoc99_scanf@PLT
	movq	-64(%rbp), %rsi
	subq	%r12, (%rbx)
	addq	$8, %rbx
	cmpq	%rsi, %r12
	jl	.L10
.L9:
	movq	%r13, %rdi
	leaq	cmpnum(%rip), %rcx
	movl	$8, %edx
	call	qsort@PLT
	movq	-64(%rbp), %rdi
	cmpq	$1, %rdi
	jle	.L11
	movq	0(,%r15,8), %rdx
	leaq	-1(%rdi), %r9
	cmpq	$2, %rdi
	je	.L22
	movq	%r9, %rsi
	movq	%rdx, %xmm2
	pxor	%xmm1, %xmm1
	xorl	%eax, %eax
	shrq	%rsi
	punpcklqdq	%xmm2, %xmm2
	.p2align 4,,10
	.p2align 3
.L13:
	movq	%rax, %rcx
	addq	$1, %rax
	salq	$4, %rcx
	movdqu	8(%r13,%rcx), %xmm0
	psubq	%xmm2, %xmm0
	paddq	%xmm0, %xmm1
	cmpq	%rax, %rsi
	jne	.L13
	movdqa	%xmm1, %xmm0
	movq	%r9, %rax
	psrldq	$8, %xmm0
	orq	$1, %rax
	andl	$1, %r9d
	paddq	%xmm0, %xmm1
	movq	%xmm1, %r8
	je	.L15
.L12:
	movq	0(%r13,%rax,8), %rax
	subq	%rdx, %rax
	addq	%rax, %r8
.L15:
	leaq	-2(%rdi), %rcx
	xorl	%eax, %eax
	.p2align 4,,10
	.p2align 3
.L20:
	addq	$1, %rax
	movq	0(%r13,%rax,8), %rsi
	cmpq	%rdx, %rsi
	je	.L18
	testq	%rcx, %rcx
	jle	.L17
	movq	%rsi, %rdx
	subq	-8(%r13,%rax,8), %rdx
	imulq	%rcx, %rdx
	cmpq	%r8, %rdx
	jg	.L19
	subq	%rdx, %r8
	movq	%rsi, %rdx
.L18:
	subq	$2, %rcx
	cmpq	%rdi, %rax
	jl	.L20
.L17:
	xorl	%eax, %eax
	movq	%r8, %rdx
	movl	$1, %edi
	leaq	.LC1(%rip), %rsi
	call	__printf_chk@PLT
	movq	-56(%rbp), %rax
	subq	%fs:40, %rax
	jne	.L33
	leaq	-40(%rbp), %rsp
	xorl	%eax, %eax
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_remember_state
	.cfi_def_cfa 7, 8
	ret
.L19:
	.cfi_restore_state
	movq	%r8, %rax
	cqto
	idivq	%rcx
	cmpq	%r8, %rdx
	cmovle	%rdx, %r8
	subq	%rdx, %rcx
	cmpq	%rcx, %r8
	cmovg	%rcx, %r8
	jmp	.L17
.L32:
	orq	$0, -8(%rsp,%rdx)
	jmp	.L8
.L11:
	jne	.L23
	movq	0(,%r15,8), %rdx
	xorl	%r8d, %r8d
	jmp	.L15
.L22:
	movl	$1, %eax
	xorl	%r8d, %r8d
	jmp	.L12
.L23:
	xorl	%r8d, %r8d
	jmp	.L17
.L33:
	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 cmpnum(const void * n1, const void * n2) {
	if (*(long *)n1 > *(long *)n2)
	{
		return 1;
	}
	else if (*(long *)n1 < *(long *)n2)
	{
		return -1;
	}
	else
	{
		return 0;
	}
}

int main(void) {

  long n;
  scanf("%ld", &n);
  long a[n];
  for (long i = 0; i < n; i++) {
    scanf("%ld", &a[i]);
    a[i] -= i+1;
  }
  qsort(a, n, sizeof(long), cmpnum);
  long all = 0;
  for (long i = 1; i < n; i++) {
    all += a[i]-a[0];
  }
  long sadness = all;
  long min = all;
  long level = a[0];
  long width,height;
  for (long i = 0; i < n; i++) {
    if (a[i+1] == level) {
      continue;
    }
    width = i+1;
    if (n-width*2 <= 0) {
      break;
    }
    height = a[i+1]-a[i];
    if (height*(n-width*2) <= sadness) {
      level = a[i+1];
      sadness -= height*(n-width*2);
      min = sadness;
    } else {
      height = sadness/(n-width*2);
      level += height;
      sadness -= height*(n-width*2);
      if (sadness <= min) {
        min = sadness;
      }
      sadness = -(sadness-(n-width*2));
      if (sadness <= min) {
        min = sadness;
      }
      break;
    }
  }
  printf("%ld\n", min);

  return 0;
}
5
2 2 3 5 5

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 cmpnum(const void * n1, const void * n2) {
	if (*(long *)n1 > *(long *)n2)
	{
		return 1;
	}
	else if (*(long *)n1 < *(long *)n2)
	{
		return -1;
	}
	else
	{
		return 0;
	}
}

int main(void) {

  long n;
  scanf("%ld", &n);
  long a[n];
  for (long i = 0; i < n; i++) {
    scanf("%ld", &a[i]);
    a[i] -= i+1;
  }
  qsort(a, n, sizeof(long), cmpnum);
  long all = 0;
  for (long i = 1; i < n; i++) {
    all += a[i]-a[0];
  }
  long sadness = all;
  long min = all;
  long level = a[0];
  long width,height;
  for (long i = 0; i < n; i++) {
    if (a[i+1] == level) {
      continue;
    }
    width = i+1;
    if (n-width*2 <= 0) {
      break;
    }
    height = a[i+1]-a[i];
    if (height*(n-width*2) <= sadness) {
      level = a[i+1];
      sadness -= height*(n-width*2);
      min = sadness;
    } else {
      height = sadness/(n-width*2);
      level += height;
      sadness -= height*(n-width*2);
      if (sadness <= min) {
        min = sadness;
      }
      sadness = -(sadness-(n-width*2));
      if (sadness <= min) {
        min = sadness;
      }
      break;
    }
  }
  printf("%ld\n", min);

  return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	cmpnum
	.type	cmpnum, @function
cmpnum:
.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), %rax
	cmpq	%rax, %rdx
	jle	.L2
	movl	$1, %eax
	jmp	.L3
.L2:
	movq	-8(%rbp), %rax
	movq	(%rax), %rdx
	movq	-16(%rbp), %rax
	movq	(%rax), %rax
	cmpq	%rax, %rdx
	jge	.L4
	movl	$-1, %eax
	jmp	.L3
.L4:
	movl	$0, %eax
.L3:
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	cmpnum, .-cmpnum
	.section	.rodata
.LC0:
	.string	"%ld"
.LC1:
	.string	"%ld\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	%r15
	pushq	%r14
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	subq	$120, %rsp
	.cfi_offset 15, -24
	.cfi_offset 14, -32
	.cfi_offset 13, -40
	.cfi_offset 12, -48
	.cfi_offset 3, -56
	movq	%fs:40, %rax
	movq	%rax, -56(%rbp)
	xorl	%eax, %eax
	movq	%rsp, %rax
	movq	%rax, %rbx
	leaq	-152(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	-152(%rbp), %rax
	leaq	-1(%rax), %rdx
	movq	%rdx, -88(%rbp)
	movq	%rax, %rdx
	movq	%rdx, %r14
	movl	$0, %r15d
	movq	%rax, %rdx
	movq	%rdx, %r12
	movl	$0, %r13d
	leaq	0(,%rax,8), %rdx
	movl	$16, %eax
	subq	$1, %rax
	addq	%rdx, %rax
	movl	$16, %esi
	movl	$0, %edx
	divq	%rsi
	imulq	$16, %rax, %rax
	movq	%rax, %rcx
	andq	$-4096, %rcx
	movq	%rsp, %rdx
	subq	%rcx, %rdx
.L6:
	cmpq	%rdx, %rsp
	je	.L7
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L6
.L7:
	movq	%rax, %rdx
	andl	$4095, %edx
	subq	%rdx, %rsp
	movq	%rax, %rdx
	andl	$4095, %edx
	testq	%rdx, %rdx
	je	.L8
	andl	$4095, %eax
	subq	$8, %rax
	addq	%rsp, %rax
	orq	$0, (%rax)
.L8:
	movq	%rsp, %rax
	addq	$7, %rax
	shrq	$3, %rax
	salq	$3, %rax
	movq	%rax, -80(%rbp)
	movq	$0, -144(%rbp)
	jmp	.L9
.L10:
	movq	-144(%rbp), %rax
	leaq	0(,%rax,8), %rdx
	movq	-80(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	-80(%rbp), %rax
	movq	-144(%rbp), %rdx
	movq	(%rax,%rdx,8), %rax
	movq	-144(%rbp), %rdx
	addq	$1, %rdx
	subq	%rdx, %rax
	movq	%rax, %rcx
	movq	-80(%rbp), %rax
	movq	-144(%rbp), %rdx
	movq	%rcx, (%rax,%rdx,8)
	addq	$1, -144(%rbp)
.L9:
	movq	-152(%rbp), %rax
	cmpq	%rax, -144(%rbp)
	jl	.L10
	movq	-152(%rbp), %rax
	movq	%rax, %rsi
	movq	-80(%rbp), %rax
	leaq	cmpnum(%rip), %rdx
	movq	%rdx, %rcx
	movl	$8, %edx
	movq	%rax, %rdi
	call	qsort@PLT
	movq	$0, -136(%rbp)
	movq	$1, -128(%rbp)
	jmp	.L11
.L12:
	movq	-80(%rbp), %rax
	movq	-128(%rbp), %rdx
	movq	(%rax,%rdx,8), %rdx
	movq	-80(%rbp), %rax
	movq	(%rax), %rcx
	movq	%rdx, %rax
	subq	%rcx, %rax
	addq	%rax, -136(%rbp)
	addq	$1, -128(%rbp)
.L11:
	movq	-152(%rbp), %rax
	cmpq	%rax, -128(%rbp)
	jl	.L12
	movq	-136(%rbp), %rax
	movq	%rax, -120(%rbp)
	movq	-136(%rbp), %rax
	movq	%rax, -112(%rbp)
	movq	-80(%rbp), %rax
	movq	(%rax), %rax
	movq	%rax, -104(%rbp)
	movq	$0, -96(%rbp)
	jmp	.L13
.L21:
	movq	-96(%rbp), %rax
	leaq	1(%rax), %rdx
	movq	-80(%rbp), %rax
	movq	(%rax,%rdx,8), %rax
	cmpq	%rax, -104(%rbp)
	je	.L24
	movq	-96(%rbp), %rax
	addq	$1, %rax
	movq	%rax, -72(%rbp)
	movq	-152(%rbp), %rax
	movq	-72(%rbp), %rdx
	addq	%rdx, %rdx
	subq	%rdx, %rax
	testq	%rax, %rax
	jle	.L25
	movq	-96(%rbp), %rax
	leaq	1(%rax), %rdx
	movq	-80(%rbp), %rax
	movq	(%rax,%rdx,8), %rcx
	movq	-80(%rbp), %rax
	movq	-96(%rbp), %rdx
	movq	(%rax,%rdx,8), %rdx
	movq	%rcx, %rax
	subq	%rdx, %rax
	movq	%rax, -64(%rbp)
	movq	-152(%rbp), %rax
	movq	-72(%rbp), %rdx
	addq	%rdx, %rdx
	subq	%rdx, %rax
	imulq	-64(%rbp), %rax
	cmpq	%rax, -120(%rbp)
	jl	.L18
	movq	-96(%rbp), %rax
	leaq	1(%rax), %rdx
	movq	-80(%rbp), %rax
	movq	(%rax,%rdx,8), %rax
	movq	%rax, -104(%rbp)
	movq	-152(%rbp), %rax
	movq	-72(%rbp), %rdx
	addq	%rdx, %rdx
	subq	%rdx, %rax
	imulq	-64(%rbp), %rax
	subq	%rax, -120(%rbp)
	movq	-120(%rbp), %rax
	movq	%rax, -112(%rbp)
	jmp	.L15
.L18:
	movq	-152(%rbp), %rax
	movq	-72(%rbp), %rdx
	leaq	(%rdx,%rdx), %rcx
	subq	%rcx, %rax
	movq	%rax, %rdi
	movq	-120(%rbp), %rax
	cqto
	idivq	%rdi
	movq	%rax, -64(%rbp)
	movq	-64(%rbp), %rax
	addq	%rax, -104(%rbp)
	movq	-152(%rbp), %rax
	movq	-72(%rbp), %rdx
	addq	%rdx, %rdx
	subq	%rdx, %rax
	imulq	-64(%rbp), %rax
	subq	%rax, -120(%rbp)
	movq	-120(%rbp), %rax
	cmpq	-112(%rbp), %rax
	jg	.L19
	movq	-120(%rbp), %rax
	movq	%rax, -112(%rbp)
.L19:
	movq	-152(%rbp), %rax
	movq	-72(%rbp), %rdx
	addq	%rdx, %rdx
	subq	%rdx, %rax
	subq	-120(%rbp), %rax
	movq	%rax, -120(%rbp)
	movq	-120(%rbp), %rax
	cmpq	-112(%rbp), %rax
	jg	.L26
	movq	-120(%rbp), %rax
	movq	%rax, -112(%rbp)
	jmp	.L26
.L24:
	nop
.L15:
	addq	$1, -96(%rbp)
.L13:
	movq	-152(%rbp), %rax
	cmpq	%rax, -96(%rbp)
	jl	.L21
	jmp	.L17
.L25:
	nop
	jmp	.L17
.L26:
	nop
.L17:
	movq	-112(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	%rbx, %rsp
	movq	-56(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L23
	call	__stack_chk_fail@PLT
.L23:
	leaq	-40(%rbp), %rsp
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	main, .-main
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:
```

Only output the optimized assembly code. Do not include any other text. Do not write any comments in the assembly code. Wrap the assembly code in ```assembly``` tags.
train
	.file	"temp.c"
	.text
	.globl	cmpnum
	.type	cmpnum, @function
cmpnum:
.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), %rax
	cmpq	%rax, %rdx
	jle	.L2
	movl	$1, %eax
	jmp	.L3
.L2:
	movq	-8(%rbp), %rax
	movq	(%rax), %rdx
	movq	-16(%rbp), %rax
	movq	(%rax), %rax
	cmpq	%rax, %rdx
	jge	.L4
	movl	$-1, %eax
	jmp	.L3
.L4:
	movl	$0, %eax
.L3:
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	cmpnum, .-cmpnum
	.section	.rodata
.LC0:
	.string	"%ld"
.LC1:
	.string	"%ld\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	%r15
	pushq	%r14
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	subq	$120, %rsp
	.cfi_offset 15, -24
	.cfi_offset 14, -32
	.cfi_offset 13, -40
	.cfi_offset 12, -48
	.cfi_offset 3, -56
	movq	%fs:40, %rax
	movq	%rax, -56(%rbp)
	xorl	%eax, %eax
	movq	%rsp, %rax
	movq	%rax, %rbx
	leaq	-152(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	-152(%rbp), %rax
	leaq	-1(%rax), %rdx
	movq	%rdx, -88(%rbp)
	movq	%rax, %rdx
	movq	%rdx, %r14
	movl	$0, %r15d
	movq	%rax, %rdx
	movq	%rdx, %r12
	movl	$0, %r13d
	leaq	0(,%rax,8), %rdx
	movl	$16, %eax
	subq	$1, %rax
	addq	%rdx, %rax
	movl	$16, %esi
	movl	$0, %edx
	divq	%rsi
	imulq	$16, %rax, %rax
	movq	%rax, %rcx
	andq	$-4096, %rcx
	movq	%rsp, %rdx
	subq	%rcx, %rdx
.L6:
	cmpq	%rdx, %rsp
	je	.L7
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L6
.L7:
	movq	%rax, %rdx
	andl	$4095, %edx
	subq	%rdx, %rsp
	movq	%rax, %rdx
	andl	$4095, %edx
	testq	%rdx, %rdx
	je	.L8
	andl	$4095, %eax
	subq	$8, %rax
	addq	%rsp, %rax
	orq	$0, (%rax)
.L8:
	movq	%rsp, %rax
	addq	$7, %rax
	shrq	$3, %rax
	salq	$3, %rax
	movq	%rax, -80(%rbp)
	movq	$0, -144(%rbp)
	jmp	.L9
.L10:
	movq	-144(%rbp), %rax
	leaq	0(,%rax,8), %rdx
	movq	-80(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movq	-80(%rbp), %rax
	movq	-144(%rbp), %rdx
	movq	(%rax,%rdx,8), %rax
	movq	-144(%rbp), %rdx
	addq	$1, %rdx
	subq	%rdx, %rax
	movq	%rax, %rcx
	movq	-80(%rbp), %rax
	movq	-144(%rbp), %rdx
	movq	%rcx, (%rax,%rdx,8)
	addq	$1, -144(%rbp)
.L9:
	movq	-152(%rbp), %rax
	cmpq	%rax, -144(%rbp)
	jl	.L10
	movq	-152(%rbp), %rax
	movq	%rax, %rsi
	movq	-80(%rbp), %rax
	leaq	cmpnum(%rip), %rdx
	movq	%rdx, %rcx
	movl	$8, %edx
	movq	%rax, %rdi
	call	qsort@PLT
	movq	$0, -136(%rbp)
	movq	$1, -128(%rbp)
	jmp	.L11
.L12:
	movq	-80(%rbp), %rax
	movq	-128(%rbp), %rdx
	movq	(%rax,%rdx,8), %rdx
	movq	-80(%rbp), %rax
	movq	(%rax), %rcx
	movq	%rdx, %rax
	subq	%rcx, %rax
	addq	%rax, -136(%rbp)
	addq	$1, -128(%rbp)
.L11:
	movq	-152(%rbp), %rax
	cmpq	%rax, -128(%rbp)
	jl	.L12
	movq	-136(%rbp), %rax
	movq	%rax, -120(%rbp)
	movq	-136(%rbp), %rax
	movq	%rax, -112(%rbp)
	movq	-80(%rbp), %rax
	movq	(%rax), %rax
	movq	%rax, -104(%rbp)
	movq	$0, -96(%rbp)
	jmp	.L13
.L21:
	movq	-96(%rbp), %rax
	leaq	1(%rax), %rdx
	movq	-80(%rbp), %rax
	movq	(%rax,%rdx,8), %rax
	cmpq	%rax, -104(%rbp)
	je	.L24
	movq	-96(%rbp), %rax
	addq	$1, %rax
	movq	%rax, -72(%rbp)
	movq	-152(%rbp), %rax
	movq	-72(%rbp), %rdx
	addq	%rdx, %rdx
	subq	%rdx, %rax
	testq	%rax, %rax
	jle	.L25
	movq	-96(%rbp), %rax
	leaq	1(%rax), %rdx
	movq	-80(%rbp), %rax
	movq	(%rax,%rdx,8), %rcx
	movq	-80(%rbp), %rax
	movq	-96(%rbp), %rdx
	movq	(%rax,%rdx,8), %rdx
	movq	%rcx, %rax
	subq	%rdx, %rax
	movq	%rax, -64(%rbp)
	movq	-152(%rbp), %rax
	movq	-72(%rbp), %rdx
	addq	%rdx, %rdx
	subq	%rdx, %rax
	imulq	-64(%rbp), %rax
	cmpq	%rax, -120(%rbp)
	jl	.L18
	movq	-96(%rbp), %rax
	leaq	1(%rax), %rdx
	movq	-80(%rbp), %rax
	movq	(%rax,%rdx,8), %rax
	movq	%rax, -104(%rbp)
	movq	-152(%rbp), %rax
	movq	-72(%rbp), %rdx
	addq	%rdx, %rdx
	subq	%rdx, %rax
	imulq	-64(%rbp), %rax
	subq	%rax, -120(%rbp)
	movq	-120(%rbp), %rax
	movq	%rax, -112(%rbp)
	jmp	.L15
.L18:
	movq	-152(%rbp), %rax
	movq	-72(%rbp), %rdx
	leaq	(%rdx,%rdx), %rcx
	subq	%rcx, %rax
	movq	%rax, %rdi
	movq	-120(%rbp), %rax
	cqto
	idivq	%rdi
	movq	%rax, -64(%rbp)
	movq	-64(%rbp), %rax
	addq	%rax, -104(%rbp)
	movq	-152(%rbp), %rax
	movq	-72(%rbp), %rdx
	addq	%rdx, %rdx
	subq	%rdx, %rax
	imulq	-64(%rbp), %rax
	subq	%rax, -120(%rbp)
	movq	-120(%rbp), %rax
	cmpq	-112(%rbp), %rax
	jg	.L19
	movq	-120(%rbp), %rax
	movq	%rax, -112(%rbp)
.L19:
	movq	-152(%rbp), %rax
	movq	-72(%rbp), %rdx
	addq	%rdx, %rdx
	subq	%rdx, %rax
	subq	-120(%rbp), %rax
	movq	%rax, -120(%rbp)
	movq	-120(%rbp), %rax
	cmpq	-112(%rbp), %rax
	jg	.L26
	movq	-120(%rbp), %rax
	movq	%rax, -112(%rbp)
	jmp	.L26
.L24:
	nop
.L15:
	addq	$1, -96(%rbp)
.L13:
	movq	-152(%rbp), %rax
	cmpq	%rax, -96(%rbp)
	jl	.L21
	jmp	.L17
.L25:
	nop
	jmp	.L17
.L26:
	nop
.L17:
	movq	-112(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	%rbx, %rsp
	movq	-56(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L23
	call	__stack_chk_fail@PLT
.L23:
	leaq	-40(%rbp), %rsp
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	main, .-main
	.ident	"GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:
