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>

#define D_MAX 1000000000
#define N_MAX 100000
#define M_MAX 10000
#define min(x,y) (((x)<(y))?(x):(y))

int d;
int n;
int m;

int ad[N_MAX+1];
int ak[M_MAX+1];
int awork[N_MAX+1];

void MergeSort(int array[],int left,int right){
  int mid;
  int i;
  int j;
  int x;
  int y;
  
  if( left >= right ){
    return;
  }
  
  mid = (left + right) / 2;
  MergeSort( array, left, mid);
  MergeSort( array, mid+1, right);
  
  for( i=left; i<=mid; i++){
    awork[i] = array[i];
  }
  
  j = right;
  for( i=mid+1; i<=right; i++){
    awork[i] = array[j];
    j--;
  }
  
  x = left;
  y = right;
  
  for( i=left; i<=right; i++){
    if(awork[x] <= awork[y]){
      array[i] = awork[x];
      x++;
    }else{
      array[i] = awork[y];
      y--;
    }
  }
}


int calcDist(void){
  int i;
  int j = 1;
  int sum = 0;
  int diff;
  int preDiff = 0;
  int minDist = d;
  int tmpDist;
  int halfDist = d >> 1;
  
  for( i=1; i<=m; i++){
    
    while(ad[j] < ak[i]){
      j++;
    }
    minDist = min( abs(ad[j-1]-ak[i]),abs(ad[j]-ak[i]) );
    sum += minDist;
    
  }
  
  return sum;
}


void input(void){
  int i;
  scanf("%d",&d);
  if( d != 0){
    scanf("%d",&n);
    scanf("%d",&m);
    ad[0] = 0;
    for( i=1; i<=n-1; i++){
      scanf("%d",&ad[i]);
    }
    ad[n] = d;
    for( i=1; i<=m; i++){
      scanf("%d",&ak[i]);
    }
  }
}

int main(void){
  int i;
  int sumDist = 0;
  while( 1 ){
    input();
    if( d == 0 ){
      break;
    }
    MergeSort( ad, 0, n);
    MergeSort( ak, 1, m);
    sumDist = calcDist();
    printf("%d\n",sumDist);
    sumDist = 0;
  }
}


```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	d
	.bss
	.align 4
	.type	d, @object
	.size	d, 4
d:
	.zero	4
	.globl	n
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.globl	m
	.align 4
	.type	m, @object
	.size	m, 4
m:
	.zero	4
	.globl	ad
	.align 32
	.type	ad, @object
	.size	ad, 400004
ad:
	.zero	400004
	.globl	ak
	.align 32
	.type	ak, @object
	.size	ak, 40004
ak:
	.zero	40004
	.globl	awork
	.align 32
	.type	awork, @object
	.size	awork, 400004
awork:
	.zero	400004
	.text
	.globl	MergeSort
	.type	MergeSort, @function
MergeSort:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$48, %rsp
	movq	%rdi, -40(%rbp)
	movl	%esi, -44(%rbp)
	movl	%edx, -48(%rbp)
	movl	-44(%rbp), %eax
	cmpl	-48(%rbp), %eax
	jge	.L12
	movl	-44(%rbp), %edx
	movl	-48(%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	-44(%rbp), %ecx
	movq	-40(%rbp), %rax
	movl	%ecx, %esi
	movq	%rax, %rdi
	call	MergeSort
	movl	-4(%rbp), %eax
	leal	1(%rax), %ecx
	movl	-48(%rbp), %edx
	movq	-40(%rbp), %rax
	movl	%ecx, %esi
	movq	%rax, %rdi
	call	MergeSort
	movl	-44(%rbp), %eax
	movl	%eax, -20(%rbp)
	jmp	.L4
.L5:
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-40(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	-20(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	awork(%rip), %rdx
	movl	%eax, (%rcx,%rdx)
	addl	$1, -20(%rbp)
.L4:
	movl	-20(%rbp), %eax
	cmpl	-4(%rbp), %eax
	jle	.L5
	movl	-48(%rbp), %eax
	movl	%eax, -16(%rbp)
	movl	-4(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -20(%rbp)
	jmp	.L6
.L7:
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-40(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	-20(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	awork(%rip), %rdx
	movl	%eax, (%rcx,%rdx)
	subl	$1, -16(%rbp)
	addl	$1, -20(%rbp)
.L6:
	movl	-20(%rbp), %eax
	cmpl	-48(%rbp), %eax
	jle	.L7
	movl	-44(%rbp), %eax
	movl	%eax, -12(%rbp)
	movl	-48(%rbp), %eax
	movl	%eax, -8(%rbp)
	movl	-44(%rbp), %eax
	movl	%eax, -20(%rbp)
	jmp	.L8
.L11:
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	awork(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	awork(%rip), %rax
	movl	(%rcx,%rax), %eax
	cmpl	%eax, %edx
	jg	.L9
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-40(%rbp), %rax
	addq	%rax, %rdx
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	awork(%rip), %rax
	movl	(%rcx,%rax), %eax
	movl	%eax, (%rdx)
	addl	$1, -12(%rbp)
	jmp	.L10
.L9:
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-40(%rbp), %rax
	addq	%rax, %rdx
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	awork(%rip), %rax
	movl	(%rcx,%rax), %eax
	movl	%eax, (%rdx)
	subl	$1, -8(%rbp)
.L10:
	addl	$1, -20(%rbp)
.L8:
	movl	-20(%rbp), %eax
	cmpl	-48(%rbp), %eax
	jle	.L11
	jmp	.L1
.L12:
	nop
.L1:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	MergeSort, .-MergeSort
	.globl	calcDist
	.type	calcDist, @function
calcDist:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	$1, -20(%rbp)
	movl	$0, -16(%rbp)
	movl	$0, -12(%rbp)
	movl	d(%rip), %eax
	movl	%eax, -8(%rbp)
	movl	d(%rip), %eax
	sarl	%eax
	movl	%eax, -4(%rbp)
	movl	$1, -24(%rbp)
	jmp	.L14
.L16:
	addl	$1, -20(%rbp)
.L15:
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	ad(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-24(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	ak(%rip), %rax
	movl	(%rcx,%rax), %eax
	cmpl	%eax, %edx
	jl	.L16
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	ad(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	-24(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	ak(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	subl	%edx, %eax
	movl	%eax, %edx
	negl	%edx
	cmovs	%eax, %edx
	movl	-20(%rbp), %eax
	subl	$1, %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	ad(%rip), %rax
	movl	(%rcx,%rax), %eax
	movl	-24(%rbp), %ecx
	movslq	%ecx, %rcx
	leaq	0(,%rcx,4), %rsi
	leaq	ak(%rip), %rcx
	movl	(%rsi,%rcx), %ecx
	subl	%ecx, %eax
	movl	%eax, %ecx
	negl	%ecx
	cmovns	%ecx, %eax
	cmpl	%eax, %edx
	cmovle	%edx, %eax
	movl	%eax, -8(%rbp)
	movl	-8(%rbp), %eax
	addl	%eax, -16(%rbp)
	addl	$1, -24(%rbp)
.L14:
	movl	m(%rip), %eax
	cmpl	%eax, -24(%rbp)
	jle	.L15
	movl	-16(%rbp), %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	calcDist, .-calcDist
	.section	.rodata
.LC0:
	.string	"%d"
	.text
	.globl	input
	.type	input, @function
input:
.LFB8:
	.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	d(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	d(%rip), %eax
	testl	%eax, %eax
	je	.L25
	leaq	n(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	leaq	m(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, ad(%rip)
	movl	$1, -4(%rbp)
	jmp	.L21
.L22:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	ad(%rip), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -4(%rbp)
.L21:
	movl	n(%rip), %eax
	cmpl	%eax, -4(%rbp)
	jl	.L22
	movl	n(%rip), %edx
	movl	d(%rip), %eax
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	ad(%rip), %rdx
	movl	%eax, (%rcx,%rdx)
	movl	$1, -4(%rbp)
	jmp	.L23
.L24:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	ak(%rip), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -4(%rbp)
.L23:
	movl	m(%rip), %eax
	cmpl	%eax, -4(%rbp)
	jle	.L24
.L25:
	nop
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.size	input, .-input
	.section	.rodata
.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	$16, %rsp
	movl	$0, -4(%rbp)
.L29:
	call	input
	movl	d(%rip), %eax
	testl	%eax, %eax
	je	.L32
	movl	n(%rip), %eax
	movl	%eax, %edx
	movl	$0, %esi
	leaq	ad(%rip), %rax
	movq	%rax, %rdi
	call	MergeSort
	movl	m(%rip), %eax
	movl	%eax, %edx
	movl	$1, %esi
	leaq	ak(%rip), %rax
	movq	%rax, %rdi
	call	MergeSort
	call	calcDist
	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, -4(%rbp)
	jmp	.L29
.L32:
	nop
	movl	$0, %eax
	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
	.type	MergeSort.part.0, @function
MergeSort.part.0:
.LFB43:
	.cfi_startproc
	leal	(%rsi,%rdx), %eax
	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
	movq	%rdi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movl	%eax, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	shrl	$31, %r12d
	movl	%esi, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	addl	%eax, %r12d
	movl	%edx, %ebx
	sarl	%r12d
	leal	1(%r12), %r14d
	subq	$8, %rsp
	.cfi_def_cfa_offset 64
	cmpl	%r12d, %esi
	jl	.L47
	cmpl	%r14d, %edx
	jg	.L48
	cmpl	%r12d, %esi
	jne	.L16
.L3:
	movslq	%ebp, %rax
	leaq	awork(%rip), %rdx
	movl	%r12d, %edi
	leaq	0(,%rax,4), %rcx
	subl	%ebp, %edi
	leaq	(%rdx,%rcx), %r8
	leaq	4(%r13,%rcx), %r9
	movq	%r8, %rsi
	subq	%r9, %rsi
	cmpq	$8, %rsi
	jbe	.L35
	cmpl	%r12d, %ebp
	setle	%r9b
	cmpl	$2, %edi
	seta	%sil
	testb	%sil, %r9b
	je	.L35
	addl	$1, %edi
	movl	$1, %eax
	cmpl	%r12d, %ebp
	cmovg	%eax, %edi
	addq	%r13, %rcx
	xorl	%eax, %eax
	movl	%edi, %esi
	shrl	$2, %esi
	salq	$4, %rsi
	.p2align 4,,10
	.p2align 3
.L14:
	movdqu	(%rcx,%rax), %xmm1
	movups	%xmm1, (%r8,%rax)
	addq	$16, %rax
	cmpq	%rsi, %rax
	jne	.L14
	movl	%edi, %ecx
	andl	$-4, %ecx
	leal	(%rcx,%rbp), %eax
	cmpl	%ecx, %edi
	je	.L16
	movslq	%eax, %rcx
	movl	0(%r13,%rcx,4), %esi
	movl	%esi, (%rdx,%rcx,4)
	leal	1(%rax), %ecx
	cmpl	%ecx, %r12d
	jl	.L16
	movslq	%ecx, %rcx
	addl	$2, %eax
	movl	0(%r13,%rcx,4), %esi
	leaq	0(,%rcx,4), %rdi
	movl	%esi, (%rdx,%rcx,4)
	cmpl	%eax, %r12d
	jl	.L16
	movl	4(%r13,%rdi), %ecx
	cltq
	movl	%ecx, (%rdx,%rax,4)
.L16:
	cmpl	%r14d, %ebx
	jl	.L12
.L6:
	movl	%ebx, %r10d
	movslq	%ebx, %rcx
	movl	$4, %eax
	movslq	%r14d, %rsi
	subl	%r12d, %r10d
	leaq	4(,%rcx,4), %r11
	leaq	0(,%rcx,4), %rdi
	movq	%rax, %rcx
	movl	%r10d, %r9d
	leaq	0(,%rsi,4), %r15
	leaq	awork(%rip), %rdx
	salq	$2, %r9
	cmpl	%r12d, %ebx
	leaq	(%rdx,%r15), %r8
	cmovg	%r9, %rcx
	subq	%r9, %rax
	xorl	%r9d, %r9d
	addq	%r15, %rcx
	addq	%rdx, %rcx
	cmpl	%r12d, %ebx
	cmovle	%r9, %rax
	addq	%rdi, %rax
	addq	%r13, %rax
	cmpq	%rax, %rcx
	leaq	0(%r13,%r11), %rcx
	setbe	%al
	cmpq	%rcx, %r8
	setnb	%cl
	orb	%cl, %al
	je	.L11
	leal	-1(%r10), %eax
	cmpl	$2, %eax
	seta	%cl
	cmpl	%r12d, %ebx
	setg	%al
	testb	%al, %cl
	je	.L11
	cmpl	%r12d, %ebx
	movl	$1, %r9d
	leaq	-16(%r13,%r11), %rsi
	movq	%r8, %rcx
	cmovg	%r10d, %r9d
	leaq	-16(%rsi), %rax
	movl	%r9d, %edi
	shrl	$2, %edi
	leal	-1(%rdi), %r8d
	movq	%rax, %rdi
	salq	$4, %r8
	subq	%r8, %rdi
	jmp	.L24
	.p2align 4,,10
	.p2align 3
.L49:
	subq	$16, %rax
.L24:
	movdqu	(%rsi), %xmm0
	addq	$16, %rcx
	movq	%rax, %rsi
	pshufd	$27, %xmm0, %xmm0
	movups	%xmm0, -16(%rcx)
	cmpq	%rax, %rdi
	jne	.L49
	movl	%r9d, %ecx
	movl	%ebx, %eax
	andl	$-4, %ecx
	subl	%ecx, %eax
	addl	%ecx, %r14d
	cmpl	%ecx, %r9d
	je	.L12
	movslq	%eax, %rcx
	subl	$1, %eax
	movl	0(%r13,%rcx,4), %esi
	movslq	%r14d, %rcx
	movl	%esi, (%rdx,%rcx,4)
	leal	1(%r14), %ecx
	cmpl	%ecx, %ebx
	jl	.L12
	cltq
	movslq	%ecx, %rcx
	addl	$2, %r14d
	leaq	0(,%rax,4), %rsi
	movl	0(%r13,%rax,4), %eax
	movl	%eax, (%rdx,%rcx,4)
	cmpl	%r14d, %ebx
	jl	.L12
	movl	-4(%r13,%rsi), %eax
	movslq	%r14d, %r14
	movl	%eax, (%rdx,%r14,4)
.L12:
	cmpl	%ebx, %ebp
	jg	.L1
	movl	%ebx, %edx
	movslq	%ebp, %r8
	movslq	%ebx, %rcx
	subl	%ebp, %edx
	leaq	0(%r13,%r8,4), %rax
	addq	%r8, %rdx
	leaq	4(%r13,%rdx,4), %r9
	leaq	awork(%rip), %rdx
	.p2align 4,,10
	.p2align 3
.L28:
	movl	(%rdx,%r8,4), %edi
	movl	(%rdx,%rcx,4), %esi
	cmpl	%edi, %esi
	jl	.L26
.L50:
	movl	%edi, (%rax)
	addq	$4, %rax
	addl	$1, %ebp
	cmpq	%rax, %r9
	je	.L1
	movslq	%ebp, %r8
	movl	(%rdx,%rcx,4), %esi
	movl	(%rdx,%r8,4), %edi
	cmpl	%edi, %esi
	jge	.L50
.L26:
	movl	%esi, (%rax)
	addq	$4, %rax
	subl	$1, %ebx
	cmpq	%rax, %r9
	je	.L1
	movslq	%ebx, %rcx
	jmp	.L28
	.p2align 4,,10
	.p2align 3
.L35:
	movl	0(%r13,%rax,4), %ecx
	movl	%ecx, (%rdx,%rax,4)
	addq	$1, %rax
	cmpl	%eax, %r12d
	jge	.L35
	jmp	.L16
	.p2align 4,,10
	.p2align 3
.L48:
	movl	%ebx, %edx
	movl	%r14d, %esi
	movq	%r13, %rdi
	call	MergeSort.part.0
	cmpl	%r12d, %ebp
	jle	.L3
	jmp	.L6
	.p2align 4,,10
	.p2align 3
.L1:
	addq	$8, %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
	.p2align 4,,10
	.p2align 3
.L47:
	.cfi_restore_state
	movl	%r12d, %edx
	call	MergeSort.part.0
	cmpl	%r14d, %ebx
	jle	.L3
	movl	%ebx, %edx
	movl	%r14d, %esi
	movq	%r13, %rdi
	call	MergeSort.part.0
	jmp	.L3
	.p2align 4,,10
	.p2align 3
.L11:
	leaq	0(%r13,%rdi), %rcx
	.p2align 4,,10
	.p2align 3
.L22:
	movl	(%rcx), %eax
	subq	$4, %rcx
	movl	%eax, (%rdx,%rsi,4)
	addq	$1, %rsi
	cmpl	%esi, %ebx
	jge	.L22
	jmp	.L12
	.cfi_endproc
.LFE43:
	.size	MergeSort.part.0, .-MergeSort.part.0
	.p2align 4
	.globl	MergeSort
	.type	MergeSort, @function
MergeSort:
.LFB39:
	.cfi_startproc
	endbr64
	cmpl	%edx, %esi
	jl	.L53
	ret
	.p2align 4,,10
	.p2align 3
.L53:
	jmp	MergeSort.part.0
	.cfi_endproc
.LFE39:
	.size	MergeSort, .-MergeSort
	.p2align 4
	.globl	calcDist
	.type	calcDist, @function
calcDist:
.LFB40:
	.cfi_startproc
	endbr64
	movl	m(%rip), %eax
	testl	%eax, %eax
	jle	.L60
	leaq	4+ak(%rip), %r9
	leal	-1(%rax), %ecx
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	xorl	%r10d, %r10d
	leaq	4(%r9), %rax
	movl	4+ad(%rip), %edx
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movl	$1, %edi
	leaq	-4+ad(%rip), %r8
	leaq	(%rax,%rcx,4), %r11
	leaq	4(%r8), %rbx
	.p2align 4,,10
	.p2align 3
.L56:
	movl	(%r9), %esi
	leal	1(%rdi), %eax
	cltq
	cmpl	%edx, %esi
	jle	.L67
	.p2align 4,,10
	.p2align 3
.L57:
	movl	%eax, %edi
	addq	$1, %rax
	movl	%edx, %ecx
	movl	(%r8,%rax,4), %edx
	cmpl	%esi, %edx
	jl	.L57
.L59:
	movl	%edx, %ebp
	subl	%esi, %ebp
	movl	%ebp, %eax
	negl	%eax
	cmovs	%ebp, %eax
	subl	%esi, %ecx
	movl	%ecx, %esi
	negl	%esi
	cmovns	%esi, %ecx
	cmpl	%ecx, %eax
	cmovg	%ecx, %eax
	addq	$4, %r9
	addl	%eax, %r10d
	cmpq	%r9, %r11
	jne	.L56
	movl	%r10d, %eax
	popq	%rbx
	.cfi_remember_state
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.p2align 4,,10
	.p2align 3
.L67:
	.cfi_restore_state
	leal	-1(%rdi), %eax
	cltq
	movl	(%rbx,%rax,4), %ecx
	jmp	.L59
.L60:
	.cfi_def_cfa_offset 8
	.cfi_restore 3
	.cfi_restore 6
	xorl	%eax, %eax
	ret
	.cfi_endproc
.LFE40:
	.size	calcDist, .-calcDist
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d"
	.text
	.p2align 4
	.globl	input
	.type	input, @function
input:
.LFB41:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	leaq	.LC0(%rip), %r12
	leaq	d(%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	d(%rip), %edx
	testl	%edx, %edx
	jne	.L76
.L68:
	popq	%rbx
	.cfi_remember_state
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.p2align 4,,10
	.p2align 3
.L76:
	.cfi_restore_state
	leaq	n(%rip), %rsi
	movq	%r12, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	leaq	m(%rip), %rsi
	movq	%r12, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movslq	n(%rip), %rax
	movl	$0, ad(%rip)
	cmpl	$1, %eax
	jle	.L70
	leaq	4+ad(%rip), %rbp
	movl	$1, %ebx
	.p2align 4,,10
	.p2align 3
.L71:
	movq	%rbp, %rsi
	movq	%r12, %rdi
	xorl	%eax, %eax
	addl	$1, %ebx
	call	__isoc99_scanf@PLT
	movslq	n(%rip), %rax
	addq	$4, %rbp
	cmpl	%eax, %ebx
	jl	.L71
.L70:
	movl	d(%rip), %ecx
	leaq	ad(%rip), %rdx
	movl	%ecx, (%rdx,%rax,4)
	movl	m(%rip), %eax
	testl	%eax, %eax
	jle	.L68
	leaq	4+ak(%rip), %rbp
	movl	$1, %ebx
	.p2align 4,,10
	.p2align 3
.L72:
	movq	%rbp, %rsi
	xorl	%eax, %eax
	movq	%r12, %rdi
	addl	$1, %ebx
	call	__isoc99_scanf@PLT
	addq	$4, %rbp
	cmpl	m(%rip), %ebx
	jle	.L72
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE41:
	.size	input, .-input
	.section	.rodata.str1.1
.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
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	leaq	ak(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	leaq	d(%rip), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	leaq	ad(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	leaq	.LC0(%rip), %rbx
	subq	$8, %rsp
	.cfi_def_cfa_offset 64
	.p2align 4,,10
	.p2align 3
.L92:
	movq	%r12, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	d(%rip), %ecx
	testl	%ecx, %ecx
	jne	.L104
.L78:
	addq	$8, %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
.L104:
	.cfi_restore_state
	leaq	n(%rip), %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	leaq	m(%rip), %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movslq	n(%rip), %rax
	movl	$0, ad(%rip)
	cmpl	$1, %eax
	jle	.L79
	leaq	4+ad(%rip), %r15
	movl	$1, %r14d
	.p2align 4,,10
	.p2align 3
.L80:
	movq	%r15, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	addl	$1, %r14d
	call	__isoc99_scanf@PLT
	movslq	n(%rip), %rax
	addq	$4, %r15
	cmpl	%eax, %r14d
	jl	.L80
.L79:
	movl	d(%rip), %edx
	leaq	4+ak(%rip), %r15
	movl	$1, %r14d
	movl	%edx, 0(%rbp,%rax,4)
	movl	m(%rip), %edx
	testl	%edx, %edx
	jle	.L84
	.p2align 4,,10
	.p2align 3
.L83:
	movq	%r15, %rsi
	xorl	%eax, %eax
	movq	%rbx, %rdi
	addl	$1, %r14d
	call	__isoc99_scanf@PLT
	addq	$4, %r15
	cmpl	m(%rip), %r14d
	jle	.L83
.L84:
	movl	d(%rip), %eax
	testl	%eax, %eax
	je	.L78
	movl	n(%rip), %edx
	testl	%edx, %edx
	jle	.L85
	xorl	%esi, %esi
	movq	%rbp, %rdi
	call	MergeSort.part.0
.L85:
	movl	m(%rip), %r8d
	cmpl	$1, %r8d
	jle	.L86
	movl	%r8d, %edx
	movl	$1, %esi
	movq	%r13, %rdi
	call	MergeSort.part.0
	movl	m(%rip), %r8d
.L86:
	testl	%r8d, %r8d
	jle	.L93
	leaq	4+ak(%rip), %r9
	leal	-1(%r8), %ecx
	movl	$1, %edi
	xorl	%r10d, %r10d
	leaq	4(%r9), %rax
	movl	4+ad(%rip), %edx
	leaq	-4+ad(%rip), %r8
	leaq	(%rax,%rcx,4), %r11
	.p2align 4,,10
	.p2align 3
.L88:
	movl	(%r9), %esi
	leal	1(%rdi), %eax
	cltq
	cmpl	%edx, %esi
	jle	.L105
	.p2align 4,,10
	.p2align 3
.L89:
	movl	%eax, %edi
	addq	$1, %rax
	movl	%edx, %ecx
	movl	(%r8,%rax,4), %edx
	cmpl	%esi, %edx
	jl	.L89
.L91:
	movl	%edx, %r14d
	subl	%esi, %r14d
	movl	%r14d, %eax
	negl	%eax
	cmovs	%r14d, %eax
	subl	%esi, %ecx
	movl	%ecx, %esi
	negl	%esi
	cmovns	%esi, %ecx
	cmpl	%ecx, %eax
	cmovg	%ecx, %eax
	addq	$4, %r9
	addl	%eax, %r10d
	cmpq	%r9, %r11
	jne	.L88
.L87:
	movl	%r10d, %edx
	leaq	.LC1(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L92
	.p2align 4,,10
	.p2align 3
.L105:
	leal	-1(%rdi), %eax
	cltq
	movl	0(%rbp,%rax,4), %ecx
	jmp	.L91
.L93:
	xorl	%r10d, %r10d
	jmp	.L87
	.cfi_endproc
.LFE42:
	.size	main, .-main
	.globl	awork
	.bss
	.align 32
	.type	awork, @object
	.size	awork, 400004
awork:
	.zero	400004
	.globl	ak
	.align 32
	.type	ak, @object
	.size	ak, 40004
ak:
	.zero	40004
	.globl	ad
	.align 32
	.type	ad, @object
	.size	ad, 400004
ad:
	.zero	400004
	.globl	m
	.align 4
	.type	m, @object
	.size	m, 4
m:
	.zero	4
	.globl	n
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.globl	d
	.align 4
	.type	d, @object
	.size	d, 4
d:
	.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
	.type	MergeSort.part.0, @function
MergeSort.part.0:
.LFB43:
	.cfi_startproc
	leal	(%rsi,%rdx), %eax
	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
	movq	%rdi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movl	%eax, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	shrl	$31, %r12d
	movl	%esi, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	addl	%eax, %r12d
	movl	%edx, %ebx
	sarl	%r12d
	leal	1(%r12), %r14d
	subq	$8, %rsp
	.cfi_def_cfa_offset 64
	cmpl	%r12d, %esi
	jl	.L47
	cmpl	%r14d, %edx
	jg	.L48
	cmpl	%r12d, %esi
	jne	.L16
.L3:
	movslq	%ebp, %rax
	leaq	awork(%rip), %rdx
	movl	%r12d, %edi
	leaq	0(,%rax,4), %rcx
	subl	%ebp, %edi
	leaq	(%rdx,%rcx), %r8
	leaq	4(%r13,%rcx), %r9
	movq	%r8, %rsi
	subq	%r9, %rsi
	cmpq	$8, %rsi
	jbe	.L35
	cmpl	%r12d, %ebp
	setle	%r9b
	cmpl	$2, %edi
	seta	%sil
	testb	%sil, %r9b
	je	.L35
	addl	$1, %edi
	movl	$1, %eax
	cmpl	%r12d, %ebp
	cmovg	%eax, %edi
	addq	%r13, %rcx
	xorl	%eax, %eax
	movl	%edi, %esi
	shrl	$2, %esi
	salq	$4, %rsi
	.p2align 4,,10
	.p2align 3
.L14:
	movdqu	(%rcx,%rax), %xmm1
	movups	%xmm1, (%r8,%rax)
	addq	$16, %rax
	cmpq	%rsi, %rax
	jne	.L14
	movl	%edi, %ecx
	andl	$-4, %ecx
	leal	(%rcx,%rbp), %eax
	cmpl	%ecx, %edi
	je	.L16
	movslq	%eax, %rcx
	movl	0(%r13,%rcx,4), %esi
	movl	%esi, (%rdx,%rcx,4)
	leal	1(%rax), %ecx
	cmpl	%ecx, %r12d
	jl	.L16
	movslq	%ecx, %rcx
	addl	$2, %eax
	movl	0(%r13,%rcx,4), %esi
	leaq	0(,%rcx,4), %rdi
	movl	%esi, (%rdx,%rcx,4)
	cmpl	%eax, %r12d
	jl	.L16
	movl	4(%r13,%rdi), %ecx
	cltq
	movl	%ecx, (%rdx,%rax,4)
.L16:
	cmpl	%r14d, %ebx
	jl	.L12
.L6:
	movl	%ebx, %r10d
	movslq	%ebx, %rcx
	movl	$4, %eax
	movslq	%r14d, %rsi
	subl	%r12d, %r10d
	leaq	4(,%rcx,4), %r11
	leaq	0(,%rcx,4), %rdi
	movq	%rax, %rcx
	movl	%r10d, %r9d
	leaq	0(,%rsi,4), %r15
	leaq	awork(%rip), %rdx
	salq	$2, %r9
	cmpl	%r12d, %ebx
	leaq	(%rdx,%r15), %r8
	cmovg	%r9, %rcx
	subq	%r9, %rax
	xorl	%r9d, %r9d
	addq	%r15, %rcx
	addq	%rdx, %rcx
	cmpl	%r12d, %ebx
	cmovle	%r9, %rax
	addq	%rdi, %rax
	addq	%r13, %rax
	cmpq	%rax, %rcx
	leaq	0(%r13,%r11), %rcx
	setbe	%al
	cmpq	%rcx, %r8
	setnb	%cl
	orb	%cl, %al
	je	.L11
	leal	-1(%r10), %eax
	cmpl	$2, %eax
	seta	%cl
	cmpl	%r12d, %ebx
	setg	%al
	testb	%al, %cl
	je	.L11
	cmpl	%r12d, %ebx
	movl	$1, %r9d
	leaq	-16(%r13,%r11), %rsi
	movq	%r8, %rcx
	cmovg	%r10d, %r9d
	leaq	-16(%rsi), %rax
	movl	%r9d, %edi
	shrl	$2, %edi
	leal	-1(%rdi), %r8d
	movq	%rax, %rdi
	salq	$4, %r8
	subq	%r8, %rdi
	jmp	.L24
	.p2align 4,,10
	.p2align 3
.L49:
	subq	$16, %rax
.L24:
	movdqu	(%rsi), %xmm0
	addq	$16, %rcx
	movq	%rax, %rsi
	pshufd	$27, %xmm0, %xmm0
	movups	%xmm0, -16(%rcx)
	cmpq	%rax, %rdi
	jne	.L49
	movl	%r9d, %ecx
	movl	%ebx, %eax
	andl	$-4, %ecx
	subl	%ecx, %eax
	addl	%ecx, %r14d
	cmpl	%ecx, %r9d
	je	.L12
	movslq	%eax, %rcx
	subl	$1, %eax
	movl	0(%r13,%rcx,4), %esi
	movslq	%r14d, %rcx
	movl	%esi, (%rdx,%rcx,4)
	leal	1(%r14), %ecx
	cmpl	%ecx, %ebx
	jl	.L12
	cltq
	movslq	%ecx, %rcx
	addl	$2, %r14d
	leaq	0(,%rax,4), %rsi
	movl	0(%r13,%rax,4), %eax
	movl	%eax, (%rdx,%rcx,4)
	cmpl	%r14d, %ebx
	jl	.L12
	movl	-4(%r13,%rsi), %eax
	movslq	%r14d, %r14
	movl	%eax, (%rdx,%r14,4)
.L12:
	cmpl	%ebx, %ebp
	jg	.L1
	movl	%ebx, %edx
	movslq	%ebp, %r8
	movslq	%ebx, %rcx
	subl	%ebp, %edx
	leaq	0(%r13,%r8,4), %rax
	addq	%r8, %rdx
	leaq	4(%r13,%rdx,4), %r9
	leaq	awork(%rip), %rdx
	.p2align 4,,10
	.p2align 3
.L28:
	movl	(%rdx,%r8,4), %edi
	movl	(%rdx,%rcx,4), %esi
	cmpl	%edi, %esi
	jl	.L26
.L50:
	movl	%edi, (%rax)
	addq	$4, %rax
	addl	$1, %ebp
	cmpq	%rax, %r9
	je	.L1
	movslq	%ebp, %r8
	movl	(%rdx,%rcx,4), %esi
	movl	(%rdx,%r8,4), %edi
	cmpl	%edi, %esi
	jge	.L50
.L26:
	movl	%esi, (%rax)
	addq	$4, %rax
	subl	$1, %ebx
	cmpq	%rax, %r9
	je	.L1
	movslq	%ebx, %rcx
	jmp	.L28
	.p2align 4,,10
	.p2align 3
.L35:
	movl	0(%r13,%rax,4), %ecx
	movl	%ecx, (%rdx,%rax,4)
	addq	$1, %rax
	cmpl	%eax, %r12d
	jge	.L35
	jmp	.L16
	.p2align 4,,10
	.p2align 3
.L48:
	movl	%ebx, %edx
	movl	%r14d, %esi
	movq	%r13, %rdi
	call	MergeSort.part.0
	cmpl	%r12d, %ebp
	jle	.L3
	jmp	.L6
	.p2align 4,,10
	.p2align 3
.L1:
	addq	$8, %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
	.p2align 4,,10
	.p2align 3
.L47:
	.cfi_restore_state
	movl	%r12d, %edx
	call	MergeSort.part.0
	cmpl	%r14d, %ebx
	jle	.L3
	movl	%ebx, %edx
	movl	%r14d, %esi
	movq	%r13, %rdi
	call	MergeSort.part.0
	jmp	.L3
	.p2align 4,,10
	.p2align 3
.L11:
	leaq	0(%r13,%rdi), %rcx
	.p2align 4,,10
	.p2align 3
.L22:
	movl	(%rcx), %eax
	subq	$4, %rcx
	movl	%eax, (%rdx,%rsi,4)
	addq	$1, %rsi
	cmpl	%esi, %ebx
	jge	.L22
	jmp	.L12
	.cfi_endproc
.LFE43:
	.size	MergeSort.part.0, .-MergeSort.part.0
	.p2align 4
	.globl	MergeSort
	.type	MergeSort, @function
MergeSort:
.LFB39:
	.cfi_startproc
	endbr64
	cmpl	%edx, %esi
	jl	.L53
	ret
	.p2align 4,,10
	.p2align 3
.L53:
	jmp	MergeSort.part.0
	.cfi_endproc
.LFE39:
	.size	MergeSort, .-MergeSort
	.p2align 4
	.globl	calcDist
	.type	calcDist, @function
calcDist:
.LFB40:
	.cfi_startproc
	endbr64
	movl	m(%rip), %eax
	testl	%eax, %eax
	jle	.L60
	leaq	4+ak(%rip), %r9
	leal	-1(%rax), %ecx
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	xorl	%r10d, %r10d
	leaq	4(%r9), %rax
	movl	4+ad(%rip), %edx
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movl	$1, %edi
	leaq	-4+ad(%rip), %r8
	leaq	(%rax,%rcx,4), %r11
	leaq	4(%r8), %rbx
	.p2align 4,,10
	.p2align 3
.L56:
	movl	(%r9), %esi
	leal	1(%rdi), %eax
	cltq
	cmpl	%edx, %esi
	jle	.L67
	.p2align 4,,10
	.p2align 3
.L57:
	movl	%eax, %edi
	addq	$1, %rax
	movl	%edx, %ecx
	movl	(%r8,%rax,4), %edx
	cmpl	%esi, %edx
	jl	.L57
.L59:
	movl	%edx, %ebp
	subl	%esi, %ebp
	movl	%ebp, %eax
	negl	%eax
	cmovs	%ebp, %eax
	subl	%esi, %ecx
	movl	%ecx, %esi
	negl	%esi
	cmovns	%esi, %ecx
	cmpl	%ecx, %eax
	cmovg	%ecx, %eax
	addq	$4, %r9
	addl	%eax, %r10d
	cmpq	%r9, %r11
	jne	.L56
	movl	%r10d, %eax
	popq	%rbx
	.cfi_remember_state
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.p2align 4,,10
	.p2align 3
.L67:
	.cfi_restore_state
	leal	-1(%rdi), %eax
	cltq
	movl	(%rbx,%rax,4), %ecx
	jmp	.L59
.L60:
	.cfi_def_cfa_offset 8
	.cfi_restore 3
	.cfi_restore 6
	xorl	%eax, %eax
	ret
	.cfi_endproc
.LFE40:
	.size	calcDist, .-calcDist
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d"
	.text
	.p2align 4
	.globl	input
	.type	input, @function
input:
.LFB41:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	leaq	.LC0(%rip), %r12
	leaq	d(%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	d(%rip), %edx
	testl	%edx, %edx
	jne	.L76
.L68:
	popq	%rbx
	.cfi_remember_state
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.p2align 4,,10
	.p2align 3
.L76:
	.cfi_restore_state
	leaq	n(%rip), %rsi
	movq	%r12, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	leaq	m(%rip), %rsi
	movq	%r12, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movslq	n(%rip), %rax
	movl	$0, ad(%rip)
	cmpl	$1, %eax
	jle	.L70
	leaq	4+ad(%rip), %rbp
	movl	$1, %ebx
	.p2align 4,,10
	.p2align 3
.L71:
	movq	%rbp, %rsi
	movq	%r12, %rdi
	xorl	%eax, %eax
	addl	$1, %ebx
	call	__isoc99_scanf@PLT
	movslq	n(%rip), %rax
	addq	$4, %rbp
	cmpl	%eax, %ebx
	jl	.L71
.L70:
	movl	d(%rip), %ecx
	leaq	ad(%rip), %rdx
	movl	%ecx, (%rdx,%rax,4)
	movl	m(%rip), %eax
	testl	%eax, %eax
	jle	.L68
	leaq	4+ak(%rip), %rbp
	movl	$1, %ebx
	.p2align 4,,10
	.p2align 3
.L72:
	movq	%rbp, %rsi
	xorl	%eax, %eax
	movq	%r12, %rdi
	addl	$1, %ebx
	call	__isoc99_scanf@PLT
	addq	$4, %rbp
	cmpl	m(%rip), %ebx
	jle	.L72
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE41:
	.size	input, .-input
	.section	.rodata.str1.1
.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
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	leaq	ak(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	leaq	d(%rip), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	leaq	ad(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	leaq	.LC0(%rip), %rbx
	subq	$8, %rsp
	.cfi_def_cfa_offset 64
	.p2align 4,,10
	.p2align 3
.L92:
	movq	%r12, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movl	d(%rip), %ecx
	testl	%ecx, %ecx
	jne	.L104
.L78:
	addq	$8, %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
.L104:
	.cfi_restore_state
	leaq	n(%rip), %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	leaq	m(%rip), %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	call	__isoc99_scanf@PLT
	movslq	n(%rip), %rax
	movl	$0, ad(%rip)
	cmpl	$1, %eax
	jle	.L79
	leaq	4+ad(%rip), %r15
	movl	$1, %r14d
	.p2align 4,,10
	.p2align 3
.L80:
	movq	%r15, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	addl	$1, %r14d
	call	__isoc99_scanf@PLT
	movslq	n(%rip), %rax
	addq	$4, %r15
	cmpl	%eax, %r14d
	jl	.L80
.L79:
	movl	d(%rip), %edx
	leaq	4+ak(%rip), %r15
	movl	$1, %r14d
	movl	%edx, 0(%rbp,%rax,4)
	movl	m(%rip), %edx
	testl	%edx, %edx
	jle	.L84
	.p2align 4,,10
	.p2align 3
.L83:
	movq	%r15, %rsi
	xorl	%eax, %eax
	movq	%rbx, %rdi
	addl	$1, %r14d
	call	__isoc99_scanf@PLT
	addq	$4, %r15
	cmpl	m(%rip), %r14d
	jle	.L83
.L84:
	movl	d(%rip), %eax
	testl	%eax, %eax
	je	.L78
	movl	n(%rip), %edx
	testl	%edx, %edx
	jle	.L85
	xorl	%esi, %esi
	movq	%rbp, %rdi
	call	MergeSort.part.0
.L85:
	movl	m(%rip), %r8d
	cmpl	$1, %r8d
	jle	.L86
	movl	%r8d, %edx
	movl	$1, %esi
	movq	%r13, %rdi
	call	MergeSort.part.0
	movl	m(%rip), %r8d
.L86:
	testl	%r8d, %r8d
	jle	.L93
	leaq	4+ak(%rip), %r9
	leal	-1(%r8), %ecx
	movl	$1, %edi
	xorl	%r10d, %r10d
	leaq	4(%r9), %rax
	movl	4+ad(%rip), %edx
	leaq	-4+ad(%rip), %r8
	leaq	(%rax,%rcx,4), %r11
	.p2align 4,,10
	.p2align 3
.L88:
	movl	(%r9), %esi
	leal	1(%rdi), %eax
	cltq
	cmpl	%edx, %esi
	jle	.L105
	.p2align 4,,10
	.p2align 3
.L89:
	movl	%eax, %edi
	addq	$1, %rax
	movl	%edx, %ecx
	movl	(%r8,%rax,4), %edx
	cmpl	%esi, %edx
	jl	.L89
.L91:
	movl	%edx, %r14d
	subl	%esi, %r14d
	movl	%r14d, %eax
	negl	%eax
	cmovs	%r14d, %eax
	subl	%esi, %ecx
	movl	%ecx, %esi
	negl	%esi
	cmovns	%esi, %ecx
	cmpl	%ecx, %eax
	cmovg	%ecx, %eax
	addq	$4, %r9
	addl	%eax, %r10d
	cmpq	%r9, %r11
	jne	.L88
.L87:
	movl	%r10d, %edx
	leaq	.LC1(%rip), %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L92
	.p2align 4,,10
	.p2align 3
.L105:
	leal	-1(%rdi), %eax
	cltq
	movl	0(%rbp,%rax,4), %ecx
	jmp	.L91
.L93:
	xorl	%r10d, %r10d
	jmp	.L87
	.cfi_endproc
.LFE42:
	.size	main, .-main
	.globl	awork
	.bss
	.align 32
	.type	awork, @object
	.size	awork, 400004
awork:
	.zero	400004
	.globl	ak
	.align 32
	.type	ak, @object
	.size	ak, 40004
ak:
	.zero	40004
	.globl	ad
	.align 32
	.type	ad, @object
	.size	ad, 400004
ad:
	.zero	400004
	.globl	m
	.align 4
	.type	m, @object
	.size	m, 4
m:
	.zero	4
	.globl	n
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.globl	d
	.align 4
	.type	d, @object
	.size	d, 4
d:
	.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>

#define D_MAX 1000000000
#define N_MAX 100000
#define M_MAX 10000
#define min(x,y) (((x)<(y))?(x):(y))

int d;
int n;
int m;

int ad[N_MAX+1];
int ak[M_MAX+1];
int awork[N_MAX+1];

void MergeSort(int array[],int left,int right){
  int mid;
  int i;
  int j;
  int x;
  int y;
  
  if( left >= right ){
    return;
  }
  
  mid = (left + right) / 2;
  MergeSort( array, left, mid);
  MergeSort( array, mid+1, right);
  
  for( i=left; i<=mid; i++){
    awork[i] = array[i];
  }
  
  j = right;
  for( i=mid+1; i<=right; i++){
    awork[i] = array[j];
    j--;
  }
  
  x = left;
  y = right;
  
  for( i=left; i<=right; i++){
    if(awork[x] <= awork[y]){
      array[i] = awork[x];
      x++;
    }else{
      array[i] = awork[y];
      y--;
    }
  }
}


int calcDist(void){
  int i;
  int j = 1;
  int sum = 0;
  int diff;
  int preDiff = 0;
  int minDist = d;
  int tmpDist;
  int halfDist = d >> 1;
  
  for( i=1; i<=m; i++){
    
    while(ad[j] < ak[i]){
      j++;
    }
    minDist = min( abs(ad[j-1]-ak[i]),abs(ad[j]-ak[i]) );
    sum += minDist;
    
  }
  
  return sum;
}


void input(void){
  int i;
  scanf("%d",&d);
  if( d != 0){
    scanf("%d",&n);
    scanf("%d",&m);
    ad[0] = 0;
    for( i=1; i<=n-1; i++){
      scanf("%d",&ad[i]);
    }
    ad[n] = d;
    for( i=1; i<=m; i++){
      scanf("%d",&ak[i]);
    }
  }
}

int main(void){
  int i;
  int sumDist = 0;
  while( 1 ){
    input();
    if( d == 0 ){
      break;
    }
    MergeSort( ad, 0, n);
    MergeSort( ak, 1, m);
    sumDist = calcDist();
    printf("%d\n",sumDist);
    sumDist = 0;
  }
}



8
3
2
3
1
4
6
20
4
4
10
8
16
7
7
11
8
0
 8
3
2
3
1
4
6
20
4
4
12
8
16
7
7
4
8
0
 8
3
2
3
1
4
6
20
4
4
14
8
16
7
7
11
8
0
 8
3
2
3
1
7
7
12
4
4
12
8
16
7
7
4
8
0
 8
3
2
3
1
7
6
20
4
4
12
0
16
7
7
4
8
0
 8
3
2
3
1
7
6
12
4
4
12
8
16
4
7
4
8
0
 8
3
2
3
1
4
6
20
4
4
12
8
16
12
7
7
8
0
 8
3
2
3
0
4
6
20
4
4
14
14
23
7
7
11
8
0
 8
3
2
3
1
7
7
12
4
4
3
8
16
1
7
4
8
0
 8
3
2
3
1
4
6
20
4
4
1
8
16
11
7
4
8
0

3
3
 3
6
 3
5
 2
6
 3
18
 3
9
 3
2
 3
23
 2
3
 3
7

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>

#define D_MAX 1000000000
#define N_MAX 100000
#define M_MAX 10000
#define min(x,y) (((x)<(y))?(x):(y))

int d;
int n;
int m;

int ad[N_MAX+1];
int ak[M_MAX+1];
int awork[N_MAX+1];

void MergeSort(int array[],int left,int right){
  int mid;
  int i;
  int j;
  int x;
  int y;
  
  if( left >= right ){
    return;
  }
  
  mid = (left + right) / 2;
  MergeSort( array, left, mid);
  MergeSort( array, mid+1, right);
  
  for( i=left; i<=mid; i++){
    awork[i] = array[i];
  }
  
  j = right;
  for( i=mid+1; i<=right; i++){
    awork[i] = array[j];
    j--;
  }
  
  x = left;
  y = right;
  
  for( i=left; i<=right; i++){
    if(awork[x] <= awork[y]){
      array[i] = awork[x];
      x++;
    }else{
      array[i] = awork[y];
      y--;
    }
  }
}


int calcDist(void){
  int i;
  int j = 1;
  int sum = 0;
  int diff;
  int preDiff = 0;
  int minDist = d;
  int tmpDist;
  int halfDist = d >> 1;
  
  for( i=1; i<=m; i++){
    
    while(ad[j] < ak[i]){
      j++;
    }
    minDist = min( abs(ad[j-1]-ak[i]),abs(ad[j]-ak[i]) );
    sum += minDist;
    
  }
  
  return sum;
}


void input(void){
  int i;
  scanf("%d",&d);
  if( d != 0){
    scanf("%d",&n);
    scanf("%d",&m);
    ad[0] = 0;
    for( i=1; i<=n-1; i++){
      scanf("%d",&ad[i]);
    }
    ad[n] = d;
    for( i=1; i<=m; i++){
      scanf("%d",&ak[i]);
    }
  }
}

int main(void){
  int i;
  int sumDist = 0;
  while( 1 ){
    input();
    if( d == 0 ){
      break;
    }
    MergeSort( ad, 0, n);
    MergeSort( ak, 1, m);
    sumDist = calcDist();
    printf("%d\n",sumDist);
    sumDist = 0;
  }
}


```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	d
	.bss
	.align 4
	.type	d, @object
	.size	d, 4
d:
	.zero	4
	.globl	n
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.globl	m
	.align 4
	.type	m, @object
	.size	m, 4
m:
	.zero	4
	.globl	ad
	.align 32
	.type	ad, @object
	.size	ad, 400004
ad:
	.zero	400004
	.globl	ak
	.align 32
	.type	ak, @object
	.size	ak, 40004
ak:
	.zero	40004
	.globl	awork
	.align 32
	.type	awork, @object
	.size	awork, 400004
awork:
	.zero	400004
	.text
	.globl	MergeSort
	.type	MergeSort, @function
MergeSort:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$48, %rsp
	movq	%rdi, -40(%rbp)
	movl	%esi, -44(%rbp)
	movl	%edx, -48(%rbp)
	movl	-44(%rbp), %eax
	cmpl	-48(%rbp), %eax
	jge	.L12
	movl	-44(%rbp), %edx
	movl	-48(%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	-44(%rbp), %ecx
	movq	-40(%rbp), %rax
	movl	%ecx, %esi
	movq	%rax, %rdi
	call	MergeSort
	movl	-4(%rbp), %eax
	leal	1(%rax), %ecx
	movl	-48(%rbp), %edx
	movq	-40(%rbp), %rax
	movl	%ecx, %esi
	movq	%rax, %rdi
	call	MergeSort
	movl	-44(%rbp), %eax
	movl	%eax, -20(%rbp)
	jmp	.L4
.L5:
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-40(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	-20(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	awork(%rip), %rdx
	movl	%eax, (%rcx,%rdx)
	addl	$1, -20(%rbp)
.L4:
	movl	-20(%rbp), %eax
	cmpl	-4(%rbp), %eax
	jle	.L5
	movl	-48(%rbp), %eax
	movl	%eax, -16(%rbp)
	movl	-4(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -20(%rbp)
	jmp	.L6
.L7:
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-40(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	-20(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	awork(%rip), %rdx
	movl	%eax, (%rcx,%rdx)
	subl	$1, -16(%rbp)
	addl	$1, -20(%rbp)
.L6:
	movl	-20(%rbp), %eax
	cmpl	-48(%rbp), %eax
	jle	.L7
	movl	-44(%rbp), %eax
	movl	%eax, -12(%rbp)
	movl	-48(%rbp), %eax
	movl	%eax, -8(%rbp)
	movl	-44(%rbp), %eax
	movl	%eax, -20(%rbp)
	jmp	.L8
.L11:
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	awork(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	awork(%rip), %rax
	movl	(%rcx,%rax), %eax
	cmpl	%eax, %edx
	jg	.L9
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-40(%rbp), %rax
	addq	%rax, %rdx
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	awork(%rip), %rax
	movl	(%rcx,%rax), %eax
	movl	%eax, (%rdx)
	addl	$1, -12(%rbp)
	jmp	.L10
.L9:
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-40(%rbp), %rax
	addq	%rax, %rdx
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	awork(%rip), %rax
	movl	(%rcx,%rax), %eax
	movl	%eax, (%rdx)
	subl	$1, -8(%rbp)
.L10:
	addl	$1, -20(%rbp)
.L8:
	movl	-20(%rbp), %eax
	cmpl	-48(%rbp), %eax
	jle	.L11
	jmp	.L1
.L12:
	nop
.L1:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	MergeSort, .-MergeSort
	.globl	calcDist
	.type	calcDist, @function
calcDist:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	$1, -20(%rbp)
	movl	$0, -16(%rbp)
	movl	$0, -12(%rbp)
	movl	d(%rip), %eax
	movl	%eax, -8(%rbp)
	movl	d(%rip), %eax
	sarl	%eax
	movl	%eax, -4(%rbp)
	movl	$1, -24(%rbp)
	jmp	.L14
.L16:
	addl	$1, -20(%rbp)
.L15:
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	ad(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-24(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	ak(%rip), %rax
	movl	(%rcx,%rax), %eax
	cmpl	%eax, %edx
	jl	.L16
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	ad(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	-24(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	ak(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	subl	%edx, %eax
	movl	%eax, %edx
	negl	%edx
	cmovs	%eax, %edx
	movl	-20(%rbp), %eax
	subl	$1, %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	ad(%rip), %rax
	movl	(%rcx,%rax), %eax
	movl	-24(%rbp), %ecx
	movslq	%ecx, %rcx
	leaq	0(,%rcx,4), %rsi
	leaq	ak(%rip), %rcx
	movl	(%rsi,%rcx), %ecx
	subl	%ecx, %eax
	movl	%eax, %ecx
	negl	%ecx
	cmovns	%ecx, %eax
	cmpl	%eax, %edx
	cmovle	%edx, %eax
	movl	%eax, -8(%rbp)
	movl	-8(%rbp), %eax
	addl	%eax, -16(%rbp)
	addl	$1, -24(%rbp)
.L14:
	movl	m(%rip), %eax
	cmpl	%eax, -24(%rbp)
	jle	.L15
	movl	-16(%rbp), %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	calcDist, .-calcDist
	.section	.rodata
.LC0:
	.string	"%d"
	.text
	.globl	input
	.type	input, @function
input:
.LFB8:
	.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	d(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	d(%rip), %eax
	testl	%eax, %eax
	je	.L25
	leaq	n(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	leaq	m(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, ad(%rip)
	movl	$1, -4(%rbp)
	jmp	.L21
.L22:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	ad(%rip), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -4(%rbp)
.L21:
	movl	n(%rip), %eax
	cmpl	%eax, -4(%rbp)
	jl	.L22
	movl	n(%rip), %edx
	movl	d(%rip), %eax
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	ad(%rip), %rdx
	movl	%eax, (%rcx,%rdx)
	movl	$1, -4(%rbp)
	jmp	.L23
.L24:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	ak(%rip), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -4(%rbp)
.L23:
	movl	m(%rip), %eax
	cmpl	%eax, -4(%rbp)
	jle	.L24
.L25:
	nop
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.size	input, .-input
	.section	.rodata
.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	$16, %rsp
	movl	$0, -4(%rbp)
.L29:
	call	input
	movl	d(%rip), %eax
	testl	%eax, %eax
	je	.L32
	movl	n(%rip), %eax
	movl	%eax, %edx
	movl	$0, %esi
	leaq	ad(%rip), %rax
	movq	%rax, %rdi
	call	MergeSort
	movl	m(%rip), %eax
	movl	%eax, %edx
	movl	$1, %esi
	leaq	ak(%rip), %rax
	movq	%rax, %rdi
	call	MergeSort
	call	calcDist
	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, -4(%rbp)
	jmp	.L29
.L32:
	nop
	movl	$0, %eax
	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	d
	.bss
	.align 4
	.type	d, @object
	.size	d, 4
d:
	.zero	4
	.globl	n
	.align 4
	.type	n, @object
	.size	n, 4
n:
	.zero	4
	.globl	m
	.align 4
	.type	m, @object
	.size	m, 4
m:
	.zero	4
	.globl	ad
	.align 32
	.type	ad, @object
	.size	ad, 400004
ad:
	.zero	400004
	.globl	ak
	.align 32
	.type	ak, @object
	.size	ak, 40004
ak:
	.zero	40004
	.globl	awork
	.align 32
	.type	awork, @object
	.size	awork, 400004
awork:
	.zero	400004
	.text
	.globl	MergeSort
	.type	MergeSort, @function
MergeSort:
.LFB6:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$48, %rsp
	movq	%rdi, -40(%rbp)
	movl	%esi, -44(%rbp)
	movl	%edx, -48(%rbp)
	movl	-44(%rbp), %eax
	cmpl	-48(%rbp), %eax
	jge	.L12
	movl	-44(%rbp), %edx
	movl	-48(%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	-44(%rbp), %ecx
	movq	-40(%rbp), %rax
	movl	%ecx, %esi
	movq	%rax, %rdi
	call	MergeSort
	movl	-4(%rbp), %eax
	leal	1(%rax), %ecx
	movl	-48(%rbp), %edx
	movq	-40(%rbp), %rax
	movl	%ecx, %esi
	movq	%rax, %rdi
	call	MergeSort
	movl	-44(%rbp), %eax
	movl	%eax, -20(%rbp)
	jmp	.L4
.L5:
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-40(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	-20(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	awork(%rip), %rdx
	movl	%eax, (%rcx,%rdx)
	addl	$1, -20(%rbp)
.L4:
	movl	-20(%rbp), %eax
	cmpl	-4(%rbp), %eax
	jle	.L5
	movl	-48(%rbp), %eax
	movl	%eax, -16(%rbp)
	movl	-4(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -20(%rbp)
	jmp	.L6
.L7:
	movl	-16(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-40(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	-20(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	awork(%rip), %rdx
	movl	%eax, (%rcx,%rdx)
	subl	$1, -16(%rbp)
	addl	$1, -20(%rbp)
.L6:
	movl	-20(%rbp), %eax
	cmpl	-48(%rbp), %eax
	jle	.L7
	movl	-44(%rbp), %eax
	movl	%eax, -12(%rbp)
	movl	-48(%rbp), %eax
	movl	%eax, -8(%rbp)
	movl	-44(%rbp), %eax
	movl	%eax, -20(%rbp)
	jmp	.L8
.L11:
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	awork(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	awork(%rip), %rax
	movl	(%rcx,%rax), %eax
	cmpl	%eax, %edx
	jg	.L9
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-40(%rbp), %rax
	addq	%rax, %rdx
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	awork(%rip), %rax
	movl	(%rcx,%rax), %eax
	movl	%eax, (%rdx)
	addl	$1, -12(%rbp)
	jmp	.L10
.L9:
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-40(%rbp), %rax
	addq	%rax, %rdx
	movl	-8(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	awork(%rip), %rax
	movl	(%rcx,%rax), %eax
	movl	%eax, (%rdx)
	subl	$1, -8(%rbp)
.L10:
	addl	$1, -20(%rbp)
.L8:
	movl	-20(%rbp), %eax
	cmpl	-48(%rbp), %eax
	jle	.L11
	jmp	.L1
.L12:
	nop
.L1:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	MergeSort, .-MergeSort
	.globl	calcDist
	.type	calcDist, @function
calcDist:
.LFB7:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	movl	$1, -20(%rbp)
	movl	$0, -16(%rbp)
	movl	$0, -12(%rbp)
	movl	d(%rip), %eax
	movl	%eax, -8(%rbp)
	movl	d(%rip), %eax
	sarl	%eax
	movl	%eax, -4(%rbp)
	movl	$1, -24(%rbp)
	jmp	.L14
.L16:
	addl	$1, -20(%rbp)
.L15:
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	ad(%rip), %rax
	movl	(%rdx,%rax), %edx
	movl	-24(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	ak(%rip), %rax
	movl	(%rcx,%rax), %eax
	cmpl	%eax, %edx
	jl	.L16
	movl	-20(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	ad(%rip), %rax
	movl	(%rdx,%rax), %eax
	movl	-24(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	ak(%rip), %rdx
	movl	(%rcx,%rdx), %edx
	subl	%edx, %eax
	movl	%eax, %edx
	negl	%edx
	cmovs	%eax, %edx
	movl	-20(%rbp), %eax
	subl	$1, %eax
	cltq
	leaq	0(,%rax,4), %rcx
	leaq	ad(%rip), %rax
	movl	(%rcx,%rax), %eax
	movl	-24(%rbp), %ecx
	movslq	%ecx, %rcx
	leaq	0(,%rcx,4), %rsi
	leaq	ak(%rip), %rcx
	movl	(%rsi,%rcx), %ecx
	subl	%ecx, %eax
	movl	%eax, %ecx
	negl	%ecx
	cmovns	%ecx, %eax
	cmpl	%eax, %edx
	cmovle	%edx, %eax
	movl	%eax, -8(%rbp)
	movl	-8(%rbp), %eax
	addl	%eax, -16(%rbp)
	addl	$1, -24(%rbp)
.L14:
	movl	m(%rip), %eax
	cmpl	%eax, -24(%rbp)
	jle	.L15
	movl	-16(%rbp), %eax
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	calcDist, .-calcDist
	.section	.rodata
.LC0:
	.string	"%d"
	.text
	.globl	input
	.type	input, @function
input:
.LFB8:
	.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	d(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	d(%rip), %eax
	testl	%eax, %eax
	je	.L25
	leaq	n(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	leaq	m(%rip), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, ad(%rip)
	movl	$1, -4(%rbp)
	jmp	.L21
.L22:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	ad(%rip), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -4(%rbp)
.L21:
	movl	n(%rip), %eax
	cmpl	%eax, -4(%rbp)
	jl	.L22
	movl	n(%rip), %edx
	movl	d(%rip), %eax
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	leaq	ad(%rip), %rdx
	movl	%eax, (%rcx,%rdx)
	movl	$1, -4(%rbp)
	jmp	.L23
.L24:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	leaq	ak(%rip), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -4(%rbp)
.L23:
	movl	m(%rip), %eax
	cmpl	%eax, -4(%rbp)
	jle	.L24
.L25:
	nop
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.size	input, .-input
	.section	.rodata
.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	$16, %rsp
	movl	$0, -4(%rbp)
.L29:
	call	input
	movl	d(%rip), %eax
	testl	%eax, %eax
	je	.L32
	movl	n(%rip), %eax
	movl	%eax, %edx
	movl	$0, %esi
	leaq	ad(%rip), %rax
	movq	%rax, %rdi
	call	MergeSort
	movl	m(%rip), %eax
	movl	%eax, %edx
	movl	$1, %esi
	leaq	ak(%rip), %rax
	movq	%rax, %rdi
	call	MergeSort
	call	calcDist
	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, -4(%rbp)
	jmp	.L29
.L32:
	nop
	movl	$0, %eax
	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:
