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>

void swap(int *a, int *b) {
  int tmp = *a;
  *a = *b;
  *b = tmp;
}

int pop_max(int *a, int *n) {
  int i, last = *n - 1;
  for (i = last - 1; i >= 0; i--) {
    if (a[last] < a[i]) {
      swap(a+i, a+last);
    }
  }
  *n = *n - 1;
  return a[last];
}

int best_pizza(int n, int Bp, int Tp, int Bc, int *Tc_arr) {
  int c_sum = Bc;
  int p_sum = Bp;
  while (n > 0) {
    int new_c_sum = c_sum + pop_max(Tc_arr, &n);
    int new_p_sum = p_sum + Tp;
    if (new_c_sum/new_p_sum < c_sum/p_sum) {
      break;
    }
    c_sum = new_c_sum;
    p_sum = new_p_sum;
  }
  return c_sum/p_sum;
}

int main() {
  int i, N, Bp, Tp, Bc, *Tc_arr;
  scanf("%d", &N);
  scanf("%d %d", &Bp, &Tp);
  scanf("%d", &Bc);
  Tc_arr = (int*)malloc(sizeof(int)*N);
  for (i = 0; i < N; i++) {
    scanf("%d", Tc_arr+i);
  }
  printf("%d\n", best_pizza(N, Bp, Tp, Bc, Tc_arr));
  return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	swap
	.type	swap, @function
swap:
.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, -24(%rbp)
	movq	%rsi, -32(%rbp)
	movq	-24(%rbp), %rax
	movl	(%rax), %eax
	movl	%eax, -4(%rbp)
	movq	-32(%rbp), %rax
	movl	(%rax), %edx
	movq	-24(%rbp), %rax
	movl	%edx, (%rax)
	movq	-32(%rbp), %rax
	movl	-4(%rbp), %edx
	movl	%edx, (%rax)
	nop
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	swap, .-swap
	.globl	pop_max
	.type	pop_max, @function
pop_max:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$32, %rsp
	movq	%rdi, -24(%rbp)
	movq	%rsi, -32(%rbp)
	movq	-32(%rbp), %rax
	movl	(%rax), %eax
	subl	$1, %eax
	movl	%eax, -4(%rbp)
	movl	-4(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -8(%rbp)
	jmp	.L3
.L5:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	movq	-24(%rbp), %rax
	addq	%rcx, %rax
	movl	(%rax), %eax
	cmpl	%eax, %edx
	jge	.L4
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rax, %rdx
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	movq	-24(%rbp), %rax
	addq	%rcx, %rax
	movq	%rdx, %rsi
	movq	%rax, %rdi
	call	swap
.L4:
	subl	$1, -8(%rbp)
.L3:
	cmpl	$0, -8(%rbp)
	jns	.L5
	movq	-32(%rbp), %rax
	movl	(%rax), %eax
	leal	-1(%rax), %edx
	movq	-32(%rbp), %rax
	movl	%edx, (%rax)
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	pop_max, .-pop_max
	.globl	best_pizza
	.type	best_pizza, @function
best_pizza:
.LFB8:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$40, %rsp
	movl	%edi, -20(%rbp)
	movl	%esi, -24(%rbp)
	movl	%edx, -28(%rbp)
	movl	%ecx, -32(%rbp)
	movq	%r8, -40(%rbp)
	movl	-32(%rbp), %eax
	movl	%eax, -16(%rbp)
	movl	-24(%rbp), %eax
	movl	%eax, -12(%rbp)
	jmp	.L8
.L11:
	leaq	-20(%rbp), %rdx
	movq	-40(%rbp), %rax
	movq	%rdx, %rsi
	movq	%rax, %rdi
	call	pop_max
	movl	-16(%rbp), %edx
	addl	%edx, %eax
	movl	%eax, -8(%rbp)
	movl	-12(%rbp), %edx
	movl	-28(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, -4(%rbp)
	movl	-8(%rbp), %eax
	cltd
	idivl	-4(%rbp)
	movl	%eax, %ecx
	movl	-16(%rbp), %eax
	cltd
	idivl	-12(%rbp)
	cmpl	%eax, %ecx
	jl	.L13
	movl	-8(%rbp), %eax
	movl	%eax, -16(%rbp)
	movl	-4(%rbp), %eax
	movl	%eax, -12(%rbp)
.L8:
	movl	-20(%rbp), %eax
	testl	%eax, %eax
	jg	.L11
	jmp	.L10
.L13:
	nop
.L10:
	movl	-16(%rbp), %eax
	cltd
	idivl	-12(%rbp)
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.size	best_pizza, .-best_pizza
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d %d"
.LC2:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB9:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$48, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-36(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	leaq	-28(%rbp), %rdx
	leaq	-32(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	leaq	-24(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-36(%rbp), %eax
	cltq
	salq	$2, %rax
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -16(%rbp)
	movl	$0, -20(%rbp)
	jmp	.L15
.L16:
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -20(%rbp)
.L15:
	movl	-36(%rbp), %eax
	cmpl	%eax, -20(%rbp)
	jl	.L16
	movl	-24(%rbp), %ecx
	movl	-28(%rbp), %edx
	movl	-32(%rbp), %esi
	movl	-36(%rbp), %eax
	movq	-16(%rbp), %rdi
	movq	%rdi, %r8
	movl	%eax, %edi
	call	best_pizza
	movl	%eax, %esi
	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	.L18
	call	__stack_chk_fail@PLT
.L18:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE9:
	.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	swap
	.type	swap, @function
swap:
.LFB39:
	.cfi_startproc
	endbr64
	movl	(%rdi), %eax
	movl	(%rsi), %edx
	movl	%edx, (%rdi)
	movl	%eax, (%rsi)
	ret
	.cfi_endproc
.LFE39:
	.size	swap, .-swap
	.p2align 4
	.globl	pop_max
	.type	pop_max, @function
pop_max:
.LFB40:
	.cfi_startproc
	endbr64
	movl	(%rsi), %eax
	leal	-1(%rax), %edx
	movslq	%edx, %rcx
	leaq	(%rdi,%rcx,4), %r8
	subl	$2, %eax
	js	.L4
	movl	(%r8), %ecx
	cltq
	.p2align 4,,10
	.p2align 3
.L6:
	movl	(%rdi,%rax,4), %edx
	cmpl	%ecx, %edx
	jle	.L5
	movl	%ecx, (%rdi,%rax,4)
	movl	%edx, %ecx
	movl	%edx, (%r8)
.L5:
	subq	$1, %rax
	testl	%eax, %eax
	jns	.L6
	movl	(%rsi), %eax
	leal	-1(%rax), %edx
.L4:
	movl	%edx, (%rsi)
	movl	(%r8), %eax
	ret
	.cfi_endproc
.LFE40:
	.size	pop_max, .-pop_max
	.p2align 4
	.globl	best_pizza
	.type	best_pizza, @function
best_pizza:
.LFB41:
	.cfi_startproc
	endbr64
	movl	%edx, %r11d
	movslq	%edi, %rdx
	subl	$2, %edi
	movl	%esi, %r9d
	leaq	(%r8,%rdx,4), %r10
	leal	2(%rdi), %edx
	movl	%ecx, %eax
	testl	%edx, %edx
	jle	.L19
	.p2align 4,,10
	.p2align 3
.L14:
	movl	-4(%r10), %esi
	cmpl	$-1, %edi
	je	.L10
	movslq	%edi, %rdx
	.p2align 4,,10
	.p2align 3
.L12:
	movl	(%r8,%rdx,4), %ecx
	cmpl	%esi, %ecx
	jle	.L11
	movl	%esi, (%r8,%rdx,4)
	movl	%ecx, %esi
	movl	%ecx, -4(%r10)
.L11:
	subq	$1, %rdx
	cmpl	$-1, %edx
	jne	.L12
.L10:
	cltd
	addl	%eax, %esi
	leal	(%r9,%r11), %ecx
	subq	$4, %r10
	idivl	%r9d
	subl	$1, %edi
	movl	%eax, %r9d
	movl	%esi, %eax
	cltd
	idivl	%ecx
	cmpl	%r9d, %eax
	jl	.L8
	leal	2(%rdi), %edx
	movl	%ecx, %r9d
	movl	%esi, %eax
	testl	%edx, %edx
	jg	.L14
.L19:
	cltd
	idivl	%r9d
	movl	%eax, %r9d
.L8:
	movl	%r9d, %eax
	ret
	.cfi_endproc
.LFE41:
	.size	best_pizza, .-best_pizza
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d"
.LC1:
	.string	"%d %d"
.LC2:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB42:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	leaq	.LC0(%rip), %r14
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	movq	%r14, %rdi
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	subq	$32, %rsp
	.cfi_def_cfa_offset 80
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rsi
	call	__isoc99_scanf@PLT
	leaq	16(%rsp), %rdx
	leaq	12(%rsp), %rsi
	xorl	%eax, %eax
	leaq	.LC1(%rip), %rdi
	call	__isoc99_scanf@PLT
	leaq	20(%rsp), %rsi
	movq	%r14, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movslq	8(%rsp), %rbp
	leaq	0(,%rbp,4), %rdi
	call	malloc@PLT
	movq	%rax, %rbx
	testl	%ebp, %ebp
	jle	.L37
	movq	%rax, %r12
	xorl	%ebp, %ebp
	.p2align 4,,10
	.p2align 3
.L22:
	movq	%r12, %rsi
	movq	%r14, %rdi
	xorl	%eax, %eax
	addl	$1, %ebp
	call	__isoc99_scanf@PLT
	movl	8(%rsp), %r13d
	addq	$4, %r12
	cmpl	%ebp, %r13d
	jg	.L22
	movslq	%r13d, %rbp
.L21:
	leal	-2(%r13), %edi
	movl	20(%rsp), %r9d
	movl	16(%rsp), %r11d
	leaq	(%rbx,%rbp,4), %r8
	leal	2(%rdi), %eax
	movl	12(%rsp), %r10d
	testl	%eax, %eax
	jle	.L28
	.p2align 4,,10
	.p2align 3
.L27:
	movl	-4(%r8), %eax
	cmpl	$-1, %edi
	je	.L24
	movslq	%edi, %rcx
	.p2align 4,,10
	.p2align 3
.L26:
	movl	(%rbx,%rcx,4), %esi
	cmpl	%eax, %esi
	jle	.L25
	movl	%eax, (%rbx,%rcx,4)
	movl	%esi, %eax
	movl	%esi, -4(%r8)
.L25:
	subq	$1, %rcx
	cmpl	$-1, %ecx
	jne	.L26
.L24:
	leal	(%r9,%rax), %ecx
	leal	(%r11,%r10), %esi
	subq	$4, %r8
	subl	$1, %edi
	movl	%ecx, %eax
	cltd
	idivl	%esi
	movl	%eax, %ebp
	movl	%r9d, %eax
	cltd
	idivl	%r10d
	cmpl	%eax, %ebp
	jl	.L28
	leal	2(%rdi), %eax
	movl	%esi, %r10d
	movl	%ecx, %r9d
	testl	%eax, %eax
	jg	.L27
.L28:
	movl	%r9d, %eax
	leaq	.LC2(%rip), %rsi
	movl	$1, %edi
	cltd
	idivl	%r10d
	movl	%eax, %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	24(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L39
	addq	$32, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 48
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
.L37:
	.cfi_restore_state
	movq	%rbp, %r13
	jmp	.L21
.L39:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE42:
	.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	swap
	.type	swap, @function
swap:
.LFB39:
	.cfi_startproc
	endbr64
	movl	(%rdi), %eax
	movl	(%rsi), %edx
	movl	%edx, (%rdi)
	movl	%eax, (%rsi)
	ret
	.cfi_endproc
.LFE39:
	.size	swap, .-swap
	.p2align 4
	.globl	pop_max
	.type	pop_max, @function
pop_max:
.LFB40:
	.cfi_startproc
	endbr64
	movl	(%rsi), %eax
	leal	-1(%rax), %edx
	movslq	%edx, %rcx
	leaq	(%rdi,%rcx,4), %r8
	subl	$2, %eax
	js	.L4
	movl	(%r8), %ecx
	cltq
	.p2align 4,,10
	.p2align 3
.L6:
	movl	(%rdi,%rax,4), %edx
	cmpl	%ecx, %edx
	jle	.L5
	movl	%ecx, (%rdi,%rax,4)
	movl	%edx, %ecx
	movl	%edx, (%r8)
.L5:
	subq	$1, %rax
	testl	%eax, %eax
	jns	.L6
	movl	(%rsi), %eax
	leal	-1(%rax), %edx
.L4:
	movl	%edx, (%rsi)
	movl	(%r8), %eax
	ret
	.cfi_endproc
.LFE40:
	.size	pop_max, .-pop_max
	.p2align 4
	.globl	best_pizza
	.type	best_pizza, @function
best_pizza:
.LFB41:
	.cfi_startproc
	endbr64
	movl	%edx, %r11d
	movslq	%edi, %rdx
	subl	$2, %edi
	movl	%esi, %r9d
	leaq	(%r8,%rdx,4), %r10
	leal	2(%rdi), %edx
	movl	%ecx, %eax
	testl	%edx, %edx
	jle	.L19
	.p2align 4,,10
	.p2align 3
.L14:
	movl	-4(%r10), %esi
	cmpl	$-1, %edi
	je	.L10
	movslq	%edi, %rdx
	.p2align 4,,10
	.p2align 3
.L12:
	movl	(%r8,%rdx,4), %ecx
	cmpl	%esi, %ecx
	jle	.L11
	movl	%esi, (%r8,%rdx,4)
	movl	%ecx, %esi
	movl	%ecx, -4(%r10)
.L11:
	subq	$1, %rdx
	cmpl	$-1, %edx
	jne	.L12
.L10:
	cltd
	addl	%eax, %esi
	leal	(%r9,%r11), %ecx
	subq	$4, %r10
	idivl	%r9d
	subl	$1, %edi
	movl	%eax, %r9d
	movl	%esi, %eax
	cltd
	idivl	%ecx
	cmpl	%r9d, %eax
	jl	.L8
	leal	2(%rdi), %edx
	movl	%ecx, %r9d
	movl	%esi, %eax
	testl	%edx, %edx
	jg	.L14
.L19:
	cltd
	idivl	%r9d
	movl	%eax, %r9d
.L8:
	movl	%r9d, %eax
	ret
	.cfi_endproc
.LFE41:
	.size	best_pizza, .-best_pizza
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d"
.LC1:
	.string	"%d %d"
.LC2:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB42:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	leaq	.LC0(%rip), %r14
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	movq	%r14, %rdi
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	subq	$32, %rsp
	.cfi_def_cfa_offset 80
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rsi
	call	__isoc99_scanf@PLT
	leaq	16(%rsp), %rdx
	leaq	12(%rsp), %rsi
	xorl	%eax, %eax
	leaq	.LC1(%rip), %rdi
	call	__isoc99_scanf@PLT
	leaq	20(%rsp), %rsi
	movq	%r14, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movslq	8(%rsp), %rbp
	leaq	0(,%rbp,4), %rdi
	call	malloc@PLT
	movq	%rax, %rbx
	testl	%ebp, %ebp
	jle	.L37
	movq	%rax, %r12
	xorl	%ebp, %ebp
	.p2align 4,,10
	.p2align 3
.L22:
	movq	%r12, %rsi
	movq	%r14, %rdi
	xorl	%eax, %eax
	addl	$1, %ebp
	call	__isoc99_scanf@PLT
	movl	8(%rsp), %r13d
	addq	$4, %r12
	cmpl	%ebp, %r13d
	jg	.L22
	movslq	%r13d, %rbp
.L21:
	leal	-2(%r13), %edi
	movl	20(%rsp), %r9d
	movl	16(%rsp), %r11d
	leaq	(%rbx,%rbp,4), %r8
	leal	2(%rdi), %eax
	movl	12(%rsp), %r10d
	testl	%eax, %eax
	jle	.L28
	.p2align 4,,10
	.p2align 3
.L27:
	movl	-4(%r8), %eax
	cmpl	$-1, %edi
	je	.L24
	movslq	%edi, %rcx
	.p2align 4,,10
	.p2align 3
.L26:
	movl	(%rbx,%rcx,4), %esi
	cmpl	%eax, %esi
	jle	.L25
	movl	%eax, (%rbx,%rcx,4)
	movl	%esi, %eax
	movl	%esi, -4(%r8)
.L25:
	subq	$1, %rcx
	cmpl	$-1, %ecx
	jne	.L26
.L24:
	leal	(%r9,%rax), %ecx
	leal	(%r11,%r10), %esi
	subq	$4, %r8
	subl	$1, %edi
	movl	%ecx, %eax
	cltd
	idivl	%esi
	movl	%eax, %ebp
	movl	%r9d, %eax
	cltd
	idivl	%r10d
	cmpl	%eax, %ebp
	jl	.L28
	leal	2(%rdi), %eax
	movl	%esi, %r10d
	movl	%ecx, %r9d
	testl	%eax, %eax
	jg	.L27
.L28:
	movl	%r9d, %eax
	leaq	.LC2(%rip), %rsi
	movl	$1, %edi
	cltd
	idivl	%r10d
	movl	%eax, %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	24(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L39
	addq	$32, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 48
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
.L37:
	.cfi_restore_state
	movq	%rbp, %r13
	jmp	.L21
.L39:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE42:
	.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>

void swap(int *a, int *b) {
  int tmp = *a;
  *a = *b;
  *b = tmp;
}

int pop_max(int *a, int *n) {
  int i, last = *n - 1;
  for (i = last - 1; i >= 0; i--) {
    if (a[last] < a[i]) {
      swap(a+i, a+last);
    }
  }
  *n = *n - 1;
  return a[last];
}

int best_pizza(int n, int Bp, int Tp, int Bc, int *Tc_arr) {
  int c_sum = Bc;
  int p_sum = Bp;
  while (n > 0) {
    int new_c_sum = c_sum + pop_max(Tc_arr, &n);
    int new_p_sum = p_sum + Tp;
    if (new_c_sum/new_p_sum < c_sum/p_sum) {
      break;
    }
    c_sum = new_c_sum;
    p_sum = new_p_sum;
  }
  return c_sum/p_sum;
}

int main() {
  int i, N, Bp, Tp, Bc, *Tc_arr;
  scanf("%d", &N);
  scanf("%d %d", &Bp, &Tp);
  scanf("%d", &Bc);
  Tc_arr = (int*)malloc(sizeof(int)*N);
  for (i = 0; i < N; i++) {
    scanf("%d", Tc_arr+i);
  }
  printf("%d\n", best_pizza(N, Bp, Tp, Bc, Tc_arr));
  return 0;
}
3
12 2
200
50
300
110
 3
17 2
200
73
300
110
 3
12 2
200
50
599
100
 3
12 2
200
73
575
110
 3
17 2
200
50
300
010
 3
17 2
63
50
300
010
 3
12 2
200
54
506
110
 3
17 2
38
50
300
010
 3
12 2
358
87
575
010
 3
12 2
200
54
383
110

38
 29
 57
 55
 26
 19
 51
 18
 66
 43

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>

void swap(int *a, int *b) {
  int tmp = *a;
  *a = *b;
  *b = tmp;
}

int pop_max(int *a, int *n) {
  int i, last = *n - 1;
  for (i = last - 1; i >= 0; i--) {
    if (a[last] < a[i]) {
      swap(a+i, a+last);
    }
  }
  *n = *n - 1;
  return a[last];
}

int best_pizza(int n, int Bp, int Tp, int Bc, int *Tc_arr) {
  int c_sum = Bc;
  int p_sum = Bp;
  while (n > 0) {
    int new_c_sum = c_sum + pop_max(Tc_arr, &n);
    int new_p_sum = p_sum + Tp;
    if (new_c_sum/new_p_sum < c_sum/p_sum) {
      break;
    }
    c_sum = new_c_sum;
    p_sum = new_p_sum;
  }
  return c_sum/p_sum;
}

int main() {
  int i, N, Bp, Tp, Bc, *Tc_arr;
  scanf("%d", &N);
  scanf("%d %d", &Bp, &Tp);
  scanf("%d", &Bc);
  Tc_arr = (int*)malloc(sizeof(int)*N);
  for (i = 0; i < N; i++) {
    scanf("%d", Tc_arr+i);
  }
  printf("%d\n", best_pizza(N, Bp, Tp, Bc, Tc_arr));
  return 0;
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	swap
	.type	swap, @function
swap:
.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, -24(%rbp)
	movq	%rsi, -32(%rbp)
	movq	-24(%rbp), %rax
	movl	(%rax), %eax
	movl	%eax, -4(%rbp)
	movq	-32(%rbp), %rax
	movl	(%rax), %edx
	movq	-24(%rbp), %rax
	movl	%edx, (%rax)
	movq	-32(%rbp), %rax
	movl	-4(%rbp), %edx
	movl	%edx, (%rax)
	nop
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	swap, .-swap
	.globl	pop_max
	.type	pop_max, @function
pop_max:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$32, %rsp
	movq	%rdi, -24(%rbp)
	movq	%rsi, -32(%rbp)
	movq	-32(%rbp), %rax
	movl	(%rax), %eax
	subl	$1, %eax
	movl	%eax, -4(%rbp)
	movl	-4(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -8(%rbp)
	jmp	.L3
.L5:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	movq	-24(%rbp), %rax
	addq	%rcx, %rax
	movl	(%rax), %eax
	cmpl	%eax, %edx
	jge	.L4
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rax, %rdx
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	movq	-24(%rbp), %rax
	addq	%rcx, %rax
	movq	%rdx, %rsi
	movq	%rax, %rdi
	call	swap
.L4:
	subl	$1, -8(%rbp)
.L3:
	cmpl	$0, -8(%rbp)
	jns	.L5
	movq	-32(%rbp), %rax
	movl	(%rax), %eax
	leal	-1(%rax), %edx
	movq	-32(%rbp), %rax
	movl	%edx, (%rax)
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	pop_max, .-pop_max
	.globl	best_pizza
	.type	best_pizza, @function
best_pizza:
.LFB8:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$40, %rsp
	movl	%edi, -20(%rbp)
	movl	%esi, -24(%rbp)
	movl	%edx, -28(%rbp)
	movl	%ecx, -32(%rbp)
	movq	%r8, -40(%rbp)
	movl	-32(%rbp), %eax
	movl	%eax, -16(%rbp)
	movl	-24(%rbp), %eax
	movl	%eax, -12(%rbp)
	jmp	.L8
.L11:
	leaq	-20(%rbp), %rdx
	movq	-40(%rbp), %rax
	movq	%rdx, %rsi
	movq	%rax, %rdi
	call	pop_max
	movl	-16(%rbp), %edx
	addl	%edx, %eax
	movl	%eax, -8(%rbp)
	movl	-12(%rbp), %edx
	movl	-28(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, -4(%rbp)
	movl	-8(%rbp), %eax
	cltd
	idivl	-4(%rbp)
	movl	%eax, %ecx
	movl	-16(%rbp), %eax
	cltd
	idivl	-12(%rbp)
	cmpl	%eax, %ecx
	jl	.L13
	movl	-8(%rbp), %eax
	movl	%eax, -16(%rbp)
	movl	-4(%rbp), %eax
	movl	%eax, -12(%rbp)
.L8:
	movl	-20(%rbp), %eax
	testl	%eax, %eax
	jg	.L11
	jmp	.L10
.L13:
	nop
.L10:
	movl	-16(%rbp), %eax
	cltd
	idivl	-12(%rbp)
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.size	best_pizza, .-best_pizza
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d %d"
.LC2:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB9:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$48, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-36(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	leaq	-28(%rbp), %rdx
	leaq	-32(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	leaq	-24(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-36(%rbp), %eax
	cltq
	salq	$2, %rax
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -16(%rbp)
	movl	$0, -20(%rbp)
	jmp	.L15
.L16:
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -20(%rbp)
.L15:
	movl	-36(%rbp), %eax
	cmpl	%eax, -20(%rbp)
	jl	.L16
	movl	-24(%rbp), %ecx
	movl	-28(%rbp), %edx
	movl	-32(%rbp), %esi
	movl	-36(%rbp), %eax
	movq	-16(%rbp), %rdi
	movq	%rdi, %r8
	movl	%eax, %edi
	call	best_pizza
	movl	%eax, %esi
	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	.L18
	call	__stack_chk_fail@PLT
.L18:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE9:
	.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	swap
	.type	swap, @function
swap:
.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, -24(%rbp)
	movq	%rsi, -32(%rbp)
	movq	-24(%rbp), %rax
	movl	(%rax), %eax
	movl	%eax, -4(%rbp)
	movq	-32(%rbp), %rax
	movl	(%rax), %edx
	movq	-24(%rbp), %rax
	movl	%edx, (%rax)
	movq	-32(%rbp), %rax
	movl	-4(%rbp), %edx
	movl	%edx, (%rax)
	nop
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	swap, .-swap
	.globl	pop_max
	.type	pop_max, @function
pop_max:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$32, %rsp
	movq	%rdi, -24(%rbp)
	movq	%rsi, -32(%rbp)
	movq	-32(%rbp), %rax
	movl	(%rax), %eax
	subl	$1, %eax
	movl	%eax, -4(%rbp)
	movl	-4(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -8(%rbp)
	jmp	.L3
.L5:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	movq	-24(%rbp), %rax
	addq	%rcx, %rax
	movl	(%rax), %eax
	cmpl	%eax, %edx
	jge	.L4
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rax, %rdx
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	movq	-24(%rbp), %rax
	addq	%rcx, %rax
	movq	%rdx, %rsi
	movq	%rax, %rdi
	call	swap
.L4:
	subl	$1, -8(%rbp)
.L3:
	cmpl	$0, -8(%rbp)
	jns	.L5
	movq	-32(%rbp), %rax
	movl	(%rax), %eax
	leal	-1(%rax), %edx
	movq	-32(%rbp), %rax
	movl	%edx, (%rax)
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	pop_max, .-pop_max
	.globl	best_pizza
	.type	best_pizza, @function
best_pizza:
.LFB8:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$40, %rsp
	movl	%edi, -20(%rbp)
	movl	%esi, -24(%rbp)
	movl	%edx, -28(%rbp)
	movl	%ecx, -32(%rbp)
	movq	%r8, -40(%rbp)
	movl	-32(%rbp), %eax
	movl	%eax, -16(%rbp)
	movl	-24(%rbp), %eax
	movl	%eax, -12(%rbp)
	jmp	.L8
.L11:
	leaq	-20(%rbp), %rdx
	movq	-40(%rbp), %rax
	movq	%rdx, %rsi
	movq	%rax, %rdi
	call	pop_max
	movl	-16(%rbp), %edx
	addl	%edx, %eax
	movl	%eax, -8(%rbp)
	movl	-12(%rbp), %edx
	movl	-28(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, -4(%rbp)
	movl	-8(%rbp), %eax
	cltd
	idivl	-4(%rbp)
	movl	%eax, %ecx
	movl	-16(%rbp), %eax
	cltd
	idivl	-12(%rbp)
	cmpl	%eax, %ecx
	jl	.L13
	movl	-8(%rbp), %eax
	movl	%eax, -16(%rbp)
	movl	-4(%rbp), %eax
	movl	%eax, -12(%rbp)
.L8:
	movl	-20(%rbp), %eax
	testl	%eax, %eax
	jg	.L11
	jmp	.L10
.L13:
	nop
.L10:
	movl	-16(%rbp), %eax
	cltd
	idivl	-12(%rbp)
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.size	best_pizza, .-best_pizza
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d %d"
.LC2:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB9:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$48, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-36(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	leaq	-28(%rbp), %rdx
	leaq	-32(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	leaq	-24(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-36(%rbp), %eax
	cltq
	salq	$2, %rax
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -16(%rbp)
	movl	$0, -20(%rbp)
	jmp	.L15
.L16:
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-16(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -20(%rbp)
.L15:
	movl	-36(%rbp), %eax
	cmpl	%eax, -20(%rbp)
	jl	.L16
	movl	-24(%rbp), %ecx
	movl	-28(%rbp), %edx
	movl	-32(%rbp), %esi
	movl	-36(%rbp), %eax
	movq	-16(%rbp), %rdi
	movq	%rdi, %r8
	movl	%eax, %edi
	call	best_pizza
	movl	%eax, %esi
	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	.L18
	call	__stack_chk_fail@PLT
.L18:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE9:
	.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:
