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>
void RSort(int *,int,int);
void Reverse(int *,int,int,int);
double sum=0;
int main()
{
  int i,n;
  int N[200000];
   
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&N[i]);
  }
 
  RSort(N,0,n);
 
 /* for(i=0;i<n;i++){
    printf("%d ",N[i]);
  }*/
   
  printf("%.0f\n",sum);
 
  return 0;
}
 
void RSort(int *A,int left,int right)
{
  int mid,temp;
  if(left+1<right){
    mid=(left+right)/2;
    RSort(A,left,mid);
    RSort(A,mid,right);
    Reverse(A,left,mid,right);
  }
}
 
void Reverse(int *A,int left,int mid,int right)
{
  int k,n1,n2,L[200000],R[200000],i,j;
  n1=mid-left;
  n2=right-mid;
  for(i=0;i<n1;i++){
    L[i]=A[left+i];
  }
  for(i=0;i<n2;i++){
    R[i]=A[mid+i];
  }
  L[n1]=1000000000;
  R[n2]=1000000000;
  i=0;
  j=0;
  for(k=left;k<right;k++){
    if(L[i]<R[j]){
      A[k]=L[i];
      i++;
    }
    else{
      A[k]=R[j];
      sum+=n1-i;
      j++;
    }
  }
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	sum
	.bss
	.align 8
	.type	sum, @object
	.size	sum, 8
sum:
	.zero	8
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%.0f\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	leaq	-798720(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$1312, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-800024(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -800020(%rbp)
	jmp	.L2
.L3:
	leaq	-800016(%rbp), %rdx
	movl	-800020(%rbp), %eax
	cltq
	salq	$2, %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -800020(%rbp)
.L2:
	movl	-800024(%rbp), %eax
	cmpl	%eax, -800020(%rbp)
	jl	.L3
	movl	-800024(%rbp), %edx
	leaq	-800016(%rbp), %rax
	movl	$0, %esi
	movq	%rax, %rdi
	call	RSort
	movq	sum(%rip), %rax
	movq	%rax, %xmm0
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$1, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L5
	call	__stack_chk_fail@PLT
.L5:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	main, .-main
	.globl	RSort
	.type	RSort, @function
RSort:
.LFB1:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$32, %rsp
	movq	%rdi, -24(%rbp)
	movl	%esi, -28(%rbp)
	movl	%edx, -32(%rbp)
	movl	-28(%rbp), %eax
	addl	$1, %eax
	cmpl	%eax, -32(%rbp)
	jle	.L8
	movl	-28(%rbp), %edx
	movl	-32(%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	-28(%rbp), %ecx
	movq	-24(%rbp), %rax
	movl	%ecx, %esi
	movq	%rax, %rdi
	call	RSort
	movl	-32(%rbp), %edx
	movl	-4(%rbp), %ecx
	movq	-24(%rbp), %rax
	movl	%ecx, %esi
	movq	%rax, %rdi
	call	RSort
	movl	-32(%rbp), %ecx
	movl	-4(%rbp), %edx
	movl	-28(%rbp), %esi
	movq	-24(%rbp), %rax
	movq	%rax, %rdi
	call	Reverse
.L8:
	nop
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.size	RSort, .-RSort
	.globl	Reverse
	.type	Reverse, @function
Reverse:
.LFB2:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	leaq	-1597440(%rsp), %r11
.LPSRL1:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL1
	subq	$2640, %rsp
	movq	%rdi, -1600056(%rbp)
	movl	%esi, -1600060(%rbp)
	movl	%edx, -1600064(%rbp)
	movl	%ecx, -1600068(%rbp)
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	-1600064(%rbp), %eax
	subl	-1600060(%rbp), %eax
	movl	%eax, -1600024(%rbp)
	movl	-1600068(%rbp), %eax
	subl	-1600064(%rbp), %eax
	movl	%eax, -1600020(%rbp)
	movl	$0, -1600032(%rbp)
	jmp	.L10
.L11:
	movl	-1600060(%rbp), %edx
	movl	-1600032(%rbp), %eax
	addl	%edx, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-1600056(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-1600032(%rbp), %eax
	cltq
	movl	%edx, -1600016(%rbp,%rax,4)
	addl	$1, -1600032(%rbp)
.L10:
	movl	-1600032(%rbp), %eax
	cmpl	-1600024(%rbp), %eax
	jl	.L11
	movl	$0, -1600032(%rbp)
	jmp	.L12
.L13:
	movl	-1600064(%rbp), %edx
	movl	-1600032(%rbp), %eax
	addl	%edx, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-1600056(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-1600032(%rbp), %eax
	cltq
	movl	%edx, -800016(%rbp,%rax,4)
	addl	$1, -1600032(%rbp)
.L12:
	movl	-1600032(%rbp), %eax
	cmpl	-1600020(%rbp), %eax
	jl	.L13
	movl	-1600024(%rbp), %eax
	cltq
	movl	$1000000000, -1600016(%rbp,%rax,4)
	movl	-1600020(%rbp), %eax
	cltq
	movl	$1000000000, -800016(%rbp,%rax,4)
	movl	$0, -1600032(%rbp)
	movl	$0, -1600028(%rbp)
	movl	-1600060(%rbp), %eax
	movl	%eax, -1600036(%rbp)
	jmp	.L14
.L17:
	movl	-1600032(%rbp), %eax
	cltq
	movl	-1600016(%rbp,%rax,4), %edx
	movl	-1600028(%rbp), %eax
	cltq
	movl	-800016(%rbp,%rax,4), %eax
	cmpl	%eax, %edx
	jge	.L15
	movl	-1600036(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-1600056(%rbp), %rax
	addq	%rax, %rdx
	movl	-1600032(%rbp), %eax
	cltq
	movl	-1600016(%rbp,%rax,4), %eax
	movl	%eax, (%rdx)
	addl	$1, -1600032(%rbp)
	jmp	.L16
.L15:
	movl	-1600036(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-1600056(%rbp), %rax
	addq	%rax, %rdx
	movl	-1600028(%rbp), %eax
	cltq
	movl	-800016(%rbp,%rax,4), %eax
	movl	%eax, (%rdx)
	movl	-1600024(%rbp), %eax
	subl	-1600032(%rbp), %eax
	pxor	%xmm1, %xmm1
	cvtsi2sdl	%eax, %xmm1
	movsd	sum(%rip), %xmm0
	addsd	%xmm1, %xmm0
	movsd	%xmm0, sum(%rip)
	addl	$1, -1600028(%rbp)
.L16:
	addl	$1, -1600036(%rbp)
.L14:
	movl	-1600036(%rbp), %eax
	cmpl	-1600068(%rbp), %eax
	jl	.L17
	nop
	movq	-8(%rbp), %rax
	subq	%fs:40, %rax
	je	.L18
	call	__stack_chk_fail@PLT
.L18:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE2:
	.size	Reverse, .-Reverse
	.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	Reverse
	.type	Reverse, @function
Reverse:
.LFB25:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	leaq	-1597440(%rsp), %r11
	.cfi_def_cfa 11, 1597496
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$2600, %rsp
	.cfi_def_cfa_offset 1600096
	movslq	%edx, %r13
	movl	%ecx, %ebx
	movq	%rdi, %r14
	movl	%esi, %r12d
	movq	%fs:40, %rax
	movq	%rax, 1600024(%rsp)
	xorl	%eax, %eax
	movl	%r13d, %ebp
	subl	%r13d, %ecx
	subl	%esi, %ebp
	testl	%ebp, %ebp
	jle	.L15
	movslq	%esi, %rax
	movslq	%ebp, %r15
	leaq	16(%rsp), %rdi
	movl	%ecx, 8(%rsp)
	leaq	0(,%r15,4), %rdx
	leaq	(%r14,%rax,4), %rsi
	call	memcpy@PLT
	movl	8(%rsp), %ecx
	testl	%ecx, %ecx
	jle	.L16
.L3:
	movslq	%ecx, %rcx
	leaq	800016(%rsp), %rdi
	leaq	(%r14,%r13,4), %rsi
	leaq	0(,%rcx,4), %rdx
	movq	%rcx, 8(%rsp)
	call	memcpy@PLT
	movq	8(%rsp), %rcx
.L4:
	movl	$1000000000, 16(%rsp,%r15,4)
	movl	$1000000000, 800016(%rsp,%rcx,4)
	cmpl	%ebx, %r12d
	jge	.L1
	subl	$1, %ebx
	movslq	%r12d, %rdx
	xorl	%edi, %edi
	subl	%r12d, %ebx
	leaq	(%r14,%rdx,4), %rax
	addq	%rdx, %rbx
	xorl	%edx, %edx
	leaq	4(%r14,%rbx,4), %r8
	jmp	.L10
	.p2align 4,,10
	.p2align 3
.L17:
	movl	%esi, (%rax)
	addq	$4, %rax
	addl	$1, %edx
	cmpq	%rax, %r8
	je	.L1
.L10:
	movslq	%edx, %rcx
	movl	16(%rsp,%rcx,4), %esi
	movslq	%edi, %rcx
	movl	800016(%rsp,%rcx,4), %ecx
	cmpl	%ecx, %esi
	jl	.L17
	movl	%ecx, (%rax)
	movl	%ebp, %ecx
	pxor	%xmm0, %xmm0
	addq	$4, %rax
	subl	%edx, %ecx
	addl	$1, %edi
	cvtsi2sdl	%ecx, %xmm0
	addsd	sum(%rip), %xmm0
	movsd	%xmm0, sum(%rip)
	cmpq	%rax, %r8
	jne	.L10
.L1:
	movq	1600024(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L18
	addq	$1600040, %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
.L15:
	.cfi_restore_state
	movslq	%ebp, %r15
	testl	%ecx, %ecx
	jg	.L3
	.p2align 4,,10
	.p2align 3
.L16:
	movslq	%ecx, %rcx
	jmp	.L4
.L18:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE25:
	.size	Reverse, .-Reverse
	.p2align 4
	.type	RSort.part.0, @function
RSort.part.0:
.LFB26:
	.cfi_startproc
	leal	(%rsi,%rdx), %eax
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movq	%rdi, %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movl	%edx, %r13d
	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
	leal	1(%rsi), %eax
	sarl	%r12d
	subq	$8, %rsp
	.cfi_def_cfa_offset 64
	cmpl	%eax, %r12d
	jg	.L35
	leal	1(%r12), %eax
	cmpl	%eax, %r13d
	jg	.L36
.L27:
	addq	$8, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	movl	%r13d, %ecx
	movl	%r12d, %edx
	movl	%ebp, %esi
	popq	%rbx
	.cfi_def_cfa_offset 48
	movq	%r15, %rdi
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	jmp	Reverse
	.p2align 4,,10
	.p2align 3
.L35:
	.cfi_restore_state
	leal	(%rsi,%r12), %edx
	movl	%edx, %r14d
	shrl	$31, %r14d
	addl	%edx, %r14d
	sarl	%r14d
	cmpl	%r14d, %eax
	jl	.L37
	leal	1(%r14), %eax
	cmpl	%eax, %r12d
	jg	.L38
.L24:
	movl	%r12d, %ecx
	movl	%r14d, %edx
	movl	%ebp, %esi
	movq	%r15, %rdi
	call	Reverse
	leal	1(%r12), %eax
	cmpl	%eax, %r13d
	jle	.L27
.L36:
	leal	0(%r13,%r12), %edx
	movl	%edx, %r14d
	shrl	$31, %r14d
	addl	%edx, %r14d
	sarl	%r14d
	cmpl	%r14d, %eax
	jl	.L39
.L28:
	leal	1(%r14), %eax
	cmpl	%eax, %r13d
	jg	.L40
.L31:
	movl	%r13d, %ecx
	movl	%r14d, %edx
	movl	%r12d, %esi
	movq	%r15, %rdi
	call	Reverse
	jmp	.L27
	.p2align 4,,10
	.p2align 3
.L37:
	leal	(%rsi,%r14), %edx
	movl	%edx, %ebx
	shrl	$31, %ebx
	addl	%edx, %ebx
	sarl	%ebx
	cmpl	%ebx, %eax
	jl	.L41
.L22:
	leal	1(%rbx), %eax
	cmpl	%eax, %r14d
	jg	.L42
.L23:
	movl	%r14d, %ecx
	movl	%ebx, %edx
	movl	%ebp, %esi
	movq	%r15, %rdi
	call	Reverse
	leal	1(%r14), %eax
	cmpl	%eax, %r12d
	jle	.L24
.L38:
	leal	(%r12,%r14), %edx
	movl	%edx, %ebx
	shrl	$31, %ebx
	addl	%edx, %ebx
	sarl	%ebx
	cmpl	%ebx, %eax
	jl	.L43
.L25:
	leal	1(%rbx), %eax
	cmpl	%eax, %r12d
	jg	.L44
.L26:
	movl	%r12d, %ecx
	movl	%ebx, %edx
	movl	%r14d, %esi
	movq	%r15, %rdi
	call	Reverse
	jmp	.L24
	.p2align 4,,10
	.p2align 3
.L40:
	leal	0(%r13,%r14), %edx
	movl	%edx, %ebx
	shrl	$31, %ebx
	addl	%edx, %ebx
	sarl	%ebx
	cmpl	%ebx, %eax
	jl	.L45
.L32:
	leal	1(%rbx), %eax
	cmpl	%eax, %r13d
	jg	.L46
.L33:
	movl	%r13d, %ecx
	movl	%ebx, %edx
	movl	%r14d, %esi
	movq	%r15, %rdi
	call	Reverse
	jmp	.L31
	.p2align 4,,10
	.p2align 3
.L39:
	leal	(%r12,%r14), %edx
	movl	%edx, %ebx
	shrl	$31, %ebx
	addl	%edx, %ebx
	sarl	%ebx
	cmpl	%ebx, %eax
	jl	.L47
.L29:
	leal	1(%rbx), %eax
	cmpl	%eax, %r14d
	jg	.L48
.L30:
	movl	%r14d, %ecx
	movl	%ebx, %edx
	movl	%r12d, %esi
	movq	%r15, %rdi
	call	Reverse
	jmp	.L28
	.p2align 4,,10
	.p2align 3
.L41:
	movl	%ebx, %edx
	call	RSort.part.0
	jmp	.L22
	.p2align 4,,10
	.p2align 3
.L44:
	movl	%r12d, %edx
	movl	%ebx, %esi
	movq	%r15, %rdi
	call	RSort.part.0
	jmp	.L26
	.p2align 4,,10
	.p2align 3
.L43:
	movl	%ebx, %edx
	movl	%r14d, %esi
	movq	%r15, %rdi
	call	RSort.part.0
	jmp	.L25
	.p2align 4,,10
	.p2align 3
.L48:
	movl	%r14d, %edx
	movl	%ebx, %esi
	movq	%r15, %rdi
	call	RSort.part.0
	jmp	.L30
	.p2align 4,,10
	.p2align 3
.L47:
	movl	%ebx, %edx
	movl	%r12d, %esi
	movq	%r15, %rdi
	call	RSort.part.0
	jmp	.L29
	.p2align 4,,10
	.p2align 3
.L46:
	movl	%r13d, %edx
	movl	%ebx, %esi
	movq	%r15, %rdi
	call	RSort.part.0
	jmp	.L33
	.p2align 4,,10
	.p2align 3
.L45:
	movl	%ebx, %edx
	movl	%r14d, %esi
	movq	%r15, %rdi
	call	RSort.part.0
	jmp	.L32
	.p2align 4,,10
	.p2align 3
.L42:
	movl	%r14d, %edx
	movl	%ebx, %esi
	movq	%r15, %rdi
	call	RSort.part.0
	jmp	.L23
	.cfi_endproc
.LFE26:
	.size	RSort.part.0, .-RSort.part.0
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d"
.LC1:
	.string	"%.0f\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	leaq	-798720(%rsp), %r11
	.cfi_def_cfa 11, 798760
.LPSRL1:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL1
	.cfi_def_cfa_register 7
	subq	$1320, %rsp
	.cfi_def_cfa_offset 800080
	leaq	.LC0(%rip), %r12
	movq	%r12, %rdi
	movq	%fs:40, %rax
	movq	%rax, 800024(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rsi
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %eax
	testl	%eax, %eax
	jle	.L50
	leaq	16(%rsp), %r13
	xorl	%ebx, %ebx
	movq	%r13, %rbp
	.p2align 4,,10
	.p2align 3
.L51:
	movq	%rbp, %rsi
	movq	%r12, %rdi
	xorl	%eax, %eax
	addl	$1, %ebx
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %edx
	addq	$4, %rbp
	cmpl	%ebx, %edx
	jg	.L51
	cmpl	$1, %edx
	jle	.L50
	xorl	%esi, %esi
	movq	%r13, %rdi
	call	RSort.part.0
.L50:
	movsd	sum(%rip), %xmm0
	movl	$1, %edi
	movl	$1, %eax
	leaq	.LC1(%rip), %rsi
	call	__printf_chk@PLT
	movq	800024(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L55
	addq	$800040, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 40
	xorl	%eax, %eax
	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
.L55:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE23:
	.size	main, .-main
	.text
	.p2align 4
	.globl	RSort
	.type	RSort, @function
RSort:
.LFB24:
	.cfi_startproc
	endbr64
	leal	1(%rsi), %eax
	cmpl	%edx, %eax
	jl	.L67
	ret
	.p2align 4,,10
	.p2align 3
.L67:
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movq	%rdi, %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movl	%edx, %r12d
	leal	(%rsi,%rdx), %edx
	movl	%edx, %r13d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	%esi, %ebp
	shrl	$31, %r13d
	addl	%edx, %r13d
	sarl	%r13d
	cmpl	%r13d, %eax
	jl	.L68
	leal	1(%r13), %eax
	cmpl	%eax, %r12d
	jg	.L69
.L61:
	movl	%r12d, %ecx
	movl	%r13d, %edx
	movl	%ebp, %esi
	movq	%r14, %rdi
	popq	%rbp
	.cfi_remember_state
	.cfi_restore 6
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_restore 12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_restore 13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_restore 14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_restore 15
	.cfi_def_cfa_offset 8
	jmp	Reverse
	.p2align 4,,10
	.p2align 3
.L68:
	.cfi_restore_state
	leal	(%rsi,%r13), %edx
	movl	%edx, %r15d
	shrl	$31, %r15d
	addl	%edx, %r15d
	sarl	%r15d
	cmpl	%r15d, %eax
	jl	.L70
.L59:
	leal	1(%r15), %eax
	cmpl	%eax, %r13d
	jg	.L71
.L60:
	movl	%r13d, %ecx
	movl	%r15d, %edx
	movl	%ebp, %esi
	movq	%r14, %rdi
	call	Reverse
	leal	1(%r13), %eax
	cmpl	%eax, %r12d
	jle	.L61
.L69:
	leal	(%r12,%r13), %edx
	movl	%edx, %r15d
	shrl	$31, %r15d
	addl	%edx, %r15d
	sarl	%r15d
	cmpl	%r15d, %eax
	jl	.L72
.L62:
	leal	1(%r15), %eax
	cmpl	%eax, %r12d
	jg	.L73
.L63:
	movl	%r12d, %ecx
	movl	%r15d, %edx
	movl	%r13d, %esi
	movq	%r14, %rdi
	call	Reverse
	jmp	.L61
	.p2align 4,,10
	.p2align 3
.L70:
	movl	%r15d, %edx
	call	RSort.part.0
	jmp	.L59
	.p2align 4,,10
	.p2align 3
.L73:
	movl	%r12d, %edx
	movl	%r15d, %esi
	movq	%r14, %rdi
	call	RSort.part.0
	jmp	.L63
	.p2align 4,,10
	.p2align 3
.L72:
	movl	%r15d, %edx
	movl	%r13d, %esi
	movq	%r14, %rdi
	call	RSort.part.0
	jmp	.L62
	.p2align 4,,10
	.p2align 3
.L71:
	movl	%r13d, %edx
	movl	%r15d, %esi
	movq	%r14, %rdi
	call	RSort.part.0
	jmp	.L60
	.cfi_endproc
.LFE24:
	.size	RSort, .-RSort
	.globl	sum
	.bss
	.align 8
	.type	sum, @object
	.size	sum, 8
sum:
	.zero	8
	.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	Reverse
	.type	Reverse, @function
Reverse:
.LFB25:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	leaq	-1597440(%rsp), %r11
	.cfi_def_cfa 11, 1597496
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$2600, %rsp
	.cfi_def_cfa_offset 1600096
	movslq	%edx, %r13
	movl	%ecx, %ebx
	movq	%rdi, %r14
	movl	%esi, %r12d
	movq	%fs:40, %rax
	movq	%rax, 1600024(%rsp)
	xorl	%eax, %eax
	movl	%r13d, %ebp
	subl	%r13d, %ecx
	subl	%esi, %ebp
	testl	%ebp, %ebp
	jle	.L15
	movslq	%esi, %rax
	movslq	%ebp, %r15
	leaq	16(%rsp), %rdi
	movl	%ecx, 8(%rsp)
	leaq	0(,%r15,4), %rdx
	leaq	(%r14,%rax,4), %rsi
	call	memcpy@PLT
	movl	8(%rsp), %ecx
	testl	%ecx, %ecx
	jle	.L16
.L3:
	movslq	%ecx, %rcx
	leaq	800016(%rsp), %rdi
	leaq	(%r14,%r13,4), %rsi
	leaq	0(,%rcx,4), %rdx
	movq	%rcx, 8(%rsp)
	call	memcpy@PLT
	movq	8(%rsp), %rcx
.L4:
	movl	$1000000000, 16(%rsp,%r15,4)
	movl	$1000000000, 800016(%rsp,%rcx,4)
	cmpl	%ebx, %r12d
	jge	.L1
	subl	$1, %ebx
	movslq	%r12d, %rdx
	xorl	%edi, %edi
	subl	%r12d, %ebx
	leaq	(%r14,%rdx,4), %rax
	addq	%rdx, %rbx
	xorl	%edx, %edx
	leaq	4(%r14,%rbx,4), %r8
	jmp	.L10
	.p2align 4,,10
	.p2align 3
.L17:
	movl	%esi, (%rax)
	addq	$4, %rax
	addl	$1, %edx
	cmpq	%rax, %r8
	je	.L1
.L10:
	movslq	%edx, %rcx
	movl	16(%rsp,%rcx,4), %esi
	movslq	%edi, %rcx
	movl	800016(%rsp,%rcx,4), %ecx
	cmpl	%ecx, %esi
	jl	.L17
	movl	%ecx, (%rax)
	movl	%ebp, %ecx
	pxor	%xmm0, %xmm0
	addq	$4, %rax
	subl	%edx, %ecx
	addl	$1, %edi
	cvtsi2sdl	%ecx, %xmm0
	addsd	sum(%rip), %xmm0
	movsd	%xmm0, sum(%rip)
	cmpq	%rax, %r8
	jne	.L10
.L1:
	movq	1600024(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L18
	addq	$1600040, %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
.L15:
	.cfi_restore_state
	movslq	%ebp, %r15
	testl	%ecx, %ecx
	jg	.L3
	.p2align 4,,10
	.p2align 3
.L16:
	movslq	%ecx, %rcx
	jmp	.L4
.L18:
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE25:
	.size	Reverse, .-Reverse
	.p2align 4
	.type	RSort.part.0, @function
RSort.part.0:
.LFB26:
	.cfi_startproc
	leal	(%rsi,%rdx), %eax
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movq	%rdi, %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movl	%edx, %r13d
	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
	leal	1(%rsi), %eax
	sarl	%r12d
	subq	$8, %rsp
	.cfi_def_cfa_offset 64
	cmpl	%eax, %r12d
	jg	.L35
	leal	1(%r12), %eax
	cmpl	%eax, %r13d
	jg	.L36
.L27:
	addq	$8, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 56
	movl	%r13d, %ecx
	movl	%r12d, %edx
	movl	%ebp, %esi
	popq	%rbx
	.cfi_def_cfa_offset 48
	movq	%r15, %rdi
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	jmp	Reverse
	.p2align 4,,10
	.p2align 3
.L35:
	.cfi_restore_state
	leal	(%rsi,%r12), %edx
	movl	%edx, %r14d
	shrl	$31, %r14d
	addl	%edx, %r14d
	sarl	%r14d
	cmpl	%r14d, %eax
	jl	.L37
	leal	1(%r14), %eax
	cmpl	%eax, %r12d
	jg	.L38
.L24:
	movl	%r12d, %ecx
	movl	%r14d, %edx
	movl	%ebp, %esi
	movq	%r15, %rdi
	call	Reverse
	leal	1(%r12), %eax
	cmpl	%eax, %r13d
	jle	.L27
.L36:
	leal	0(%r13,%r12), %edx
	movl	%edx, %r14d
	shrl	$31, %r14d
	addl	%edx, %r14d
	sarl	%r14d
	cmpl	%r14d, %eax
	jl	.L39
.L28:
	leal	1(%r14), %eax
	cmpl	%eax, %r13d
	jg	.L40
.L31:
	movl	%r13d, %ecx
	movl	%r14d, %edx
	movl	%r12d, %esi
	movq	%r15, %rdi
	call	Reverse
	jmp	.L27
	.p2align 4,,10
	.p2align 3
.L37:
	leal	(%rsi,%r14), %edx
	movl	%edx, %ebx
	shrl	$31, %ebx
	addl	%edx, %ebx
	sarl	%ebx
	cmpl	%ebx, %eax
	jl	.L41
.L22:
	leal	1(%rbx), %eax
	cmpl	%eax, %r14d
	jg	.L42
.L23:
	movl	%r14d, %ecx
	movl	%ebx, %edx
	movl	%ebp, %esi
	movq	%r15, %rdi
	call	Reverse
	leal	1(%r14), %eax
	cmpl	%eax, %r12d
	jle	.L24
.L38:
	leal	(%r12,%r14), %edx
	movl	%edx, %ebx
	shrl	$31, %ebx
	addl	%edx, %ebx
	sarl	%ebx
	cmpl	%ebx, %eax
	jl	.L43
.L25:
	leal	1(%rbx), %eax
	cmpl	%eax, %r12d
	jg	.L44
.L26:
	movl	%r12d, %ecx
	movl	%ebx, %edx
	movl	%r14d, %esi
	movq	%r15, %rdi
	call	Reverse
	jmp	.L24
	.p2align 4,,10
	.p2align 3
.L40:
	leal	0(%r13,%r14), %edx
	movl	%edx, %ebx
	shrl	$31, %ebx
	addl	%edx, %ebx
	sarl	%ebx
	cmpl	%ebx, %eax
	jl	.L45
.L32:
	leal	1(%rbx), %eax
	cmpl	%eax, %r13d
	jg	.L46
.L33:
	movl	%r13d, %ecx
	movl	%ebx, %edx
	movl	%r14d, %esi
	movq	%r15, %rdi
	call	Reverse
	jmp	.L31
	.p2align 4,,10
	.p2align 3
.L39:
	leal	(%r12,%r14), %edx
	movl	%edx, %ebx
	shrl	$31, %ebx
	addl	%edx, %ebx
	sarl	%ebx
	cmpl	%ebx, %eax
	jl	.L47
.L29:
	leal	1(%rbx), %eax
	cmpl	%eax, %r14d
	jg	.L48
.L30:
	movl	%r14d, %ecx
	movl	%ebx, %edx
	movl	%r12d, %esi
	movq	%r15, %rdi
	call	Reverse
	jmp	.L28
	.p2align 4,,10
	.p2align 3
.L41:
	movl	%ebx, %edx
	call	RSort.part.0
	jmp	.L22
	.p2align 4,,10
	.p2align 3
.L44:
	movl	%r12d, %edx
	movl	%ebx, %esi
	movq	%r15, %rdi
	call	RSort.part.0
	jmp	.L26
	.p2align 4,,10
	.p2align 3
.L43:
	movl	%ebx, %edx
	movl	%r14d, %esi
	movq	%r15, %rdi
	call	RSort.part.0
	jmp	.L25
	.p2align 4,,10
	.p2align 3
.L48:
	movl	%r14d, %edx
	movl	%ebx, %esi
	movq	%r15, %rdi
	call	RSort.part.0
	jmp	.L30
	.p2align 4,,10
	.p2align 3
.L47:
	movl	%ebx, %edx
	movl	%r12d, %esi
	movq	%r15, %rdi
	call	RSort.part.0
	jmp	.L29
	.p2align 4,,10
	.p2align 3
.L46:
	movl	%r13d, %edx
	movl	%ebx, %esi
	movq	%r15, %rdi
	call	RSort.part.0
	jmp	.L33
	.p2align 4,,10
	.p2align 3
.L45:
	movl	%ebx, %edx
	movl	%r14d, %esi
	movq	%r15, %rdi
	call	RSort.part.0
	jmp	.L32
	.p2align 4,,10
	.p2align 3
.L42:
	movl	%r14d, %edx
	movl	%ebx, %esi
	movq	%r15, %rdi
	call	RSort.part.0
	jmp	.L23
	.cfi_endproc
.LFE26:
	.size	RSort.part.0, .-RSort.part.0
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d"
.LC1:
	.string	"%.0f\n"
	.section	.text.startup,"ax",@progbits
	.p2align 4
	.globl	main
	.type	main, @function
main:
.LFB23:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	leaq	-798720(%rsp), %r11
	.cfi_def_cfa 11, 798760
.LPSRL1:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL1
	.cfi_def_cfa_register 7
	subq	$1320, %rsp
	.cfi_def_cfa_offset 800080
	leaq	.LC0(%rip), %r12
	movq	%r12, %rdi
	movq	%fs:40, %rax
	movq	%rax, 800024(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rsi
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %eax
	testl	%eax, %eax
	jle	.L50
	leaq	16(%rsp), %r13
	xorl	%ebx, %ebx
	movq	%r13, %rbp
	.p2align 4,,10
	.p2align 3
.L51:
	movq	%rbp, %rsi
	movq	%r12, %rdi
	xorl	%eax, %eax
	addl	$1, %ebx
	call	__isoc99_scanf@PLT
	movl	12(%rsp), %edx
	addq	$4, %rbp
	cmpl	%ebx, %edx
	jg	.L51
	cmpl	$1, %edx
	jle	.L50
	xorl	%esi, %esi
	movq	%r13, %rdi
	call	RSort.part.0
.L50:
	movsd	sum(%rip), %xmm0
	movl	$1, %edi
	movl	$1, %eax
	leaq	.LC1(%rip), %rsi
	call	__printf_chk@PLT
	movq	800024(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L55
	addq	$800040, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 40
	xorl	%eax, %eax
	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
.L55:
	.cfi_restore_state
	call	__stack_chk_fail@PLT
	.cfi_endproc
.LFE23:
	.size	main, .-main
	.text
	.p2align 4
	.globl	RSort
	.type	RSort, @function
RSort:
.LFB24:
	.cfi_startproc
	endbr64
	leal	1(%rsi), %eax
	cmpl	%edx, %eax
	jl	.L67
	ret
	.p2align 4,,10
	.p2align 3
.L67:
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movq	%rdi, %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movl	%edx, %r12d
	leal	(%rsi,%rdx), %edx
	movl	%edx, %r13d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	%esi, %ebp
	shrl	$31, %r13d
	addl	%edx, %r13d
	sarl	%r13d
	cmpl	%r13d, %eax
	jl	.L68
	leal	1(%r13), %eax
	cmpl	%eax, %r12d
	jg	.L69
.L61:
	movl	%r12d, %ecx
	movl	%r13d, %edx
	movl	%ebp, %esi
	movq	%r14, %rdi
	popq	%rbp
	.cfi_remember_state
	.cfi_restore 6
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_restore 12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_restore 13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_restore 14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_restore 15
	.cfi_def_cfa_offset 8
	jmp	Reverse
	.p2align 4,,10
	.p2align 3
.L68:
	.cfi_restore_state
	leal	(%rsi,%r13), %edx
	movl	%edx, %r15d
	shrl	$31, %r15d
	addl	%edx, %r15d
	sarl	%r15d
	cmpl	%r15d, %eax
	jl	.L70
.L59:
	leal	1(%r15), %eax
	cmpl	%eax, %r13d
	jg	.L71
.L60:
	movl	%r13d, %ecx
	movl	%r15d, %edx
	movl	%ebp, %esi
	movq	%r14, %rdi
	call	Reverse
	leal	1(%r13), %eax
	cmpl	%eax, %r12d
	jle	.L61
.L69:
	leal	(%r12,%r13), %edx
	movl	%edx, %r15d
	shrl	$31, %r15d
	addl	%edx, %r15d
	sarl	%r15d
	cmpl	%r15d, %eax
	jl	.L72
.L62:
	leal	1(%r15), %eax
	cmpl	%eax, %r12d
	jg	.L73
.L63:
	movl	%r12d, %ecx
	movl	%r15d, %edx
	movl	%r13d, %esi
	movq	%r14, %rdi
	call	Reverse
	jmp	.L61
	.p2align 4,,10
	.p2align 3
.L70:
	movl	%r15d, %edx
	call	RSort.part.0
	jmp	.L59
	.p2align 4,,10
	.p2align 3
.L73:
	movl	%r12d, %edx
	movl	%r15d, %esi
	movq	%r14, %rdi
	call	RSort.part.0
	jmp	.L63
	.p2align 4,,10
	.p2align 3
.L72:
	movl	%r15d, %edx
	movl	%r13d, %esi
	movq	%r14, %rdi
	call	RSort.part.0
	jmp	.L62
	.p2align 4,,10
	.p2align 3
.L71:
	movl	%r13d, %edx
	movl	%r15d, %esi
	movq	%r14, %rdi
	call	RSort.part.0
	jmp	.L60
	.cfi_endproc
.LFE24:
	.size	RSort, .-RSort
	.globl	sum
	.bss
	.align 8
	.type	sum, @object
	.size	sum, 8
sum:
	.zero	8
	.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>
void RSort(int *,int,int);
void Reverse(int *,int,int,int);
double sum=0;
int main()
{
  int i,n;
  int N[200000];
   
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&N[i]);
  }
 
  RSort(N,0,n);
 
 /* for(i=0;i<n;i++){
    printf("%d ",N[i]);
  }*/
   
  printf("%.0f\n",sum);
 
  return 0;
}
 
void RSort(int *A,int left,int right)
{
  int mid,temp;
  if(left+1<right){
    mid=(left+right)/2;
    RSort(A,left,mid);
    RSort(A,mid,right);
    Reverse(A,left,mid,right);
  }
}
 
void Reverse(int *A,int left,int mid,int right)
{
  int k,n1,n2,L[200000],R[200000],i,j;
  n1=mid-left;
  n2=right-mid;
  for(i=0;i<n1;i++){
    L[i]=A[left+i];
  }
  for(i=0;i<n2;i++){
    R[i]=A[mid+i];
  }
  L[n1]=1000000000;
  R[n2]=1000000000;
  i=0;
  j=0;
  for(k=left;k<right;k++){
    if(L[i]<R[j]){
      A[k]=L[i];
      i++;
    }
    else{
      A[k]=R[j];
      sum+=n1-i;
      j++;
    }
  }
}
3
6 1 2
 5
3 10 2 1 4
 3
6 1 0
 5
3 10 1 1 4
 3
0 -1 1
 5
1 6 1 0 0
 3
-2 -2 -2
 5
0 -13 17 1 0
 5
2 0 -1 -2 -1
 5
4 1 0 0 -1

2
 6
 3
 6
 1
 9
 3
 5
 9
 10

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>
void RSort(int *,int,int);
void Reverse(int *,int,int,int);
double sum=0;
int main()
{
  int i,n;
  int N[200000];
   
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&N[i]);
  }
 
  RSort(N,0,n);
 
 /* for(i=0;i<n;i++){
    printf("%d ",N[i]);
  }*/
   
  printf("%.0f\n",sum);
 
  return 0;
}
 
void RSort(int *A,int left,int right)
{
  int mid,temp;
  if(left+1<right){
    mid=(left+right)/2;
    RSort(A,left,mid);
    RSort(A,mid,right);
    Reverse(A,left,mid,right);
  }
}
 
void Reverse(int *A,int left,int mid,int right)
{
  int k,n1,n2,L[200000],R[200000],i,j;
  n1=mid-left;
  n2=right-mid;
  for(i=0;i<n1;i++){
    L[i]=A[left+i];
  }
  for(i=0;i<n2;i++){
    R[i]=A[mid+i];
  }
  L[n1]=1000000000;
  R[n2]=1000000000;
  i=0;
  j=0;
  for(k=left;k<right;k++){
    if(L[i]<R[j]){
      A[k]=L[i];
      i++;
    }
    else{
      A[k]=R[j];
      sum+=n1-i;
      j++;
    }
  }
}```

Unoptimized Assembly Code:

```assembly
	.file	"temp.c"
	.text
	.globl	sum
	.bss
	.align 8
	.type	sum, @object
	.size	sum, 8
sum:
	.zero	8
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%.0f\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	leaq	-798720(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$1312, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-800024(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -800020(%rbp)
	jmp	.L2
.L3:
	leaq	-800016(%rbp), %rdx
	movl	-800020(%rbp), %eax
	cltq
	salq	$2, %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -800020(%rbp)
.L2:
	movl	-800024(%rbp), %eax
	cmpl	%eax, -800020(%rbp)
	jl	.L3
	movl	-800024(%rbp), %edx
	leaq	-800016(%rbp), %rax
	movl	$0, %esi
	movq	%rax, %rdi
	call	RSort
	movq	sum(%rip), %rax
	movq	%rax, %xmm0
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$1, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L5
	call	__stack_chk_fail@PLT
.L5:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	main, .-main
	.globl	RSort
	.type	RSort, @function
RSort:
.LFB1:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$32, %rsp
	movq	%rdi, -24(%rbp)
	movl	%esi, -28(%rbp)
	movl	%edx, -32(%rbp)
	movl	-28(%rbp), %eax
	addl	$1, %eax
	cmpl	%eax, -32(%rbp)
	jle	.L8
	movl	-28(%rbp), %edx
	movl	-32(%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	-28(%rbp), %ecx
	movq	-24(%rbp), %rax
	movl	%ecx, %esi
	movq	%rax, %rdi
	call	RSort
	movl	-32(%rbp), %edx
	movl	-4(%rbp), %ecx
	movq	-24(%rbp), %rax
	movl	%ecx, %esi
	movq	%rax, %rdi
	call	RSort
	movl	-32(%rbp), %ecx
	movl	-4(%rbp), %edx
	movl	-28(%rbp), %esi
	movq	-24(%rbp), %rax
	movq	%rax, %rdi
	call	Reverse
.L8:
	nop
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.size	RSort, .-RSort
	.globl	Reverse
	.type	Reverse, @function
Reverse:
.LFB2:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	leaq	-1597440(%rsp), %r11
.LPSRL1:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL1
	subq	$2640, %rsp
	movq	%rdi, -1600056(%rbp)
	movl	%esi, -1600060(%rbp)
	movl	%edx, -1600064(%rbp)
	movl	%ecx, -1600068(%rbp)
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	-1600064(%rbp), %eax
	subl	-1600060(%rbp), %eax
	movl	%eax, -1600024(%rbp)
	movl	-1600068(%rbp), %eax
	subl	-1600064(%rbp), %eax
	movl	%eax, -1600020(%rbp)
	movl	$0, -1600032(%rbp)
	jmp	.L10
.L11:
	movl	-1600060(%rbp), %edx
	movl	-1600032(%rbp), %eax
	addl	%edx, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-1600056(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-1600032(%rbp), %eax
	cltq
	movl	%edx, -1600016(%rbp,%rax,4)
	addl	$1, -1600032(%rbp)
.L10:
	movl	-1600032(%rbp), %eax
	cmpl	-1600024(%rbp), %eax
	jl	.L11
	movl	$0, -1600032(%rbp)
	jmp	.L12
.L13:
	movl	-1600064(%rbp), %edx
	movl	-1600032(%rbp), %eax
	addl	%edx, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-1600056(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-1600032(%rbp), %eax
	cltq
	movl	%edx, -800016(%rbp,%rax,4)
	addl	$1, -1600032(%rbp)
.L12:
	movl	-1600032(%rbp), %eax
	cmpl	-1600020(%rbp), %eax
	jl	.L13
	movl	-1600024(%rbp), %eax
	cltq
	movl	$1000000000, -1600016(%rbp,%rax,4)
	movl	-1600020(%rbp), %eax
	cltq
	movl	$1000000000, -800016(%rbp,%rax,4)
	movl	$0, -1600032(%rbp)
	movl	$0, -1600028(%rbp)
	movl	-1600060(%rbp), %eax
	movl	%eax, -1600036(%rbp)
	jmp	.L14
.L17:
	movl	-1600032(%rbp), %eax
	cltq
	movl	-1600016(%rbp,%rax,4), %edx
	movl	-1600028(%rbp), %eax
	cltq
	movl	-800016(%rbp,%rax,4), %eax
	cmpl	%eax, %edx
	jge	.L15
	movl	-1600036(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-1600056(%rbp), %rax
	addq	%rax, %rdx
	movl	-1600032(%rbp), %eax
	cltq
	movl	-1600016(%rbp,%rax,4), %eax
	movl	%eax, (%rdx)
	addl	$1, -1600032(%rbp)
	jmp	.L16
.L15:
	movl	-1600036(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-1600056(%rbp), %rax
	addq	%rax, %rdx
	movl	-1600028(%rbp), %eax
	cltq
	movl	-800016(%rbp,%rax,4), %eax
	movl	%eax, (%rdx)
	movl	-1600024(%rbp), %eax
	subl	-1600032(%rbp), %eax
	pxor	%xmm1, %xmm1
	cvtsi2sdl	%eax, %xmm1
	movsd	sum(%rip), %xmm0
	addsd	%xmm1, %xmm0
	movsd	%xmm0, sum(%rip)
	addl	$1, -1600028(%rbp)
.L16:
	addl	$1, -1600036(%rbp)
.L14:
	movl	-1600036(%rbp), %eax
	cmpl	-1600068(%rbp), %eax
	jl	.L17
	nop
	movq	-8(%rbp), %rax
	subq	%fs:40, %rax
	je	.L18
	call	__stack_chk_fail@PLT
.L18:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE2:
	.size	Reverse, .-Reverse
	.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	sum
	.bss
	.align 8
	.type	sum, @object
	.size	sum, 8
sum:
	.zero	8
	.section	.rodata
.LC0:
	.string	"%d"
.LC1:
	.string	"%.0f\n"
	.text
	.globl	main
	.type	main, @function
main:
.LFB0:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	leaq	-798720(%rsp), %r11
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	subq	$1312, %rsp
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	leaq	-800024(%rbp), %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	movl	$0, -800020(%rbp)
	jmp	.L2
.L3:
	leaq	-800016(%rbp), %rdx
	movl	-800020(%rbp), %eax
	cltq
	salq	$2, %rax
	addq	%rdx, %rax
	movq	%rax, %rsi
	leaq	.LC0(%rip), %rax
	movq	%rax, %rdi
	movl	$0, %eax
	call	__isoc99_scanf@PLT
	addl	$1, -800020(%rbp)
.L2:
	movl	-800024(%rbp), %eax
	cmpl	%eax, -800020(%rbp)
	jl	.L3
	movl	-800024(%rbp), %edx
	leaq	-800016(%rbp), %rax
	movl	$0, %esi
	movq	%rax, %rdi
	call	RSort
	movq	sum(%rip), %rax
	movq	%rax, %xmm0
	leaq	.LC1(%rip), %rax
	movq	%rax, %rdi
	movl	$1, %eax
	call	printf@PLT
	movl	$0, %eax
	movq	-8(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L5
	call	__stack_chk_fail@PLT
.L5:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE0:
	.size	main, .-main
	.globl	RSort
	.type	RSort, @function
RSort:
.LFB1:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	subq	$32, %rsp
	movq	%rdi, -24(%rbp)
	movl	%esi, -28(%rbp)
	movl	%edx, -32(%rbp)
	movl	-28(%rbp), %eax
	addl	$1, %eax
	cmpl	%eax, -32(%rbp)
	jle	.L8
	movl	-28(%rbp), %edx
	movl	-32(%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	-28(%rbp), %ecx
	movq	-24(%rbp), %rax
	movl	%ecx, %esi
	movq	%rax, %rdi
	call	RSort
	movl	-32(%rbp), %edx
	movl	-4(%rbp), %ecx
	movq	-24(%rbp), %rax
	movl	%ecx, %esi
	movq	%rax, %rdi
	call	RSort
	movl	-32(%rbp), %ecx
	movl	-4(%rbp), %edx
	movl	-28(%rbp), %esi
	movq	-24(%rbp), %rax
	movq	%rax, %rdi
	call	Reverse
.L8:
	nop
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE1:
	.size	RSort, .-RSort
	.globl	Reverse
	.type	Reverse, @function
Reverse:
.LFB2:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	leaq	-1597440(%rsp), %r11
.LPSRL1:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL1
	subq	$2640, %rsp
	movq	%rdi, -1600056(%rbp)
	movl	%esi, -1600060(%rbp)
	movl	%edx, -1600064(%rbp)
	movl	%ecx, -1600068(%rbp)
	movq	%fs:40, %rax
	movq	%rax, -8(%rbp)
	xorl	%eax, %eax
	movl	-1600064(%rbp), %eax
	subl	-1600060(%rbp), %eax
	movl	%eax, -1600024(%rbp)
	movl	-1600068(%rbp), %eax
	subl	-1600064(%rbp), %eax
	movl	%eax, -1600020(%rbp)
	movl	$0, -1600032(%rbp)
	jmp	.L10
.L11:
	movl	-1600060(%rbp), %edx
	movl	-1600032(%rbp), %eax
	addl	%edx, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-1600056(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-1600032(%rbp), %eax
	cltq
	movl	%edx, -1600016(%rbp,%rax,4)
	addl	$1, -1600032(%rbp)
.L10:
	movl	-1600032(%rbp), %eax
	cmpl	-1600024(%rbp), %eax
	jl	.L11
	movl	$0, -1600032(%rbp)
	jmp	.L12
.L13:
	movl	-1600064(%rbp), %edx
	movl	-1600032(%rbp), %eax
	addl	%edx, %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-1600056(%rbp), %rax
	addq	%rdx, %rax
	movl	(%rax), %edx
	movl	-1600032(%rbp), %eax
	cltq
	movl	%edx, -800016(%rbp,%rax,4)
	addl	$1, -1600032(%rbp)
.L12:
	movl	-1600032(%rbp), %eax
	cmpl	-1600020(%rbp), %eax
	jl	.L13
	movl	-1600024(%rbp), %eax
	cltq
	movl	$1000000000, -1600016(%rbp,%rax,4)
	movl	-1600020(%rbp), %eax
	cltq
	movl	$1000000000, -800016(%rbp,%rax,4)
	movl	$0, -1600032(%rbp)
	movl	$0, -1600028(%rbp)
	movl	-1600060(%rbp), %eax
	movl	%eax, -1600036(%rbp)
	jmp	.L14
.L17:
	movl	-1600032(%rbp), %eax
	cltq
	movl	-1600016(%rbp,%rax,4), %edx
	movl	-1600028(%rbp), %eax
	cltq
	movl	-800016(%rbp,%rax,4), %eax
	cmpl	%eax, %edx
	jge	.L15
	movl	-1600036(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-1600056(%rbp), %rax
	addq	%rax, %rdx
	movl	-1600032(%rbp), %eax
	cltq
	movl	-1600016(%rbp,%rax,4), %eax
	movl	%eax, (%rdx)
	addl	$1, -1600032(%rbp)
	jmp	.L16
.L15:
	movl	-1600036(%rbp), %eax
	cltq
	leaq	0(,%rax,4), %rdx
	movq	-1600056(%rbp), %rax
	addq	%rax, %rdx
	movl	-1600028(%rbp), %eax
	cltq
	movl	-800016(%rbp,%rax,4), %eax
	movl	%eax, (%rdx)
	movl	-1600024(%rbp), %eax
	subl	-1600032(%rbp), %eax
	pxor	%xmm1, %xmm1
	cvtsi2sdl	%eax, %xmm1
	movsd	sum(%rip), %xmm0
	addsd	%xmm1, %xmm0
	movsd	%xmm0, sum(%rip)
	addl	$1, -1600028(%rbp)
.L16:
	addl	$1, -1600036(%rbp)
.L14:
	movl	-1600036(%rbp), %eax
	cmpl	-1600068(%rbp), %eax
	jl	.L17
	nop
	movq	-8(%rbp), %rax
	subq	%fs:40, %rax
	je	.L18
	call	__stack_chk_fail@PLT
.L18:
	leave
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE2:
	.size	Reverse, .-Reverse
	.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:
