#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 */
struct timeval {
  double tv_usec;
  int /*<<< orphan*/ tv_sec;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fnDispArray(int *, int);
int /*<<< orphan*/ fnGenRandInput(int *, int);
int /*<<< orphan*/ fnMergeSort(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, double);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int main(int argc, char **argv) {
  FILE *fp;
  struct timeval tv;
  double dStart, dEnd;
  int iaArr[500000], iNum, iPos, iKey, i, iChoice;
  for (;;) {
    printf("\n1.Plot the Graph\n2.MergeSort\n3.Exit");
    printf("\nEnter your choice\n");
    scanf("%d", &iChoice);
    switch (iChoice) {
    case 1:
      fp = fopen("MergePlot.dat", "w");
      for (i = 100; i < 100000; i += 100) {
        fnGenRandInput(iaArr, i);
        gettimeofday(&tv, NULL);
        dStart = tv.tv_sec + (tv.tv_usec / 1000000.0);
        fnMergeSort(iaArr, 0, i - 1);
        gettimeofday(&tv, NULL);
        dEnd = tv.tv_sec + (tv.tv_usec / 1000000.0);
        fprintf(fp, "%d\t%lf\n", i, dEnd - dStart);
      }
      fclose(fp);
      printf("\nData File generated and stored in file < MergePlot.dat >.\n "
             "Use a plotting utility\n");
      break;
    case 2:
      printf("\nEnter the number of elements to sort\n");
      scanf("%d", &iNum);
      printf("\nUnsorted Array\n");
      fnGenRandInput(iaArr, iNum);
      fnDispArray(iaArr, iNum);
      fnMergeSort(iaArr, 0, iNum - 1);
      printf("\nSorted Array\n");
      fnDispArray(iaArr, iNum);
      break;
    case 3:
      exit(0);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1e84e0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe48(%rip),%rdi
call   1070 <printf@plt>
lea    0xe61(%rip),%rdi
call   1070 <printf@plt>
lea    0xe69(%rip),%rdi
lea    -0x1e84d4(%rbp),%rsi
call   10a0 <scanf@plt>
mov    -0x1e84d4(%rbp),%eax
mov    %eax,-0x1e84d8(%rbp)
sub    $0x1,%eax
je     1226 <main+0x86>
jmp    11fe <main+0x5e>
mov    -0x1e84d8(%rbp),%eax
sub    $0x2,%eax
je     1326 <main+0x186>
jmp    1212 <main+0x72>
mov    -0x1e84d8(%rbp),%eax
sub    $0x3,%eax
je     13af <main+0x20f>
jmp    13b6 <main+0x216>
lea    0xe17(%rip),%rdi
lea    0xe1e(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x64,-0x1e84d0(%rbp)
cmpl   $0x186a0,-0x1e84d0(%rbp)
jge    130c <main+0x16c>
lea    -0x1e84c0(%rbp),%rdi
mov    -0x1e84d0(%rbp),%esi
call   1050 <fnGenRandInput@plt>
lea    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1080 <gettimeofday@plt>
cvtsi2sdl -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  0xd78(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
lea    -0x1e84c0(%rbp),%rdi
mov    -0x1e84d0(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1030 <fnMergeSort@plt>
lea    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1080 <gettimeofday@plt>
cvtsi2sdl -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  0xd35(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1e84d0(%rbp),%edx
movsd  -0x38(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
lea    0xd61(%rip),%rsi
call   1090 <fprintf@plt>
mov    -0x1e84d0(%rbp),%eax
add    $0x64,%eax
mov    %eax,-0x1e84d0(%rbp)
jmp    1247 <main+0xa7>
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
lea    0xd40(%rip),%rdi
call   1070 <printf@plt>
jmp    13b6 <main+0x216>
lea    0xd83(%rip),%rdi
call   1070 <printf@plt>
lea    0xd08(%rip),%rdi
lea    -0x1e84c4(%rbp),%rsi
call   10a0 <scanf@plt>
lea    0xd8b(%rip),%rdi
call   1070 <printf@plt>
lea    -0x1e84c0(%rbp),%rdi
mov    -0x1e84c4(%rbp),%esi
call   1050 <fnGenRandInput@plt>
lea    -0x1e84c0(%rbp),%rdi
mov    -0x1e84c4(%rbp),%esi
call   1040 <fnDispArray@plt>
lea    -0x1e84c0(%rbp),%rdi
mov    -0x1e84c4(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1030 <fnMergeSort@plt>
lea    0xd55(%rip),%rdi
call   1070 <printf@plt>
lea    -0x1e84c0(%rbp),%rdi
mov    -0x1e84c4(%rbp),%esi
call   1040 <fnDispArray@plt>
jmp    13b6 <main+0x216>
xor    %edi,%edi
call   10c0 <exit@plt>
jmp    11b9 <main+0x19>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1e84c8,%rsp
lea    0xe48(%rip),%r15
lea    0xe81(%rip),%r12
lea    0xe5f(%rip),%rbx
lea    0x40(%rsp),%r13
lea    0x10(%rsp),%rbp
lea    0xe61(%rip),%r14
jmp    1256 <main+0xa6>
nopl   0x0(%rax)
lea    0xe6c(%rip),%rdi
call   1050 <puts@plt>
mov    %rbx,%rdi
lea    0x8(%rsp),%rsi
call   10b0 <scanf@plt>
lea    0xe79(%rip),%rdi
call   1050 <puts@plt>
mov    0x8(%rsp),%esi
mov    %r13,%rdi
call   1060 <fnGenRandInput@plt>
mov    0x8(%rsp),%esi
mov    %r13,%rdi
call   1040 <fnDispArray@plt>
mov    0x8(%rsp),%edx
add    $0xffffffff,%edx
mov    %r13,%rdi
xor    %esi,%esi
call   1030 <fnMergeSort@plt>
lea    0xe54(%rip),%rdi
call   1050 <puts@plt>
mov    0x8(%rsp),%esi
mov    %r13,%rdi
call   1040 <fnDispArray@plt>
mov    %r15,%rdi
call   1080 <printf@plt>
mov    %r12,%rdi
call   1050 <puts@plt>
mov    %rbx,%rdi
lea    0xc(%rsp),%rsi
call   10b0 <scanf@plt>
mov    0xc(%rsp),%eax
cmp    $0x1,%eax
je     1290 <main+0xe0>
cmp    $0x2,%eax
je     11f0 <main+0x40>
cmp    $0x3,%eax
jne    1256 <main+0xa6>
jmp    1375 <main+0x1c5>
nop
mov    %r15,%rbx
lea    0xd9e(%rip),%rdi
lea    0xda5(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%r15
mov    $0x64,%r12d
nop
mov    %r13,%rdi
mov    %r12d,%esi
call   1060 <fnGenRandInput@plt>
mov    %rbp,%rdi
xor    %esi,%esi
call   1090 <gettimeofday@plt>
lea    -0x1(%r12),%edx
movss  0x18(%rsp),%xmm0
movaps %xmm0,0x20(%rsp)
movsd  0x10(%rsp),%xmm0
movaps %xmm0,0x30(%rsp)
mov    %r13,%rdi
xor    %esi,%esi
call   1030 <fnMergeSort@plt>
mov    %rbp,%rdi
xor    %esi,%esi
call   1090 <gettimeofday@plt>
movaps 0x10(%rsp),%xmm0
movaps 0x20(%rsp),%xmm1
shufps $0xe4,%xmm0,%xmm1
shufps $0xe2,%xmm1,%xmm1
cvtdq2pd %xmm1,%xmm1
unpcklpd 0x30(%rsp),%xmm0
divpd  0xce8(%rip),%xmm0
addpd  %xmm1,%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
subsd  %xmm1,%xmm0
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r12d,%edx
call   10a0 <fprintf@plt>
lea    0x64(%r12),%eax
cmp    $0x1863c,%r12d
mov    %eax,%r12d
jb     12b0 <main+0x100>
mov    %r15,%rdi
call   1070 <fclose@plt>
lea    0xd4d(%rip),%rdi
call   1050 <puts@plt>
mov    %rbx,%r15
lea    0xce7(%rip),%r12
lea    0xcc5(%rip),%rbx
jmp    1256 <main+0xa6>
xor    %edi,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { double, i32 }
@.str = [37 x i8] c"\0A1.Plot the Graph\0A2.MergeSort\0A3.Exit\00"
@.str.1 = [20 x i8] c"\0AEnter your choice\0A\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [14 x i8] c"MergePlot.dat\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [8 x i8] c"%d\09%lf\0A\00"
@.str.6 = [84 x i8] c"\0AData File generated and stored in file < MergePlot.dat >.\0A Use a plotting utility\0A\00"
@.str.7 = [39 x i8] c"\0AEnter the number of elements to sort\0A\00"
@.str.8 = [17 x i8] c"\0AUnsorted Array\0A\00"
@.str.9 = [15 x i8] c"\0ASorted Array\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca %struct.timeval
%8 = alloca double
%9 = alloca double
%10 = alloca [500000 x i32]
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %16
16: ; preds = %83, %2
%17 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %15)
%20 = load i32, i32* %15
switch i32 %20, label %83 [
i32 1, label %21
i32 2, label %63
i32 3, label %81
]
21: ; preds = %16
%22 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %22, i32** %6
store i32 100, i32* %14
br label %23
23: ; preds = %56, %21
%24 = load i32, i32* %14
%25 = icmp slt i32 %24, 100000
br i1 %25, label %26, label %59
26: ; preds = %23
%27 = getelementptr inbounds [500000 x i32], [500000 x i32]* %10, i64 0, i64 0
%28 = load i32, i32* %14
%29 = call i32 @fnGenRandInput(i32* %27, i32 %28)
%30 = call i32 @gettimeofday(%struct.timeval* %7, i32* null)
%31 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
%32 = load i32, i32* %31
%33 = sitofp i32 %32 to double
%34 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
%35 = load double, double* %34
%36 = fdiv double %35, 1.000000e+06
%37 = fadd double %33, %36
store double %37, double* %8
%38 = getelementptr inbounds [500000 x i32], [500000 x i32]* %10, i64 0, i64 0
%39 = load i32, i32* %14
%40 = sub nsw i32 %39, 1
%41 = call i32 @fnMergeSort(i32* %38, i32 0, i32 %40)
%42 = call i32 @gettimeofday(%struct.timeval* %7, i32* null)
%43 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
%44 = load i32, i32* %43
%45 = sitofp i32 %44 to double
%46 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
%47 = load double, double* %46
%48 = fdiv double %47, 1.000000e+06
%49 = fadd double %45, %48
store double %49, double* %9
%50 = load i32*, i32** %6
%51 = load i32, i32* %14
%52 = load double, double* %9
%53 = load double, double* %8
%54 = fsub double %52, %53
%55 = call i32 @fprintf(i32* %50, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 %51, double %54)
br label %56
56: ; preds = %26
%57 = load i32, i32* %14
%58 = add nsw i32 %57, 100
store i32 %58, i32* %14
br label %23
59: ; preds = %23
%60 = load i32*, i32** %6
%61 = call i32 @fclose(i32* %60)
%62 = call i32 @printf(i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.6, i64 0, i64 0))
br label %83
63: ; preds = %16
%64 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.7, i64 0, i64 0))
%65 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %11)
%66 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0))
%67 = getelementptr inbounds [500000 x i32], [500000 x i32]* %10, i64 0, i64 0
%68 = load i32, i32* %11
%69 = call i32 @fnGenRandInput(i32* %67, i32 %68)
%70 = getelementptr inbounds [500000 x i32], [500000 x i32]* %10, i64 0, i64 0
%71 = load i32, i32* %11
%72 = call i32 @fnDispArray(i32* %70, i32 %71)
%73 = getelementptr inbounds [500000 x i32], [500000 x i32]* %10, i64 0, i64 0
%74 = load i32, i32* %11
%75 = sub nsw i32 %74, 1
%76 = call i32 @fnMergeSort(i32* %73, i32 0, i32 %75)
%77 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0))
%78 = getelementptr inbounds [500000 x i32], [500000 x i32]* %10, i64 0, i64 0
%79 = load i32, i32* %11
%80 = call i32 @fnDispArray(i32* %78, i32 %79)
br label %83
81: ; preds = %16
%82 = call i32 @exit(i32 0)
unreachable
83: ; preds = %16, %63, %59
br label %16
}

LLVM IR (-O2):
%struct.timeval = type { double, i32 }
@.str = [37 x i8] c"\0A1.Plot the Graph\0A2.MergeSort\0A3.Exit\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [14 x i8] c"MergePlot.dat\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [8 x i8] c"%d\09%lf\0A\00"
@str = [19 x i8] c"\0AEnter your choice\00"
@str.10 = [38 x i8] c"\0AEnter the number of elements to sort\00"
@str.11 = [16 x i8] c"\0AUnsorted Array\00"
@str.12 = [14 x i8] c"\0ASorted Array\00"
@str.13 = [83 x i8] c"\0AData File generated and stored in file < MergePlot.dat >.\0A Use a plotting utility\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca <4 x i32>
%4 = bitcast <4 x i32>* %3 to %struct.timeval*
%5 = alloca [500000 x i32]
%6 = alloca i32
%7 = alloca i32
%8 = bitcast <4 x i32>* %3 to i8*
%9 = bitcast [500000 x i32]* %5 to i8*
%10 = bitcast i32* %6 to i8*
%11 = bitcast i32* %7 to i8*
%12 = getelementptr inbounds [500000 x i32], [500000 x i32]* %5, i64 0, i64 0
%13 = getelementptr inbounds <4 x i32>, <4 x i32>* %3, i64 0, i64 2
%14 = bitcast <4 x i32>* %3 to double*
br label %15
15: ; preds = %20, %2
%16 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %7)
%19 = load i32, i32* %7
switch i32 %19, label %20 [
i32 1, label %21
i32 2, label %49
i32 3, label %63
]
20: ; preds = %15, %49, %46
br label %15
21: ; preds = %15
%22 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %23
23: ; preds = %21, %23
%24 = phi i32 [ 100, %21 ], [ %44, %23 ]
%25 = call i32 @fnGenRandInput(i32* %12, i32 %24)
%26 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%27 = load i32, i32* %13
%28 = load double, double* %14
%29 = add nsw i32 %24, -1
%30 = call i32 @fnMergeSort(i32* %12, i32 0, i32 %29)
%31 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%32 = load <4 x i32>, <4 x i32>* %3
%33 = shufflevector <4 x i32> %32, <4 x i32> poison, <2 x i32> <i32 2, i32 undef>
%34 = insertelement <2 x i32> %33, i32 %27, i64 1
%35 = sitofp <2 x i32> %34 to <2 x double>
%36 = bitcast <4 x i32> %32 to <2 x double>
%37 = insertelement <2 x double> %36, double %28, i64 1
%38 = fdiv <2 x double> %37, <double 1.000000e+06, double 1.000000e+06>
%39 = fadd <2 x double> %38, %35
%40 = shufflevector <2 x double> %39, <2 x double> poison, <2 x i32> <i32 1, i32 undef>
%41 = fsub <2 x double> %39, %40
%42 = extractelement <2 x double> %41, i64 0
%43 = call i32 @fprintf(i32* %22, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 %24, double %42)
%44 = add nuw nsw i32 %24, 100
%45 = icmp ult i32 %24, 99900
br i1 %45, label %23, label %46
46: ; preds = %23
%47 = call i32 @fclose(i32* %22)
%48 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([83 x i8], [83 x i8]* @str.13, i64 0, i64 0))
br label %20
49: ; preds = %15
%50 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.10, i64 0, i64 0))
%51 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %6)
%52 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.11, i64 0, i64 0))
%53 = load i32, i32* %6
%54 = call i32 @fnGenRandInput(i32* %12, i32 %53)
%55 = load i32, i32* %6
%56 = call i32 @fnDispArray(i32* %12, i32 %55)
%57 = load i32, i32* %6
%58 = add nsw i32 %57, -1
%59 = call i32 @fnMergeSort(i32* %12, i32 0, i32 %58)
%60 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.12, i64 0, i64 0))
%61 = load i32, i32* %6
%62 = call i32 @fnDispArray(i32* %12, i32 %61)
br label %20
63: ; preds = %15
%64 = call i32 @exit(i32 0)
unreachable
}