#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 /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ clear_file(char *);
scalar_t__ clock();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
unsigned long pow(int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ random_vector(unsigned long *, unsigned long);
scalar_t__ realloc(unsigned long *, unsigned long);
int /*<<< orphan*/ sort_methods(unsigned long *, double *, int, unsigned long);
int /*<<< orphan*/ write_file(double *, unsigned long);
int main(void) {
  long unsigned *vector = NULL, lenght;
  int i, j, tests = 0;
  clear_file("data.db");
  printf("Sorting vectors with random distinct numbers\n");
  for (i = 1; i <= 7; i++) {
    lenght = pow(10, i);
    vector = (long unsigned *)realloc(vector, lenght * sizeof(long));
    if (vector == NULL) {
      printf("Is not possible alloc memory for vector of n = %li elements\n",
             lenght);
      exit(EXIT_FAILURE);
    }
    clock_t t;
    t = clock();
    random_vector(vector, lenght);
    t = clock() - t;
    printf("[random]time to generate (%li): %.10fs\n", lenght,
           (double)t / CLOCKS_PER_SEC);
    double temp_times[3];
    for (j = 0; j < 20; j++) {
      printf("Execution j = %d\n", j);
      sort_methods(vector, temp_times, j, lenght);
      write_file(temp_times, lenght);
      printf("\n");
    }
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
lea    0xe4b(%rip),%rdi
call   1070 <clear_file@plt>
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x1c(%rbp)
cmpl   $0x7,-0x1c(%rbp)
jg     12e6 <main+0x156>
mov    -0x1c(%rbp),%esi
mov    $0xa,%edi
call   1090 <pow@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
shl    $0x3,%rsi
call   1080 <realloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    122a <main+0x9a>
mov    -0x18(%rbp),%rsi
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <random_vector@plt>
mov    $0x0,%al
call   1040 <clock@plt>
sub    -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rsi
cvtsi2sdq -0x30(%rbp),%xmm0
mov    0x2d86(%rip),%rax
divsd  (%rax),%xmm0
lea    0xe06(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movl   $0x0,-0x20(%rbp)
cmpl   $0x14,-0x20(%rbp)
jge    12d3 <main+0x143>
mov    -0x20(%rbp),%esi
lea    0xe0c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x50(%rbp),%rsi
mov    -0x20(%rbp),%edx
mov    -0x18(%rbp),%rcx
call   10b0 <sort_methods@plt>
lea    -0x50(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <write_file@plt>
lea    0xded(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    127b <main+0xeb>
jmp    12d8 <main+0x148>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11cf <main+0x3f>
mov    0x2ce3(%rip),%rax
mov    (%rax),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
lea    0xe3b(%rip),%rdi
call   1090 <clear_file@plt>
lea    0xeae(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%r15d
lea    0xe8a(%rip),%r12
lea    0x10(%rsp),%r13
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    $0xa,%edi
mov    %r15d,%esi
call   10b0 <pow@plt>
mov    %rax,%rbp
lea    0x0(,%rax,8),%rsi
mov    %rbx,%rdi
call   10a0 <realloc@plt>
test   %rax,%rax
je     12d3 <main+0x123>
mov    %rax,%rbx
xor    %r14d,%r14d
xor    %eax,%eax
call   1060 <clock@plt>
mov    %rax,0x8(%rsp)
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1030 <random_vector@plt>
xor    %eax,%eax
call   1060 <clock@plt>
sub    0x8(%rsp),%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mov    0x2d97(%rip),%rax
divsd  (%rax),%xmm0
lea    0xde9(%rip),%rdi
mov    %rbp,%rsi
mov    $0x1,%al
call   1070 <printf@plt>
cs nopw 0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r14d,%edx
mov    %rbp,%rcx
call   10d0 <sort_methods@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
call   1080 <write_file@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
add    $0x1,%r14d
cmp    $0x14,%r14d
jne    1270 <main+0xc0>
add    $0x1,%r15d
cmp    $0x8,%r15d
jne    11f0 <main+0x40>
mov    0x2d0e(%rip),%rax
mov    (%rax),%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd2e(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2ced(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"data.db\00"
@.str.1 = [46 x i8] c"Sorting vectors with random distinct numbers\0A\00"
@.str.2 = [61 x i8] c"Is not possible alloc memory for vector of n = %li elements\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [40 x i8] c"[random]time to generate (%li): %.10fs\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.4 = [18 x i8] c"Execution j = %d\0A\00"
@.str.5 = [2 x i8] c"\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i64*
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
%8 = alloca [3 x double]
store i32 0, i32* %1
store i64* null, i64** %2
store i32 0, i32* %6
%9 = call i32 @clear_file(i8* getelementptr inbounds ([8 x i8], [8 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))
store i32 1, i32* %4
br label %11
11: ; preds = %62, %0
%12 = load i32, i32* %4
%13 = icmp sle i32 %12, 7
br i1 %13, label %14, label %65
14: ; preds = %11
%15 = load i32, i32* %4
%16 = call i64 @pow(i32 10, i32 %15)
store i64 %16, i64* %3
%17 = load i64*, i64** %2
%18 = load i64, i64* %3
%19 = mul i64 %18, 8
%20 = call i64 @realloc(i64* %17, i64 %19)
%21 = inttoptr i64 %20 to i64*
store i64* %21, i64** %2
%22 = load i64*, i64** %2
%23 = icmp eq i64* %22, null
br i1 %23, label %24, label %29
24: ; preds = %14
%25 = load i64, i64* %3
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.2, i64 0, i64 0), i64 %25)
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %14
%30 = call i64 (...) @clock()
store i64 %30, i64* %7
%31 = load i64*, i64** %2
%32 = load i64, i64* %3
%33 = call i32 @random_vector(i64* %31, i64 %32)
%34 = call i64 (...) @clock()
%35 = load i64, i64* %7
%36 = sub nsw i64 %34, %35
store i64 %36, i64* %7
%37 = load i64, i64* %3
%38 = load i64, i64* %7
%39 = sitofp i64 %38 to double
%40 = load double, double* @CLOCKS_PER_SEC
%41 = fdiv double %39, %40
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i64 %37, double %41)
store i32 0, i32* %5
br label %43
43: ; preds = %58, %29
%44 = load i32, i32* %5
%45 = icmp slt i32 %44, 20
br i1 %45, label %46, label %61
46: ; preds = %43
%47 = load i32, i32* %5
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %47)
%49 = load i64*, i64** %2
%50 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 0
%51 = load i32, i32* %5
%52 = load i64, i64* %3
%53 = call i32 @sort_methods(i64* %49, double* %50, i32 %51, i64 %52)
%54 = getelementptr inbounds [3 x double], [3 x double]* %8, i64 0, i64 0
%55 = load i64, i64* %3
%56 = call i32 @write_file(double* %54, i64 %55)
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %58
58: ; preds = %46
%59 = load i32, i32* %5
%60 = add nsw i32 %59, 1
store i32 %60, i32* %5
br label %43
61: ; preds = %43
br label %62
62: ; preds = %61
%63 = load i32, i32* %4
%64 = add nsw i32 %63, 1
store i32 %64, i32* %4
br label %11
65: ; preds = %11
%66 = load i32, i32* @EXIT_SUCCESS
ret i32 %66
}

LLVM IR (-O2):
@.str = [8 x i8] c"data.db\00"
@.str.2 = [61 x i8] c"Is not possible alloc memory for vector of n = %li elements\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [40 x i8] c"[random]time to generate (%li): %.10fs\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.4 = [18 x i8] c"Execution j = %d\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [45 x i8] c"Sorting vectors with random distinct numbers\00"
define i32 @main() {
%1 = alloca [3 x double]
%2 = tail call i32 @clear_file(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str, i64 0, i64 0))
%4 = bitcast [3 x double]* %1 to i8*
%5 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 0, i64 0
br label %6
6: ; preds = %0, %35
%7 = phi i64* [ null, %0 ], [ %12, %35 ]
%8 = phi i32 [ 1, %0 ], [ %36, %35 ]
%9 = call i64 @pow(i32 10, i32 %8)
%10 = shl i64 %9, 3
%11 = call i64 @realloc(i64* %7, i64 %10)
%12 = inttoptr i64 %11 to i64*
%13 = icmp eq i64 %11, 0
br i1 %13, label %14, label %18
14: ; preds = %6
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @.str.2, i64 0, i64 0), i64 %9)
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %6
%19 = call i64 (...) @clock()
%20 = call i32 @random_vector(i64* %12, i64 %9)
%21 = call i64 (...) @clock()
%22 = sub nsw i64 %21, %19
%23 = sitofp i64 %22 to double
%24 = load double, double* @CLOCKS_PER_SEC
%25 = fdiv double %23, %24
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i64 %9, double %25)
br label %27
27: ; preds = %18, %27
%28 = phi i32 [ 0, %18 ], [ %33, %27 ]
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %28)
%30 = call i32 @sort_methods(i64* %12, double* %5, i32 %28, i64 %9)
%31 = call i32 @write_file(double* %5, i64 %9)
%32 = call i32 @putchar(i32 10)
%33 = add nuw nsw i32 %28, 1
%34 = icmp eq i32 %33, 20
br i1 %34, label %35, label %27
35: ; preds = %27
%36 = add nuw nsw i32 %8, 1
%37 = icmp eq i32 %36, 8
br i1 %37, label %38, label %6
38: ; preds = %35
%39 = load i32, i32* @EXIT_SUCCESS
ret i32 %39
}