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<math.h>
#define MAX 1000
#define VMAX 10000

int n, A[MAX], s;
int B[MAX], T[VMAX+1];

int partition(int A[], int p, int r){
  int i, j;
  int x, t;
  x = A[r];
  i = p-1;
  for( j = p ; j < r ; j++ ){
    if( A[j] <= x ){
      i++;
      t = A[i];
      A[i] = A[j];
      A[j] = t;
    }
  }
  t = A[i+1];
  A[i+1] = A[r];
  A[r] = t;
  return i + 1;
}

void quickSort(int A[], int p, int r){
  int q;
  if( p < r ){
    q = partition(A, p, r);
    quickSort(A, p, q-1);
    quickSort(A, q+1, r);
  }
}


int solve(){
  int i, ans = 0;

  int V[MAX];
  for( i = 0 ; i < n ; i++ ){
    B[i] = A[i];
    V[i] = 0;
  }
  quickSort(B, 0, n-1);
  for( i = 0 ; i < n ; i++ ) T[B[i]] = i;
  for( i = 0 ; i < n ; i++ ){
    if( V[i] ) continue;
    int cur = i;
    int S = 0;
    int m = VMAX;
    int an = 0;
    while( 1 ){
      V[cur] = 1;
      an++;
      int v = A[cur];
      m = fmin(m, v);
      S += v;
      cur = T[v];
      if( V[cur] ) break;
    }
    ans += fmin(S+(an-2)*m, m+S+(an+1)*s);
  }

  return ans;
}

int main(){
  int i;
  scanf("%d",&n);
  s = VMAX;
  for( i = 0 ; i < n ; i++ ){
    scanf("%d", &A[i]);
    s = fmin(s, A[i]);
  }
  int ans = solve();
  printf("%d\n", ans);

  return 0;
}

