#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 */
double CLOCKS_PER_SEC;
int EXIT_SUCCESS;
scalar_t__ clock();
int /*<<< orphan*/ err(char *);
int /*<<< orphan*/ free(int *);
int *mergeSort(int, int *);
int /*<<< orphan*/ printVector(int *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ readVectorFromFile(int **, int *, char *, char *);
int main(int argc, char **argv) {
  printf("------ Begin MergeSort ------\n");
  int n, i = 0;
  int *vectorToSort, *sortedVector;
  clock_t start, end;
  char error[128];
  if (argc == 1) {
    err("Err. The input file must be given as an argument.\n");
  }
  if (!readVectorFromFile(&vectorToSort, &n, argv[1], error)) {
    err(error);
  }
  start = clock();
  sortedVector = mergeSort(n, vectorToSort);
  end = clock();
  printf("The sorted vector is: ");
  printVector(sortedVector, n);
  printf("\n");
  free(vectorToSort);
  free(sortedVector);
  printf("Elapsed: %f seconds while sorting.\n",
         (double)(end - start) / CLOCKS_PER_SEC);
  printf("------- End MergeSort -------\n");
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11b4 <main+0x44>
lea    0xe70(%rip),%rdi
call   1090 <err@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    -0xc0(%rbp),%rcx
lea    -0x20(%rbp),%rdi
lea    -0x14(%rbp),%rsi
call   1050 <readVectorFromFile@plt>
cmp    $0x0,%eax
jne    11e5 <main+0x75>
lea    -0xc0(%rbp),%rdi
call   1090 <err@plt>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1080 <mergeSort@plt>
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x38(%rbp)
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1070 <printVector@plt>
lea    0xdf1(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rax
sub    -0x30(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2d8f(%rip),%rax
divsd  (%rax),%xmm0
lea    0xe05(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2d58(%rip),%rax
mov    (%rax),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x90,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xec7(%rip),%rdi
call   1050 <puts@plt>
cmp    $0x1,%ebp
jne    11bd <main+0x2d>
lea    0xe48(%rip),%rdi
call   10b0 <err@plt>
mov    0x8(%rbx),%rdx
lea    0x8(%rsp),%rdi
lea    0x4(%rsp),%rsi
lea    0x10(%rsp),%rcx
call   1070 <readVectorFromFile@plt>
test   %eax,%eax
jne    11e3 <main+0x53>
lea    0x10(%rsp),%rdi
call   10b0 <err@plt>
xor    %eax,%eax
call   1060 <clock@plt>
mov    %rax,%r14
mov    0x4(%rsp),%edi
mov    0x8(%rsp),%rsi
call   10a0 <mergeSort@plt>
mov    %rax,%rbp
xor    %eax,%eax
call   1060 <clock@plt>
mov    %rax,%rbx
lea    0xe24(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x4(%rsp),%esi
mov    %rbp,%rdi
call   1090 <printVector@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
sub    %r14,%rbx
cvtsi2sd %rbx,%xmm0
mov    0x2d9b(%rip),%rax
divsd  (%rax),%xmm0
lea    0xdf2(%rip),%rdi
mov    $0x1,%al
call   1080 <printf@plt>
lea    0xe26(%rip),%rdi
call   1050 <puts@plt>
mov    0x2d66(%rip),%rax
mov    (%rax),%eax
add    $0x90,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [31 x i8] c"------ Begin MergeSort ------\0A\00"
@.str.1 = [51 x i8] c"Err. The input file must be given as an argument.\0A\00"
@.str.2 = [23 x i8] c"The sorted vector is: \00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [36 x i8] c"Elapsed: %f seconds while sorting.\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.5 = [31 x i8] c"------- End MergeSort -------\0A\00"
@EXIT_SUCCESS = global i32 0
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 i64
%11 = alloca i64
%12 = alloca [128 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %7
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 @err(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16, %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = getelementptr inbounds [128 x i8], [128 x i8]* %12, i64 0, i64 0
%23 = call i32 @readVectorFromFile(i32** %8, i32* %6, i8* %21, i8* %22)
%24 = icmp ne i32 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %18
%26 = getelementptr inbounds [128 x i8], [128 x i8]* %12, i64 0, i64 0
%27 = call i32 @err(i8* %26)
br label %28
28: ; preds = %25, %18
%29 = call i64 (...) @clock()
store i64 %29, i64* %10
%30 = load i32, i32* %6
%31 = load i32*, i32** %8
%32 = call i32* @mergeSort(i32 %30, i32* %31)
store i32* %32, i32** %9
%33 = call i64 (...) @clock()
store i64 %33, i64* %11
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%35 = load i32*, i32** %9
%36 = load i32, i32* %6
%37 = call i32 @printVector(i32* %35, i32 %36)
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%39 = load i32*, i32** %8
%40 = call i32 @free(i32* %39)
%41 = load i32*, i32** %9
%42 = call i32 @free(i32* %41)
%43 = load i64, i64* %11
%44 = load i64, i64* %10
%45 = sub nsw i64 %43, %44
%46 = sitofp i64 %45 to double
%47 = load double, double* @CLOCKS_PER_SEC
%48 = fdiv double %46, %47
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), double %48)
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
%51 = load i32, i32* @EXIT_SUCCESS
ret i32 %51
}

LLVM IR (-O2):
@.str.1 = [51 x i8] c"Err. The input file must be given as an argument.\0A\00"
@.str.2 = [23 x i8] c"The sorted vector is: \00"
@.str.4 = [36 x i8] c"Elapsed: %f seconds while sorting.\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@EXIT_SUCCESS = global i32 0
@str = [30 x i8] c"------ Begin MergeSort ------\00"
@str.6 = [30 x i8] c"------- End MergeSort -------\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca [128 x i8]
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32** %4 to i8*
%9 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%10 = icmp eq i32 %0, 1
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = tail call i32 @err(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %11, %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @readVectorFromFile(i32** %4, i32* %3, i8* %15, i8* %9)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = call i32 @err(i8* %9)
br label %20
20: ; preds = %18, %13
%21 = call i64 (...) @clock()
%22 = load i32, i32* %3
%23 = load i32*, i32** %4
%24 = call i32* @mergeSort(i32 %22, i32* %23)
%25 = call i64 (...) @clock()
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%27 = load i32, i32* %3
%28 = call i32 @printVector(i32* %24, i32 %27)
%29 = call i32 @putchar(i32 10)
%30 = load i32*, i32** %4
%31 = call i32 @free(i32* %30)
%32 = call i32 @free(i32* %24)
%33 = sub nsw i64 %25, %21
%34 = sitofp i64 %33 to double
%35 = load double, double* @CLOCKS_PER_SEC
%36 = fdiv double %34, %35
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), double %36)
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.6, i64 0, i64 0))
%39 = load i32, i32* @EXIT_SUCCESS
ret i32 %39
}