#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 *malloc(int);
int /*<<< orphan*/ merge_sort(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int i, *A;
  printf("Enter the size of ther array: ");
  scanf(" %d ", &i);
  A = malloc(sizeof(int) * i);
  for (int j = 0; j < i; j++) {
    printf("Enter %d element: ", (j + 1));
    scanf("%d", &A[j]);
  }
  printf("Before Sorting \n");
  for (int j = 0; j < i; j++)
    printf("%d element: %d\n", (j + 1), A[j]);
  merge_sort(A, 0, i - 1);
  printf("After Sorting \n");
  for (int j = 0; j < i; j++)
    printf("%d element: %d\n", (j + 1), A[j]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xebb(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11d0 <main+0x90>
mov    -0x14(%rbp),%esi
add    $0x1,%esi
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe7a(%rip),%rdi
call   1060 <scanf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1187 <main+0x47>
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    121e <main+0xde>
mov    -0x18(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11e5 <main+0xa5>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1050 <merge_sort@plt>
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    127d <main+0x13d>
mov    -0x1c(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xde3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1244 <main+0x104>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xe9c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xead(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1070 <scanf@plt>
mov    0xc(%rsp),%ebx
lea    0x0(,%rbx,4),%edi
call   1050 <malloc@plt>
mov    %rax,%r12
test   %ebx,%ebx
jle    11d9 <main+0x89>
lea    0xe8a(%rip),%r14
lea    0xe96(%rip),%r15
mov    %r12,%r13
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rbx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   1070 <scanf@plt>
movslq 0xc(%rsp),%rax
add    $0x4,%r13
cmp    %rax,%rbx
jl     11b0 <main+0x60>
lea    0xe6a(%rip),%rdi
call   1030 <puts@plt>
mov    0xc(%rsp),%edx
test   %edx,%edx
jle    121e <main+0xce>
lea    0xe46(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    (%r12,%rbx,4),%edx
add    $0x1,%rbx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movslq 0xc(%rsp),%rdx
cmp    %rdx,%rbx
jl     1200 <main+0xb0>
add    $0xffffffff,%edx
mov    %r12,%rdi
xor    %esi,%esi
call   1060 <merge_sort@plt>
lea    0xe28(%rip),%rdi
call   1030 <puts@plt>
cmpl   $0x0,0xc(%rsp)
jle    126e <main+0x11e>
lea    0xdf5(%rip),%r14
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    (%r12,%rbx,4),%edx
add    $0x1,%rbx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movslq 0xc(%rsp),%rax
cmp    %rax,%rbx
jl     1250 <main+0x100>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [31 x i8] c"Enter the size of ther array: \00"
@.str.1 = [5 x i8] c" %d \00"
@.str.2 = [19 x i8] c"Enter %d element: \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [17 x i8] c"Before Sorting \0A\00"
@.str.5 = [16 x i8] c"%d element: %d\0A\00"
@.str.6 = [16 x i8] c"After Sorting \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%9 = load i32, i32* %2
%10 = sext i32 %9 to i64
%11 = mul i64 4, %10
%12 = trunc i64 %11 to i32
%13 = call i32* @malloc(i32 %12)
store i32* %13, i32** %3
store i32 0, i32* %4
br label %14
14: ; preds = %27, %0
%15 = load i32, i32* %4
%16 = load i32, i32* %2
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %30
18: ; preds = %14
%19 = load i32, i32* %4
%20 = add nsw i32 %19, 1
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%22 = load i32*, i32** %3
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
%26 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %25)
br label %27
27: ; preds = %18
%28 = load i32, i32* %4
%29 = add nsw i32 %28, 1
store i32 %29, i32* %4
br label %14
30: ; preds = %14
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %5
br label %32
32: ; preds = %45, %30
%33 = load i32, i32* %5
%34 = load i32, i32* %2
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %48
36: ; preds = %32
%37 = load i32, i32* %5
%38 = add nsw i32 %37, 1
%39 = load i32*, i32** %3
%40 = load i32, i32* %5
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i32, i32* %39, i64 %41
%43 = load i32, i32* %42
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 %38, i32 %43)
br label %45
45: ; preds = %36
%46 = load i32, i32* %5
%47 = add nsw i32 %46, 1
store i32 %47, i32* %5
br label %32
48: ; preds = %32
%49 = load i32*, i32** %3
%50 = load i32, i32* %2
%51 = sub nsw i32 %50, 1
%52 = call i32 @merge_sort(i32* %49, i32 0, i32 %51)
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %6
br label %54
54: ; preds = %67, %48
%55 = load i32, i32* %6
%56 = load i32, i32* %2
%57 = icmp slt i32 %55, %56
br i1 %57, label %58, label %70
58: ; preds = %54
%59 = load i32, i32* %6
%60 = add nsw i32 %59, 1
%61 = load i32*, i32** %3
%62 = load i32, i32* %6
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i32, i32* %61, i64 %63
%65 = load i32, i32* %64
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 %60, i32 %65)
br label %67
67: ; preds = %58
%68 = load i32, i32* %6
%69 = add nsw i32 %68, 1
store i32 %69, i32* %6
br label %54
70: ; preds = %54
ret i32 0
}

LLVM IR (-O2):
@.str = [31 x i8] c"Enter the size of ther array: \00"
@.str.1 = [5 x i8] c" %d \00"
@.str.2 = [19 x i8] c"Enter %d element: \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.5 = [16 x i8] c"%d element: %d\0A\00"
@str = [16 x i8] c"Before Sorting \00"
@str.7 = [15 x i8] c"After Sorting \00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = shl i32 %5, 2
%7 = call i32* @malloc(i32 %6)
%8 = icmp sgt i32 %5, 0
br i1 %8, label %13, label %9
9: ; preds = %13, %0
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%11 = load i32, i32* %1
%12 = icmp sgt i32 %11, 0
br i1 %12, label %30, label %23
13: ; preds = %0, %13
%14 = phi i64 [ %15, %13 ], [ 0, %0 ]
%15 = add nuw nsw i64 %14, 1
%16 = trunc i64 %15 to i32
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%18 = getelementptr inbounds i32, i32* %7, i64 %14
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %18)
%20 = load i32, i32* %1
%21 = sext i32 %20 to i64
%22 = icmp slt i64 %15, %21
br i1 %22, label %13, label %9
23: ; preds = %30, %9
%24 = phi i32 [ %11, %9 ], [ %37, %30 ]
%25 = add nsw i32 %24, -1
%26 = call i32 @merge_sort(i32* %7, i32 0, i32 %25)
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.7, i64 0, i64 0))
%28 = load i32, i32* %1
%29 = icmp sgt i32 %28, 0
br i1 %29, label %41, label %40
30: ; preds = %9, %30
%31 = phi i64 [ %32, %30 ], [ 0, %9 ]
%32 = add nuw nsw i64 %31, 1
%33 = getelementptr inbounds i32, i32* %7, i64 %31
%34 = load i32, i32* %33
%35 = trunc i64 %32 to i32
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 %35, i32 %34)
%37 = load i32, i32* %1
%38 = sext i32 %37 to i64
%39 = icmp slt i64 %32, %38
br i1 %39, label %30, label %23
40: ; preds = %41, %23
ret i32 0
41: ; preds = %23, %41
%42 = phi i64 [ %43, %41 ], [ 0, %23 ]
%43 = add nuw nsw i64 %42, 1
%44 = getelementptr inbounds i32, i32* %7, i64 %42
%45 = load i32, i32* %44
%46 = trunc i64 %43 to i32
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 %46, i32 %45)
%48 = load i32, i32* %1
%49 = sext i32 %48 to i64
%50 = icmp slt i64 %43, %49
br i1 %50, label %41, label %40
}