```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	n
	.bss
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.globl	A
	.align 32
	.type	A, @object
	.size	A, 4000
A:
	.zero	4000
	.globl	s
	.align 4
	.type	s, @object
	.size	s, 4
s:
	.zero	4
	.globl	B
	.align 32
	.type	B, @object
	.size	B, 4000
B:
	.zero	4000
	.globl	T
	.align 32
	.type	T, @object
	.size	T, 40004
T:
	.zero	40004
	.text
	.globl	partition
	.type	partition, @function
partition:
.LFB0:
	.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)
	movl	%esi, -28(%rbp)
	movl	%edx, -32(%rbp)
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, -8(%rbp)
	movl	-28(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -16(%rbp)
	movl	-28(%rbp), %eax
	movl	%eax, -12(%rbp)
	jmp	.L2
.L4:
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	cmpl	%eax, -8(%rbp)
	jl	.L3
	addl	$1, -16(%rbp)
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, -4(%rbp)
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	-16(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	movq	-24(%rbp), %rdx
	addq	%rcx, %rdx
	movl	(%rax), %eax
	movl	%eax, (%rdx)
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rax, %rdx
	movl	-4(%rbp), %eax
	movl	%eax, (%rdx)
.L3:
	addl	$1, -12(%rbp)
.L2:
	movl	-12(%rbp), %eax
	cmpl	-32(%rbp), %eax
	jl	.L4
	movl	-16(%rbp), %eax
	cltq
	addq	$1, %rax
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, -4(%rbp)
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	-16(%rbp), %edx
	movslq	%edx, %rdx
	addq	$1, %rdx
	leaq	0(,%rdx,4), %rcx
	movq	-24(%rbp), %rdx
	addq	%rcx, %rdx
	movl	(%rax), %eax
	movl	%eax, (%rdx)
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rax, %rdx
	movl	-4(%rbp), %eax
	movl	%eax, (%rdx)
	movl	-16(%rbp), %eax
	addl	$1, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	partition, .-partition
	.globl	quickSort
	.type	quickSort, @function
quickSort:
.LFB1:
	.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)
	movl	%esi, -28(%rbp)
	movl	%edx, -32(%rbp)
	movl	-28(%rbp), %eax
	cmpl	-32(%rbp), %eax
	jge	.L8
	movl	-32(%rbp), %edx
	movl	-28(%rbp), %ecx
	movq	-24(%rbp), %rax
	movl	%ecx, %esi
	movq	%rax, %rdi
	call	partition
	movl	%eax, -4(%rbp)
	movl	-4(%rbp), %eax
	leal	-1(%rax), %edx
	movl	-28(%rbp), %ecx
	movq	-24(%rbp), %rax
	movl	%ecx, %esi
	movq	%rax, %rdi
	call	quickSort
	movl	-4(%rbp), %eax
	leal	1(%rax), %ecx
	movl	-32(%rbp), %edx
	movq	-24(%rbp), %rax
	movl	%ecx, %esi
	movq	%rax, %rdi
	call	quickSort
.L8:
	nop
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.size	quickSort, .-quickSort
	.globl	solve
	.type	solve, @function
solve:
.LFB2:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$4064, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -4040(%rbp)
	movl	$0, -4044(%rbp)
	jmp	.L10
.L11:
	movl	-4044(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	-4044(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	B(%rip), %rdx
	movl	%eax, (%rcx,%rdx)
	movl	-4044(%rbp), %eax
	cltq
	movl	$0, -4016(%rbp,%rax,4)
	addl	$1, -4044(%rbp)
.L10:
	movl	n(%rip), %eax
	cmpl	%eax, -4044(%rbp)
	jl	.L11
	movl	n(%rip), %eax
	subl	$1, %eax
	movl	%eax, %edx
	movl	$0, %esi
	leaq	B(%rip), %rax
	movq	%rax, %rdi
	call	quickSort
	movl	$0, -4044(%rbp)
	jmp	.L12
.L13:
	movl	-4044(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	B(%rip), %rax
	movl	(%rdx,%rax), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	T(%rip), %rdx
	movl	-4044(%rbp), %eax
	movl	%eax, (%rcx,%rdx)
	addl	$1, -4044(%rbp)
.L12:
	movl	n(%rip), %eax
	cmpl	%eax, -4044(%rbp)
	jl	.L13
	movl	$0, -4044(%rbp)
	jmp	.L14
.L20:
	movl	-4044(%rbp), %eax
	cltq
	movl	-4016(%rbp,%rax,4), %eax
	testl	%eax, %eax
	jne	.L24
	movl	-4044(%rbp), %eax
	movl	%eax, -4036(%rbp)
	movl	$0, -4032(%rbp)
	movl	$10000, -4028(%rbp)
	movl	$0, -4024(%rbp)
.L19:
	movl	-4036(%rbp), %eax
	cltq
	movl	$1, -4016(%rbp,%rax,4)
	addl	$1, -4024(%rbp)
	movl	-4036(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, -4020(%rbp)
	pxor	%xmm0, %xmm0
	cvtsi2sdl	-4020(%rbp), %xmm0
	pxor	%xmm2, %xmm2
	cvtsi2sdl	-4028(%rbp), %xmm2
	movq	%xmm2, %rax
	movapd	%xmm0, %xmm1
	movq	%rax, %xmm0
	call	fmin@PLT
	cvttsd2sil	%xmm0, %eax
	movl	%eax, -4028(%rbp)
	movl	-4020(%rbp), %eax
	addl	%eax, -4032(%rbp)
	movl	-4020(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	T(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, -4036(%rbp)
	movl	-4036(%rbp), %eax
	cltq
	movl	-4016(%rbp,%rax,4), %eax
	testl	%eax, %eax
	jne	.L25
	jmp	.L19
.L25:
	nop
	pxor	%xmm3, %xmm3
	cvtsi2sdl	-4040(%rbp), %xmm3
	movsd	%xmm3, -4056(%rbp)
	movl	-4028(%rbp), %edx
	movl	-4032(%rbp), %eax
	leal	(%rdx,%rax), %ecx
	movl	-4024(%rbp), %eax
	leal	1(%rax), %edx
	movl	s(%rip), %eax
	imull	%edx, %eax
	addl	%ecx, %eax
	pxor	%xmm0, %xmm0
	cvtsi2sdl	%eax, %xmm0
	movl	-4024(%rbp), %eax
	subl	$2, %eax
	imull	-4028(%rbp), %eax
	movl	%eax, %edx
	movl	-4032(%rbp), %eax
	addl	%edx, %eax
	pxor	%xmm4, %xmm4
	cvtsi2sdl	%eax, %xmm4
	movq	%xmm4, %rax
	movapd	%xmm0, %xmm1
	movq	%rax, %xmm0
	call	fmin@PLT
	addsd	-4056(%rbp), %xmm0
	cvttsd2sil	%xmm0, %eax
	movl	%eax, -4040(%rbp)
	jmp	.L16
.L24:
	nop
.L16:
	addl	$1, -4044(%rbp)
.L14:
	movl	n(%rip), %eax
	cmpl	%eax, -4044(%rbp)
	jl	.L20
	movl	-4040(%rbp), %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L22
	call	__stack_chk_fail@PLT
.L22:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE2:
	.size	solve, .-solve
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB3:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	leaq	n(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$10000, s(%rip)
	movl	$0, -8(%rbp)
	jmp	.L27
.L28:
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	(%rdx,%rax), %eax
	pxor	%xmm0, %xmm0
	cvtsi2sdl	%eax, %xmm0
	movl	s(%rip), %eax
	pxor	%xmm2, %xmm2
	cvtsi2sdl	%eax, %xmm2
	movq	%xmm2, %rax
	movapd	%xmm0, %xmm1
	movq	%rax, %xmm0
	call	fmin@PLT
	cvttsd2sil	%xmm0, %eax
	movl	%eax, s(%rip)
	addl	$1, -8(%rbp)
.L27:
	movl	n(%rip), %eax
	cmpl	%eax, -8(%rbp)
	jl	.L28
	movl	$0, %eax
	call	solve
	movl	%eax, -4(%rbp)
	movl	-4(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE3:
	.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	partition
	.type	partition, @function
partition:
.LFB23:
	.cfi_startproc
	endbr64
	movslq	%edx, %rax
	movq	%rdi, %r9
	leaq	(%rdi,%rax,4), %r11
	leal	-1(%rsi), %edi
	movl	(%r11), %r8d
	cmpl	%esi, %edx
	jle	.L5
	subl	%esi, %edx
	movslq	%esi, %r10
	leal	-1(%rdx), %eax
	leaq	(%r9,%r10,4), %rcx
	addq	%r10, %rax
	leaq	4(%r9,%rax,4), %rsi
	.p2align 4,,10
	.p2align 3
.L4:
	movl	(%rcx), %eax
	cmpl	%r8d, %eax
	jg	.L3
	addl	$1, %edi
	movslq	%edi, %rdx
	leaq	(%r9,%rdx,4), %rdx
	movl	(%rdx), %r10d
	movl	%eax, (%rdx)
	movl	%r10d, (%rcx)
.L3:
	addq	$4, %rcx
	cmpq	%rcx, %rsi
	jne	.L4
	movl	(%r11), %r8d
	leal	1(%rdi), %eax
.L2:
	movslq	%edi, %rdi
	leaq	4(%r9,%rdi,4), %rdx
	movl	(%rdx), %ecx
	movl	%r8d, (%rdx)
	movl	%ecx, (%r11)
	ret
	.p2align 4,,10
	.p2align 3
.L5:
	movl	%esi, %eax
	jmp	.L2
	.cfi_endproc
.LFE23:
	.size	partition, .-partition
	.p2align 4
	.globl	quickSort
	.type	quickSort, @function
quickSort:
.LFB24:
	.cfi_startproc
	endbr64
	cmpl	%esi, %edx
	jle	.L16
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movslq	%edx, %rax
	movl	%esi, %r8d
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	leaq	(%rdi,%rax,4), %r13
	movl	%edx, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movq	%rdi, %rbx
	subq	$8, %rsp
	.cfi_def_cfa_offset 48
.L12:
	movl	0(%r13), %esi
	leal	-1(%r8), %ebp
	movslq	%r8d, %rax
	.p2align 4,,10
	.p2align 3
.L11:
	movl	(%rbx,%rax,4), %edx
	cmpl	%edx, %esi
	jl	.L10
	addl	$1, %ebp
	movslq	%ebp, %rcx
	leaq	(%rbx,%rcx,4), %rcx
	movl	(%rcx), %edi
	movl	%edx, (%rcx)
	movl	%edi, (%rbx,%rax,4)
.L10:
	addq	$1, %rax
	cmpl	%eax, %r12d
	jg	.L11
	movslq	%ebp, %rax
	movl	0(%r13), %ecx
	movl	%r8d, %esi
	movq	%rbx, %rdi
	leaq	4(%rbx,%rax,4), %rax
	movl	(%rax), %edx
	movl	%ecx, (%rax)
	movl	%edx, 0(%r13)
	movl	%ebp, %edx
	call	quickSort
	leal	2(%rbp), %r8d
	cmpl	%r12d, %r8d
	jl	.L12
	addq	$8, %rsp
	.cfi_def_cfa_offset 40
	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
.L16:
	.cfi_restore 3
	.cfi_restore 6
	.cfi_restore 12
	.cfi_restore 13
	ret
	.cfi_endproc
.LFE24:
	.size	quickSort, .-quickSort
	.p2align 4
	.globl	solve
	.type	solve, @function
solve:
.LFB25:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$4056, %rsp
	.cfi_def_cfa_offset 4112
	movl	n(%rip), %ebp
	movq	%fs:40, %rax
	movq	%rax, 4040(%rsp)
	xorl	%eax, %eax
	testl	%ebp, %ebp
	jle	.L31
	movslq	%ebp, %rax
	leaq	B(%rip), %rbx
	leaq	A(%rip), %rsi
	leaq	0(,%rax,4), %r12
	movq	%rbx, %rdi
	movq	%rax, 8(%rsp)
	movq	%r12, %rdx
	call	memcpy@PLT
	leaq	32(%rsp), %rdi
	xorl	%esi, %esi
	movq	%r12, %rdx
	movq	%rdi, 16(%rsp)
	call	memset@PLT
	subl	$1, %ebp
	je	.L21
	movslq	%ebp, %rax
	xorl	%r8d, %r8d
	leaq	(%rbx,%rax,4), %r11
.L24:
	movl	(%r11), %esi
	leal	-1(%r8), %r9d
	movslq	%r8d, %rax
	.p2align 4,,10
	.p2align 3
.L23:
	movl	(%rbx,%rax,4), %edx
	cmpl	%edx, %esi
	jl	.L22
	addl	$1, %r9d
	movslq	%r9d, %rcx
	leaq	(%rbx,%rcx,4), %rcx
	movl	(%rcx), %edi
	movl	%edx, (%rcx)
	movl	%edi, (%rbx,%rax,4)
.L22:
	addq	$1, %rax
	cmpl	%eax, %ebp
	jg	.L23
	movslq	%r9d, %rax
	movl	(%r11), %ecx
	movl	%r8d, %esi
	movq	%rbx, %rdi
	leaq	4(%rbx,%rax,4), %rax
	movl	(%rax), %edx
	movl	%ecx, (%rax)
	movl	%edx, (%r11)
	movl	%r9d, %edx
	call	quickSort
	leal	2(%r9), %r8d
	cmpl	%ebp, %r8d
	jl	.L24
	movl	n(%rip), %ebp
	testl	%ebp, %ebp
	jle	.L31
	movslq	%ebp, %rax
	movq	%rax, 8(%rsp)
.L21:
	xorl	%eax, %eax
	leaq	T(%rip), %r13
	.p2align 4,,10
	.p2align 3
.L25:
	movslq	(%rbx,%rax,4), %rdx
	movl	%eax, 0(%r13,%rdx,4)
	addq	$1, %rax
	cmpq	%rax, 8(%rsp)
	jne	.L25
	movl	s(%rip), %eax
	movl	$0, 24(%rsp)
	xorl	%r12d, %r12d
	movl	%eax, 28(%rsp)
	jmp	.L28
	.p2align 4,,10
	.p2align 3
.L26:
	addq	$1, %r12
	cmpq	8(%rsp), %r12
	je	.L19
.L28:
	movq	16(%rsp), %rsi
	movslq	%r12d, %rax
	movl	(%rsi,%r12,4), %r15d
	testl	%r15d, %r15d
	jne	.L26
	xorl	%ebx, %ebx
	movl	$10000, %ecx
	.p2align 4,,10
	.p2align 3
.L27:
	leaq	A(%rip), %rdi
	pxor	%xmm0, %xmm0
	pxor	%xmm1, %xmm1
	movl	$1, 32(%rsp,%rax,4)
	movl	(%rdi,%rax,4), %r14d
	cvtsi2sdl	%ecx, %xmm0
	movl	%r15d, %ebp
	addl	$1, %r15d
	cvtsi2sdl	%r14d, %xmm1
	addl	%r14d, %ebx
	call	fmin@PLT
	movslq	%r14d, %rax
	movslq	0(%r13,%rax,4), %rax
	cvttsd2sil	%xmm0, %ecx
	movl	32(%rsp,%rax,4), %edx
	testl	%edx, %edx
	je	.L27
	leal	2(%rbp), %eax
	subl	$1, %ebp
	leal	(%rcx,%rbx), %edx
	addq	$1, %r12
	imull	%ecx, %ebp
	pxor	%xmm0, %xmm0
	pxor	%xmm1, %xmm1
	imull	28(%rsp), %eax
	addl	%ebx, %ebp
	addl	%edx, %eax
	cvtsi2sdl	%ebp, %xmm0
	cvtsi2sdl	%eax, %xmm1
	call	fmin@PLT
	movapd	%xmm0, %xmm1
	pxor	%xmm0, %xmm0
	cvtsi2sdl	24(%rsp), %xmm0
	addsd	%xmm1, %xmm0
	cvttsd2sil	%xmm0, %eax
	movl	%eax, 24(%rsp)
	cmpq	8(%rsp), %r12
	jne	.L28
.L19:
	movq	4040(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L41
	movl	24(%rsp), %eax
	addq	$4056, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
.L31:
	.cfi_restore_state
	movl	$0, 24(%rsp)
	jmp	.L19
.L41:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE25:
	.size	solve, .-solve
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d"
.LC1:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB26:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	leaq	.LC0(%rip), %r12
	leaq	n(%rip), %rsi
	xorl	%eax, %eax
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movq	%r12, %rdi
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	call	__isoc99_scanf@PLT
	movl	n(%rip), %eax
	movl	$10000, s(%rip)
	testl	%eax, %eax
	jle	.L43
	leaq	A(%rip), %rbx
	xorl	%ebp, %ebp
	.p2align 4,,10
	.p2align 3
.L44:
	movq	%rbx, %rsi
	movq	%r12, %rdi
	xorl	%eax, %eax
	addl	$1, %ebp
	call	__isoc99_scanf@PLT
	pxor	%xmm0, %xmm0
	pxor	%xmm1, %xmm1
	addq	$4, %rbx
	cvtsi2sdl	-4(%rbx), %xmm1
	cvtsi2sdl	s(%rip), %xmm0
	call	fmin@PLT
	cmpl	%ebp, n(%rip)
	cvttsd2sil	%xmm0, %eax
	movl	%eax, s(%rip)
	jg	.L44
.L43:
	xorl	%eax, %eax
	call	solve
	leaq	.LC1(%rip), %rsi
	movl	$1, %edi
	movl	%eax, %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	popq	%rbx
	.cfi_def_cfa_offset 24
	xorl	%eax, %eax
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE26:
	.size	main, .-main
	.globl	T
	.bss
	.align 32
	.type	T, @object
	.size	T, 40004
T:
	.zero	40004
	.globl	B
	.align 32
	.type	B, @object
	.size	B, 4000
B:
	.zero	4000
	.globl	s
	.align 4
	.type	s, @object
	.size	s, 4
s:
	.zero	4
	.globl	A
	.align 32
	.type	A, @object
	.size	A, 4000
A:
	.zero	4000
	.globl	n
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.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	partition
	.type	partition, @function
partition:
.LFB23:
	.cfi_startproc
	endbr64
	movslq	%edx, %rax
	movq	%rdi, %r9
	leaq	(%rdi,%rax,4), %r11
	leal	-1(%rsi), %edi
	movl	(%r11), %r8d
	cmpl	%esi, %edx
	jle	.L5
	subl	%esi, %edx
	movslq	%esi, %r10
	leal	-1(%rdx), %eax
	leaq	(%r9,%r10,4), %rcx
	addq	%r10, %rax
	leaq	4(%r9,%rax,4), %rsi
	.p2align 4,,10
	.p2align 3
.L4:
	movl	(%rcx), %eax
	cmpl	%r8d, %eax
	jg	.L3
	addl	$1, %edi
	movslq	%edi, %rdx
	leaq	(%r9,%rdx,4), %rdx
	movl	(%rdx), %r10d
	movl	%eax, (%rdx)
	movl	%r10d, (%rcx)
.L3:
	addq	$4, %rcx
	cmpq	%rcx, %rsi
	jne	.L4
	movl	(%r11), %r8d
	leal	1(%rdi), %eax
.L2:
	movslq	%edi, %rdi
	leaq	4(%r9,%rdi,4), %rdx
	movl	(%rdx), %ecx
	movl	%r8d, (%rdx)
	movl	%ecx, (%r11)
	ret
	.p2align 4,,10
	.p2align 3
.L5:
	movl	%esi, %eax
	jmp	.L2
	.cfi_endproc
.LFE23:
	.size	partition, .-partition
	.p2align 4
	.globl	quickSort
	.type	quickSort, @function
quickSort:
.LFB24:
	.cfi_startproc
	endbr64
	cmpl	%esi, %edx
	jle	.L16
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movslq	%edx, %rax
	movl	%esi, %r8d
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	leaq	(%rdi,%rax,4), %r13
	movl	%edx, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movq	%rdi, %rbx
	subq	$8, %rsp
	.cfi_def_cfa_offset 48
.L12:
	movl	0(%r13), %esi
	leal	-1(%r8), %ebp
	movslq	%r8d, %rax
	.p2align 4,,10
	.p2align 3
.L11:
	movl	(%rbx,%rax,4), %edx
	cmpl	%edx, %esi
	jl	.L10
	addl	$1, %ebp
	movslq	%ebp, %rcx
	leaq	(%rbx,%rcx,4), %rcx
	movl	(%rcx), %edi
	movl	%edx, (%rcx)
	movl	%edi, (%rbx,%rax,4)
.L10:
	addq	$1, %rax
	cmpl	%eax, %r12d
	jg	.L11
	movslq	%ebp, %rax
	movl	0(%r13), %ecx
	movl	%r8d, %esi
	movq	%rbx, %rdi
	leaq	4(%rbx,%rax,4), %rax
	movl	(%rax), %edx
	movl	%ecx, (%rax)
	movl	%edx, 0(%r13)
	movl	%ebp, %edx
	call	quickSort
	leal	2(%rbp), %r8d
	cmpl	%r12d, %r8d
	jl	.L12
	addq	$8, %rsp
	.cfi_def_cfa_offset 40
	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
.L16:
	.cfi_restore 3
	.cfi_restore 6
	.cfi_restore 12
	.cfi_restore 13
	ret
	.cfi_endproc
.LFE24:
	.size	quickSort, .-quickSort
	.p2align 4
	.globl	solve
	.type	solve, @function
solve:
.LFB25:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$4056, %rsp
	.cfi_def_cfa_offset 4112
	movl	n(%rip), %ebp
	movq	%fs:40, %rax
	movq	%rax, 4040(%rsp)
	xorl	%eax, %eax
	testl	%ebp, %ebp
	jle	.L31
	movslq	%ebp, %rax
	leaq	B(%rip), %rbx
	leaq	A(%rip), %rsi
	leaq	0(,%rax,4), %r12
	movq	%rbx, %rdi
	movq	%rax, 8(%rsp)
	movq	%r12, %rdx
	call	memcpy@PLT
	leaq	32(%rsp), %rdi
	xorl	%esi, %esi
	movq	%r12, %rdx
	movq	%rdi, 16(%rsp)
	call	memset@PLT
	subl	$1, %ebp
	je	.L21
	movslq	%ebp, %rax
	xorl	%r8d, %r8d
	leaq	(%rbx,%rax,4), %r11
.L24:
	movl	(%r11), %esi
	leal	-1(%r8), %r9d
	movslq	%r8d, %rax
	.p2align 4,,10
	.p2align 3
.L23:
	movl	(%rbx,%rax,4), %edx
	cmpl	%edx, %esi
	jl	.L22
	addl	$1, %r9d
	movslq	%r9d, %rcx
	leaq	(%rbx,%rcx,4), %rcx
	movl	(%rcx), %edi
	movl	%edx, (%rcx)
	movl	%edi, (%rbx,%rax,4)
.L22:
	addq	$1, %rax
	cmpl	%eax, %ebp
	jg	.L23
	movslq	%r9d, %rax
	movl	(%r11), %ecx
	movl	%r8d, %esi
	movq	%rbx, %rdi
	leaq	4(%rbx,%rax,4), %rax
	movl	(%rax), %edx
	movl	%ecx, (%rax)
	movl	%edx, (%r11)
	movl	%r9d, %edx
	call	quickSort
	leal	2(%r9), %r8d
	cmpl	%ebp, %r8d
	jl	.L24
	movl	n(%rip), %ebp
	testl	%ebp, %ebp
	jle	.L31
	movslq	%ebp, %rax
	movq	%rax, 8(%rsp)
.L21:
	xorl	%eax, %eax
	leaq	T(%rip), %r13
	.p2align 4,,10
	.p2align 3
.L25:
	movslq	(%rbx,%rax,4), %rdx
	movl	%eax, 0(%r13,%rdx,4)
	addq	$1, %rax
	cmpq	%rax, 8(%rsp)
	jne	.L25
	movl	s(%rip), %eax
	movl	$0, 24(%rsp)
	xorl	%r12d, %r12d
	movl	%eax, 28(%rsp)
	jmp	.L28
	.p2align 4,,10
	.p2align 3
.L26:
	addq	$1, %r12
	cmpq	8(%rsp), %r12
	je	.L19
.L28:
	movq	16(%rsp), %rsi
	movslq	%r12d, %rax
	movl	(%rsi,%r12,4), %r15d
	testl	%r15d, %r15d
	jne	.L26
	xorl	%ebx, %ebx
	movl	$10000, %ecx
	.p2align 4,,10
	.p2align 3
.L27:
	leaq	A(%rip), %rdi
	pxor	%xmm0, %xmm0
	pxor	%xmm1, %xmm1
	movl	$1, 32(%rsp,%rax,4)
	movl	(%rdi,%rax,4), %r14d
	cvtsi2sdl	%ecx, %xmm0
	movl	%r15d, %ebp
	addl	$1, %r15d
	cvtsi2sdl	%r14d, %xmm1
	addl	%r14d, %ebx
	call	fmin@PLT
	movslq	%r14d, %rax
	movslq	0(%r13,%rax,4), %rax
	cvttsd2sil	%xmm0, %ecx
	movl	32(%rsp,%rax,4), %edx
	testl	%edx, %edx
	je	.L27
	leal	2(%rbp), %eax
	subl	$1, %ebp
	leal	(%rcx,%rbx), %edx
	addq	$1, %r12
	imull	%ecx, %ebp
	pxor	%xmm0, %xmm0
	pxor	%xmm1, %xmm1
	imull	28(%rsp), %eax
	addl	%ebx, %ebp
	addl	%edx, %eax
	cvtsi2sdl	%ebp, %xmm0
	cvtsi2sdl	%eax, %xmm1
	call	fmin@PLT
	movapd	%xmm0, %xmm1
	pxor	%xmm0, %xmm0
	cvtsi2sdl	24(%rsp), %xmm0
	addsd	%xmm1, %xmm0
	cvttsd2sil	%xmm0, %eax
	movl	%eax, 24(%rsp)
	cmpq	8(%rsp), %r12
	jne	.L28
.L19:
	movq	4040(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L41
	movl	24(%rsp), %eax
	addq	$4056, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
.L31:
	.cfi_restore_state
	movl	$0, 24(%rsp)
	jmp	.L19
.L41:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE25:
	.size	solve, .-solve
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d"
.LC1:
	.string	"%d\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB26:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	leaq	.LC0(%rip), %r12
	leaq	n(%rip), %rsi
	xorl	%eax, %eax
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movq	%r12, %rdi
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	call	__isoc99_scanf@PLT
	movl	n(%rip), %eax
	movl	$10000, s(%rip)
	testl	%eax, %eax
	jle	.L43
	leaq	A(%rip), %rbx
	xorl	%ebp, %ebp
	.p2align 4,,10
	.p2align 3
.L44:
	movq	%rbx, %rsi
	movq	%r12, %rdi
	xorl	%eax, %eax
	addl	$1, %ebp
	call	__isoc99_scanf@PLT
	pxor	%xmm0, %xmm0
	pxor	%xmm1, %xmm1
	addq	$4, %rbx
	cvtsi2sdl	-4(%rbx), %xmm1
	cvtsi2sdl	s(%rip), %xmm0
	call	fmin@PLT
	cmpl	%ebp, n(%rip)
	cvttsd2sil	%xmm0, %eax
	movl	%eax, s(%rip)
	jg	.L44
.L43:
	xorl	%eax, %eax
	call	solve
	leaq	.LC1(%rip), %rsi
	movl	$1, %edi
	movl	%eax, %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	popq	%rbx
	.cfi_def_cfa_offset 24
	xorl	%eax, %eax
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE26:
	.size	main, .-main
	.globl	T
	.bss
	.align 32
	.type	T, @object
	.size	T, 40004
T:
	.zero	40004
	.globl	B
	.align 32
	.type	B, @object
	.size	B, 4000
B:
	.zero	4000
	.globl	s
	.align 4
	.type	s, @object
	.size	s, 4
s:
	.zero	4
	.globl	A
	.align 32
	.type	A, @object
	.size	A, 4000
A:
	.zero	4000
	.globl	n
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.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<math.h>
#define MAX 1000
#define VMAX 10000

int n, A[MAX], s;
int B[MAX], T[VMAX+1];

int partition(int A[], int p, int r){
  int i, j;
  int x, t;
  x = A[r];
  i = p-1;
  for( j = p ; j < r ; j++ ){
    if( A[j] <= x ){
      i++;
      t = A[i];
      A[i] = A[j];
      A[j] = t;
    }
  }
  t = A[i+1];
  A[i+1] = A[r];
  A[r] = t;
  return i + 1;
}

void quickSort(int A[], int p, int r){
  int q;
  if( p < r ){
    q = partition(A, p, r);
    quickSort(A, p, q-1);
    quickSort(A, q+1, r);
  }
}


int solve(){
  int i, ans = 0;

  int V[MAX];
  for( i = 0 ; i < n ; i++ ){
    B[i] = A[i];
    V[i] = 0;
  }
  quickSort(B, 0, n-1);
  for( i = 0 ; i < n ; i++ ) T[B[i]] = i;
  for( i = 0 ; i < n ; i++ ){
    if( V[i] ) continue;
    int cur = i;
    int S = 0;
    int m = VMAX;
    int an = 0;
    while( 1 ){
      V[cur] = 1;
      an++;
      int v = A[cur];
      m = fmin(m, v);
      S += v;
      cur = T[v];
      if( V[cur] ) break;
    }
    ans += fmin(S+(an-2)*m, m+S+(an+1)*s);
  }

  return ans;
}

int main(){
  int i;
  scanf("%d",&n);
  s = VMAX;
  for( i = 0 ; i < n ; i++ ){
    scanf("%d", &A[i]);
    s = fmin(s, A[i]);
  }
  int ans = solve();
  printf("%d\n", ans);

  return 0;
}


4
8 3 2 1
 5
0 5 3 4 2
 5
0 5 3 1 2
 5
1 8 3 4 2
 5
0 9 3 1 2
 5
1 8 3 4 0
 5
0 15 3 1 2
 5
1 5 3 8 2
 5
0 5 6 4 2
 5
0 5 3 1 4

14
 7
 12
 10
 16
 9
 22
 17
 19
 11

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<math.h>
#define MAX 1000
#define VMAX 10000

int n, A[MAX], s;
int B[MAX], T[VMAX+1];

int partition(int A[], int p, int r){
  int i, j;
  int x, t;
  x = A[r];
  i = p-1;
  for( j = p ; j < r ; j++ ){
    if( A[j] <= x ){
      i++;
      t = A[i];
      A[i] = A[j];
      A[j] = t;
    }
  }
  t = A[i+1];
  A[i+1] = A[r];
  A[r] = t;
  return i + 1;
}

void quickSort(int A[], int p, int r){
  int q;
  if( p < r ){
    q = partition(A, p, r);
    quickSort(A, p, q-1);
    quickSort(A, q+1, r);
  }
}


int solve(){
  int i, ans = 0;

  int V[MAX];
  for( i = 0 ; i < n ; i++ ){
    B[i] = A[i];
    V[i] = 0;
  }
  quickSort(B, 0, n-1);
  for( i = 0 ; i < n ; i++ ) T[B[i]] = i;
  for( i = 0 ; i < n ; i++ ){
    if( V[i] ) continue;
    int cur = i;
    int S = 0;
    int m = VMAX;
    int an = 0;
    while( 1 ){
      V[cur] = 1;
      an++;
      int v = A[cur];
      m = fmin(m, v);
      S += v;
      cur = T[v];
      if( V[cur] ) break;
    }
    ans += fmin(S+(an-2)*m, m+S+(an+1)*s);
  }

  return ans;
}

int main(){
  int i;
  scanf("%d",&n);
  s = VMAX;
  for( i = 0 ; i < n ; i++ ){
    scanf("%d", &A[i]);
    s = fmin(s, A[i]);
  }
  int ans = solve();
  printf("%d\n", ans);

  return 0;
}

```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	n
	.bss
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.globl	A
	.align 32
	.type	A, @object
	.size	A, 4000
