#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 *, long long *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ readVectorFromFile(int **, int *, char *, char *);
int main(int argc, char **argv) {
  printf("------ Begin InversionsCount ------\n");
  int n, i = 0;
  int *vectorToSort, *sortedVector;
  clock_t start, end;
  char error[128];
  long long inversionsCount = 0;
  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, &inversionsCount);
  end = clock();
  free(vectorToSort);
  free(sortedVector);
  printf("Number of inversions: %lld\n", inversionsCount);
  printf("Elapsed: %f seconds.\n", (double)(end - start) / CLOCKS_PER_SEC);
  printf("------- End InversionsCount -------\n");
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x18(%rbp)
movq   $0x0,-0xc8(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11af <main+0x4f>
lea    0xe7b(%rip),%rdi
call   1080 <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    11e0 <main+0x80>
lea    -0xc0(%rbp),%rdi
call   1080 <err@plt>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
lea    -0xc8(%rbp),%rdx
call   1070 <mergeSort@plt>
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0xc8(%rbp),%rsi
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x38(%rbp),%rax
sub    -0x30(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2da0(%rip),%rax
divsd  (%rax),%xmm0
lea    0xe21(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2d69(%rip),%rax
mov    (%rax),%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0xa0,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xede(%rip),%rdi
call   1040 <puts@plt>
movq   $0x0,0x10(%rsp)
cmp    $0x1,%ebp
jne    11a6 <main+0x36>
lea    0xe5f(%rip),%rdi
call   1090 <err@plt>
mov    0x8(%rbx),%rdx
lea    0x18(%rsp),%rdi
lea    0xc(%rsp),%rsi
lea    0x20(%rsp),%rcx
call   1060 <readVectorFromFile@plt>
test   %eax,%eax
jne    11cc <main+0x5c>
lea    0x20(%rsp),%rdi
call   1090 <err@plt>
xor    %eax,%eax
call   1050 <clock@plt>
mov    %rax,%r14
mov    0xc(%rsp),%edi
mov    0x18(%rsp),%rsi
lea    0x10(%rsp),%rdx
call   1080 <mergeSort@plt>
mov    %rax,%rbp
xor    %eax,%eax
call   1050 <clock@plt>
mov    %rax,%rbx
mov    0x18(%rsp),%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    0x10(%rsp),%rsi
lea    0xe1f(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
sub    %r14,%rbx
cvtsi2sd %rbx,%xmm0
mov    0x2dbe(%rip),%rax
divsd  (%rax),%xmm0
lea    0xe1a(%rip),%rdi
mov    $0x1,%al
call   1070 <printf@plt>
lea    0xe46(%rip),%rdi
call   1040 <puts@plt>
mov    0x2d89(%rip),%rax
mov    (%rax),%eax
add    $0xa0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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