#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 */
typedef scalar_t__ clock_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
double CLOCKS_PER_SEC;
int atoi(char *);
scalar_t__ clock();
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *);
int *malloc(int);
int /*<<< orphan*/ merge_sort(int /*<<< orphan*/, int, int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main(int argC, char *arg[]) {
  int size, i, k = 20;
  FILE *fp;
  fp = fopen("arr.txt", "r");
  if (argC == 1) {
    printf("\nEnter the size of array");
    scanf("%d", &size);
  } else {
    size = atoi(arg[1]);
  }
  int *arr;
  arr = malloc(sizeof(int) * (size + 1));
  printf("\n%d \n", size);
  for (i = 0; i < size; i++) {
    char str[20];
    fscanf(fp, "%s  ", str);
    arr[i] = atoi(str);
  }
  fclose(fp);
  clock_t begin = clock();
  merge_sort(0, size - 1, arr);
  clock_t end = clock();
  printf("\nElapsed: %f seconds\n", (double)(begin - end) / CLOCKS_PER_SEC);
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x14,-0x1c(%rbp)
lea    0xe4c(%rip),%rdi
lea    0xe4d(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11f1 <main+0x61>
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe40(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1090 <scanf@plt>
jmp    1201 <main+0x71>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1274 <main+0xe4>
mov    -0x28(%rbp),%rdi
lea    -0x50(%rbp),%rdx
lea    0xde1(%rip),%rsi
call   1060 <fscanf@plt>
lea    -0x50(%rbp),%rdi
call   10b0 <atoi@plt>
mov    %eax,%edx
mov    -0x30(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1230 <main+0xa0>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x58(%rbp)
mov    -0x14(%rbp),%esi
sub    $0x1,%esi
mov    -0x30(%rbp),%rdx
xor    %edi,%edi
call   1080 <merge_sort@plt>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x60(%rbp)
mov    -0x58(%rbp),%rax
sub    -0x60(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2d30(%rip),%rax
divsd  (%rax),%xmm0
lea    0xd6e(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
lea    0xd59(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe48(%rip),%rdi
lea    0xe49(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%r14
cmp    $0x1,%ebp
jne    11f2 <main+0x52>
lea    0xe37(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe42(%rip),%rdi
lea    0xc(%rsp),%rsi
call   10a0 <scanf@plt>
mov    0xc(%rsp),%r15d
jmp    1202 <main+0x62>
mov    0x8(%rbx),%rdi
call   10c0 <atoi@plt>
mov    %eax,%r15d
mov    %eax,0xc(%rsp)
lea    0x4(,%r15,4),%edi
call   1080 <malloc@plt>
mov    %rax,%r12
lea    0xe0d(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
cmpl   $0x0,0xc(%rsp)
jle    1268 <main+0xc8>
xor    %ebp,%ebp
lea    0xdf9(%rip),%r15
lea    0x10(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1070 <fscanf@plt>
mov    %rbx,%rdi
call   10c0 <atoi@plt>
mov    %eax,(%r12,%rbp,4)
add    $0x1,%rbp
movslq 0xc(%rsp),%rax
cmp    %rax,%rbp
jl     1240 <main+0xa0>
mov    %r14,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%rbx
mov    0xc(%rsp),%esi
add    $0xffffffff,%esi
xor    %edi,%edi
mov    %r12,%rdx
call   1090 <merge_sort@plt>
xor    %eax,%eax
call   1040 <clock@plt>
sub    %rax,%rbx
cvtsi2sd %rbx,%xmm0
mov    0x2d47(%rip),%rax
divsd  (%rax),%xmm0
lea    0xd85(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [8 x i8] c"arr.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [25 x i8] c"\0AEnter the size of array\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [6 x i8] c"\0A%d \0A\00"
@.str.5 = [5 x i8] c"%s \00"
@.str.6 = [22 x i8] c"\0AElapsed: %f seconds\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [20 x i8]
%5 = bitcast i32* %3 to i8*
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32 %0, 1
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%11 = load i32, i32* %3
br label %16
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32 @atoi(i8* %14)
store i32 %15, i32* %3
br label %16
16: ; preds = %12, %8
%17 = phi i32 [ %15, %12 ], [ %11, %8 ]
%18 = shl i32 %17, 2
%19 = add i32 %18, 4
%20 = call i32* @malloc(i32 %19)
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %17)
%22 = load i32, i32* %3
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %35
24: ; preds = %16
%25 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
br label %26
26: ; preds = %24, %26
%27 = phi i64 [ 0, %24 ], [ %31, %26 ]
%28 = call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %25)
%29 = call i32 @atoi(i8* %25)
%30 = getelementptr inbounds i32, i32* %20, i64 %27
store i32 %29, i32* %30
%31 = add nuw nsw i64 %27, 1
%32 = load i32, i32* %3
%33 = sext i32 %32 to i64
%34 = icmp slt i64 %31, %33
br i1 %34, label %26, label %35
35: ; preds = %26, %16
%36 = call i32 @fclose(i32* %6)
%37 = call i64 (...) @clock()
%38 = load i32, i32* %3
%39 = add nsw i32 %38, -1
%40 = call i32 @merge_sort(i32 0, i32 %39, i32* %20)
%41 = call i64 (...) @clock()
%42 = sub nsw i64 %37, %41
%43 = sitofp i64 %42 to double
%44 = load double, double* @CLOCKS_PER_SEC
%45 = fdiv double %43, %44
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), double %45)
%47 = call i32 @putchar(i32 10)
ret i32 0
}