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>
#include<limits.h>
   
   
   
int n,cost;
int A[1001],B[1001];
int L[501],R[502];
   
   
void merge(int left,int mid,int right){
  int i,j,n1=mid-left,n2=right-mid;
  for(i=0;i<n1;i++) L[i]=A[left+i];
  L[n1]=INT_MAX;
  for(i=0;i<n2;i++) R[i]=A[mid+i];
  R[n2]=INT_MAX;
  int l=0,r=0;
  for(i=left;i<right;i++){
    if(L[l]<=R[r]){
      A[i]=L[l];
      l++;
    }
    else{
      A[i]=R[r];
      r++;
    }
  }
}
   
   
void m_sort(int left,int right){
  int mid;
  if( left+1 >= right) return;
  mid=(left+right)/2;
  m_sort(left,mid);
  m_sort(mid,right);
  merge(left,mid,right);
}
   
   
void swap(int a,int b,int *C){
  int swap;
  swap=C[a];
  C[a]=C[b];
  C[b]=swap;
}
   
   
   
   
   
   
     
    
     
   
int main(){
  scanf("%d",&n);
  int i,j;
  int cnt,sum,min,start,x;
  int C[1001]={};
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
    B[i]=A[i];
  }
  m_sort(0,n);
  for(i=0;i<n;i++){
    if(A[i]==B[i]) C[i]=1;
  }
  cost=0;
  for(i=0;i<n;i++){
    if(C[i]!=1){
      C[i]=1;
      cnt=0;
      sum=0;
      min=B[i];
      x=i;
      while(1){
        for(j=0;j<n;j++){
          if(B[x]==A[j]){
            C[j]=1;
            cnt++;
            sum+=B[j];
            if(min > B[j]) min=B[j];
            x=j;
            break;
          }
        }
        if(x==i) break;
      }
      sum-=min;
      if( (cnt -1)*min > (cnt -1)*A[0]+2*(min +A[0])) cost+=sum+(cnt-1)*A[0]+2*(min +A[0]);
      else cost+=sum+(cnt-1)*min;
    }
  }
  printf("%d\n",cost);
  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	cost
	.align 4
	.type	cost, @object
	.size	cost, 4
cost:
	.zero	4
	.globl	A
	.align 32
	.type	A, @object
	.size	A, 4004
A:
	.zero	4004
	.globl	B
	.align 32
	.type	B, @object
	.size	B, 4004
B:
	.zero	4004
	.globl	L
	.align 32
	.type	L, @object
	.size	L, 2004
L:
	.zero	2004
	.globl	R
	.align 32
	.type	R, @object
	.size	R, 2008
R:
	.zero	2008
	.text
	.globl	merge
	.type	merge, @function
merge:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -36(%rbp)
	movl	%esi, -40(%rbp)
	movl	%edx, -44(%rbp)
	movl	-40(%rbp), %eax
	subl	-36(%rbp), %eax
	movl	%eax, -8(%rbp)
	movl	-44(%rbp), %eax
	subl	-40(%rbp), %eax
	movl	%eax, -4(%rbp)
	movl	$0, -20(%rbp)
	jmp	.L2
