#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 /*<<< orphan*/ printVector(int *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ quickSort(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ readVectorFromFile(int **, int *, char *, char *);
int main(int argc, char **argv) {
  printf("------ Begin QuickSort ------\n");
  int n, i = 0;
  int *vectorToSort;
  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();
  quickSort(vectorToSort, 0, n - 1);
  end = clock();
  printf("The sorted vector is: ");
  printVector(vectorToSort, n);
  printf("\n");
  free(vectorToSort);
  printf("Elapsed: %f seconds while sorting.\n",
         (double)(end - start) / CLOCKS_PER_SEC);
  printf("------- End QuickSort -------\n");
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%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   1080 <err@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    -0xb0(%rbp),%rcx
lea    -0x20(%rbp),%rdi
lea    -0x14(%rbp),%rsi
call   1050 <readVectorFromFile@plt>
cmp    $0x0,%eax
jne    11e5 <main+0x75>
lea    -0xb0(%rbp),%rdi
call   1080 <err@plt>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1090 <quickSort@plt>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x30(%rbp)
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1070 <printVector@plt>
lea    0xdf0(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rax
sub    -0x28(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2d97(%rip),%rax
divsd  (%rax),%xmm0
lea    0xe0d(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2d60(%rip),%rax
mov    (%rax),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x98,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xec9(%rip),%rdi
call   1050 <puts@plt>
cmp    $0x1,%ebp
jne    11bb <main+0x2b>
lea    0xe4a(%rip),%rdi
call   10a0 <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    11e1 <main+0x51>
lea    0x10(%rsp),%rdi
call   10a0 <err@plt>
xor    %eax,%eax
call   1060 <clock@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%rdi
mov    0x4(%rsp),%edx
add    $0xffffffff,%edx
xor    %esi,%esi
call   10b0 <quickSort@plt>
xor    %eax,%eax
call   1060 <clock@plt>
mov    %rax,%rbp
lea    0xe24(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x8(%rsp),%rdi
mov    0x4(%rsp),%esi
call   1090 <printVector@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
sub    %rbx,%rbp
cvtsi2sd %rbp,%xmm0
mov    0x2da1(%rip),%rax
divsd  (%rax),%xmm0
lea    0xdf8(%rip),%rdi
mov    $0x1,%al
call   1080 <printf@plt>
lea    0xe2c(%rip),%rdi
call   1050 <puts@plt>
mov    0x2d6c(%rip),%rax
mov    (%rax),%eax
add    $0x98,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [31 x i8] c"------ Begin QuickSort ------\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 QuickSort -------\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 i64
%10 = alloca i64
%11 = alloca [128 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %7
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 @err(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %15, %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %11, i64 0, i64 0
%22 = call i32 @readVectorFromFile(i32** %8, i32* %6, i8* %20, i8* %21)
%23 = icmp ne i32 %22, 0
br i1 %23, label %27, label %24
24: ; preds = %17
%25 = getelementptr inbounds [128 x i8], [128 x i8]* %11, i64 0, i64 0
%26 = call i32 @err(i8* %25)
br label %27
27: ; preds = %24, %17
%28 = call i64 (...) @clock()
store i64 %28, i64* %9
%29 = load i32*, i32** %8
%30 = load i32, i32* %6
%31 = sub nsw i32 %30, 1
%32 = call i32 @quickSort(i32* %29, i32 0, i32 %31)
%33 = call i64 (...) @clock()
store i64 %33, i64* %10
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%35 = load i32*, i32** %8
%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 i64, i64* %10
%42 = load i64, i64* %9
%43 = sub nsw i64 %41, %42
%44 = sitofp i64 %43 to double
%45 = load double, double* @CLOCKS_PER_SEC
%46 = fdiv double %44, %45
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), double %46)
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
%49 = load i32, i32* @EXIT_SUCCESS
ret i32 %49
}

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 QuickSort ------\00"
@str.6 = [30 x i8] c"------- End QuickSort -------\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** %4
%23 = load i32, i32* %3
%24 = add nsw i32 %23, -1
%25 = call i32 @quickSort(i32* %22, i32 0, i32 %24)
%26 = call i64 (...) @clock()
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%28 = load i32*, i32** %4
%29 = load i32, i32* %3
%30 = call i32 @printVector(i32* %28, i32 %29)
%31 = call i32 @putchar(i32 10)
%32 = load i32*, i32** %4
%33 = call i32 @free(i32* %32)
%34 = sub nsw i64 %26, %21
%35 = sitofp i64 %34 to double
%36 = load double, double* @CLOCKS_PER_SEC
%37 = fdiv double %35, %36
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), double %37)
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.6, i64 0, i64 0))
%40 = load i32, i32* @EXIT_SUCCESS
ret i32 %40
}