#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*/ fnHeapSort(int *, 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(void) {
  FILE *fp;
  struct timeval tv;
  double dStart, dEnd;
  int iaArr[500000], iNum, iPos, iKey, i, iChoice;
  for (;;) {
    printf("\n1.Plot the Graph\n2.HeapSort\n3.Exit");
    printf("\nEnter your choice\n");
    scanf("%d", &iChoice);
    switch (iChoice) {
    case 1:
      fp = fopen("HeapPlot.dat", "w");
      for (i = 100; i < 100000; i += 100) {
        fnGenRandInput(iaArr, i);
        gettimeofday(&tv, NULL);
        dStart = tv.tv_sec + (tv.tv_usec / 1000000.0);
        fnHeapSort(iaArr, i);
        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 < HeapPlot.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);
      fnHeapSort(iaArr, iNum);
      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    $0x1e84d0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe4f(%rip),%rdi
call   1060 <printf@plt>
lea    0xe67(%rip),%rdi
call   1060 <printf@plt>
lea    0xe6f(%rip),%rdi
lea    -0x1e84c4(%rbp),%rsi
call   10a0 <scanf@plt>
mov    -0x1e84c4(%rbp),%eax
mov    %eax,-0x1e84c8(%rbp)
sub    $0x1,%eax
je     121f <main+0x7f>
jmp    11f7 <main+0x57>
mov    -0x1e84c8(%rbp),%eax
sub    $0x2,%eax
je     131a <main+0x17a>
jmp    120b <main+0x6b>
mov    -0x1e84c8(%rbp),%eax
sub    $0x3,%eax
je     139e <main+0x1fe>
jmp    13a5 <main+0x205>
lea    0xe1d(%rip),%rdi
lea    0xe23(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x10(%rbp)
movl   $0x64,-0x1e84c0(%rbp)
cmpl   $0x186a0,-0x1e84c0(%rbp)
jge    1300 <main+0x160>
lea    -0x1e84b0(%rbp),%rdi
mov    -0x1e84c0(%rbp),%esi
call   1040 <fnGenRandInput@plt>
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <gettimeofday@plt>
cvtsi2sdl -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  0xd7f(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
lea    -0x1e84b0(%rbp),%rdi
mov    -0x1e84c0(%rbp),%esi
call   1080 <fnHeapSort@plt>
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <gettimeofday@plt>
cvtsi2sdl -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  0xd41(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x1e84c0(%rbp),%edx
movsd  -0x30(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
lea    0xd6b(%rip),%rsi
call   1090 <fprintf@plt>
mov    -0x1e84c0(%rbp),%eax
add    $0x64,%eax
mov    %eax,-0x1e84c0(%rbp)
jmp    1240 <main+0xa0>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
lea    0xd4a(%rip),%rdi
call   1060 <printf@plt>
jmp    13a5 <main+0x205>
lea    0xd8c(%rip),%rdi
call   1060 <printf@plt>
lea    0xd13(%rip),%rdi
lea    -0x1e84b4(%rbp),%rsi
call   10a0 <scanf@plt>
lea    0xd94(%rip),%rdi
call   1060 <printf@plt>
lea    -0x1e84b0(%rbp),%rdi
mov    -0x1e84b4(%rbp),%esi
call   1040 <fnGenRandInput@plt>
lea    -0x1e84b0(%rbp),%rdi
mov    -0x1e84b4(%rbp),%esi
call   1030 <fnDispArray@plt>
lea    -0x1e84b0(%rbp),%rdi
mov    -0x1e84b4(%rbp),%esi
call   1080 <fnHeapSort@plt>
lea    0xd63(%rip),%rdi
call   1060 <printf@plt>
lea    -0x1e84b0(%rbp),%rdi
mov    -0x1e84b4(%rbp),%esi
call   1030 <fnDispArray@plt>
jmp    13a5 <main+0x205>
xor    %edi,%edi
call   10c0 <exit@plt>
jmp    11b2 <main+0x12>

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    0xe7f(%rip),%r12
lea    0xe5e(%rip),%rbx
lea    0x40(%rsp),%r13
lea    0x10(%rsp),%rbp
lea    0xe5f(%rip),%r14
jmp    1251 <main+0xa1>
nopl   0x0(%rax)
lea    0xe6a(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
lea    0x8(%rsp),%rsi
call   10b0 <scanf@plt>
lea    0xe77(%rip),%rdi
call   1040 <puts@plt>
mov    0x8(%rsp),%esi
mov    %r13,%rdi
call   1050 <fnGenRandInput@plt>
mov    0x8(%rsp),%esi
mov    %r13,%rdi
call   1030 <fnDispArray@plt>
mov    0x8(%rsp),%esi
mov    %r13,%rdi
call   1090 <fnHeapSort@plt>
lea    0xe57(%rip),%rdi
call   1040 <puts@plt>
mov    0x8(%rsp),%esi
mov    %r13,%rdi
call   1030 <fnDispArray@plt>
mov    %r15,%rdi
call   1070 <printf@plt>
mov    %r12,%rdi
call   1040 <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    1251 <main+0xa1>
jmp    136d <main+0x1bd>
nopw   0x0(%rax,%rax,1)
mov    %r15,%rbx
lea    0xd9d(%rip),%rdi
lea    0xda3(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%r15
xor    %r12d,%r12d
nopl   0x0(%rax)
add    $0x64,%r12d
mov    %r13,%rdi
mov    %r12d,%esi
call   1050 <fnGenRandInput@plt>
mov    %rbp,%rdi
xor    %esi,%esi
call   1080 <gettimeofday@plt>
movss  0x18(%rsp),%xmm0
movaps %xmm0,0x20(%rsp)
movsd  0x10(%rsp),%xmm0
movaps %xmm0,0x30(%rsp)
mov    %r13,%rdi
mov    %r12d,%esi
call   1090 <fnHeapSort@plt>
mov    %rbp,%rdi
xor    %esi,%esi
call   1080 <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>
cmp    $0x1863c,%r12d
jb     12b0 <main+0x100>
mov    %r15,%rdi
call   1060 <fclose@plt>
lea    0xd53(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%r15
lea    0xced(%rip),%r12
lea    0xccc(%rip),%rbx
jmp    1251 <main+0xa1>
xor    %edi,%edi
call   10d0 <exit@plt>

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

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