#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ mergeSort(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printArray(int *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int arr_size, n;
  scanf("%d", &arr_size);
  n = arr_size;
  int *A = (int *)malloc(sizeof(int) * arr_size);
  for (int i = 0; i < n; i++) {
    scanf(" %d", &A[i]);
  }
  printArray(A, arr_size);
  mergeSort(A, 0, arr_size - 1);
  printf("\nSorted array is \n");
  printArray(A, arr_size);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9b(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11c4 <main+0x74>
mov    -0x18(%rbp),%rsi
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe4f(%rip),%rdi
call   1060 <scanf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    118f <main+0x3f>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1070 <printArray@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1040 <mergeSort@plt>
lea    0xe1c(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1070 <printArray@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    0xea2(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1060 <scanf@plt>
mov    0x4(%rsp),%r12d
lea    0x0(,%r12,4),%edi
call   1050 <malloc@plt>
mov    %rax,%r14
test   %r12d,%r12d
jle    11a5 <main+0x55>
lea    0xe76(%rip),%r15
mov    %r14,%rbx
nopl   (%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
add    $0x4,%rbx
add    $0xffffffffffffffff,%r12
jne    1190 <main+0x40>
mov    0x4(%rsp),%esi
mov    %r14,%rdi
call   1070 <printArray@plt>
mov    0x4(%rsp),%edx
add    $0xffffffff,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <mergeSort@plt>
lea    0xe3b(%rip),%rdi
call   1030 <puts@plt>
mov    0x4(%rsp),%esi
mov    %r14,%rdi
call   1070 <printArray@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 = [4 x i8] c" %d\00"
@.str.2 = [19 x i8] c"\0ASorted array is \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%7 = load i32, i32* %2
store i32 %7, i32* %3
%8 = load i32, i32* %2
%9 = sext i32 %8 to i64
%10 = mul i64 4, %9
%11 = trunc i64 %10 to i32
%12 = call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i32*
store i32* %13, i32** %4
store i32 0, i32* %5
br label %14
14: ; preds = %24, %0
%15 = load i32, i32* %5
%16 = load i32, i32* %3
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %27
18: ; preds = %14
%19 = load i32*, i32** %4
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %19, i64 %21
%23 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* %22)
br label %24
24: ; preds = %18
%25 = load i32, i32* %5
%26 = add nsw i32 %25, 1
store i32 %26, i32* %5
br label %14
27: ; preds = %14
%28 = load i32*, i32** %4
%29 = load i32, i32* %2
%30 = call i32 @printArray(i32* %28, i32 %29)
%31 = load i32*, i32** %4
%32 = load i32, i32* %2
%33 = sub nsw i32 %32, 1
%34 = call i32 @mergeSort(i32* %31, i32 0, i32 %33)
%35 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%36 = load i32*, i32** %4
%37 = load i32, i32* %2
%38 = call i32 @printArray(i32* %36, i32 %37)
ret i32 0
}

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