#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;
scalar_t__ clock();
int *malloc(int);
int /*<<< orphan*/ mergeSort(int *, int *, int, int);
int /*<<< orphan*/ populateTheArray(int *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int arraySize;
  double seconds;
  int *theArray;
  int *theArrayCopy;
  scanf("%d", &arraySize);
  if ((theArray = malloc(arraySize * sizeof(int))) == NULL) {
    printf("Failed to allocate memory. exit");
  }
  theArray = malloc(arraySize * sizeof(int));
  theArrayCopy = malloc(arraySize * sizeof(int));
  populateTheArray(theArray, arraySize);
  int begin = theArray[0];
  int end = arraySize;
  clock_t clockStarts = clock();
  mergeSort(theArray, theArrayCopy, begin, end);
  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)
lea    0xe8a(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1080 <scanf@plt>
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11aa <main+0x4a>
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1040 <populateTheArray@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    -0x28(%rbp),%ecx
call   1060 <mergeSort@plt>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
sub    -0x30(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2dc0(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
cvtsi2sdq -0x30(%rbp),%xmm0
mov    0x2da5(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
lea    0xdd0(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
cvtsi2sdq -0x38(%rbp),%xmm0
mov    0x2d81(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
lea    0xdbc(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  -0x10(%rbp),%xmm0
lea    0xdbb(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    $0x1,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xe8d(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1080 <scanf@plt>
mov    0x4(%rsp),%r14d
lea    0x0(,%r14,4),%ebp
mov    %ebp,%edi
call   1070 <malloc@plt>
test   %rax,%rax
jne    11b1 <main+0x51>
lea    0xe66(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4(%rsp),%r14d
lea    0x0(,%r14,4),%ebp
mov    %ebp,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %ebp,%edi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %r14d,%esi
call   1040 <populateTheArray@plt>
mov    (%rbx),%r12d
mov    0x4(%rsp),%r14d
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12d,%edx
mov    %r14d,%ecx
call   1060 <mergeSort@plt>
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%rbx
sub    %rbp,%rax
cvtsi2sd %rax,%xmm0
mov    0x2ddc(%rip),%r14
cvtsi2sdq (%r14),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %rbp,%xmm0
divsd  %xmm1,%xmm0
lea    0xdf5(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rbx,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sdq (%r14),%xmm1
divsd  %xmm1,%xmm0
lea    0xde3(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
lea    0xde7(%rip),%rdi
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1050 <printf@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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