.L3:
	movl	-36(%rbp), %edx
	movl	-20(%rbp), %eax
	addl	%edx, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	-20(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	L(%rip), %rdx
	movl	%eax, (%rcx,%rdx)
	addl	$1, -20(%rbp)
.L2:
	movl	-20(%rbp), %eax
	cmpl	-8(%rbp), %eax
	jl	.L3
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	L(%rip), %rax
	movl	$2147483647, (%rdx,%rax)
	movl	$0, -20(%rbp)
	jmp	.L4
.L5:
	movl	-40(%rbp), %edx
	movl	-20(%rbp), %eax
	addl	%edx, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	-20(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	R(%rip), %rdx
	movl	%eax, (%rcx,%rdx)
	addl	$1, -20(%rbp)
.L4:
	movl	-20(%rbp), %eax
	cmpl	-4(%rbp), %eax
	jl	.L5
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	R(%rip), %rax
	movl	$2147483647, (%rdx,%rax)
	movl	$0, -16(%rbp)
	movl	$0, -12(%rbp)
	movl	-36(%rbp), %eax
	movl	%eax, -20(%rbp)
	jmp	.L6
.L9:
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	L(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	R(%rip), %rax
	movl	(%rcx,%rax), %eax
	cmpl	%eax, %edx
	jg	.L7
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	L(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	-20(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	A(%rip), %rdx
	movl	%eax, (%rcx,%rdx)
	addl	$1, -16(%rbp)
	jmp	.L8
.L7:
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	R(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	-20(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	A(%rip), %rdx
	movl	%eax, (%rcx,%rdx)
	addl	$1, -12(%rbp)
.L8:
	addl	$1, -20(%rbp)
.L6:
	movl	-20(%rbp), %eax
	cmpl	-44(%rbp), %eax
	jl	.L9
	nop
	nop
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	merge, .-merge
	.globl	m_sort
	.type	m_sort, @function
m_sort:
.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
	movl	%edi, -20(%rbp)
	movl	%esi, -24(%rbp)
	movl	-20(%rbp), %eax
	addl	$1, %eax
	cmpl	%eax, -24(%rbp)
	jle	.L13
	movl	-20(%rbp), %edx
	movl	-24(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	movl	%eax, -4(%rbp)
	movl	-4(%rbp), %edx
	movl	-20(%rbp), %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	m_sort
	movl	-24(%rbp), %edx
	movl	-4(%rbp), %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	m_sort
	movl	-24(%rbp), %edx
	movl	-4(%rbp), %ecx
	movl	-20(%rbp), %eax
	movl	%ecx, %esi
	movl	%eax, %edi
	call	merge
	jmp	.L10
.L13:
	nop
.L10:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	m_sort, .-m_sort
	.globl	swap
	.type	swap, @function
swap:
.LFB8:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -20(%rbp)
	movl	%esi, -24(%rbp)
	movq	%rdx, -32(%rbp)
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-32(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, -4(%rbp)
	movl	-24(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-32(%rbp), %rax
	addq	%rdx, %rax
	movl	-20(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	movq	-32(%rbp), %rdx
	addq	%rcx, %rdx
	movl	(%rax), %eax
	movl	%eax, (%rdx)
	movl	-24(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-32(%rbp), %rax
	addq	%rax, %rdx
	movl	-4(%rbp), %eax
	movl	%eax, (%rdx)
	nop
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.size	swap, .-swap
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.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	$4048, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	n(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	leaq	-4016(%rbp), %rdx
	movl	$0, %eax
	movl	$500, %ecx
	movq	%rdx, %rdi
	rep stosq
	movq	%rdi, %rdx
	movl	%eax, (%rdx)
	addq	$4, %rdx
	movl	$0, -4040(%rbp)
	jmp	.L16
.L17:
	movl	-4040(%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	-4040(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	-4040(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	B(%rip), %rdx
	movl	%eax, (%rcx,%rdx)
	addl	$1, -4040(%rbp)
.L16:
	movl	n(%rip), %eax
	cmpl	%eax, -4040(%rbp)
	jl	.L17
	movl	n(%rip), %eax
	movl	%eax, %esi
	movl	$0, %edi
	call	m_sort
	movl	$0, -4040(%rbp)
	jmp	.L18
.L20:
	movl	-4040(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-4040(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	B(%rip), %rax
	movl	(%rcx,%rax), %eax
	cmpl	%eax, %edx
	jne	.L19
	movl	-4040(%rbp), %eax
	cltq
	movl	$1, -4016(%rbp,%rax,4)
.L19:
	addl	$1, -4040(%rbp)
.L18:
	movl	n(%rip), %eax
	cmpl	%eax, -4040(%rbp)
	jl	.L20
	movl	$0, cost(%rip)
	movl	$0, -4040(%rbp)
	jmp	.L21
.L32:
	movl	-4040(%rbp), %eax
	cltq
	movl	-4016(%rbp,%rax,4), %eax
	cmpl	$1, %eax
	je	.L22
	movl	-4040(%rbp), %eax
	cltq
	movl	$1, -4016(%rbp,%rax,4)
	movl	$0, -4032(%rbp)
	movl	$0, -4028(%rbp)
	movl	-4040(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	B(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, -4024(%rbp)
	movl	-4040(%rbp), %eax
	movl	%eax, -4020(%rbp)
.L30:
	movl	$0, -4036(%rbp)
	jmp	.L23
.L27:
	movl	-4020(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	B(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-4036(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	A(%rip), %rax
	movl	(%rcx,%rax), %eax
	cmpl	%eax, %edx
	jne	.L24
	movl	-4036(%rbp), %eax
	cltq
	movl	$1, -4016(%rbp,%rax,4)
	addl	$1, -4032(%rbp)
	movl	-4036(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	B(%rip), %rax
	movl	(%rdx,%rax), %eax
	addl	%eax, -4028(%rbp)
	movl	-4036(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	B(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	%eax, -4024(%rbp)
	jle	.L25
	movl	-4036(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	B(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, -4024(%rbp)
.L25:
	movl	-4036(%rbp), %eax
	movl	%eax, -4020(%rbp)
	jmp	.L26
.L24:
	addl	$1, -4036(%rbp)
.L23:
	movl	n(%rip), %eax
	cmpl	%eax, -4036(%rbp)
	jl	.L27
.L26:
	movl	-4020(%rbp), %eax
	cmpl	-4040(%rbp), %eax
	je	.L36
	jmp	.L30
.L36:
	nop
	movl	-4024(%rbp), %eax
	subl	%eax, -4028(%rbp)
	movl	-4032(%rbp), %eax
	subl	$1, %eax
	imull	-4024(%rbp), %eax
	movl	-4032(%rbp), %edx
	leal	-1(%rdx), %ecx
	movl	A(%rip), %edx
	imull	%edx, %ecx
	movl	A(%rip), %esi
	movl	-4024(%rbp), %edx
	addl	%esi, %edx
	addl	%edx, %edx
	addl	%ecx, %edx
	cmpl	%edx, %eax
	jle	.L31
	movl	-4032(%rbp), %eax
	leal	-1(%rax), %edx
	movl	A(%rip), %eax
	imull	%eax, %edx
	movl	-4028(%rbp), %eax
	leal	(%rdx,%rax), %ecx
	movl	A(%rip), %edx
	movl	-4024(%rbp), %eax
	addl	%edx, %eax
	addl	%eax, %eax
	leal	(%rcx,%rax), %edx
	movl	cost(%rip), %eax
	addl	%edx, %eax
	movl	%eax, cost(%rip)
	jmp	.L22
.L31:
	movl	-4032(%rbp), %eax
	subl	$1, %eax
	imull	-4024(%rbp), %eax
	movl	%eax, %edx
	movl	-4028(%rbp), %eax
	addl	%eax, %edx
	movl	cost(%rip), %eax
	addl	%edx, %eax
	movl	%eax, cost(%rip)
.L22:
	addl	$1, -4040(%rbp)
.L21:
	movl	n(%rip), %eax
	cmpl	%eax, -4040(%rbp)
	jl	.L32
	movl	cost(%rip), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L34
	call	__stack_chk_fail@PLT
.L34:
	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	merge
	.type	merge, @function
merge:
.LFB39:
	.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
	movl	%edx, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movslq	%esi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movl	%r13d, %eax
	movl	%edi, %r12d
	subl	%r13d, %r14d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	subl	%edi, %eax
	leaq	L(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movslq	%eax, %r15
	movl	%edx, %ebx
	subq	$8, %rsp
	.cfi_def_cfa_offset 64
	testl	%eax, %eax
	jle	.L2
	movslq	%edi, %rax
	leaq	A(%rip), %rcx
	movq	%rbp, %rdi
	leaq	0(,%r15,4), %rdx
	leaq	(%rcx,%rax,4), %rsi
	call	memcpy@PLT
.L2:
	testl	%r14d, %r14d
	leaq	R(%rip), %r10
	movslq	%r14d, %r14
	movl	$2147483647, 0(%rbp,%r15,4)
	jle	.L3
	leaq	A(%rip), %rax
	movq	%r10, %rdi
	leaq	0(,%r14,4), %rdx
	leaq	(%rax,%r13,4), %rsi
	call	memcpy@PLT
	movq	%rax, %r10
.L3:
	movl	$2147483647, (%r10,%r14,4)
	cmpl	%ebx, %r12d
	jge	.L1
	subl	$1, %ebx
	movslq	%r12d, %rdx
	leaq	A(%rip), %rax
	xorl	%r9d, %r9d
	subl	%r12d, %ebx
	leaq	(%rax,%rdx,4), %rax
	xorl	%r8d, %r8d
	xorl	%edi, %edi
	addq	%rdx, %rbx
	leaq	4+A(%rip), %rdx
	xorl	%esi, %esi
	leaq	(%rdx,%rbx,4), %r11
	.p2align 4,,10
	.p2align 3
.L7:
	movl	0(%rbp,%rdi,4), %ecx
	movl	(%r10,%rsi,4), %edx
	cmpl	%edx, %ecx
	jg	.L5
.L15:
	movl	%ecx, (%rax)
	addq	$4, %rax
	addl	$1, %r8d
	cmpq	%r11, %rax
	je	.L1
	movslq	%r8d, %rdi
	movl	(%r10,%rsi,4), %edx
	movl	0(%rbp,%rdi,4), %ecx
	cmpl	%edx, %ecx
	jle	.L15
.L5:
	movl	%edx, (%rax)
	addq	$4, %rax
	addl	$1, %r9d
	cmpq	%rax, %r11
	je	.L1
	movslq	%r9d, %rsi
	jmp	.L7
	.p2align 4,,10
	.p2align 3
.L1:
	addq	$8, %rsp
	.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
	.cfi_endproc
.LFE39:
	.size	merge, .-merge
	.p2align 4
	.type	m_sort.part.0, @function
m_sort.part.0:
.LFB43:
	.cfi_startproc
	leal	(%rdi,%rsi), %eax
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movl	%esi, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movl	%edi, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	%eax, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	shrl	$31, %ebp
	addl	%eax, %ebp
	leal	1(%rdi), %eax
	sarl	%ebp
	subq	$8, %rsp
	.cfi_def_cfa_offset 64
	cmpl	%eax, %ebp
	jg	.L48
	leal	1(%rbp), %eax
	cmpl	%eax, %r14d
	jg	.L49
.L32:
	addq	$8, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	movl	%r14d, %edx
	movl	%ebp, %esi
	movl	%r13d, %edi
	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
	jmp	merge
	.p2align 4,,10
	.p2align 3
.L48:
	.cfi_restore_state
	leal	(%rdi,%rbp), %edx
	movl	%edx, %r12d
	shrl	$31, %r12d
	addl	%edx, %r12d
	sarl	%r12d
	cmpl	%r12d, %eax
	jge	.L18
	leal	(%rdi,%r12), %edx
	movl	%edx, %r15d
	shrl	$31, %r15d
	addl	%edx, %r15d
	sarl	%r15d
	cmpl	%r15d, %eax
	jl	.L50
	leal	1(%r15), %eax
	cmpl	%eax, %r12d
	jg	.L51
.L22:
	movl	%r12d, %edx
	movl	%r15d, %esi
	movl	%r13d, %edi
	call	merge
.L18:
	leal	1(%r12), %eax
	cmpl	%eax, %ebp
	jle	.L25
	leal	0(%rbp,%r12), %edx
	movl	%edx, %r15d
	shrl	$31, %r15d
	addl	%edx, %r15d
	sarl	%r15d
	cmpl	%r15d, %eax
	jl	.L52
	leal	1(%r15), %eax
	cmpl	%eax, %ebp
	jg	.L53
.L29:
	movl	%ebp, %edx
	movl	%r15d, %esi
	movl	%r12d, %edi
	call	merge
.L25:
	movl	%ebp, %edx
	movl	%r12d, %esi
	movl	%r13d, %edi
	call	merge
	leal	1(%rbp), %eax
	cmpl	%eax, %r14d
	jle	.L32
.L49:
	leal	(%r14,%rbp), %edx
	movl	%edx, %r12d
	shrl	$31, %r12d
	addl	%edx, %r12d
	sarl	%r12d
	cmpl	%r12d, %eax
	jge	.L33
	leal	0(%rbp,%r12), %edx
	movl	%edx, %r15d
	shrl	$31, %r15d
	addl	%edx, %r15d
	sarl	%r15d
	cmpl	%r15d, %eax
	jl	.L54
	leal	1(%r15), %eax
	cmpl	%eax, %r12d
	jg	.L55
.L37:
	movl	%r12d, %edx
	movl	%r15d, %esi
	movl	%ebp, %edi
	call	merge
.L33:
	leal	1(%r12), %eax
	cmpl	%eax, %r14d
	jle	.L40
	leal	(%r14,%r12), %edx
	movl	%edx, %r15d
	shrl	$31, %r15d
	addl	%edx, %r15d
	sarl	%r15d
	cmpl	%r15d, %eax
	jl	.L56
	leal	1(%r15), %eax
	cmpl	%eax, %r14d
	jg	.L57
.L44:
	movl	%r14d, %edx
	movl	%r15d, %esi
	movl	%r12d, %edi
	call	merge
.L40:
	movl	%r14d, %edx
	movl	%r12d, %esi
	movl	%ebp, %edi
	call	merge
	jmp	.L32
	.p2align 4,,10
	.p2align 3
.L57:
	leal	(%r14,%r15), %edx
	movl	%edx, %ebx
	shrl	$31, %ebx
	addl	%edx, %ebx
	sarl	%ebx
	cmpl	%ebx, %eax
	jge	.L45
	movl	%ebx, %esi
	movl	%r15d, %edi
	call	m_sort.part.0
.L45:
	leal	1(%rbx), %eax
	cmpl	%eax, %r14d
	jle	.L46
	movl	%r14d, %esi
	movl	%ebx, %edi
	call	m_sort.part.0
.L46:
	movl	%r14d, %edx
	movl	%ebx, %esi
	movl	%r15d, %edi
	call	merge
	jmp	.L44
	.p2align 4,,10
	.p2align 3
.L56:
	leal	(%r12,%r15), %edx
	movl	%edx, %ebx
	shrl	$31, %ebx
	addl	%edx, %ebx
	sarl	%ebx
	cmpl	%ebx, %eax
	jge	.L42
	movl	%ebx, %esi
	movl	%r12d, %edi
	call	m_sort.part.0
.L42:
	leal	1(%rbx), %eax
	cmpl	%eax, %r15d
	jle	.L43
	movl	%r15d, %esi
	movl	%ebx, %edi
	call	m_sort.part.0
.L43:
	movl	%r15d, %edx
	movl	%ebx, %esi
	movl	%r12d, %edi
	call	merge
	leal	1(%r15), %eax
	cmpl	%eax, %r14d
	jle	.L44
	jmp	.L57
	.p2align 4,,10
	.p2align 3
.L55:
	leal	(%r12,%r15), %edx
	movl	%edx, %ebx
	shrl	$31, %ebx
	addl	%edx, %ebx
	sarl	%ebx
	cmpl	%ebx, %eax
	jge	.L38
	movl	%ebx, %esi
	movl	%r15d, %edi
	call	m_sort.part.0
.L38:
	leal	1(%rbx), %eax
	cmpl	%eax, %r12d
	jle	.L39
	movl	%r12d, %esi
	movl	%ebx, %edi
	call	m_sort.part.0
.L39:
	movl	%r12d, %edx
	movl	%ebx, %esi
	movl	%r15d, %edi
	call	merge
	jmp	.L37
	.p2align 4,,10
	.p2align 3
.L54:
	leal	0(%rbp,%r15), %edx
	movl	%edx, %ebx
	shrl	$31, %ebx
	addl	%edx, %ebx
	sarl	%ebx
	cmpl	%ebx, %eax
	jge	.L35
	movl	%ebx, %esi
	movl	%ebp, %edi
	call	m_sort.part.0
.L35:
	leal	1(%rbx), %eax
	cmpl	%eax, %r15d
	jle	.L36
	movl	%r15d, %esi
	movl	%ebx, %edi
	call	m_sort.part.0
.L36:
	movl	%r15d, %edx
	movl	%ebx, %esi
	movl	%ebp, %edi
	call	merge
	leal	1(%r15), %eax
	cmpl	%eax, %r12d
	jle	.L37
	jmp	.L55
	.p2align 4,,10
	.p2align 3
.L53:
	leal	0(%rbp,%r15), %edx
	movl	%edx, %ebx
	shrl	$31, %ebx
	addl	%edx, %ebx
	sarl	%ebx
	cmpl	%ebx, %eax
	jge	.L30
	movl	%ebx, %esi
	movl	%r15d, %edi
	call	m_sort.part.0
.L30:
	leal	1(%rbx), %eax
	cmpl	%eax, %ebp
	jle	.L31
	movl	%ebp, %esi
	movl	%ebx, %edi
	call	m_sort.part.0
.L31:
	movl	%ebp, %edx
	movl	%ebx, %esi
	movl	%r15d, %edi
	call	merge
	jmp	.L29
	.p2align 4,,10
	.p2align 3
.L52:
	leal	(%r12,%r15), %edx
	movl	%edx, %ebx
	shrl	$31, %ebx
	addl	%edx, %ebx
	sarl	%ebx
	cmpl	%ebx, %eax
	jge	.L27
	movl	%ebx, %esi
	movl	%r12d, %edi
	call	m_sort.part.0
.L27:
	leal	1(%rbx), %eax
	cmpl	%eax, %r15d
	jle	.L28
	movl	%r15d, %esi
	movl	%ebx, %edi
	call	m_sort.part.0
.L28:
	movl	%r15d, %edx
	movl	%ebx, %esi
	movl	%r12d, %edi
	call	merge
	leal	1(%r15), %eax
	cmpl	%eax, %ebp
	jle	.L29
	jmp	.L53
	.p2align 4,,10
	.p2align 3
.L51:
	leal	(%r12,%r15), %edx
	movl	%edx, %ebx
	shrl	$31, %ebx
	addl	%edx, %ebx
	sarl	%ebx
	cmpl	%ebx, %eax
	jge	.L23
	movl	%ebx, %esi
	movl	%r15d, %edi
	call	m_sort.part.0
.L23:
	leal	1(%rbx), %eax
	cmpl	%eax, %r12d
	jle	.L24
	movl	%r12d, %esi
	movl	%ebx, %edi
	call	m_sort.part.0
.L24:
	movl	%r12d, %edx
	movl	%ebx, %esi
	movl	%r15d, %edi
	call	merge
	jmp	.L22
	.p2align 4,,10
	.p2align 3
.L50:
	leal	(%rdi,%r15), %edx
	movl	%edx, %ebx
	shrl	$31, %ebx
	addl	%edx, %ebx
	sarl	%ebx
	cmpl	%ebx, %eax
	jge	.L20
	movl	%ebx, %esi
	call	m_sort.part.0
.L20:
	leal	1(%rbx), %eax
	cmpl	%eax, %r15d
	jle	.L21
	movl	%r15d, %esi
	movl	%ebx, %edi
	call	m_sort.part.0
.L21:
	movl	%r15d, %edx
	movl	%ebx, %esi
	movl	%r13d, %edi
	call	merge
	leal	1(%r15), %eax
	cmpl	%eax, %r12d
	jle	.L22
	jmp	.L51
	.cfi_endproc
.LFE43:
	.size	m_sort.part.0, .-m_sort.part.0
	.p2align 4
	.globl	m_sort
	.type	m_sort, @function
m_sort:
.LFB40:
	.cfi_startproc
	endbr64
	leal	1(%rdi), %eax
	cmpl	%esi, %eax
	jl	.L69
	ret
	.p2align 4,,10
	.p2align 3
.L69:
	leal	(%rdi,%rsi), %edx
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	movl	%edi, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	movl	%esi, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	movl	%edx, %ebp
	shrl	$31, %ebp
	addl	%edx, %ebp
	sarl	%ebp
	subq	$8, %rsp
	.cfi_def_cfa_offset 48
	cmpl	%ebp, %eax
	jge	.L60
	leal	(%rdi,%rbp), %edx
	movl	%edx, %r13d
	shrl	$31, %r13d
	addl	%edx, %r13d
	sarl	%r13d
	cmpl	%r13d, %eax
	jl	.L70
	leal	1(%r13), %eax
	cmpl	%eax, %ebp
	jg	.L71
.L62:
	movl	%ebp, %edx
	movl	%r13d, %esi
	movl	%r14d, %edi
	call	merge
.L60:
	leal	1(%rbp), %eax
	cmpl	%eax, %r12d
	jle	.L63
	leal	(%r12,%rbp), %edx
	movl	%edx, %r13d
	shrl	$31, %r13d
	addl	%edx, %r13d
	sarl	%r13d
	cmpl	%r13d, %eax
	jl	.L72
	leal	1(%r13), %eax
	cmpl	%eax, %r12d
	jg	.L73
.L65:
	movl	%r12d, %edx
	movl	%r13d, %esi
	movl	%ebp, %edi
	call	merge
.L63:
	addq	$8, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 40
	movl	%r12d, %edx
	movl	%ebp, %esi
	movl	%r14d, %edi
	popq	%rbp
	.cfi_restore 6
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_restore 12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_restore 13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_restore 14
	.cfi_def_cfa_offset 8
	jmp	merge
	.p2align 4,,10
	.p2align 3
.L73:
	.cfi_restore_state
	movl	%r12d, %esi
	movl	%r13d, %edi
	call	m_sort.part.0
	jmp	.L65
	.p2align 4,,10
	.p2align 3
.L72:
	movl	%r13d, %esi
	movl	%ebp, %edi
	call	m_sort.part.0
	leal	1(%r13), %eax
	cmpl	%eax, %r12d
	jle	.L65
	jmp	.L73
	.p2align 4,,10
	.p2align 3
.L71:
	movl	%ebp, %esi
	movl	%r13d, %edi
	call	m_sort.part.0
	jmp	.L62
	.p2align 4,,10
	.p2align 3
.L70:
	movl	%r13d, %esi
	call	m_sort.part.0
	leal	1(%r13), %eax
	cmpl	%eax, %ebp
	jle	.L62
	jmp	.L71
	.cfi_endproc
.LFE40:
	.size	m_sort, .-m_sort
	.p2align 4
	.globl	swap
	.type	swap, @function
swap:
.LFB41:
	.cfi_startproc
	endbr64
	movslq	%edi, %rdi
	movslq	%esi, %rsi
	leaq	(%rdx,%rdi,4), %rcx
	leaq	(%rdx,%rsi,4), %rax
	movl	(%rcx), %edi
	movl	(%rax), %edx
	movl	%edx, (%rcx)
	movl	%edi, (%rax)
	ret
	.cfi_endproc
.LFE41:
	.size	swap, .-swap
	.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:
.LFB42:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	.LC0(%rip), %r15
	leaq	n(%rip), %rsi
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movq	%r15, %rdi
	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	$4024, %rsp
	.cfi_def_cfa_offset 4080
	movq	%fs:40, %rax
	movq	%rax, 4008(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %rbx
	call	__isoc99_scanf@PLT
	xorl	%eax, %eax
	movl	$500, %ecx
	movq	%rbx, %rdi
	rep stosq
	movl	n(%rip), %eax
	movl	$0, (%rdi)
	testl	%eax, %eax
	jle	.L76
	leaq	A(%rip), %rbp
	xorl	%r13d, %r13d
	leaq	B(%rip), %r12
	movq	%rbp, %r14
	.p2align 4,,10
	.p2align 3
.L77:
	movq	%r14, %rsi
	movq	%r15, %rdi
	xorl	%eax, %eax
	addq	$4, %r14
	call	__isoc99_scanf@PLT
	movl	-4(%r14), %eax
	movslq	n(%rip), %rsi
	movl	%eax, (%r12,%r13,4)
	addq	$1, %r13
	cmpl	%r13d, %esi
	jg	.L77
	cmpl	$1, %esi
	jg	.L102
.L78:
	testl	%esi, %esi
	jle	.L76
	xorl	%eax, %eax
	.p2align 4,,10
	.p2align 3
.L80:
	movl	(%r12,%rax,4), %edi
	cmpl	%edi, 0(%rbp,%rax,4)
	jne	.L79
	movl	$1, (%rbx,%rax,4)
.L79:
	addq	$1, %rax
	cmpq	%rax, %rsi
	jne	.L80
	movl	A(%rip), %r11d
	xorl	%edi, %edi
	xorl	%eax, %eax
	xorl	%r10d, %r10d
	movl	$0, cost(%rip)
	jmp	.L88
	.p2align 4,,10
	.p2align 3
.L82:
	addq	$1, %rdi
	cmpq	%rdi, %rsi
	je	.L103
.L88:
	cmpl	$1, (%rbx,%rdi,4)
	movl	%edi, %r13d
	je	.L82
	movl	(%r12,%rdi,4), %edx
	movl	$1, (%rbx,%rdi,4)
	xorl	%r14d, %r14d
	xorl	%r9d, %r9d
	movl	%edx, %r8d
	.p2align 4,,10
	.p2align 3
.L86:
	xorl	%eax, %eax
	.p2align 4,,10
	.p2align 3
.L85:
	movslq	%eax, %rcx
	cmpl	%edx, 0(%rbp,%rax,4)
	je	.L104
	addq	$1, %rax
	cmpq	%rax, %rsi
	jne	.L85
	cmpl	%edi, %r13d
	jne	.L86
.L106:
	subl	$1, %r9d
	leal	(%r11,%r8), %eax
	subl	%r8d, %r14d
	movl	%r9d, %edx
	imull	%r11d, %r9d
	addl	%eax, %eax
	imull	%r8d, %edx
	leal	(%r9,%rax), %ecx
	cmpl	%ecx, %edx
	jle	.L87
	addl	%r14d, %r9d
	addq	$1, %rdi
	addl	%r9d, %eax
	addl	%eax, %r10d
	movl	$1, %eax
	cmpq	%rdi, %rsi
	jne	.L88
.L103:
	testb	%al, %al
	je	.L89
	movl	%r10d, cost(%rip)
.L89:
	movl	cost(%rip), %edx
	xorl	%eax, %eax
	movl	$1, %edi
	leaq	.LC1(%rip), %rsi
	call	__printf_chk@PLT
	movq	4008(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L105
	addq	$4024, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	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
	.p2align 4,,10
	.p2align 3
.L104:
	.cfi_restore_state
	movl	(%r12,%rcx,4), %edx
	addl	$1, %r9d
	movl	%eax, %r13d
	movl	$1, (%rsp,%rcx,4)
	addl	%edx, %r14d
	cmpl	%edx, %r8d
	cmovg	%edx, %r8d
	cmpl	%edi, %r13d
	jne	.L86
	jmp	.L106
.L87:
	addl	%r14d, %edx
	movl	$1, %eax
	addl	%edx, %r10d
	jmp	.L82
.L102:
	xorl	%edi, %edi
	call	m_sort.part.0
	movslq	n(%rip), %rsi
	jmp	.L78
.L76:
	movl	$0, cost(%rip)
	jmp	.L89
.L105:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE42:
	.size	main, .-main
	.globl	R
	.bss
	.align 32
	.type	R, @object
	.size	R, 2008
R:
	.zero	2008
	.globl	L
	.align 32
	.type	L, @object
	.size	L, 2004
L:
	.zero	2004
	.globl	B
	.align 32
	.type	B, @object
	.size	B, 4004
B:
	.zero	4004
	.globl	A
	.align 32
	.type	A, @object
	.size	A, 4004
A:
	.zero	4004
	.globl	cost
	.align 4
	.type	cost, @object
	.size	cost, 4
cost:
	.zero	4
	.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	merge
	.type	merge, @function
merge:
.LFB39:
	.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
	movl	%edx, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movslq	%esi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movl	%r13d, %eax
	movl	%edi, %r12d
	subl	%r13d, %r14d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	subl	%edi, %eax
	leaq	L(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movslq	%eax, %r15
	movl	%edx, %ebx
	subq	$8, %rsp
	.cfi_def_cfa_offset 64
	testl	%eax, %eax
	jle	.L2
	movslq	%edi, %rax
	leaq	A(%rip), %rcx
	movq	%rbp, %rdi
	leaq	0(,%r15,4), %rdx
	leaq	(%rcx,%rax,4), %rsi
	call	memcpy@PLT
.L2:
	testl	%r14d, %r14d
	leaq	R(%rip), %r10
	movslq	%r14d, %r14
	movl	$2147483647, 0(%rbp,%r15,4)
	jle	.L3
	leaq	A(%rip), %rax
	movq	%r10, %rdi
	leaq	0(,%r14,4), %rdx
	leaq	(%rax,%r13,4), %rsi
	call	memcpy@PLT
	movq	%rax, %r10
.L3:
	movl	$2147483647, (%r10,%r14,4)
	cmpl	%ebx, %r12d
	jge	.L1
	subl	$1, %ebx
	movslq	%r12d, %rdx
	leaq	A(%rip), %rax
	xorl	%r9d, %r9d
	subl	%r12d, %ebx
	leaq	(%rax,%rdx,4), %rax
	xorl	%r8d, %r8d
	xorl	%edi, %edi
	addq	%rdx, %rbx
	leaq	4+A(%rip), %rdx
	xorl	%esi, %esi
	leaq	(%rdx,%rbx,4), %r11
	.p2align 4,,10
	.p2align 3
.L7:
	movl	0(%rbp,%rdi,4), %ecx
	movl	(%r10,%rsi,4), %edx
	cmpl	%edx, %ecx
	jg	.L5
.L15:
	movl	%ecx, (%rax)
	addq	$4, %rax
	addl	$1, %r8d
	cmpq	%r11, %rax
	je	.L1
	movslq	%r8d, %rdi
	movl	(%r10,%rsi,4), %edx
	movl	0(%rbp,%rdi,4), %ecx
	cmpl	%edx, %ecx
	jle	.L15
.L5:
	movl	%edx, (%rax)
	addq	$4, %rax
	addl	$1, %r9d
	cmpq	%rax, %r11
	je	.L1
	movslq	%r9d, %rsi
	jmp	.L7
	.p2align 4,,10
	.p2align 3
.L1:
	addq	$8, %rsp
	.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
	.cfi_endproc
.LFE39:
	.size	merge, .-merge
	.p2align 4
	.type	m_sort.part.0, @function
m_sort.part.0:
.LFB43:
	.cfi_startproc
	leal	(%rdi,%rsi), %eax
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movl	%esi, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movl	%edi, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	%eax, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	shrl	$31, %ebp
	addl	%eax, %ebp
	leal	1(%rdi), %eax
	sarl	%ebp
	subq	$8, %rsp
	.cfi_def_cfa_offset 64
	cmpl	%eax, %ebp
	jg	.L48
	leal	1(%rbp), %eax
	cmpl	%eax, %r14d
	jg	.L49
.L32:
	addq	$8, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	movl	%r14d, %edx
	movl	%ebp, %esi
	movl	%r13d, %edi
	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
	jmp	merge
	.p2align 4,,10
	.p2align 3
.L48:
	.cfi_restore_state
	leal	(%rdi,%rbp), %edx
	movl	%edx, %r12d
	shrl	$31, %r12d
	addl	%edx, %r12d
	sarl	%r12d
	cmpl	%r12d, %eax
	jge	.L18
	leal	(%rdi,%r12), %edx
	movl	%edx, %r15d
	shrl	$31, %r15d
	addl	%edx, %r15d
	sarl	%r15d
	cmpl	%r15d, %eax
	jl	.L50
	leal	1(%r15), %eax
	cmpl	%eax, %r12d
	jg	.L51
.L22:
	movl	%r12d, %edx
	movl	%r15d, %esi
	movl	%r13d, %edi
	call	merge
.L18:
	leal	1(%r12), %eax
	cmpl	%eax, %ebp
	jle	.L25
	leal	0(%rbp,%r12), %edx
	movl	%edx, %r15d
	shrl	$31, %r15d
	addl	%edx, %r15d
	sarl	%r15d
	cmpl	%r15d, %eax
	jl	.L52
	leal	1(%r15), %eax
	cmpl	%eax, %ebp
	jg	.L53
.L29:
	movl	%ebp, %edx
	movl	%r15d, %esi
	movl	%r12d, %edi
	call	merge
.L25:
	movl	%ebp, %edx
	movl	%r12d, %esi
	movl	%r13d, %edi
	call	merge
	leal	1(%rbp), %eax
	cmpl	%eax, %r14d
	jle	.L32
.L49:
	leal	(%r14,%rbp), %edx
	movl	%edx, %r12d
	shrl	$31, %r12d
	addl	%edx, %r12d
	sarl	%r12d
	cmpl	%r12d, %eax
	jge	.L33
	leal	0(%rbp,%r12), %edx
	movl	%edx, %r15d
	shrl	$31, %r15d
	addl	%edx, %r15d
	sarl	%r15d
	cmpl	%r15d, %eax
	jl	.L54
	leal	1(%r15), %eax
	cmpl	%eax, %r12d
	jg	.L55
.L37:
	movl	%r12d, %edx
	movl	%r15d, %esi
	movl	%ebp, %edi
	call	merge
.L33:
	leal	1(%r12), %eax
	cmpl	%eax, %r14d
	jle	.L40
	leal	(%r14,%r12), %edx
	movl	%edx, %r15d
	shrl	$31, %r15d
	addl	%edx, %r15d
	sarl	%r15d
	cmpl	%r15d, %eax
	jl	.L56
	leal	1(%r15), %eax
	cmpl	%eax, %r14d
	jg	.L57
.L44:
	movl	%r14d, %edx
	movl	%r15d, %esi
	movl	%r12d, %edi
	call	merge
.L40:
	movl	%r14d, %edx
	movl	%r12d, %esi
	movl	%ebp, %edi
	call	merge
	jmp	.L32
	.p2align 4,,10
	.p2align 3
.L57:
	leal	(%r14,%r15), %edx
	movl	%edx, %ebx
	shrl	$31, %ebx
	addl	%edx, %ebx
	sarl	%ebx
	cmpl	%ebx, %eax
	jge	.L45
	movl	%ebx, %esi
	movl	%r15d, %edi
	call	m_sort.part.0
.L45:
	leal	1(%rbx), %eax
	cmpl	%eax, %r14d
	jle	.L46
	movl	%r14d, %esi
	movl	%ebx, %edi
	call	m_sort.part.0
.L46:
	movl	%r14d, %edx
	movl	%ebx, %esi
	movl	%r15d, %edi
	call	merge
	jmp	.L44
	.p2align 4,,10
	.p2align 3
.L56:
	leal	(%r12,%r15), %edx
	movl	%edx, %ebx
	shrl	$31, %ebx
	addl	%edx, %ebx
	sarl	%ebx
	cmpl	%ebx, %eax
	jge	.L42
	movl	%ebx, %esi
	movl	%r12d, %edi
	call	m_sort.part.0
.L42:
	leal	1(%rbx), %eax
	cmpl	%eax, %r15d
	jle	.L43
	movl	%r15d, %esi
	movl	%ebx, %edi
	call	m_sort.part.0
.L43:
	movl	%r15d, %edx
	movl	%ebx, %esi
	movl	%r12d, %edi
	call	merge
	leal	1(%r15), %eax
	cmpl	%eax, %r14d
	jle	.L44
	jmp	.L57
	.p2align 4,,10
	.p2align 3
.L55:
	leal	(%r12,%r15), %edx
	movl	%edx, %ebx
	shrl	$31, %ebx
	addl	%edx, %ebx
	sarl	%ebx
	cmpl	%ebx, %eax
	jge	.L38
	movl	%ebx, %esi
	movl	%r15d, %edi
	call	m_sort.part.0
.L38:
	leal	1(%rbx), %eax
	cmpl	%eax, %r12d
	jle	.L39
	movl	%r12d, %esi
	movl	%ebx, %edi
	call	m_sort.part.0
.L39:
	movl	%r12d, %edx
	movl	%ebx, %esi
	movl	%r15d, %edi
	call	merge
	jmp	.L37
	.p2align 4,,10
	.p2align 3
.L54:
	leal	0(%rbp,%r15), %edx
	movl	%edx, %ebx
	shrl	$31, %ebx
	addl	%edx, %ebx
	sarl	%ebx
	cmpl	%ebx, %eax
	jge	.L35
	movl	%ebx, %esi
	movl	%ebp, %edi
	call	m_sort.part.0
.L35:
	leal	1(%rbx), %eax
	cmpl	%eax, %r15d
	jle	.L36
	movl	%r15d, %esi
	movl	%ebx, %edi
	call	m_sort.part.0
.L36:
	movl	%r15d, %edx
	movl	%ebx, %esi
	movl	%ebp, %edi
	call	merge
	leal	1(%r15), %eax
	cmpl	%eax, %r12d
	jle	.L37
	jmp	.L55
	.p2align 4,,10
	.p2align 3
.L53:
	leal	0(%rbp,%r15), %edx
	movl	%edx, %ebx
	shrl	$31, %ebx
	addl	%edx, %ebx
	sarl	%ebx
	cmpl	%ebx, %eax
	jge	.L30
	movl	%ebx, %esi
	movl	%r15d, %edi
	call	m_sort.part.0
.L30:
	leal	1(%rbx), %eax
	cmpl	%eax, %ebp
	jle	.L31
	movl	%ebp, %esi
	movl	%ebx, %edi
	call	m_sort.part.0
.L31:
	movl	%ebp, %edx
	movl	%ebx, %esi
	movl	%r15d, %edi
	call	merge
	jmp	.L29
	.p2align 4,,10
	.p2align 3
.L52:
	leal	(%r12,%r15), %edx
	movl	%edx, %ebx
	shrl	$31, %ebx
	addl	%edx, %ebx
	sarl	%ebx
	cmpl	%ebx, %eax
	jge	.L27
	movl	%ebx, %esi
	movl	%r12d, %edi
	call	m_sort.part.0
.L27:
	leal	1(%rbx), %eax
	cmpl	%eax, %r15d
	jle	.L28
	movl	%r15d, %esi
	movl	%ebx, %edi
	call	m_sort.part.0
.L28:
	movl	%r15d, %edx
	movl	%ebx, %esi
	movl	%r12d, %edi
	call	merge
	leal	1(%r15), %eax
	cmpl	%eax, %ebp
	jle	.L29
	jmp	.L53
	.p2align 4,,10
	.p2align 3
.L51:
	leal	(%r12,%r15), %edx
	movl	%edx, %ebx
	shrl	$31, %ebx
	addl	%edx, %ebx
	sarl	%ebx
	cmpl	%ebx, %eax
	jge	.L23
	movl	%ebx, %esi
	movl	%r15d, %edi
	call	m_sort.part.0
.L23:
	leal	1(%rbx), %eax
	cmpl	%eax, %r12d
	jle	.L24
	movl	%r12d, %esi
	movl	%ebx, %edi
	call	m_sort.part.0
.L24:
	movl	%r12d, %edx
	movl	%ebx, %esi
	movl	%r15d, %edi
	call	merge
	jmp	.L22
	.p2align 4,,10
	.p2align 3
.L50:
	leal	(%rdi,%r15), %edx
	movl	%edx, %ebx
	shrl	$31, %ebx
	addl	%edx, %ebx
	sarl	%ebx
	cmpl	%ebx, %eax
	jge	.L20
	movl	%ebx, %esi
	call	m_sort.part.0
.L20:
	leal	1(%rbx), %eax
	cmpl	%eax, %r15d
	jle	.L21
	movl	%r15d, %esi
	movl	%ebx, %edi
	call	m_sort.part.0
.L21:
	movl	%r15d, %edx
	movl	%ebx, %esi
	movl	%r13d, %edi
	call	merge
	leal	1(%r15), %eax
	cmpl	%eax, %r12d
	jle	.L22
	jmp	.L51
	.cfi_endproc
.LFE43:
	.size	m_sort.part.0, .-m_sort.part.0
	.p2align 4
	.globl	m_sort
	.type	m_sort, @function
m_sort:
.LFB40:
	.cfi_startproc
	endbr64
	leal	1(%rdi), %eax
	cmpl	%esi, %eax
	jl	.L69
	ret
	.p2align 4,,10
	.p2align 3
.L69:
	leal	(%rdi,%rsi), %edx
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	movl	%edi, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	movl	%esi, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	movl	%edx, %ebp
	shrl	$31, %ebp
	addl	%edx, %ebp
	sarl	%ebp
	subq	$8, %rsp
	.cfi_def_cfa_offset 48
	cmpl	%ebp, %eax
	jge	.L60
	leal	(%rdi,%rbp), %edx
	movl	%edx, %r13d
	shrl	$31, %r13d
	addl	%edx, %r13d
	sarl	%r13d
	cmpl	%r13d, %eax
	jl	.L70
	leal	1(%r13), %eax
	cmpl	%eax, %ebp
	jg	.L71
.L62:
	movl	%ebp, %edx
	movl	%r13d, %esi
	movl	%r14d, %edi
	call	merge
.L60:
	leal	1(%rbp), %eax
	cmpl	%eax, %r12d
	jle	.L63
	leal	(%r12,%rbp), %edx
	movl	%edx, %r13d
	shrl	$31, %r13d
	addl	%edx, %r13d
	sarl	%r13d
	cmpl	%r13d, %eax
	jl	.L72
	leal	1(%r13), %eax
	cmpl	%eax, %r12d
	jg	.L73
.L65:
	movl	%r12d, %edx
	movl	%r13d, %esi
	movl	%ebp, %edi
	call	merge
.L63:
	addq	$8, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 40
	movl	%r12d, %edx
	movl	%ebp, %esi
	movl	%r14d, %edi
	popq	%rbp
	.cfi_restore 6
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_restore 12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_restore 13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_restore 14
	.cfi_def_cfa_offset 8
	jmp	merge
	.p2align 4,,10
	.p2align 3
.L73:
	.cfi_restore_state
	movl	%r12d, %esi
	movl	%r13d, %edi
	call	m_sort.part.0
	jmp	.L65
	.p2align 4,,10
	.p2align 3
.L72:
	movl	%r13d, %esi
	movl	%ebp, %edi
	call	m_sort.part.0
	leal	1(%r13), %eax
	cmpl	%eax, %r12d
	jle	.L65
	jmp	.L73
	.p2align 4,,10
	.p2align 3
.L71:
	movl	%ebp, %esi
	movl	%r13d, %edi
	call	m_sort.part.0
	jmp	.L62
	.p2align 4,,10
	.p2align 3
.L70:
	movl	%r13d, %esi
	call	m_sort.part.0
	leal	1(%r13), %eax
	cmpl	%eax, %ebp
	jle	.L62
	jmp	.L71
	.cfi_endproc
.LFE40:
	.size	m_sort, .-m_sort
	.p2align 4
	.globl	swap
	.type	swap, @function
swap:
.LFB41:
	.cfi_startproc
	endbr64
	movslq	%edi, %rdi
	movslq	%esi, %rsi
	leaq	(%rdx,%rdi,4), %rcx
	leaq	(%rdx,%rsi,4), %rax
	movl	(%rcx), %edi
	movl	(%rax), %edx
	movl	%edx, (%rcx)
	movl	%edi, (%rax)
	ret
	.cfi_endproc
.LFE41:
	.size	swap, .-swap
	.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:
.LFB42:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	.LC0(%rip), %r15
	leaq	n(%rip), %rsi
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movq	%r15, %rdi
	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	$4024, %rsp
	.cfi_def_cfa_offset 4080
	movq	%fs:40, %rax
	movq	%rax, 4008(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %rbx
	call	__isoc99_scanf@PLT
	xorl	%eax, %eax
	movl	$500, %ecx
	movq	%rbx, %rdi
	rep stosq
	movl	n(%rip), %eax
	movl	$0, (%rdi)
	testl	%eax, %eax
	jle	.L76
	leaq	A(%rip), %rbp
	xorl	%r13d, %r13d
	leaq	B(%rip), %r12
	movq	%rbp, %r14
	.p2align 4,,10
	.p2align 3
.L77:
	movq	%r14, %rsi
	movq	%r15, %rdi
	xorl	%eax, %eax
	addq	$4, %r14
	call	__isoc99_scanf@PLT
	movl	-4(%r14), %eax
	movslq	n(%rip), %rsi
	movl	%eax, (%r12,%r13,4)
	addq	$1, %r13
	cmpl	%r13d, %esi
	jg	.L77
	cmpl	$1, %esi
	jg	.L102
.L78:
	testl	%esi, %esi
	jle	.L76
	xorl	%eax, %eax
	.p2align 4,,10
	.p2align 3
.L80:
	movl	(%r12,%rax,4), %edi
	cmpl	%edi, 0(%rbp,%rax,4)
	jne	.L79
	movl	$1, (%rbx,%rax,4)
.L79:
	addq	$1, %rax
	cmpq	%rax, %rsi
	jne	.L80
	movl	A(%rip), %r11d
	xorl	%edi, %edi
	xorl	%eax, %eax
	xorl	%r10d, %r10d
	movl	$0, cost(%rip)
	jmp	.L88
	.p2align 4,,10
	.p2align 3
.L82:
	addq	$1, %rdi
	cmpq	%rdi, %rsi
	je	.L103
.L88:
	cmpl	$1, (%rbx,%rdi,4)
	movl	%edi, %r13d
	je	.L82
	movl	(%r12,%rdi,4), %edx
	movl	$1, (%rbx,%rdi,4)
	xorl	%r14d, %r14d
	xorl	%r9d, %r9d
	movl	%edx, %r8d
	.p2align 4,,10
	.p2align 3
.L86:
	xorl	%eax, %eax
	.p2align 4,,10
	.p2align 3
.L85:
	movslq	%eax, %rcx
	cmpl	%edx, 0(%rbp,%rax,4)
	je	.L104
	addq	$1, %rax
	cmpq	%rax, %rsi
	jne	.L85
	cmpl	%edi, %r13d
	jne	.L86
.L106:
	subl	$1, %r9d
	leal	(%r11,%r8), %eax
	subl	%r8d, %r14d
	movl	%r9d, %edx
	imull	%r11d, %r9d
	addl	%eax, %eax
	imull	%r8d, %edx
	leal	(%r9,%rax), %ecx
	cmpl	%ecx, %edx
	jle	.L87
	addl	%r14d, %r9d
	addq	$1, %rdi
	addl	%r9d, %eax
	addl	%eax, %r10d
	movl	$1, %eax
	cmpq	%rdi, %rsi
	jne	.L88
.L103:
	testb	%al, %al
	je	.L89
	movl	%r10d, cost(%rip)
.L89:
	movl	cost(%rip), %edx
	xorl	%eax, %eax
	movl	$1, %edi
	leaq	.LC1(%rip), %rsi
	call	__printf_chk@PLT
	movq	4008(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L105
	addq	$4024, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	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
	.p2align 4,,10
	.p2align 3
.L104:
	.cfi_restore_state
	movl	(%r12,%rcx,4), %edx
	addl	$1, %r9d
	movl	%eax, %r13d
	movl	$1, (%rsp,%rcx,4)
	addl	%edx, %r14d
	cmpl	%edx, %r8d
	cmovg	%edx, %r8d
	cmpl	%edi, %r13d
	jne	.L86
	jmp	.L106
.L87:
	addl	%r14d, %edx
	movl	$1, %eax
	addl	%edx, %r10d
	jmp	.L82
.L102:
	xorl	%edi, %edi
	call	m_sort.part.0
	movslq	n(%rip), %rsi
	jmp	.L78
.L76:
	movl	$0, cost(%rip)
	jmp	.L89
.L105:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE42:
	.size	main, .-main
	.globl	R
	.bss
	.align 32
	.type	R, @object
	.size	R, 2008
R:
	.zero	2008
	.globl	L
	.align 32
	.type	L, @object
	.size	L, 2004
L:
	.zero	2004
	.globl	B
	.align 32
	.type	B, @object
	.size	B, 4004
B:
	.zero	4004
	.globl	A
	.align 32
	.type	A, @object
	.size	A, 4004
A:
	.zero	4004
	.globl	cost
	.align 4
	.type	cost, @object
	.size	cost, 4
cost:
	.zero	4
	.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<stdlib.h>
#include<limits.h>
   
   
   
int n,cost;
int A[1001],B[1001];
int L[501],R[502];
   
   
void merge(int left,int mid,int right){
  int i,j,n1=mid-left,n2=right-mid;
  for(i=0;i<n1;i++) L[i]=A[left+i];
  L[n1]=INT_MAX;
  for(i=0;i<n2;i++) R[i]=A[mid+i];
  R[n2]=INT_MAX;
  int l=0,r=0;
  for(i=left;i<right;i++){
    if(L[l]<=R[r]){
      A[i]=L[l];
      l++;
    }
    else{
      A[i]=R[r];
      r++;
    }
  }
}
   
   
void m_sort(int left,int right){
  int mid;
  if( left+1 >= right) return;
  mid=(left+right)/2;
  m_sort(left,mid);
  m_sort(mid,right);
  merge(left,mid,right);
}
   
   
void swap(int a,int b,int *C){
  int swap;
  swap=C[a];
  C[a]=C[b];
  C[b]=swap;
}
   
   
   
   
   
   
     
    
     
   
int main(){
  scanf("%d",&n);
  int i,j;
  int cnt,sum,min,start,x;
  int C[1001]={};
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
    B[i]=A[i];
  }
  m_sort(0,n);
  for(i=0;i<n;i++){
    if(A[i]==B[i]) C[i]=1;
  }
  cost=0;
  for(i=0;i<n;i++){
    if(C[i]!=1){
      C[i]=1;
      cnt=0;
      sum=0;
      min=B[i];
      x=i;
      while(1){
        for(j=0;j<n;j++){
          if(B[x]==A[j]){
            C[j]=1;
            cnt++;
            sum+=B[j];
            if(min > B[j]) min=B[j];
            x=j;
            break;
          }
        }
        if(x==i) break;
      }
      sum-=min;
      if( (cnt -1)*min > (cnt -1)*A[0]+2*(min +A[0])) cost+=sum+(cnt-1)*A[0]+2*(min +A[0]);
      else cost+=sum+(cnt-1)*min;
    }
  }
  printf("%d\n",cost);
  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<stdlib.h>
#include<limits.h>
   
   
   
int n,cost;
int A[1001],B[1001];
int L[501],R[502];
   
   
void merge(int left,int mid,int right){
  int i,j,n1=mid-left,n2=right-mid;
  for(i=0;i<n1;i++) L[i]=A[left+i];
  L[n1]=INT_MAX;
  for(i=0;i<n2;i++) R[i]=A[mid+i];
  R[n2]=INT_MAX;
  int l=0,r=0;
  for(i=left;i<right;i++){
    if(L[l]<=R[r]){
      A[i]=L[l];
      l++;
    }
    else{
      A[i]=R[r];
      r++;
    }
  }
}
   
   
void m_sort(int left,int right){
  int mid;
  if( left+1 >= right) return;
  mid=(left+right)/2;
  m_sort(left,mid);
  m_sort(mid,right);
  merge(left,mid,right);
}
   
   
void swap(int a,int b,int *C){
  int swap;
  swap=C[a];
  C[a]=C[b];
  C[b]=swap;
}
   
   
   
   
   
   
     
    
     
   
int main(){
  scanf("%d",&n);
  int i,j;
  int cnt,sum,min,start,x;
  int C[1001]={};
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
    B[i]=A[i];
  }
  m_sort(0,n);
  for(i=0;i<n;i++){
    if(A[i]==B[i]) C[i]=1;
  }
  cost=0;
  for(i=0;i<n;i++){
    if(C[i]!=1){
      C[i]=1;
      cnt=0;
      sum=0;
      min=B[i];
      x=i;
      while(1){
        for(j=0;j<n;j++){
          if(B[x]==A[j]){
            C[j]=1;
            cnt++;
            sum+=B[j];
            if(min > B[j]) min=B[j];
            x=j;
            break;
          }
        }
        if(x==i) break;
      }
      sum-=min;
      if( (cnt -1)*min > (cnt -1)*A[0]+2*(min +A[0])) cost+=sum+(cnt-1)*A[0]+2*(min +A[0]);
      else cost+=sum+(cnt-1)*min;
    }
  }
  printf("%d\n",cost);
  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	cost
	.align 4
	.type	cost, @object
	.size	cost, 4
cost:
	.zero	4
	.globl	A
	.align 32
	.type	A, @object
	.size	A, 4004
A:
	.zero	4004
	.globl	B
	.align 32
	.type	B, @object
	.size	B, 4004
B:
	.zero	4004
	.globl	L
	.align 32
	.type	L, @object
	.size	L, 2004
L:
	.zero	2004
	.globl	R
	.align 32
	.type	R, @object
	.size	R, 2008
R:
	.zero	2008
	.text
	.globl	merge
	.type	merge, @function
merge:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -36(%rbp)
	movl	%esi, -40(%rbp)
	movl	%edx, -44(%rbp)
	movl	-40(%rbp), %eax
	subl	-36(%rbp), %eax
	movl	%eax, -8(%rbp)
	movl	-44(%rbp), %eax
	subl	-40(%rbp), %eax
	movl	%eax, -4(%rbp)
	movl	$0, -20(%rbp)
	jmp	.L2
.L3:
	movl	-36(%rbp), %edx
	movl	-20(%rbp), %eax
	addl	%edx, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	-20(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	L(%rip), %rdx
	movl	%eax, (%rcx,%rdx)
	addl	$1, -20(%rbp)
.L2:
	movl	-20(%rbp), %eax
	cmpl	-8(%rbp), %eax
	jl	.L3
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	L(%rip), %rax
	movl	$2147483647, (%rdx,%rax)
	movl	$0, -20(%rbp)
	jmp	.L4
.L5:
	movl	-40(%rbp), %edx
	movl	-20(%rbp), %eax
	addl	%edx, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	-20(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	R(%rip), %rdx
	movl	%eax, (%rcx,%rdx)
	addl	$1, -20(%rbp)
.L4:
	movl	-20(%rbp), %eax
	cmpl	-4(%rbp), %eax
	jl	.L5
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	R(%rip), %rax
	movl	$2147483647, (%rdx,%rax)
	movl	$0, -16(%rbp)
	movl	$0, -12(%rbp)
	movl	-36(%rbp), %eax
	movl	%eax, -20(%rbp)
	jmp	.L6
.L9:
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	L(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	R(%rip), %rax
	movl	(%rcx,%rax), %eax
	cmpl	%eax, %edx
	jg	.L7
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	L(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	-20(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	A(%rip), %rdx
	movl	%eax, (%rcx,%rdx)
	addl	$1, -16(%rbp)
	jmp	.L8
.L7:
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	R(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	-20(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	A(%rip), %rdx
	movl	%eax, (%rcx,%rdx)
	addl	$1, -12(%rbp)
.L8:
	addl	$1, -20(%rbp)
.L6:
	movl	-20(%rbp), %eax
	cmpl	-44(%rbp), %eax
	jl	.L9
	nop
	nop
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	merge, .-merge
	.globl	m_sort
	.type	m_sort, @function
m_sort:
.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
	movl	%edi, -20(%rbp)
	movl	%esi, -24(%rbp)
	movl	-20(%rbp), %eax
	addl	$1, %eax
	cmpl	%eax, -24(%rbp)
	jle	.L13
	movl	-20(%rbp), %edx
	movl	-24(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	movl	%eax, -4(%rbp)
	movl	-4(%rbp), %edx
	movl	-20(%rbp), %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	m_sort
	movl	-24(%rbp), %edx
	movl	-4(%rbp), %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	m_sort
	movl	-24(%rbp), %edx
	movl	-4(%rbp), %ecx
	movl	-20(%rbp), %eax
	movl	%ecx, %esi
	movl	%eax, %edi
	call	merge
	jmp	.L10
.L13:
	nop
.L10:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	m_sort, .-m_sort
	.globl	swap
	.type	swap, @function
swap:
.LFB8:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -20(%rbp)
	movl	%esi, -24(%rbp)
	movq	%rdx, -32(%rbp)
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-32(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, -4(%rbp)
	movl	-24(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-32(%rbp), %rax
	addq	%rdx, %rax
	movl	-20(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	movq	-32(%rbp), %rdx
	addq	%rcx, %rdx
	movl	(%rax), %eax
	movl	%eax, (%rdx)
	movl	-24(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-32(%rbp), %rax
	addq	%rax, %rdx
	movl	-4(%rbp), %eax
	movl	%eax, (%rdx)
	nop
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.size	swap, .-swap
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.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	$4048, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	n(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	leaq	-4016(%rbp), %rdx
	movl	$0, %eax
	movl	$500, %ecx
	movq	%rdx, %rdi
	rep stosq
	movq	%rdi, %rdx
	movl	%eax, (%rdx)
	addq	$4, %rdx
	movl	$0, -4040(%rbp)
	jmp	.L16
.L17:
	movl	-4040(%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	-4040(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	-4040(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	B(%rip), %rdx
	movl	%eax, (%rcx,%rdx)
	addl	$1, -4040(%rbp)
.L16:
	movl	n(%rip), %eax
	cmpl	%eax, -4040(%rbp)
	jl	.L17
	movl	n(%rip), %eax
	movl	%eax, %esi
	movl	$0, %edi
	call	m_sort
	movl	$0, -4040(%rbp)
	jmp	.L18
.L20:
	movl	-4040(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-4040(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	B(%rip), %rax
	movl	(%rcx,%rax), %eax
	cmpl	%eax, %edx
	jne	.L19
	movl	-4040(%rbp), %eax
	cltq
	movl	$1, -4016(%rbp,%rax,4)
.L19:
	addl	$1, -4040(%rbp)
.L18:
	movl	n(%rip), %eax
	cmpl	%eax, -4040(%rbp)
	jl	.L20
	movl	$0, cost(%rip)
	movl	$0, -4040(%rbp)
	jmp	.L21
.L32:
	movl	-4040(%rbp), %eax
	cltq
	movl	-4016(%rbp,%rax,4), %eax
	cmpl	$1, %eax
	je	.L22
	movl	-4040(%rbp), %eax
	cltq
	movl	$1, -4016(%rbp,%rax,4)
	movl	$0, -4032(%rbp)
	movl	$0, -4028(%rbp)
	movl	-4040(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	B(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, -4024(%rbp)
	movl	-4040(%rbp), %eax
	movl	%eax, -4020(%rbp)
.L30:
	movl	$0, -4036(%rbp)
	jmp	.L23
.L27:
	movl	-4020(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	B(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-4036(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	A(%rip), %rax
	movl	(%rcx,%rax), %eax
	cmpl	%eax, %edx
	jne	.L24
	movl	-4036(%rbp), %eax
	cltq
	movl	$1, -4016(%rbp,%rax,4)
	addl	$1, -4032(%rbp)
	movl	-4036(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	B(%rip), %rax
	movl	(%rdx,%rax), %eax
	addl	%eax, -4028(%rbp)
	movl	-4036(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	B(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	%eax, -4024(%rbp)
	jle	.L25
	movl	-4036(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	B(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, -4024(%rbp)
.L25:
	movl	-4036(%rbp), %eax
	movl	%eax, -4020(%rbp)
	jmp	.L26
.L24:
	addl	$1, -4036(%rbp)
.L23:
	movl	n(%rip), %eax
	cmpl	%eax, -4036(%rbp)
	jl	.L27
.L26:
	movl	-4020(%rbp), %eax
	cmpl	-4040(%rbp), %eax
	je	.L36
	jmp	.L30
.L36:
	nop
	movl	-4024(%rbp), %eax
	subl	%eax, -4028(%rbp)
	movl	-4032(%rbp), %eax
	subl	$1, %eax
	imull	-4024(%rbp), %eax
	movl	-4032(%rbp), %edx
	leal	-1(%rdx), %ecx
	movl	A(%rip), %edx
	imull	%edx, %ecx
	movl	A(%rip), %esi
	movl	-4024(%rbp), %edx
	addl	%esi, %edx
	addl	%edx, %edx
	addl	%ecx, %edx
	cmpl	%edx, %eax
	jle	.L31
	movl	-4032(%rbp), %eax
	leal	-1(%rax), %edx
	movl	A(%rip), %eax
	imull	%eax, %edx
	movl	-4028(%rbp), %eax
	leal	(%rdx,%rax), %ecx
	movl	A(%rip), %edx
	movl	-4024(%rbp), %eax
	addl	%edx, %eax
	addl	%eax, %eax
	leal	(%rcx,%rax), %edx
	movl	cost(%rip), %eax
	addl	%edx, %eax
	movl	%eax, cost(%rip)
	jmp	.L22
.L31:
	movl	-4032(%rbp), %eax
	subl	$1, %eax
	imull	-4024(%rbp), %eax
	movl	%eax, %edx
	movl	-4028(%rbp), %eax
	addl	%eax, %edx
	movl	cost(%rip), %eax
	addl	%edx, %eax
	movl	%eax, cost(%rip)
.L22:
	addl	$1, -4040(%rbp)
.L21:
	movl	n(%rip), %eax
	cmpl	%eax, -4040(%rbp)
	jl	.L32
	movl	cost(%rip), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L34
	call	__stack_chk_fail@PLT
.L34:
	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	n
	.bss
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.globl	cost
	.align 4
	.type	cost, @object
	.size	cost, 4
cost:
	.zero	4
	.globl	A
	.align 32
	.type	A, @object
	.size	A, 4004
A:
	.zero	4004
	.globl	B
	.align 32
	.type	B, @object
	.size	B, 4004
B:
	.zero	4004
	.globl	L
	.align 32
	.type	L, @object
	.size	L, 2004
L:
	.zero	2004
	.globl	R
	.align 32
	.type	R, @object
	.size	R, 2008
R:
	.zero	2008
	.text
	.globl	merge
	.type	merge, @function
merge:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -36(%rbp)
	movl	%esi, -40(%rbp)
	movl	%edx, -44(%rbp)
	movl	-40(%rbp), %eax
	subl	-36(%rbp), %eax
	movl	%eax, -8(%rbp)
	movl	-44(%rbp), %eax
	subl	-40(%rbp), %eax
	movl	%eax, -4(%rbp)
	movl	$0, -20(%rbp)
	jmp	.L2
.L3:
	movl	-36(%rbp), %edx
	movl	-20(%rbp), %eax
	addl	%edx, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	-20(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	L(%rip), %rdx
	movl	%eax, (%rcx,%rdx)
	addl	$1, -20(%rbp)
.L2:
	movl	-20(%rbp), %eax
	cmpl	-8(%rbp), %eax
	jl	.L3
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	L(%rip), %rax
	movl	$2147483647, (%rdx,%rax)
	movl	$0, -20(%rbp)
	jmp	.L4
.L5:
	movl	-40(%rbp), %edx
	movl	-20(%rbp), %eax
	addl	%edx, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	-20(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	R(%rip), %rdx
	movl	%eax, (%rcx,%rdx)
	addl	$1, -20(%rbp)
.L4:
	movl	-20(%rbp), %eax
	cmpl	-4(%rbp), %eax
	jl	.L5
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	R(%rip), %rax
	movl	$2147483647, (%rdx,%rax)
	movl	$0, -16(%rbp)
	movl	$0, -12(%rbp)
	movl	-36(%rbp), %eax
	movl	%eax, -20(%rbp)
	jmp	.L6
.L9:
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	L(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	R(%rip), %rax
	movl	(%rcx,%rax), %eax
	cmpl	%eax, %edx
	jg	.L7
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	L(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	-20(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	A(%rip), %rdx
	movl	%eax, (%rcx,%rdx)
	addl	$1, -16(%rbp)
	jmp	.L8
.L7:
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	R(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	-20(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	A(%rip), %rdx
	movl	%eax, (%rcx,%rdx)
	addl	$1, -12(%rbp)
.L8:
	addl	$1, -20(%rbp)
.L6:
	movl	-20(%rbp), %eax
	cmpl	-44(%rbp), %eax
	jl	.L9
	nop
	nop
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	merge, .-merge
	.globl	m_sort
	.type	m_sort, @function
m_sort:
.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
	movl	%edi, -20(%rbp)
	movl	%esi, -24(%rbp)
	movl	-20(%rbp), %eax
	addl	$1, %eax
	cmpl	%eax, -24(%rbp)
	jle	.L13
	movl	-20(%rbp), %edx
	movl	-24(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%edx, %eax
	sarl	%eax
	movl	%eax, -4(%rbp)
	movl	-4(%rbp), %edx
	movl	-20(%rbp), %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	m_sort
	movl	-24(%rbp), %edx
	movl	-4(%rbp), %eax
	movl	%edx, %esi
	movl	%eax, %edi
	call	m_sort
	movl	-24(%rbp), %edx
	movl	-4(%rbp), %ecx
	movl	-20(%rbp), %eax
	movl	%ecx, %esi
	movl	%eax, %edi
	call	merge
	jmp	.L10
.L13:
	nop
.L10:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	m_sort, .-m_sort
	.globl	swap
	.type	swap, @function
swap:
.LFB8:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	%edi, -20(%rbp)
	movl	%esi, -24(%rbp)
	movq	%rdx, -32(%rbp)
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-32(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, -4(%rbp)
	movl	-24(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-32(%rbp), %rax
	addq	%rdx, %rax
	movl	-20(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	movq	-32(%rbp), %rdx
	addq	%rcx, %rdx
	movl	(%rax), %eax
	movl	%eax, (%rdx)
	movl	-24(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-32(%rbp), %rax
	addq	%rax, %rdx
	movl	-4(%rbp), %eax
	movl	%eax, (%rdx)
	nop
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.size	swap, .-swap
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.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	$4048, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	n(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	leaq	-4016(%rbp), %rdx
	movl	$0, %eax
	movl	$500, %ecx
	movq	%rdx, %rdi
	rep stosq
	movq	%rdi, %rdx
	movl	%eax, (%rdx)
	addq	$4, %rdx
	movl	$0, -4040(%rbp)
	jmp	.L16
.L17:
	movl	-4040(%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	-4040(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	-4040(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	B(%rip), %rdx
	movl	%eax, (%rcx,%rdx)
	addl	$1, -4040(%rbp)
.L16:
	movl	n(%rip), %eax
	cmpl	%eax, -4040(%rbp)
	jl	.L17
	movl	n(%rip), %eax
	movl	%eax, %esi
	movl	$0, %edi
	call	m_sort
	movl	$0, -4040(%rbp)
	jmp	.L18
.L20:
	movl	-4040(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	A(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-4040(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	B(%rip), %rax
	movl	(%rcx,%rax), %eax
	cmpl	%eax, %edx
	jne	.L19
	movl	-4040(%rbp), %eax
	cltq
	movl	$1, -4016(%rbp,%rax,4)
.L19:
	addl	$1, -4040(%rbp)
.L18:
	movl	n(%rip), %eax
	cmpl	%eax, -4040(%rbp)
	jl	.L20
	movl	$0, cost(%rip)
	movl	$0, -4040(%rbp)
	jmp	.L21
.L32:
	movl	-4040(%rbp), %eax
	cltq
	movl	-4016(%rbp,%rax,4), %eax
	cmpl	$1, %eax
	je	.L22
	movl	-4040(%rbp), %eax
	cltq
	movl	$1, -4016(%rbp,%rax,4)
	movl	$0, -4032(%rbp)
	movl	$0, -4028(%rbp)
	movl	-4040(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	B(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, -4024(%rbp)
	movl	-4040(%rbp), %eax
	movl	%eax, -4020(%rbp)
.L30:
	movl	$0, -4036(%rbp)
	jmp	.L23
.L27:
	movl	-4020(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	B(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-4036(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	A(%rip), %rax
	movl	(%rcx,%rax), %eax
	cmpl	%eax, %edx
	jne	.L24
	movl	-4036(%rbp), %eax
	cltq
	movl	$1, -4016(%rbp,%rax,4)
	addl	$1, -4032(%rbp)
	movl	-4036(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	B(%rip), %rax
	movl	(%rdx,%rax), %eax
	addl	%eax, -4028(%rbp)
	movl	-4036(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	B(%rip), %rax
	movl	(%rdx,%rax), %eax
	cmpl	%eax, -4024(%rbp)
	jle	.L25
	movl	-4036(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	B(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	%eax, -4024(%rbp)
.L25:
	movl	-4036(%rbp), %eax
	movl	%eax, -4020(%rbp)
	jmp	.L26
.L24:
	addl	$1, -4036(%rbp)
.L23:
	movl	n(%rip), %eax
	cmpl	%eax, -4036(%rbp)
	jl	.L27
.L26:
	movl	-4020(%rbp), %eax
	cmpl	-4040(%rbp), %eax
	je	.L36
	jmp	.L30
.L36:
	nop
	movl	-4024(%rbp), %eax
	subl	%eax, -4028(%rbp)
	movl	-4032(%rbp), %eax
	subl	$1, %eax
	imull	-4024(%rbp), %eax
	movl	-4032(%rbp), %edx
	leal	-1(%rdx), %ecx
	movl	A(%rip), %edx
	imull	%edx, %ecx
	movl	A(%rip), %esi
	movl	-4024(%rbp), %edx
	addl	%esi, %edx
	addl	%edx, %edx
	addl	%ecx, %edx
	cmpl	%edx, %eax
	jle	.L31
	movl	-4032(%rbp), %eax
	leal	-1(%rax), %edx
	movl	A(%rip), %eax
	imull	%eax, %edx
	movl	-4028(%rbp), %eax
	leal	(%rdx,%rax), %ecx
	movl	A(%rip), %edx
	movl	-4024(%rbp), %eax
	addl	%edx, %eax
	addl	%eax, %eax
	leal	(%rcx,%rax), %edx
	movl	cost(%rip), %eax
	addl	%edx, %eax
	movl	%eax, cost(%rip)
	jmp	.L22
.L31:
	movl	-4032(%rbp), %eax
	subl	$1, %eax
	imull	-4024(%rbp), %eax
	movl	%eax, %edx
	movl	-4028(%rbp), %eax
	addl	%eax, %edx
	movl	cost(%rip), %eax
	addl	%edx, %eax
	movl	%eax, cost(%rip)
.L22:
	addl	$1, -4040(%rbp)
.L21:
	movl	n(%rip), %eax
	cmpl	%eax, -4040(%rbp)
	jl	.L32
	movl	cost(%rip), %eax
	movl	%eax, %esi
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L34
	call	__stack_chk_fail@PLT
.L34:
	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:
