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 CHECK printf("check\n");
void countingSort(int*,int*,int,int);
int countMinimumCost(int*,int*,int);
void printArray(int*,int);
int main(void)
{
  int i;//counter
  int n;//length of array
  int wholeMax=0;//maximum value of array
  int *arr;//array sorted by minimum cost sort
  int *sortedArr;//array sorted by counting sort
  int cost;
  scanf("%d",&n);
  arr=(int*)malloc(sizeof(int)*n);
  sortedArr=(int*)malloc(sizeof(int)*n);
  for(i=0;i<n;i++)
    {
      scanf("%d",&arr[i]);
      if(wholeMax<arr[i]) wholeMax=arr[i];
    }
  countingSort(arr,sortedArr,n,wholeMax);
  cost=countMinimumCost(arr,sortedArr,n);
  printf("%d\n",cost);
  return 0;
}
void countingSort(int *arr,int *sortedArr,int n,int max)
{
  int i;//counter
  int *countArr=(int*)malloc(sizeof(int)*(max+1));
  for(i=0;i<max+1;i++) countArr[i]=0;
  for(i=0;i<n;i++) countArr[arr[i]]++;
  for(i=1;i<max+1;i++) countArr[i]+=countArr[i-1];
  for(i=n-1;i>=0;i--)
    {
      sortedArr[countArr[arr[i]]-1]=arr[i];
      countArr[arr[i]]--;
    }
}
int countMinimumCost(int *arr,int *sortedArr,int n)
{
  int i;//counter
  int *isSortedArr=(int*)malloc(sizeof(int)*n);
  int begin;//first index that is not sorted yet
  int index;//index pointing now
  int count;//length of loop
  int sum;//sum of loop
  int min;//minimum value among loop
  int wholeMin;//minimum value in the array
  int currentCost[2];//2 pattern of sorting cost in one loop
  int sumCost=0;//sum of whole cost;
  //init isSortedArr
  wholeMin=arr[0];
  begin=n;
  for(i=0;i<n;i++)
    {
      if(arr[i]==sortedArr[i]) isSortedArr[i]=1;
      else isSortedArr[i]=0;
      if(wholeMin>arr[i]) wholeMin=arr[i];
      if(isSortedArr[i]==0&&begin==n) begin=i;
    }
  
  for(;begin<n;begin++)
    {
      if(isSortedArr[begin]==0)
	{
	  index=begin;
	  sum=0;
	  min=arr[index];
	  for(count=1;;count++)
	    {
	      isSortedArr[index]=1;
	      sum+=arr[index];
	      if(min>arr[index]) min=arr[index];
	      for(i=begin+1;i<n;i++)
		{
		  if(arr[i]==sortedArr[index]&&isSortedArr[i]==0) break;
		}
	      if(i==n) break;
	      index=i;
	    }
	  currentCost[0]=sum-min+min*(count-1);
	  currentCost[1]=(wholeMin+min)*2+(sum-min+wholeMin*(count-1));
	  if(currentCost[0]<currentCost[1]) sumCost+=currentCost[0];
	  else sumCost+=currentCost[1];
	}
    }
  return sumCost;
}
void printArray(int *arr,int n)
{
  int i;//counter
  for(i=0;i<n;i++)
    {
      if(i>0) printf(" ");
      printf("%d",arr[i]);
    }
  printf("\n");
}

```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.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	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -32(%rbp)
	leaq	-40(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-40(%rbp), %eax
	cltq
	salq	$2, %rax
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -24(%rbp)
	movl	-40(%rbp), %eax
	cltq
	salq	$2, %rax
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -16(%rbp)
	movl	$0, -36(%rbp)
	jmp	.L2
.L4:
	movl	-36(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-36(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	cmpl	%eax, -32(%rbp)
	jge	.L3
	movl	-36(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, -32(%rbp)
.L3:
	addl	$1, -36(%rbp)
.L2:
	movl	-40(%rbp), %eax
	cmpl	%eax, -36(%rbp)
	jl	.L4
	movl	-40(%rbp), %edx
	movl	-32(%rbp), %ecx
	movq	-16(%rbp), %rsi
	movq	-24(%rbp), %rax
	movq	%rax, %rdi
	call	countingSort
	movl	-40(%rbp), %edx
	movq	-16(%rbp), %rcx
	movq	-24(%rbp), %rax
	movq	%rcx, %rsi
	movq	%rax, %rdi
	call	countMinimumCost
	movl	%eax, -28(%rbp)
	movl	-28(%rbp), %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	.L6
	call	__stack_chk_fail@PLT
.L6:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	main, .-main
	.globl	countingSort
	.type	countingSort, @function
countingSort:
.LFB7:
	.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, -24(%rbp)
	movq	%rsi, -32(%rbp)
	movl	%edx, -36(%rbp)
	movl	%ecx, -40(%rbp)
	movl	-40(%rbp), %eax
	addl	$1, %eax
	cltq
	salq	$2, %rax
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -8(%rbp)
	movl	$0, -12(%rbp)
	jmp	.L8
.L9:
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-8(%rbp), %rax
	addq	%rdx, %rax
	movl	$0, (%rax)
	addl	$1, -12(%rbp)
.L8:
	movl	-40(%rbp), %eax
	cmpl	-12(%rbp), %eax
	jge	.L9
	movl	$0, -12(%rbp)
	jmp	.L10
.L11:
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-8(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	addl	$1, %edx
	movl	%edx, (%rax)
	addl	$1, -12(%rbp)
.L10:
	movl	-12(%rbp), %eax
	cmpl	-36(%rbp), %eax
	jl	.L11
	movl	$1, -12(%rbp)
	jmp	.L12
.L13:
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-8(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %ecx
	movl	-12(%rbp), %eax
	cltq
	salq	$2, %rax
	leaq	-4(%rax), %rdx
	movq	-8(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rsi
	movq	-8(%rbp), %rax
	addq	%rsi, %rax
	addl	%ecx, %edx
	movl	%edx, (%rax)
	addl	$1, -12(%rbp)
.L12:
	movl	-40(%rbp), %eax
	cmpl	-12(%rbp), %eax
	jge	.L13
	movl	-36(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -12(%rbp)
	jmp	.L14
.L15:
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	-12(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	movq	-24(%rbp), %rdx
	addq	%rcx, %rdx
	movl	(%rdx), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	movq	-8(%rbp), %rdx
	addq	%rcx, %rdx
	movl	(%rdx), %edx
	movslq	%edx, %rdx
	salq	$2, %rdx
	leaq	-4(%rdx), %rcx
	movq	-32(%rbp), %rdx
	addq	%rcx, %rdx
	movl	(%rax), %eax
	movl	%eax, (%rdx)
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-8(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	subl	$1, %edx
	movl	%edx, (%rax)
	subl	$1, -12(%rbp)
.L14:
	cmpl	$0, -12(%rbp)
	jns	.L15
	nop
	nop
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	countingSort, .-countingSort
	.globl	countMinimumCost
	.type	countMinimumCost, @function
countMinimumCost:
.LFB8:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$96, %rsp
	movq	%rdi, -72(%rbp)
	movq	%rsi, -80(%rbp)
	movl	%edx, -84(%rbp)
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	-84(%rbp), %eax
	cltq
	salq	$2, %rax
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -24(%rbp)
	movl	$0, -28(%rbp)
	movq	-72(%rbp), %rax
	movl	(%rax), %eax
	movl	%eax, -32(%rbp)
	movl	-84(%rbp), %eax
	movl	%eax, -52(%rbp)
	movl	$0, -56(%rbp)
	jmp	.L17
.L22:
	movl	-56(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-72(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-56(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	movq	-80(%rbp), %rax
	addq	%rcx, %rax
	movl	(%rax), %eax
	cmpl	%eax, %edx
	jne	.L18
	movl	-56(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	$1, (%rax)
	jmp	.L19
.L18:
	movl	-56(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	$0, (%rax)
.L19:
	movl	-56(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-72(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	cmpl	%eax, -32(%rbp)
	jle	.L20
	movl	-56(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-72(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, -32(%rbp)
.L20:
	movl	-56(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	testl	%eax, %eax
	jne	.L21
	movl	-52(%rbp), %eax
	cmpl	-84(%rbp), %eax
	jne	.L21
	movl	-56(%rbp), %eax
	movl	%eax, -52(%rbp)
.L21:
	addl	$1, -56(%rbp)
.L17:
	movl	-56(%rbp), %eax
	cmpl	-84(%rbp), %eax
	jl	.L22
	jmp	.L23
.L34:
	movl	-52(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	testl	%eax, %eax
	jne	.L24
	movl	-52(%rbp), %eax
	movl	%eax, -48(%rbp)
	movl	$0, -40(%rbp)
	movl	-48(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-72(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, -36(%rbp)
	movl	$1, -44(%rbp)
.L32:
	movl	-48(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	$1, (%rax)
	movl	-48(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-72(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	addl	%eax, -40(%rbp)
	movl	-48(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-72(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	cmpl	%eax, -36(%rbp)
	jle	.L25
	movl	-48(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-72(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, -36(%rbp)
.L25:
	movl	-52(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -56(%rbp)
	jmp	.L26
.L29:
	movl	-56(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-72(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-48(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	movq	-80(%rbp), %rax
	addq	%rcx, %rax
	movl	(%rax), %eax
	cmpl	%eax, %edx
	jne	.L27
	movl	-56(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	testl	%eax, %eax
	je	.L38
.L27:
	addl	$1, -56(%rbp)
.L26:
	movl	-56(%rbp), %eax
	cmpl	-84(%rbp), %eax
	jl	.L29
	jmp	.L28
.L38:
	nop
.L28:
	movl	-56(%rbp), %eax
	cmpl	-84(%rbp), %eax
	je	.L39
	movl	-56(%rbp), %eax
	movl	%eax, -48(%rbp)
	addl	$1, -44(%rbp)
	jmp	.L32
.L39:
	nop
	movl	-40(%rbp), %eax
	subl	-36(%rbp), %eax
	movl	%eax, %edx
	movl	-44(%rbp), %eax
	subl	$1, %eax
	imull	-36(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, -16(%rbp)
	movl	-32(%rbp), %edx
	movl	-36(%rbp), %eax
	addl	%edx, %eax
	leal	(%rax,%rax), %ecx
	movl	-40(%rbp), %eax
	subl	-36(%rbp), %eax
	movl	%eax, %edx
	movl	-44(%rbp), %eax
	subl	$1, %eax
	imull	-32(%rbp), %eax
	addl	%edx, %eax
	addl	%ecx, %eax
	movl	%eax, -12(%rbp)
	movl	-16(%rbp), %edx
	movl	-12(%rbp), %eax
	cmpl	%eax, %edx
	jge	.L33
	movl	-16(%rbp), %eax
	addl	%eax, -28(%rbp)
	jmp	.L24
.L33:
	movl	-12(%rbp), %eax
	addl	%eax, -28(%rbp)
.L24:
	addl	$1, -52(%rbp)
.L23:
	movl	-52(%rbp), %eax
	cmpl	-84(%rbp), %eax
	jl	.L34
	movl	-28(%rbp), %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L36
	call	__stack_chk_fail@PLT
.L36:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.size	countMinimumCost, .-countMinimumCost
	.globl	printArray
	.type	printArray, @function
printArray:
.LFB9:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$32, %rsp
	movq	%rdi, -24(%rbp)
	movl	%esi, -28(%rbp)
	movl	$0, -4(%rbp)
	jmp	.L41
.L43:
	cmpl	$0, -4(%rbp)
	jle	.L42
	movl	$32, %edi
	call	putchar@PLT
.L42:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	addl	$1, -4(%rbp)
.L41:
	movl	-4(%rbp), %eax
	cmpl	-28(%rbp), %eax
	jl	.L43
	movl	$10, %edi
	call	putchar@PLT
	nop
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE9:
	.size	printArray, .-printArray
	.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	countingSort
	.type	countingSort, @function
countingSort:
.LFB40:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movl	%ecx, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movq	%rsi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	movq	%rdi, %rbp
	leal	1(%rcx), %edi
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movslq	%edi, %rdi
	movl	%edx, %ebx
	salq	$2, %rdi
	subq	$8, %rsp
	.cfi_def_cfa_offset 48
	call	malloc@PLT
	movq	%rax, %rcx
	testl	%r13d, %r13d
	js	.L5
	movslq	%r13d, %rax
	movq	%rcx, %rdi
	xorl	%esi, %esi
	leaq	4(,%rax,4), %rdx
	call	memset@PLT
	movq	%rax, %rcx
.L5:
	testl	%ebx, %ebx
	jle	.L23
	leal	-1(%rbx), %esi
	movq	%rbp, %rax
	movq	%rsi, %rdx
	leaq	4(%rbp,%rsi,4), %rdi
	.p2align 4,,10
	.p2align 3
.L6:
	movslq	(%rax), %rsi
	addq	$4, %rax
	addl	$1, (%rcx,%rsi,4)
	cmpq	%rax, %rdi
	jne	.L6
	testl	%r13d, %r13d
	jle	.L10
.L8:
	movl	(%rcx), %esi
	movl	$1, %eax
	.p2align 4,,10
	.p2align 3
.L11:
	addl	(%rcx,%rax,4), %esi
	movl	%esi, (%rcx,%rax,4)
	addq	$1, %rax
	cmpl	%eax, %r13d
	jge	.L11
	testl	%edx, %edx
	js	.L1
.L10:
	movslq	%edx, %rdx
	.p2align 4,,10
	.p2align 3
.L13:
	movslq	0(%rbp,%rdx,4), %rax
	subq	$1, %rdx
	leaq	(%rcx,%rax,4), %rsi
	movq	%rax, %rdi
	movslq	(%rsi), %r8
	movq	%r8, %rax
	movl	%edi, -4(%r12,%r8,4)
	subl	$1, %eax
	movl	%eax, (%rsi)
	testl	%edx, %edx
	jns	.L13
.L1:
	addq	$8, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.p2align 4,,10
	.p2align 3
.L23:
	.cfi_restore_state
	leal	-1(%rbx), %edx
	testl	%r13d, %r13d
	jg	.L8
	jmp	.L1
	.cfi_endproc
.LFE40:
	.size	countingSort, .-countingSort
	.p2align 4
	.globl	countMinimumCost
	.type	countMinimumCost, @function
countMinimumCost:
.LFB41:
	.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
	movslq	%edx, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rsi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%rdi, %rbp
	leaq	0(,%r13,4), %rdi
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$8, %rsp
	.cfi_def_cfa_offset 64
	call	malloc@PLT
	movl	0(%rbp), %r11d
	testl	%r13d, %r13d
	jle	.L25
	movq	%rax, %rsi
	movq	%r13, %rbx
	movl	%r11d, %edx
	movl	%r13d, %edi
	xorl	%eax, %eax
	.p2align 4,,10
	.p2align 3
.L26:
	cmpl	%edx, %r11d
	movl	$1, %ecx
	cmovg	%edx, %r11d
	cmpl	%edx, (%r12,%rax,4)
	je	.L28
	cmpl	%edi, %ebx
	jne	.L44
	movl	%eax, %edi
.L44:
	xorl	%ecx, %ecx
.L28:
	movl	%ecx, (%rsi,%rax,4)
	addq	$1, %rax
	cmpq	%rax, %r13
	je	.L29
	movl	0(%rbp,%rax,4), %edx
	jmp	.L26
.L29:
	cmpl	%ebx, %edi
	jge	.L25
	movslq	%edi, %r13
	xorl	%r14d, %r14d
	salq	$2, %r13
	jmp	.L37
	.p2align 4,,10
	.p2align 3
.L30:
	addq	$4, %r13
	cmpl	%edi, %ebx
	je	.L24
.L37:
	movl	(%rsi,%r13), %r9d
	movslq	%edi, %rdx
	addl	$1, %edi
	testl	%r9d, %r9d
	jne	.L30
	movl	0(%rbp,%r13), %r8d
	movl	$1, %r10d
	movl	%r8d, %eax
	.p2align 4,,10
	.p2align 3
.L35:
	addl	%eax, %r9d
	cmpl	%eax, %r8d
	movl	$1, (%rsi,%rdx,4)
	cmovg	%eax, %r8d
	cmpl	%edi, %ebx
	jle	.L40
	movl	(%r12,%rdx,4), %r15d
	movslq	%edi, %rax
	jmp	.L33
	.p2align 4,,10
	.p2align 3
.L32:
	addq	$1, %rax
	leal	1(%rcx), %edx
	cmpl	%eax, %ebx
	jle	.L31
.L33:
	movl	%eax, %ecx
	movl	%eax, %edx
	cmpl	%r15d, 0(%rbp,%rax,4)
	jne	.L32
	cmpl	$0, (%rsi,%rax,4)
	jne	.L32
.L31:
	cmpl	%edx, %ebx
	je	.L34
	movslq	%edx, %rdx
	addl	$1, %r10d
	movl	0(%rbp,%rdx,4), %eax
	jmp	.L35
.L34:
	subl	$1, %r10d
	movl	%r8d, %edx
	subl	%r8d, %r9d
	addl	%r11d, %r8d
	imull	%r10d, %edx
	imull	%r11d, %r10d
	addl	%r9d, %edx
	leal	(%r10,%r9), %eax
	leal	(%r14,%rdx), %ecx
	leal	(%rax,%r8,2), %eax
	addl	%eax, %r14d
	cmpl	%eax, %edx
	cmovl	%ecx, %r14d
	addq	$4, %r13
	cmpl	%edi, %ebx
	jne	.L37
.L24:
	addq	$8, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	movl	%r14d, %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
.L40:
	.cfi_restore_state
	movl	%edi, %edx
	jmp	.L31
.L25:
	xorl	%r14d, %r14d
	jmp	.L24
	.cfi_endproc
.LFE41:
	.size	countMinimumCost, .-countMinimumCost
	.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:
.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
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	leaq	.LC0(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%r13, %rdi
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	leaq	20(%rsp), %rsi
	call	__isoc99_scanf@PLT
	movslq	20(%rsp), %rbp
	movl	%ebp, 12(%rsp)
	salq	$2, %rbp
	movq	%rbp, %rdi
	call	malloc@PLT
	movq	%rbp, %rdi
	movq	%rax, %r14
	call	malloc@PLT
	movl	12(%rsp), %edx
	movq	%rax, %r15
	testl	%edx, %edx
	jle	.L49
	movq	%r14, %rbx
	xorl	%r12d, %r12d
	xorl	%ebp, %ebp
	.p2align 4,,10
	.p2align 3
.L47:
	movq	%rbx, %rsi
	xorl	%eax, %eax
	movq	%r13, %rdi
	call	__isoc99_scanf@PLT
	movl	(%rbx), %eax
	movl	20(%rsp), %edx
	cmpl	%eax, %r12d
	cmovl	%eax, %r12d
	addl	$1, %ebp
	addq	$4, %rbx
	cmpl	%ebp, %edx
	jg	.L47
.L46:
	movl	%r12d, %ecx
	movq	%r15, %rsi
	movq	%r14, %rdi
	call	countingSort
	movl	20(%rsp), %edx
	movq	%r15, %rsi
	movq	%r14, %rdi
	call	countMinimumCost
	leaq	.LC1(%rip), %rsi
	movl	$1, %edi
	movl	%eax, %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	24(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L52
	addq	$40, %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
.L49:
	.cfi_restore_state
	xorl	%r12d, %r12d
	jmp	.L46
.L52:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE39:
	.size	main, .-main
	.text
	.p2align 4
	.globl	printArray
	.type	printArray, @function
printArray:
.LFB42:
	.cfi_startproc
	endbr64
	testl	%esi, %esi
	jle	.L58
	leal	-1(%rsi), %eax
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	leaq	4(%rdi,%rax,4), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	leaq	.LC0(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movq	%rdi, %rbx
	jmp	.L55
	.p2align 4,,10
	.p2align 3
.L56:
	movl	$32, %edi
	call	putchar@PLT
.L55:
	movl	(%rbx), %edx
	movq	%rbp, %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	addq	$4, %rbx
	call	__printf_chk@PLT
	cmpq	%r12, %rbx
	jne	.L56
	popq	%rbx
	.cfi_restore 3
	.cfi_def_cfa_offset 24
	movl	$10, %edi
	popq	%rbp
	.cfi_restore 6
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_restore 12
	.cfi_def_cfa_offset 8
	jmp	putchar@PLT
	.p2align 4,,10
	.p2align 3
.L58:
	movl	$10, %edi
	jmp	putchar@PLT
	.cfi_endproc
.LFE42:
	.size	printArray, .-printArray
	.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	countingSort
	.type	countingSort, @function
countingSort:
.LFB40:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movl	%ecx, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movq	%rsi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	movq	%rdi, %rbp
	leal	1(%rcx), %edi
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movslq	%edi, %rdi
	movl	%edx, %ebx
	salq	$2, %rdi
	subq	$8, %rsp
	.cfi_def_cfa_offset 48
	call	malloc@PLT
	movq	%rax, %rcx
	testl	%r13d, %r13d
	js	.L5
	movslq	%r13d, %rax
	movq	%rcx, %rdi
	xorl	%esi, %esi
	leaq	4(,%rax,4), %rdx
	call	memset@PLT
	movq	%rax, %rcx
.L5:
	testl	%ebx, %ebx
	jle	.L23
	leal	-1(%rbx), %esi
	movq	%rbp, %rax
	movq	%rsi, %rdx
	leaq	4(%rbp,%rsi,4), %rdi
	.p2align 4,,10
	.p2align 3
.L6:
	movslq	(%rax), %rsi
	addq	$4, %rax
	addl	$1, (%rcx,%rsi,4)
	cmpq	%rax, %rdi
	jne	.L6
	testl	%r13d, %r13d
	jle	.L10
.L8:
	movl	(%rcx), %esi
	movl	$1, %eax
	.p2align 4,,10
	.p2align 3
.L11:
	addl	(%rcx,%rax,4), %esi
	movl	%esi, (%rcx,%rax,4)
	addq	$1, %rax
	cmpl	%eax, %r13d
	jge	.L11
	testl	%edx, %edx
	js	.L1
.L10:
	movslq	%edx, %rdx
	.p2align 4,,10
	.p2align 3
.L13:
	movslq	0(%rbp,%rdx,4), %rax
	subq	$1, %rdx
	leaq	(%rcx,%rax,4), %rsi
	movq	%rax, %rdi
	movslq	(%rsi), %r8
	movq	%r8, %rax
	movl	%edi, -4(%r12,%r8,4)
	subl	$1, %eax
	movl	%eax, (%rsi)
	testl	%edx, %edx
	jns	.L13
.L1:
	addq	$8, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.p2align 4,,10
	.p2align 3
.L23:
	.cfi_restore_state
	leal	-1(%rbx), %edx
	testl	%r13d, %r13d
	jg	.L8
	jmp	.L1
	.cfi_endproc
.LFE40:
	.size	countingSort, .-countingSort
	.p2align 4
	.globl	countMinimumCost
	.type	countMinimumCost, @function
countMinimumCost:
.LFB41:
	.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
	movslq	%edx, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rsi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%rdi, %rbp
	leaq	0(,%r13,4), %rdi
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$8, %rsp
	.cfi_def_cfa_offset 64
	call	malloc@PLT
	movl	0(%rbp), %r11d
	testl	%r13d, %r13d
	jle	.L25
	movq	%rax, %rsi
	movq	%r13, %rbx
	movl	%r11d, %edx
	movl	%r13d, %edi
	xorl	%eax, %eax
	.p2align 4,,10
	.p2align 3
.L26:
	cmpl	%edx, %r11d
	movl	$1, %ecx
	cmovg	%edx, %r11d
	cmpl	%edx, (%r12,%rax,4)
	je	.L28
	cmpl	%edi, %ebx
	jne	.L44
	movl	%eax, %edi
.L44:
	xorl	%ecx, %ecx
.L28:
	movl	%ecx, (%rsi,%rax,4)
	addq	$1, %rax
	cmpq	%rax, %r13
	je	.L29
	movl	0(%rbp,%rax,4), %edx
	jmp	.L26
.L29:
	cmpl	%ebx, %edi
	jge	.L25
	movslq	%edi, %r13
	xorl	%r14d, %r14d
	salq	$2, %r13
	jmp	.L37
	.p2align 4,,10
	.p2align 3
.L30:
	addq	$4, %r13
	cmpl	%edi, %ebx
	je	.L24
.L37:
	movl	(%rsi,%r13), %r9d
	movslq	%edi, %rdx
	addl	$1, %edi
	testl	%r9d, %r9d
	jne	.L30
	movl	0(%rbp,%r13), %r8d
	movl	$1, %r10d
	movl	%r8d, %eax
	.p2align 4,,10
	.p2align 3
.L35:
	addl	%eax, %r9d
	cmpl	%eax, %r8d
	movl	$1, (%rsi,%rdx,4)
	cmovg	%eax, %r8d
	cmpl	%edi, %ebx
	jle	.L40
	movl	(%r12,%rdx,4), %r15d
	movslq	%edi, %rax
	jmp	.L33
	.p2align 4,,10
	.p2align 3
.L32:
	addq	$1, %rax
	leal	1(%rcx), %edx
	cmpl	%eax, %ebx
	jle	.L31
.L33:
	movl	%eax, %ecx
	movl	%eax, %edx
	cmpl	%r15d, 0(%rbp,%rax,4)
	jne	.L32
	cmpl	$0, (%rsi,%rax,4)
	jne	.L32
.L31:
	cmpl	%edx, %ebx
	je	.L34
	movslq	%edx, %rdx
	addl	$1, %r10d
	movl	0(%rbp,%rdx,4), %eax
	jmp	.L35
.L34:
	subl	$1, %r10d
	movl	%r8d, %edx
	subl	%r8d, %r9d
	addl	%r11d, %r8d
	imull	%r10d, %edx
	imull	%r11d, %r10d
	addl	%r9d, %edx
	leal	(%r10,%r9), %eax
	leal	(%r14,%rdx), %ecx
	leal	(%rax,%r8,2), %eax
	addl	%eax, %r14d
	cmpl	%eax, %edx
	cmovl	%ecx, %r14d
	addq	$4, %r13
	cmpl	%edi, %ebx
	jne	.L37
.L24:
	addq	$8, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	movl	%r14d, %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
.L40:
	.cfi_restore_state
	movl	%edi, %edx
	jmp	.L31
.L25:
	xorl	%r14d, %r14d
	jmp	.L24
	.cfi_endproc
.LFE41:
	.size	countMinimumCost, .-countMinimumCost
	.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:
.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
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	leaq	.LC0(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%r13, %rdi
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	leaq	20(%rsp), %rsi
	call	__isoc99_scanf@PLT
	movslq	20(%rsp), %rbp
	movl	%ebp, 12(%rsp)
	salq	$2, %rbp
	movq	%rbp, %rdi
	call	malloc@PLT
	movq	%rbp, %rdi
	movq	%rax, %r14
	call	malloc@PLT
	movl	12(%rsp), %edx
	movq	%rax, %r15
	testl	%edx, %edx
	jle	.L49
	movq	%r14, %rbx
	xorl	%r12d, %r12d
	xorl	%ebp, %ebp
	.p2align 4,,10
	.p2align 3
.L47:
	movq	%rbx, %rsi
	xorl	%eax, %eax
	movq	%r13, %rdi
	call	__isoc99_scanf@PLT
	movl	(%rbx), %eax
	movl	20(%rsp), %edx
	cmpl	%eax, %r12d
	cmovl	%eax, %r12d
	addl	$1, %ebp
	addq	$4, %rbx
	cmpl	%ebp, %edx
	jg	.L47
.L46:
	movl	%r12d, %ecx
	movq	%r15, %rsi
	movq	%r14, %rdi
	call	countingSort
	movl	20(%rsp), %edx
	movq	%r15, %rsi
	movq	%r14, %rdi
	call	countMinimumCost
	leaq	.LC1(%rip), %rsi
	movl	$1, %edi
	movl	%eax, %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	24(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L52
	addq	$40, %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
.L49:
	.cfi_restore_state
	xorl	%r12d, %r12d
	jmp	.L46
.L52:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE39:
	.size	main, .-main
	.text
	.p2align 4
	.globl	printArray
	.type	printArray, @function
printArray:
.LFB42:
	.cfi_startproc
	endbr64
	testl	%esi, %esi
	jle	.L58
	leal	-1(%rsi), %eax
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	leaq	4(%rdi,%rax,4), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	leaq	.LC0(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movq	%rdi, %rbx
	jmp	.L55
	.p2align 4,,10
	.p2align 3
.L56:
	movl	$32, %edi
	call	putchar@PLT
.L55:
	movl	(%rbx), %edx
	movq	%rbp, %rsi
	movl	$1, %edi
	xorl	%eax, %eax
	addq	$4, %rbx
	call	__printf_chk@PLT
	cmpq	%r12, %rbx
	jne	.L56
	popq	%rbx
	.cfi_restore 3
	.cfi_def_cfa_offset 24
	movl	$10, %edi
	popq	%rbp
	.cfi_restore 6
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_restore 12
	.cfi_def_cfa_offset 8
	jmp	putchar@PLT
	.p2align 4,,10
	.p2align 3
.L58:
	movl	$10, %edi
	jmp	putchar@PLT
	.cfi_endproc
.LFE42:
	.size	printArray, .-printArray
	.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 CHECK printf("check\n");
void countingSort(int*,int*,int,int);
int countMinimumCost(int*,int*,int);
void printArray(int*,int);
int main(void)
{
  int i;//counter
  int n;//length of array
  int wholeMax=0;//maximum value of array
  int *arr;//array sorted by minimum cost sort
  int *sortedArr;//array sorted by counting sort
  int cost;
  scanf("%d",&n);
  arr=(int*)malloc(sizeof(int)*n);
  sortedArr=(int*)malloc(sizeof(int)*n);
  for(i=0;i<n;i++)
    {
      scanf("%d",&arr[i]);
      if(wholeMax<arr[i]) wholeMax=arr[i];
    }
  countingSort(arr,sortedArr,n,wholeMax);
  cost=countMinimumCost(arr,sortedArr,n);
  printf("%d\n",cost);
  return 0;
}
void countingSort(int *arr,int *sortedArr,int n,int max)
{
  int i;//counter
  int *countArr=(int*)malloc(sizeof(int)*(max+1));
  for(i=0;i<max+1;i++) countArr[i]=0;
  for(i=0;i<n;i++) countArr[arr[i]]++;
  for(i=1;i<max+1;i++) countArr[i]+=countArr[i-1];
  for(i=n-1;i>=0;i--)
    {
      sortedArr[countArr[arr[i]]-1]=arr[i];
      countArr[arr[i]]--;
    }
}
int countMinimumCost(int *arr,int *sortedArr,int n)
{
  int i;//counter
  int *isSortedArr=(int*)malloc(sizeof(int)*n);
  int begin;//first index that is not sorted yet
  int index;//index pointing now
  int count;//length of loop
  int sum;//sum of loop
  int min;//minimum value among loop
  int wholeMin;//minimum value in the array
  int currentCost[2];//2 pattern of sorting cost in one loop
  int sumCost=0;//sum of whole cost;
  //init isSortedArr
  wholeMin=arr[0];
  begin=n;
  for(i=0;i<n;i++)
    {
      if(arr[i]==sortedArr[i]) isSortedArr[i]=1;
      else isSortedArr[i]=0;
      if(wholeMin>arr[i]) wholeMin=arr[i];
      if(isSortedArr[i]==0&&begin==n) begin=i;
    }
  
  for(;begin<n;begin++)
    {
      if(isSortedArr[begin]==0)
	{
	  index=begin;
	  sum=0;
	  min=arr[index];
	  for(count=1;;count++)
	    {
	      isSortedArr[index]=1;
	      sum+=arr[index];
	      if(min>arr[index]) min=arr[index];
	      for(i=begin+1;i<n;i++)
		{
		  if(arr[i]==sortedArr[index]&&isSortedArr[i]==0) break;
		}
	      if(i==n) break;
	      index=i;
	    }
	  currentCost[0]=sum-min+min*(count-1);
	  currentCost[1]=(wholeMin+min)*2+(sum-min+wholeMin*(count-1));
	  if(currentCost[0]<currentCost[1]) sumCost+=currentCost[0];
	  else sumCost+=currentCost[1];
	}
    }
  return sumCost;
}
void printArray(int *arr,int n)
{
  int i;//counter
  for(i=0;i<n;i++)
    {
      if(i>0) printf(" ");
      printf("%d",arr[i]);
    }
  printf("\n");
}


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>
#define CHECK printf("check\n");
void countingSort(int*,int*,int,int);
int countMinimumCost(int*,int*,int);
void printArray(int*,int);
int main(void)
{
  int i;//counter
  int n;//length of array
  int wholeMax=0;//maximum value of array
  int *arr;//array sorted by minimum cost sort
  int *sortedArr;//array sorted by counting sort
  int cost;
  scanf("%d",&n);
  arr=(int*)malloc(sizeof(int)*n);
  sortedArr=(int*)malloc(sizeof(int)*n);
  for(i=0;i<n;i++)
    {
      scanf("%d",&arr[i]);
      if(wholeMax<arr[i]) wholeMax=arr[i];
    }
  countingSort(arr,sortedArr,n,wholeMax);
  cost=countMinimumCost(arr,sortedArr,n);
  printf("%d\n",cost);
  return 0;
}
void countingSort(int *arr,int *sortedArr,int n,int max)
{
  int i;//counter
  int *countArr=(int*)malloc(sizeof(int)*(max+1));
  for(i=0;i<max+1;i++) countArr[i]=0;
  for(i=0;i<n;i++) countArr[arr[i]]++;
  for(i=1;i<max+1;i++) countArr[i]+=countArr[i-1];
  for(i=n-1;i>=0;i--)
    {
      sortedArr[countArr[arr[i]]-1]=arr[i];
      countArr[arr[i]]--;
    }
}
int countMinimumCost(int *arr,int *sortedArr,int n)
{
  int i;//counter
  int *isSortedArr=(int*)malloc(sizeof(int)*n);
  int begin;//first index that is not sorted yet
  int index;//index pointing now
  int count;//length of loop
  int sum;//sum of loop
  int min;//minimum value among loop
  int wholeMin;//minimum value in the array
  int currentCost[2];//2 pattern of sorting cost in one loop
  int sumCost=0;//sum of whole cost;
  //init isSortedArr
  wholeMin=arr[0];
  begin=n;
  for(i=0;i<n;i++)
    {
      if(arr[i]==sortedArr[i]) isSortedArr[i]=1;
      else isSortedArr[i]=0;
      if(wholeMin>arr[i]) wholeMin=arr[i];
      if(isSortedArr[i]==0&&begin==n) begin=i;
    }
  
  for(;begin<n;begin++)
    {
      if(isSortedArr[begin]==0)
	{
	  index=begin;
	  sum=0;
	  min=arr[index];
	  for(count=1;;count++)
	    {
	      isSortedArr[index]=1;
	      sum+=arr[index];
	      if(min>arr[index]) min=arr[index];
	      for(i=begin+1;i<n;i++)
		{
		  if(arr[i]==sortedArr[index]&&isSortedArr[i]==0) break;
		}
	      if(i==n) break;
	      index=i;
	    }
	  currentCost[0]=sum-min+min*(count-1);
	  currentCost[1]=(wholeMin+min)*2+(sum-min+wholeMin*(count-1));
	  if(currentCost[0]<currentCost[1]) sumCost+=currentCost[0];
	  else sumCost+=currentCost[1];
	}
    }
  return sumCost;
}
void printArray(int *arr,int n)
{
  int i;//counter
  for(i=0;i<n;i++)
    {
      if(i>0) printf(" ");
      printf("%d",arr[i]);
    }
  printf("\n");
}

```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.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	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -32(%rbp)
	leaq	-40(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-40(%rbp), %eax
	cltq
	salq	$2, %rax
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -24(%rbp)
	movl	-40(%rbp), %eax
	cltq
	salq	$2, %rax
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -16(%rbp)
	movl	$0, -36(%rbp)
	jmp	.L2
.L4:
	movl	-36(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-36(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	cmpl	%eax, -32(%rbp)
	jge	.L3
	movl	-36(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, -32(%rbp)
.L3:
	addl	$1, -36(%rbp)
.L2:
	movl	-40(%rbp), %eax
	cmpl	%eax, -36(%rbp)
	jl	.L4
	movl	-40(%rbp), %edx
	movl	-32(%rbp), %ecx
	movq	-16(%rbp), %rsi
	movq	-24(%rbp), %rax
	movq	%rax, %rdi
	call	countingSort
	movl	-40(%rbp), %edx
	movq	-16(%rbp), %rcx
	movq	-24(%rbp), %rax
	movq	%rcx, %rsi
	movq	%rax, %rdi
	call	countMinimumCost
	movl	%eax, -28(%rbp)
	movl	-28(%rbp), %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	.L6
	call	__stack_chk_fail@PLT
.L6:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	main, .-main
	.globl	countingSort
	.type	countingSort, @function
countingSort:
.LFB7:
	.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, -24(%rbp)
	movq	%rsi, -32(%rbp)
	movl	%edx, -36(%rbp)
	movl	%ecx, -40(%rbp)
	movl	-40(%rbp), %eax
	addl	$1, %eax
	cltq
	salq	$2, %rax
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -8(%rbp)
	movl	$0, -12(%rbp)
	jmp	.L8
.L9:
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-8(%rbp), %rax
	addq	%rdx, %rax
	movl	$0, (%rax)
	addl	$1, -12(%rbp)
.L8:
	movl	-40(%rbp), %eax
	cmpl	-12(%rbp), %eax
	jge	.L9
	movl	$0, -12(%rbp)
	jmp	.L10
.L11:
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-8(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	addl	$1, %edx
	movl	%edx, (%rax)
	addl	$1, -12(%rbp)
.L10:
	movl	-12(%rbp), %eax
	cmpl	-36(%rbp), %eax
	jl	.L11
	movl	$1, -12(%rbp)
	jmp	.L12
.L13:
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-8(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %ecx
	movl	-12(%rbp), %eax
	cltq
	salq	$2, %rax
	leaq	-4(%rax), %rdx
	movq	-8(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rsi
	movq	-8(%rbp), %rax
	addq	%rsi, %rax
	addl	%ecx, %edx
	movl	%edx, (%rax)
	addl	$1, -12(%rbp)
.L12:
	movl	-40(%rbp), %eax
	cmpl	-12(%rbp), %eax
	jge	.L13
	movl	-36(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -12(%rbp)
	jmp	.L14
.L15:
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	-12(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	movq	-24(%rbp), %rdx
	addq	%rcx, %rdx
	movl	(%rdx), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	movq	-8(%rbp), %rdx
	addq	%rcx, %rdx
	movl	(%rdx), %edx
	movslq	%edx, %rdx
	salq	$2, %rdx
	leaq	-4(%rdx), %rcx
	movq	-32(%rbp), %rdx
	addq	%rcx, %rdx
	movl	(%rax), %eax
	movl	%eax, (%rdx)
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-8(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	subl	$1, %edx
	movl	%edx, (%rax)
	subl	$1, -12(%rbp)
.L14:
	cmpl	$0, -12(%rbp)
	jns	.L15
	nop
	nop
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	countingSort, .-countingSort
	.globl	countMinimumCost
	.type	countMinimumCost, @function
countMinimumCost:
.LFB8:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$96, %rsp
	movq	%rdi, -72(%rbp)
	movq	%rsi, -80(%rbp)
	movl	%edx, -84(%rbp)
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	-84(%rbp), %eax
	cltq
	salq	$2, %rax
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -24(%rbp)
	movl	$0, -28(%rbp)
	movq	-72(%rbp), %rax
	movl	(%rax), %eax
	movl	%eax, -32(%rbp)
	movl	-84(%rbp), %eax
	movl	%eax, -52(%rbp)
	movl	$0, -56(%rbp)
	jmp	.L17
.L22:
	movl	-56(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-72(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-56(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	movq	-80(%rbp), %rax
	addq	%rcx, %rax
	movl	(%rax), %eax
	cmpl	%eax, %edx
	jne	.L18
	movl	-56(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	$1, (%rax)
	jmp	.L19
.L18:
	movl	-56(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	$0, (%rax)
.L19:
	movl	-56(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-72(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	cmpl	%eax, -32(%rbp)
	jle	.L20
	movl	-56(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-72(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, -32(%rbp)
.L20:
	movl	-56(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	testl	%eax, %eax
	jne	.L21
	movl	-52(%rbp), %eax
	cmpl	-84(%rbp), %eax
	jne	.L21
	movl	-56(%rbp), %eax
	movl	%eax, -52(%rbp)
.L21:
	addl	$1, -56(%rbp)
.L17:
	movl	-56(%rbp), %eax
	cmpl	-84(%rbp), %eax
	jl	.L22
	jmp	.L23
.L34:
	movl	-52(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	testl	%eax, %eax
	jne	.L24
	movl	-52(%rbp), %eax
	movl	%eax, -48(%rbp)
	movl	$0, -40(%rbp)
	movl	-48(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-72(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, -36(%rbp)
	movl	$1, -44(%rbp)
.L32:
	movl	-48(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	$1, (%rax)
	movl	-48(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-72(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	addl	%eax, -40(%rbp)
	movl	-48(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-72(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	cmpl	%eax, -36(%rbp)
	jle	.L25
	movl	-48(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-72(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, -36(%rbp)
.L25:
	movl	-52(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -56(%rbp)
	jmp	.L26
.L29:
	movl	-56(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-72(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-48(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	movq	-80(%rbp), %rax
	addq	%rcx, %rax
	movl	(%rax), %eax
	cmpl	%eax, %edx
	jne	.L27
	movl	-56(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	testl	%eax, %eax
	je	.L38
.L27:
	addl	$1, -56(%rbp)
.L26:
	movl	-56(%rbp), %eax
	cmpl	-84(%rbp), %eax
	jl	.L29
	jmp	.L28
.L38:
	nop
.L28:
	movl	-56(%rbp), %eax
	cmpl	-84(%rbp), %eax
	je	.L39
	movl	-56(%rbp), %eax
	movl	%eax, -48(%rbp)
	addl	$1, -44(%rbp)
	jmp	.L32
.L39:
	nop
	movl	-40(%rbp), %eax
	subl	-36(%rbp), %eax
	movl	%eax, %edx
	movl	-44(%rbp), %eax
	subl	$1, %eax
	imull	-36(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, -16(%rbp)
	movl	-32(%rbp), %edx
	movl	-36(%rbp), %eax
	addl	%edx, %eax
	leal	(%rax,%rax), %ecx
	movl	-40(%rbp), %eax
	subl	-36(%rbp), %eax
	movl	%eax, %edx
	movl	-44(%rbp), %eax
	subl	$1, %eax
	imull	-32(%rbp), %eax
	addl	%edx, %eax
	addl	%ecx, %eax
	movl	%eax, -12(%rbp)
	movl	-16(%rbp), %edx
	movl	-12(%rbp), %eax
	cmpl	%eax, %edx
	jge	.L33
	movl	-16(%rbp), %eax
	addl	%eax, -28(%rbp)
	jmp	.L24
.L33:
	movl	-12(%rbp), %eax
	addl	%eax, -28(%rbp)
.L24:
	addl	$1, -52(%rbp)
.L23:
	movl	-52(%rbp), %eax
	cmpl	-84(%rbp), %eax
	jl	.L34
	movl	-28(%rbp), %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L36
	call	__stack_chk_fail@PLT
.L36:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.size	countMinimumCost, .-countMinimumCost
	.globl	printArray
	.type	printArray, @function
printArray:
.LFB9:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$32, %rsp
	movq	%rdi, -24(%rbp)
	movl	%esi, -28(%rbp)
	movl	$0, -4(%rbp)
	jmp	.L41
.L43:
	cmpl	$0, -4(%rbp)
	jle	.L42
	movl	$32, %edi
	call	putchar@PLT
.L42:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	addl	$1, -4(%rbp)
.L41:
	movl	-4(%rbp), %eax
	cmpl	-28(%rbp), %eax
	jl	.L43
	movl	$10, %edi
	call	putchar@PLT
	nop
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE9:
	.size	printArray, .-printArray
	.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
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%d\n"
	.text
	.globl	main
	.type	main, @function
main:
.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	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	$0, -32(%rbp)
	leaq	-40(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-40(%rbp), %eax
	cltq
	salq	$2, %rax
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -24(%rbp)
	movl	-40(%rbp), %eax
	cltq
	salq	$2, %rax
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -16(%rbp)
	movl	$0, -36(%rbp)
	jmp	.L2
.L4:
	movl	-36(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	-36(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	cmpl	%eax, -32(%rbp)
	jge	.L3
	movl	-36(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, -32(%rbp)
.L3:
	addl	$1, -36(%rbp)
.L2:
	movl	-40(%rbp), %eax
	cmpl	%eax, -36(%rbp)
	jl	.L4
	movl	-40(%rbp), %edx
	movl	-32(%rbp), %ecx
	movq	-16(%rbp), %rsi
	movq	-24(%rbp), %rax
	movq	%rax, %rdi
	call	countingSort
	movl	-40(%rbp), %edx
	movq	-16(%rbp), %rcx
	movq	-24(%rbp), %rax
	movq	%rcx, %rsi
	movq	%rax, %rdi
	call	countMinimumCost
	movl	%eax, -28(%rbp)
	movl	-28(%rbp), %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	.L6
	call	__stack_chk_fail@PLT
.L6:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE6:
	.size	main, .-main
	.globl	countingSort
	.type	countingSort, @function
countingSort:
.LFB7:
	.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, -24(%rbp)
	movq	%rsi, -32(%rbp)
	movl	%edx, -36(%rbp)
	movl	%ecx, -40(%rbp)
	movl	-40(%rbp), %eax
	addl	$1, %eax
	cltq
	salq	$2, %rax
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -8(%rbp)
	movl	$0, -12(%rbp)
	jmp	.L8
.L9:
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-8(%rbp), %rax
	addq	%rdx, %rax
	movl	$0, (%rax)
	addl	$1, -12(%rbp)
.L8:
	movl	-40(%rbp), %eax
	cmpl	-12(%rbp), %eax
	jge	.L9
	movl	$0, -12(%rbp)
	jmp	.L10
.L11:
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-8(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	addl	$1, %edx
	movl	%edx, (%rax)
	addl	$1, -12(%rbp)
.L10:
	movl	-12(%rbp), %eax
	cmpl	-36(%rbp), %eax
	jl	.L11
	movl	$1, -12(%rbp)
	jmp	.L12
.L13:
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-8(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %ecx
	movl	-12(%rbp), %eax
	cltq
	salq	$2, %rax
	leaq	-4(%rax), %rdx
	movq	-8(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rsi
	movq	-8(%rbp), %rax
	addq	%rsi, %rax
	addl	%ecx, %edx
	movl	%edx, (%rax)
	addl	$1, -12(%rbp)
.L12:
	movl	-40(%rbp), %eax
	cmpl	-12(%rbp), %eax
	jge	.L13
	movl	-36(%rbp), %eax
	subl	$1, %eax
	movl	%eax, -12(%rbp)
	jmp	.L14
.L15:
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	-12(%rbp), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	movq	-24(%rbp), %rdx
	addq	%rcx, %rdx
	movl	(%rdx), %edx
	movslq	%edx, %rdx
	leaq	0(,%rdx,4), %rcx
	movq	-8(%rbp), %rdx
	addq	%rcx, %rdx
	movl	(%rdx), %edx
	movslq	%edx, %rdx
	salq	$2, %rdx
	leaq	-4(%rdx), %rcx
	movq	-32(%rbp), %rdx
	addq	%rcx, %rdx
	movl	(%rax), %eax
	movl	%eax, (%rdx)
	movl	-12(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-8(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	subl	$1, %edx
	movl	%edx, (%rax)
	subl	$1, -12(%rbp)
.L14:
	cmpl	$0, -12(%rbp)
	jns	.L15
	nop
	nop
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE7:
	.size	countingSort, .-countingSort
	.globl	countMinimumCost
	.type	countMinimumCost, @function
countMinimumCost:
.LFB8:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$96, %rsp
	movq	%rdi, -72(%rbp)
	movq	%rsi, -80(%rbp)
	movl	%edx, -84(%rbp)
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	-84(%rbp), %eax
	cltq
	salq	$2, %rax
	movq	%rax, %rdi
	call	malloc@PLT
	movq	%rax, -24(%rbp)
	movl	$0, -28(%rbp)
	movq	-72(%rbp), %rax
	movl	(%rax), %eax
	movl	%eax, -32(%rbp)
	movl	-84(%rbp), %eax
	movl	%eax, -52(%rbp)
	movl	$0, -56(%rbp)
	jmp	.L17
.L22:
	movl	-56(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-72(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-56(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	movq	-80(%rbp), %rax
	addq	%rcx, %rax
	movl	(%rax), %eax
	cmpl	%eax, %edx
	jne	.L18
	movl	-56(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	$1, (%rax)
	jmp	.L19
.L18:
	movl	-56(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	$0, (%rax)
.L19:
	movl	-56(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-72(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	cmpl	%eax, -32(%rbp)
	jle	.L20
	movl	-56(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-72(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, -32(%rbp)
.L20:
	movl	-56(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	testl	%eax, %eax
	jne	.L21
	movl	-52(%rbp), %eax
	cmpl	-84(%rbp), %eax
	jne	.L21
	movl	-56(%rbp), %eax
	movl	%eax, -52(%rbp)
.L21:
	addl	$1, -56(%rbp)
.L17:
	movl	-56(%rbp), %eax
	cmpl	-84(%rbp), %eax
	jl	.L22
	jmp	.L23
.L34:
	movl	-52(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	testl	%eax, %eax
	jne	.L24
	movl	-52(%rbp), %eax
	movl	%eax, -48(%rbp)
	movl	$0, -40(%rbp)
	movl	-48(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-72(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, -36(%rbp)
	movl	$1, -44(%rbp)
.L32:
	movl	-48(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	$1, (%rax)
	movl	-48(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-72(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	addl	%eax, -40(%rbp)
	movl	-48(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-72(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	cmpl	%eax, -36(%rbp)
	jle	.L25
	movl	-48(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-72(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, -36(%rbp)
.L25:
	movl	-52(%rbp), %eax
	addl	$1, %eax
	movl	%eax, -56(%rbp)
	jmp	.L26
.L29:
	movl	-56(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-72(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-48(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rcx
	movq	-80(%rbp), %rax
	addq	%rcx, %rax
	movl	(%rax), %eax
	cmpl	%eax, %edx
	jne	.L27
	movl	-56(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	testl	%eax, %eax
	je	.L38
.L27:
	addl	$1, -56(%rbp)
.L26:
	movl	-56(%rbp), %eax
	cmpl	-84(%rbp), %eax
	jl	.L29
	jmp	.L28
.L38:
	nop
.L28:
	movl	-56(%rbp), %eax
	cmpl	-84(%rbp), %eax
	je	.L39
	movl	-56(%rbp), %eax
	movl	%eax, -48(%rbp)
	addl	$1, -44(%rbp)
	jmp	.L32
.L39:
	nop
	movl	-40(%rbp), %eax
	subl	-36(%rbp), %eax
	movl	%eax, %edx
	movl	-44(%rbp), %eax
	subl	$1, %eax
	imull	-36(%rbp), %eax
	addl	%edx, %eax
	movl	%eax, -16(%rbp)
	movl	-32(%rbp), %edx
	movl	-36(%rbp), %eax
	addl	%edx, %eax
	leal	(%rax,%rax), %ecx
	movl	-40(%rbp), %eax
	subl	-36(%rbp), %eax
	movl	%eax, %edx
	movl	-44(%rbp), %eax
	subl	$1, %eax
	imull	-32(%rbp), %eax
	addl	%edx, %eax
	addl	%ecx, %eax
	movl	%eax, -12(%rbp)
	movl	-16(%rbp), %edx
	movl	-12(%rbp), %eax
	cmpl	%eax, %edx
	jge	.L33
	movl	-16(%rbp), %eax
	addl	%eax, -28(%rbp)
	jmp	.L24
.L33:
	movl	-12(%rbp), %eax
	addl	%eax, -28(%rbp)
.L24:
	addl	$1, -52(%rbp)
.L23:
	movl	-52(%rbp), %eax
	cmpl	-84(%rbp), %eax
	jl	.L34
	movl	-28(%rbp), %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L36
	call	__stack_chk_fail@PLT
.L36:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE8:
	.size	countMinimumCost, .-countMinimumCost
	.globl	printArray
	.type	printArray, @function
printArray:
.LFB9:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$32, %rsp
	movq	%rdi, -24(%rbp)
	movl	%esi, -28(%rbp)
	movl	$0, -4(%rbp)
	jmp	.L41
.L43:
	cmpl	$0, -4(%rbp)
	jle	.L42
	movl	$32, %edi
	call	putchar@PLT
.L42:
	movl	-4(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-24(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %eax
	movl	%eax, %esi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	printf@PLT
	addl	$1, -4(%rbp)
.L41:
	movl	-4(%rbp), %eax
	cmpl	-28(%rbp), %eax
	jl	.L43
	movl	$10, %edi
	call	putchar@PLT
	nop
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE9:
	.size	printArray, .-printArray
	.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:
