#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;

/* Variables and functions */
scalar_t__ CLOCKS_PER_SEC;
int /*<<< orphan*/ buildArrayWithTaxonomy(int *, int, int);
scalar_t__ clock();
int *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ quickSortWithInsertionSort(int *, int, int);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int *theArray;
  int type, size = 10000000;
  double seconds;
  printf("\nChoose the array type");
  printf("\n(1)Random | (2) Best case | (3) Worst case: ");
  scanf("%d", &type);
  if ((theArray = malloc(size * sizeof(int))) == NULL) {
    printf("Failed to allocate memory. exit");
  }
  theArray = malloc(size * sizeof(int));
  buildArrayWithTaxonomy(theArray, type, size);
  int pivot = 0;
  clock_t clockStarts = clock();
  quickSortWithInsertionSort(theArray, pivot, size);
  clock_t clockEnds = clock();
  seconds = (double)(clockEnds - clockStarts) / (double)CLOCKS_PER_SEC;
  printf("\nStarted at: %g", (double)clockStarts / (double)CLOCKS_PER_SEC);
  printf("\nCompleted at: %g", (double)clockEnds / (double)CLOCKS_PER_SEC);
  printf("\nExecution time in seconds: %g", seconds);
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x989680,-0x18(%rbp)
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xeac(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1070 <scanf@plt>
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11cd <main+0x6d>
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1040 <buildArrayWithTaxonomy@plt>
movl   $0x0,-0x24(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1080 <quickSortWithInsertionSort@plt>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
sub    -0x30(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2db9(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
cvtsi2sdq -0x30(%rbp),%xmm0
mov    0x2d9e(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
lea    0xe0e(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
cvtsi2sdq -0x38(%rbp),%xmm0
mov    0x2d7a(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
lea    0xdfa(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  -0x20(%rbp),%xmm0
lea    0xdf9(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    $0x1,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xe90(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe99(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeb9(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1070 <scanf@plt>
mov    $0x2625a00,%edi
call   1060 <malloc@plt>
test   %rax,%rax
jne    11b3 <main+0x53>
lea    0xe9c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x2625a00,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    0x4(%rsp),%esi
mov    %rax,%rdi
mov    $0x989680,%edx
call   1040 <buildArrayWithTaxonomy@plt>
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%r14
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x989680,%edx
call   1080 <quickSortWithInsertionSort@plt>
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%rbx
sub    %r14,%rax
cvtsi2sd %rax,%xmm0
mov    0x2de5(%rip),%r15
cvtsi2sdq (%r15),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %r14,%xmm0
divsd  %xmm1,%xmm0
lea    0xe43(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rbx,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sdq (%r15),%xmm1
divsd  %xmm1,%xmm0
lea    0xe31(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
lea    0xe35(%rip),%rdi
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1050 <printf@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [23 x i8] c"\0AChoose the array type\00"
@.str.1 = [46 x i8] c"\0A(1)Random | (2) Best case | (3) Worst case: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [32 x i8] c"Failed to allocate memory. exit\00"
@CLOCKS_PER_SEC = global i64 0
@.str.4 = [16 x i8] c"\0AStarted at: %g\00"
@.str.5 = [18 x i8] c"\0ACompleted at: %g\00"
@.str.6 = [31 x i8] c"\0AExecution time in seconds: %g\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca double
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
store i32 0, i32* %1
store i32 10000000, i32* %4
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%12 = load i32, i32* %4
%13 = sext i32 %12 to i64
%14 = mul i64 %13, 4
%15 = trunc i64 %14 to i32
%16 = call i32* @malloc(i32 %15)
store i32* %16, i32** %2
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %20
18: ; preds = %0
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
br label %20
20: ; preds = %18, %0
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = mul i64 %22, 4
%24 = trunc i64 %23 to i32
%25 = call i32* @malloc(i32 %24)
store i32* %25, i32** %2
%26 = load i32*, i32** %2
%27 = load i32, i32* %3
%28 = load i32, i32* %4
%29 = call i32 @buildArrayWithTaxonomy(i32* %26, i32 %27, i32 %28)
store i32 0, i32* %6
%30 = call i64 (...) @clock()
store i64 %30, i64* %7
%31 = load i32*, i32** %2
%32 = load i32, i32* %6
%33 = load i32, i32* %4
%34 = call i32 @quickSortWithInsertionSort(i32* %31, i32 %32, i32 %33)
%35 = call i64 (...) @clock()
store i64 %35, i64* %8
%36 = load i64, i64* %8
%37 = load i64, i64* %7
%38 = sub nsw i64 %36, %37
%39 = sitofp i64 %38 to double
%40 = load i64, i64* @CLOCKS_PER_SEC
%41 = sitofp i64 %40 to double
%42 = fdiv double %39, %41
store double %42, double* %5
%43 = load i64, i64* %7
%44 = sitofp i64 %43 to double
%45 = load i64, i64* @CLOCKS_PER_SEC
%46 = sitofp i64 %45 to double
%47 = fdiv double %44, %46
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), double %47)
%49 = load i64, i64* %8
%50 = sitofp i64 %49 to double
%51 = load i64, i64* @CLOCKS_PER_SEC
%52 = sitofp i64 %51 to double
%53 = fdiv double %50, %52
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), double %53)
%55 = load double, double* %5
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), double %55)
ret i32 1
}

LLVM IR (-O2):
@.str = [23 x i8] c"\0AChoose the array type\00"
@.str.1 = [46 x i8] c"\0A(1)Random | (2) Best case | (3) Worst case: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [32 x i8] c"Failed to allocate memory. exit\00"
@CLOCKS_PER_SEC = global i64 0
@.str.4 = [16 x i8] c"\0AStarted at: %g\00"
@.str.5 = [18 x i8] c"\0ACompleted at: %g\00"
@.str.6 = [31 x i8] c"\0AExecution time in seconds: %g\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%6 = call i32* @malloc(i32 40000000)
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
br label %10
10: ; preds = %8, %0
%11 = call i32* @malloc(i32 40000000)
%12 = load i32, i32* %1
%13 = call i32 @buildArrayWithTaxonomy(i32* %11, i32 %12, i32 10000000)
%14 = call i64 (...) @clock()
%15 = call i32 @quickSortWithInsertionSort(i32* %11, i32 0, i32 10000000)
%16 = call i64 (...) @clock()
%17 = sub nsw i64 %16, %14
%18 = sitofp i64 %17 to double
%19 = load i64, i64* @CLOCKS_PER_SEC
%20 = sitofp i64 %19 to double
%21 = fdiv double %18, %20
%22 = sitofp i64 %14 to double
%23 = fdiv double %22, %20
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), double %23)
%25 = sitofp i64 %16 to double
%26 = load i64, i64* @CLOCKS_PER_SEC
%27 = sitofp i64 %26 to double
%28 = fdiv double %25, %27
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), double %28)
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), double %21)
ret i32 1
}