A:
	.zero	4000
	.globl	s
	.align 4
	.type	s, @object
	.size	s, 4
s:
	.zero	4
	.globl	B
	.align 32
	.type	B, @object
	.size	B, 4000
B:
	.zero	4000
	.globl	T
	.align 32
	.type	T, @object
	.size	T, 40004
T:
	.zero	40004
	.text
	.globl	partition
	.type	partition, @function
partition:
.LFB0:
	.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)
	movl	%esi, -28(%rbp)
	movl	%edx, -32(%rbp)
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, -8(%rbp)
	movl	-28(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -16(%rbp)
	movl	-28(%rbp), %eax
	movl	%eax, -12(%rbp)
	jmp	.L2
.L4:
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	cmpl	%eax, -8(%rbp)
	jl	.L3
	addl	$1, -16(%rbp)
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, -4(%rbp)
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	-16(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	movq	-24(%rbp), %rdx
	addq	%rcx, %rdx
	movl	(%rax), %eax
	movl	%eax, (%rdx)
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rax, %rdx
	movl	-4(%rbp), %eax
	movl	%eax, (%rdx)
.L3:
	addl	$1, -12(%rbp)
.L2:
	movl	-12(%rbp), %eax
	cmpl	-32(%rbp), %eax
	jl	.L4
	movl	-16(%rbp), %eax
	cltq
	addq	$1, %rax
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, -4(%rbp)
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	-16(%rbp), %edx
	movslq	%edx, %rdx
	addq	$1, %rdx
	leaq	0(,%rdx,4), %rcx
	movq	-24(%rbp), %rdx
	addq	%rcx, %rdx
	movl	(%rax), %eax
	movl	%eax, (%rdx)
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rax, %rdx
	movl	-4(%rbp), %eax
	movl	%eax, (%rdx)
	movl	-16(%rbp), %eax
	addl	$1, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	partition, .-partition
	.globl	quickSort
	.type	quickSort, @function
quickSort:
.LFB1:
	.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)
	movl	%esi, -28(%rbp)
	movl	%edx, -32(%rbp)
	movl	-28(%rbp), %eax
	cmpl	-32(%rbp), %eax
	jge	.L8
	movl	-32(%rbp), %edx
	movl	-28(%rbp), %ecx
	movq	-24(%rbp), %rax
	movl	%ecx, %esi
	movq	%rax, %rdi
	call	partition
	movl	%eax, -4(%rbp)
	movl	-4(%rbp), %eax
	leal	-1(%rax), %edx
	movl	-28(%rbp), %ecx
	movq	-24(%rbp), %rax
	movl	%ecx, %esi
	movq	%rax, %rdi
	call	quickSort
	movl	-4(%rbp), %eax
	leal	1(%rax), %ecx
	movl	-32(%rbp), %edx
	movq	-24(%rbp), %rax
	movl	%ecx, %esi
	movq	%rax, %rdi
	call	quickSort
.L8:
	nop
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.size	quickSort, .-quickSort
	.globl	solve
	.type	solve, @function
solve:
.LFB2:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$4064, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -4040(%rbp)
	movl	$0, -4044(%rbp)
	jmp	.L10
.L11:
	movl	-4044(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	-4044(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	B(%rip), %rdx
	movl	%eax, (%rcx,%rdx)
	movl	-4044(%rbp), %eax
	cltq
	movl	$0, -4016(%rbp,%rax,4)
	addl	$1, -4044(%rbp)
.L10:
	movl	n(%rip), %eax
	cmpl	%eax, -4044(%rbp)
	jl	.L11
	movl	n(%rip), %eax
	subl	$1, %eax
	movl	%eax, %edx
	movl	$0, %esi
	leaq	B(%rip), %rax
	movq	%rax, %rdi
	call	quickSort
	movl	$0, -4044(%rbp)
	jmp	.L12
.L13:
	movl	-4044(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	B(%rip), %rax
	movl	(%rdx,%rax), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	T(%rip), %rdx
	movl	-4044(%rbp), %eax
	movl	%eax, (%rcx,%rdx)
	addl	$1, -4044(%rbp)
.L12:
	movl	n(%rip), %eax
	cmpl	%eax, -4044(%rbp)
	jl	.L13
	movl	$0, -4044(%rbp)
	jmp	.L14
.L20:
	movl	-4044(%rbp), %eax
	cltq
	movl	-4016(%rbp,%rax,4), %eax
	testl	%eax, %eax
	jne	.L24
	movl	-4044(%rbp), %eax
	movl	%eax, -4036(%rbp)
	movl	$0, -4032(%rbp)
	movl	$10000, -4028(%rbp)
	movl	$0, -4024(%rbp)
.L19:
	movl	-4036(%rbp), %eax
	cltq
	movl	$1, -4016(%rbp,%rax,4)
	addl	$1, -4024(%rbp)
	movl	-4036(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, -4020(%rbp)
	pxor	%xmm0, %xmm0
	cvtsi2sdl	-4020(%rbp), %xmm0
	pxor	%xmm2, %xmm2
	cvtsi2sdl	-4028(%rbp), %xmm2
	movq	%xmm2, %rax
	movapd	%xmm0, %xmm1
	movq	%rax, %xmm0
	call	fmin@PLT
	cvttsd2sil	%xmm0, %eax
	movl	%eax, -4028(%rbp)
	movl	-4020(%rbp), %eax
	addl	%eax, -4032(%rbp)
	movl	-4020(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	T(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, -4036(%rbp)
	movl	-4036(%rbp), %eax
	cltq
	movl	-4016(%rbp,%rax,4), %eax
	testl	%eax, %eax
	jne	.L25
	jmp	.L19
.L25:
	nop
	pxor	%xmm3, %xmm3
	cvtsi2sdl	-4040(%rbp), %xmm3
	movsd	%xmm3, -4056(%rbp)
	movl	-4028(%rbp), %edx
	movl	-4032(%rbp), %eax
	leal	(%rdx,%rax), %ecx
	movl	-4024(%rbp), %eax
	leal	1(%rax), %edx
	movl	s(%rip), %eax
	imull	%edx, %eax
	addl	%ecx, %eax
	pxor	%xmm0, %xmm0
	cvtsi2sdl	%eax, %xmm0
	movl	-4024(%rbp), %eax
	subl	$2, %eax
	imull	-4028(%rbp), %eax
	movl	%eax, %edx
	movl	-4032(%rbp), %eax
	addl	%edx, %eax
	pxor	%xmm4, %xmm4
	cvtsi2sdl	%eax, %xmm4
	movq	%xmm4, %rax
	movapd	%xmm0, %xmm1
	movq	%rax, %xmm0
	call	fmin@PLT
	addsd	-4056(%rbp), %xmm0
	cvttsd2sil	%xmm0, %eax
	movl	%eax, -4040(%rbp)
	jmp	.L16
.L24:
	nop
.L16:
	addl	$1, -4044(%rbp)
.L14:
	movl	n(%rip), %eax
	cmpl	%eax, -4044(%rbp)
	jl	.L20
	movl	-4040(%rbp), %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L22
	call	__stack_chk_fail@PLT
.L22:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE2:
	.size	solve, .-solve
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB3:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	leaq	n(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$10000, s(%rip)
	movl	$0, -8(%rbp)
	jmp	.L27
.L28:
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	(%rdx,%rax), %eax
	pxor	%xmm0, %xmm0
	cvtsi2sdl	%eax, %xmm0
	movl	s(%rip), %eax
	pxor	%xmm2, %xmm2
	cvtsi2sdl	%eax, %xmm2
	movq	%xmm2, %rax
	movapd	%xmm0, %xmm1
	movq	%rax, %xmm0
	call	fmin@PLT
	cvttsd2sil	%xmm0, %eax
	movl	%eax, s(%rip)
	addl	$1, -8(%rbp)
.L27:
	movl	n(%rip), %eax
	cmpl	%eax, -8(%rbp)
	jl	.L28
	movl	$0, %eax
	call	solve
	movl	%eax, -4(%rbp)
	movl	-4(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE3:
	.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	n
	.bss
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.globl	A
	.align 32
	.type	A, @object
	.size	A, 4000
A:
	.zero	4000
	.globl	s
	.align 4
	.type	s, @object
	.size	s, 4
s:
	.zero	4
	.globl	B
	.align 32
	.type	B, @object
	.size	B, 4000
B:
	.zero	4000
	.globl	T
	.align 32
	.type	T, @object
	.size	T, 40004
T:
	.zero	40004
	.text
	.globl	partition
	.type	partition, @function
partition:
.LFB0:
	.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)
	movl	%esi, -28(%rbp)
	movl	%edx, -32(%rbp)
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, -8(%rbp)
	movl	-28(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -16(%rbp)
	movl	-28(%rbp), %eax
	movl	%eax, -12(%rbp)
	jmp	.L2
.L4:
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	cmpl	%eax, -8(%rbp)
	jl	.L3
	addl	$1, -16(%rbp)
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, -4(%rbp)
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	-16(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	movq	-24(%rbp), %rdx
	addq	%rcx, %rdx
	movl	(%rax), %eax
	movl	%eax, (%rdx)
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rax, %rdx
	movl	-4(%rbp), %eax
	movl	%eax, (%rdx)
.L3:
	addl	$1, -12(%rbp)
.L2:
	movl	-12(%rbp), %eax
	cmpl	-32(%rbp), %eax
	jl	.L4
	movl	-16(%rbp), %eax
	cltq
	addq	$1, %rax
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, -4(%rbp)
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	-16(%rbp), %edx
	movslq	%edx, %rdx
	addq	$1, %rdx
	leaq	0(,%rdx,4), %rcx
	movq	-24(%rbp), %rdx
	addq	%rcx, %rdx
	movl	(%rax), %eax
	movl	%eax, (%rdx)
	movl	-32(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rax, %rdx
	movl	-4(%rbp), %eax
	movl	%eax, (%rdx)
	movl	-16(%rbp), %eax
	addl	$1, %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	partition, .-partition
	.globl	quickSort
	.type	quickSort, @function
quickSort:
.LFB1:
	.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)
	movl	%esi, -28(%rbp)
	movl	%edx, -32(%rbp)
	movl	-28(%rbp), %eax
	cmpl	-32(%rbp), %eax
	jge	.L8
	movl	-32(%rbp), %edx
	movl	-28(%rbp), %ecx
	movq	-24(%rbp), %rax
	movl	%ecx, %esi
	movq	%rax, %rdi
	call	partition
	movl	%eax, -4(%rbp)
	movl	-4(%rbp), %eax
	leal	-1(%rax), %edx
	movl	-28(%rbp), %ecx
	movq	-24(%rbp), %rax
	movl	%ecx, %esi
	movq	%rax, %rdi
	call	quickSort
	movl	-4(%rbp), %eax
	leal	1(%rax), %ecx
	movl	-32(%rbp), %edx
	movq	-24(%rbp), %rax
	movl	%ecx, %esi
	movq	%rax, %rdi
	call	quickSort
.L8:
	nop
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.size	quickSort, .-quickSort
	.globl	solve
	.type	solve, @function
solve:
.LFB2:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$4064, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -4040(%rbp)
	movl	$0, -4044(%rbp)
	jmp	.L10
.L11:
	movl	-4044(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	-4044(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	B(%rip), %rdx
	movl	%eax, (%rcx,%rdx)
	movl	-4044(%rbp), %eax
	cltq
	movl	$0, -4016(%rbp,%rax,4)
	addl	$1, -4044(%rbp)
.L10:
	movl	n(%rip), %eax
	cmpl	%eax, -4044(%rbp)
	jl	.L11
	movl	n(%rip), %eax
	subl	$1, %eax
	movl	%eax, %edx
	movl	$0, %esi
	leaq	B(%rip), %rax
	movq	%rax, %rdi
	call	quickSort
	movl	$0, -4044(%rbp)
	jmp	.L12
.L13:
	movl	-4044(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	B(%rip), %rax
	movl	(%rdx,%rax), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	T(%rip), %rdx
	movl	-4044(%rbp), %eax
	movl	%eax, (%rcx,%rdx)
	addl	$1, -4044(%rbp)
.L12:
	movl	n(%rip), %eax
	cmpl	%eax, -4044(%rbp)
	jl	.L13
	movl	$0, -4044(%rbp)
	jmp	.L14
.L20:
	movl	-4044(%rbp), %eax
	cltq
	movl	-4016(%rbp,%rax,4), %eax
	testl	%eax, %eax
	jne	.L24
	movl	-4044(%rbp), %eax
	movl	%eax, -4036(%rbp)
	movl	$0, -4032(%rbp)
	movl	$10000, -4028(%rbp)
	movl	$0, -4024(%rbp)
.L19:
	movl	-4036(%rbp), %eax
	cltq
	movl	$1, -4016(%rbp,%rax,4)
	addl	$1, -4024(%rbp)
	movl	-4036(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, -4020(%rbp)
	pxor	%xmm0, %xmm0
	cvtsi2sdl	-4020(%rbp), %xmm0
	pxor	%xmm2, %xmm2
	cvtsi2sdl	-4028(%rbp), %xmm2
	movq	%xmm2, %rax
	movapd	%xmm0, %xmm1
	movq	%rax, %xmm0
	call	fmin@PLT
	cvttsd2sil	%xmm0, %eax
	movl	%eax, -4028(%rbp)
	movl	-4020(%rbp), %eax
	addl	%eax, -4032(%rbp)
	movl	-4020(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	T(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, -4036(%rbp)
	movl	-4036(%rbp), %eax
	cltq
	movl	-4016(%rbp,%rax,4), %eax
	testl	%eax, %eax
	jne	.L25
	jmp	.L19
.L25:
	nop
	pxor	%xmm3, %xmm3
	cvtsi2sdl	-4040(%rbp), %xmm3
	movsd	%xmm3, -4056(%rbp)
	movl	-4028(%rbp), %edx
	movl	-4032(%rbp), %eax
	leal	(%rdx,%rax), %ecx
	movl	-4024(%rbp), %eax
	leal	1(%rax), %edx
	movl	s(%rip), %eax
	imull	%edx, %eax
	addl	%ecx, %eax
	pxor	%xmm0, %xmm0
	cvtsi2sdl	%eax, %xmm0
	movl	-4024(%rbp), %eax
	subl	$2, %eax
	imull	-4028(%rbp), %eax
	movl	%eax, %edx
	movl	-4032(%rbp), %eax
	addl	%edx, %eax
	pxor	%xmm4, %xmm4
	cvtsi2sdl	%eax, %xmm4
	movq	%xmm4, %rax
	movapd	%xmm0, %xmm1
	movq	%rax, %xmm0
	call	fmin@PLT
	addsd	-4056(%rbp), %xmm0
	cvttsd2sil	%xmm0, %eax
	movl	%eax, -4040(%rbp)
	jmp	.L16
.L24:
	nop
.L16:
	addl	$1, -4044(%rbp)
.L14:
	movl	n(%rip), %eax
	cmpl	%eax, -4044(%rbp)
	jl	.L20
	movl	-4040(%rbp), %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L22
	call	__stack_chk_fail@PLT
.L22:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE2:
	.size	solve, .-solve
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB3:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$16, %rsp
	leaq	n(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$10000, s(%rip)
	movl	$0, -8(%rbp)
	jmp	.L27
.L28:
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	(%rdx,%rax), %eax
	pxor	%xmm0, %xmm0
	cvtsi2sdl	%eax, %xmm0
	movl	s(%rip), %eax
	pxor	%xmm2, %xmm2
	cvtsi2sdl	%eax, %xmm2
	movq	%xmm2, %rax
	movapd	%xmm0, %xmm1
	movq	%rax, %xmm0
	call	fmin@PLT
	cvttsd2sil	%xmm0, %eax
	movl	%eax, s(%rip)
	addl	$1, -8(%rbp)
.L27:
	movl	n(%rip), %eax
	cmpl	%eax, -8(%rbp)
	jl	.L28
	movl	$0, %eax
	call	solve
	movl	%eax, -4(%rbp)
	movl	-4(%rbp), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE3:
	.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:
