#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ free(long long *);
scalar_t__ malloc(int);
int /*<<< orphan*/ mergeSort(long long *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printArray(long long *, int);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  int n;
  scanf("%d", &n);
  long long int *A = (long long int *)malloc(sizeof(long long int) * n);
  for (int i = 0; i < n; i++) {
    scanf(" %lld", &A[i]);
  }
  puts("Sorted array");
  mergeSort(A, 0, n - 1);
  printArray(A, n);
  free(A);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1070 <scanf@plt>
movslq -0x8(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11d2 <main+0x72>
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1070 <scanf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    119b <main+0x3b>
lea    0xe30(%rip),%rdi
call   1040 <puts@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1050 <mergeSort@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1080 <printArray@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xe91(%rip),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
mov    0x4(%rsp),%edi
shl    $0x3,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
cmpl   $0x0,0x4(%rsp)
jle    11bf <main+0x5f>
lea    0xe6b(%rip),%r15
mov    %r14,%r12
xor    %ebx,%ebx
nopl   (%rax)
mov    %r15,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
add    $0x1,%rbx
movslq 0x4(%rsp),%rax
add    $0x8,%r12
cmp    %rax,%rbx
jl     11a0 <main+0x40>
lea    0xe43(%rip),%rdi
call   1040 <puts@plt>
mov    0x4(%rsp),%edx
add    $0xffffffff,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1050 <mergeSort@plt>
mov    0x4(%rsp),%esi
mov    %r14,%rdi
call   1080 <printArray@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [6 x i8] c" %lld\00"
@.str.2 = [13 x i8] c"Sorted array\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64*
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%6 = load i32, i32* %2
%7 = sext i32 %6 to i64
%8 = mul i64 8, %7
%9 = trunc i64 %8 to i32
%10 = call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to i64*
store i64* %11, i64** %3
store i32 0, i32* %4
br label %12
12: ; preds = %22, %0
%13 = load i32, i32* %4
%14 = load i32, i32* %2
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %25
16: ; preds = %12
%17 = load i64*, i64** %3
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i64, i64* %17, i64 %19
%21 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64* %20)
br label %22
22: ; preds = %16
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
store i32 %24, i32* %4
br label %12
25: ; preds = %12
%26 = call i32 @puts(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%27 = load i64*, i64** %3
%28 = load i32, i32* %2
%29 = sub nsw i32 %28, 1
%30 = call i32 @mergeSort(i64* %27, i32 0, i32 %29)
%31 = load i64*, i64** %3
%32 = load i32, i32* %2
%33 = call i32 @printArray(i64* %31, i32 %32)
%34 = load i64*, i64** %3
%35 = call i32 @free(i64* %34)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [6 x i8] c" %lld\00"
@.str.2 = [13 x i8] c"Sorted array\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%4 = load i32, i32* %1
%5 = shl i32 %4, 3
%6 = call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to i64*
%8 = load i32, i32* %1
%9 = icmp sgt i32 %8, 0
br i1 %9, label %18, label %10
10: ; preds = %18, %0
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%12 = load i32, i32* %1
%13 = add nsw i32 %12, -1
%14 = call i32 @mergeSort(i64* %7, i32 0, i32 %13)
%15 = load i32, i32* %1
%16 = call i32 @printArray(i64* %7, i32 %15)
%17 = call i32 @free(i64* %7)
ret i32 0
18: ; preds = %0, %18
%19 = phi i64 [ %22, %18 ], [ 0, %0 ]
%20 = getelementptr inbounds i64, i64* %7, i64 %19
%21 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64* %20)
%22 = add nuw nsw i64 %19, 1
%23 = load i32, i32* %1
%24 = sext i32 %23 to i64
%25 = icmp slt i64 %22, %24
br i1 %25, label %18, label %10
}