#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*/ bubble_sort(unsigned long *, int /*<<< orphan*/,
                               unsigned long);
scalar_t__ calloc(unsigned long, int);
scalar_t__ clock();
int /*<<< orphan*/ copy_vector(unsigned long *, unsigned long *, unsigned long);
int /*<<< orphan*/ free(unsigned long *);
int /*<<< orphan*/ merge_sort(unsigned long *, int /*<<< orphan*/,
                              unsigned long);
int /*<<< orphan*/ printf(char *, char *, unsigned long, double);
int /*<<< orphan*/ quick_sort(unsigned long *, int /*<<< orphan*/,
                              unsigned long);
void sort_methods(long unsigned *vector, double times[3], int tests,
                  long unsigned lenght) {
  long unsigned *shadow = NULL;
  clock_t t;
  shadow = (long unsigned *)calloc(lenght, sizeof(long));
  copy_vector(shadow, vector, lenght);
  t = clock();
  bubble_sort(shadow, 0, lenght);
  t = clock() - t;
  printf("[%s]time to sort(%li): %4.10fs\n", "bubble_sort", lenght,
         ((double)t / CLOCKS_PER_SEC));
  times[0] = ((double)t / CLOCKS_PER_SEC);
  ;
  copy_vector(shadow, vector, lenght);
  t = clock();
  merge_sort(shadow, 0, lenght);
  t = clock() - t;
  printf("[%s]time to sort(%li): %4.10fs\n", "merge_sort", lenght,
         ((double)t / CLOCKS_PER_SEC));
  times[1] = ((double)t / CLOCKS_PER_SEC);
  ;
  copy_vector(shadow, vector, lenght);
  t = clock();
  quick_sort(shadow, 0, lenght);
  t = clock() - t;
  printf("[%s]time to sort(%li): %4.10fs\n", "quick_sort", lenght,
         ((double)t / CLOCKS_PER_SEC));
  times[2] = ((double)t / CLOCKS_PER_SEC);
  ;
  free(shadow);
}


x86 assembly (clang, -O0):
<sort_methods>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1090 <copy_vector@plt>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rdx
xor    %esi,%esi
call   10a0 <bubble_sort@plt>
mov    $0x0,%al
call   1040 <clock@plt>
sub    -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdx
cvtsi2sdq -0x30(%rbp),%xmm0
mov    0x2dec(%rip),%rax
divsd  (%rax),%xmm0
lea    0xdf9(%rip),%rdi
lea    0xe12(%rip),%rsi
call   1050 <printf@plt>
cvtsi2sdq -0x30(%rbp),%xmm0
mov    0x2dc8(%rip),%rax
divsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1090 <copy_vector@plt>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rdx
xor    %esi,%esi
call   1070 <merge_sort@plt>
mov    $0x0,%al
call   1040 <clock@plt>
sub    -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdx
cvtsi2sdq -0x30(%rbp),%xmm0
mov    0x2d71(%rip),%rax
divsd  (%rax),%xmm0
lea    0xd7e(%rip),%rdi
lea    0xda3(%rip),%rsi
call   1050 <printf@plt>
cvtsi2sdq -0x30(%rbp),%xmm0
mov    0x2d4d(%rip),%rax
divsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x8(%rax)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1090 <copy_vector@plt>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rdx
xor    %esi,%esi
call   1080 <quick_sort@plt>
mov    $0x0,%al
call   1040 <clock@plt>
sub    -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdx
cvtsi2sdq -0x30(%rbp),%xmm0
mov    0x2cf5(%rip),%rax
divsd  (%rax),%xmm0
lea    0xd02(%rip),%rdi
lea    0xd32(%rip),%rsi
call   1050 <printf@plt>
cvtsi2sdq -0x30(%rbp),%xmm0
mov    0x2cd1(%rip),%rax
divsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,0x10(%rax)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sort_methods>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%rbx
mov    %rsi,%r14
mov    %rdi,%r12
mov    %rcx,%rdi
mov    $0x8,%esi
call   1060 <calloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1090 <copy_vector@plt>
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%r13
mov    %r15,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   10a0 <bubble_sort@plt>
xor    %eax,%eax
call   1040 <clock@plt>
sub    %r13,%rax
cvtsi2sd %rax,%xmm0
movsd  %xmm0,(%rsp)
mov    0x2e04(%rip),%r13
divsd  0x0(%r13),%xmm0
lea    0xe0f(%rip),%rdi
lea    0xe28(%rip),%rsi
mov    %rbx,%rdx
call   1050 <printf@plt>
movsd  (%rsp),%xmm0
divsd  0x0(%r13),%xmm0
movsd  %xmm0,(%r14)
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1090 <copy_vector@plt>
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%rbp
mov    %r15,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1070 <merge_sort@plt>
xor    %eax,%eax
call   1040 <clock@plt>
sub    %rbp,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  %xmm0,(%rsp)
divsd  0x0(%r13),%xmm0
lea    0xdd3(%rip),%rsi
lea    0xda0(%rip),%rdi
mov    %rbx,%rdx
call   1050 <printf@plt>
movsd  (%rsp),%xmm0
divsd  0x0(%r13),%xmm0
movsd  %xmm0,0x8(%r14)
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1090 <copy_vector@plt>
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%rbp
mov    %r15,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1080 <quick_sort@plt>
xor    %eax,%eax
call   1040 <clock@plt>
sub    %rbp,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  %xmm0,(%rsp)
divsd  0x0(%r13),%xmm0
lea    0xd75(%rip),%rsi
lea    0xd37(%rip),%rdi
mov    %rbx,%rdx
call   1050 <printf@plt>
movsd  (%rsp),%xmm0
divsd  0x0(%r13),%xmm0
movsd  %xmm0,0x10(%r14)
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [32 x i8] c"[%s]time to sort(%li): %4.10fs\0A\00"
@.str.1 = [12 x i8] c"bubble_sort\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.2 = [11 x i8] c"merge_sort\00"
@.str.3 = [11 x i8] c"quick_sort\00"
define void @sort_methods(i64* %0, double* %1, i32 %2, i64 %3) {
%5 = alloca i64*
%6 = alloca double*
%7 = alloca i32
%8 = alloca i64
%9 = alloca i64*
%10 = alloca i64
store i64* %0, i64** %5
store double* %1, double** %6
store i32 %2, i32* %7
store i64 %3, i64* %8
store i64* null, i64** %9
%11 = load i64, i64* %8
%12 = call i64 @calloc(i64 %11, i32 8)
%13 = inttoptr i64 %12 to i64*
store i64* %13, i64** %9
%14 = load i64*, i64** %9
%15 = load i64*, i64** %5
%16 = load i64, i64* %8
%17 = call i32 @copy_vector(i64* %14, i64* %15, i64 %16)
%18 = call i64 (...) @clock()
store i64 %18, i64* %10
%19 = load i64*, i64** %9
%20 = load i64, i64* %8
%21 = call i32 @bubble_sort(i64* %19, i32 0, i64 %20)
%22 = call i64 (...) @clock()
%23 = load i64, i64* %10
%24 = sub nsw i64 %22, %23
store i64 %24, i64* %10
%25 = load i64, i64* %8
%26 = load i64, i64* %10
%27 = sitofp i64 %26 to double
%28 = load double, double* @CLOCKS_PER_SEC
%29 = fdiv double %27, %28
%30 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i64 %25, double %29)
%31 = load i64, i64* %10
%32 = sitofp i64 %31 to double
%33 = load double, double* @CLOCKS_PER_SEC
%34 = fdiv double %32, %33
%35 = load double*, double** %6
%36 = getelementptr inbounds double, double* %35, i64 0
store double %34, double* %36
%37 = load i64*, i64** %9
%38 = load i64*, i64** %5
%39 = load i64, i64* %8
%40 = call i32 @copy_vector(i64* %37, i64* %38, i64 %39)
%41 = call i64 (...) @clock()
store i64 %41, i64* %10
%42 = load i64*, i64** %9
%43 = load i64, i64* %8
%44 = call i32 @merge_sort(i64* %42, i32 0, i64 %43)
%45 = call i64 (...) @clock()
%46 = load i64, i64* %10
%47 = sub nsw i64 %45, %46
store i64 %47, i64* %10
%48 = load i64, i64* %8
%49 = load i64, i64* %10
%50 = sitofp i64 %49 to double
%51 = load double, double* @CLOCKS_PER_SEC
%52 = fdiv double %50, %51
%53 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i64 %48, double %52)
%54 = load i64, i64* %10
%55 = sitofp i64 %54 to double
%56 = load double, double* @CLOCKS_PER_SEC
%57 = fdiv double %55, %56
%58 = load double*, double** %6
%59 = getelementptr inbounds double, double* %58, i64 1
store double %57, double* %59
%60 = load i64*, i64** %9
%61 = load i64*, i64** %5
%62 = load i64, i64* %8
%63 = call i32 @copy_vector(i64* %60, i64* %61, i64 %62)
%64 = call i64 (...) @clock()
store i64 %64, i64* %10
%65 = load i64*, i64** %9
%66 = load i64, i64* %8
%67 = call i32 @quick_sort(i64* %65, i32 0, i64 %66)
%68 = call i64 (...) @clock()
%69 = load i64, i64* %10
%70 = sub nsw i64 %68, %69
store i64 %70, i64* %10
%71 = load i64, i64* %8
%72 = load i64, i64* %10
%73 = sitofp i64 %72 to double
%74 = load double, double* @CLOCKS_PER_SEC
%75 = fdiv double %73, %74
%76 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i64 %71, double %75)
%77 = load i64, i64* %10
%78 = sitofp i64 %77 to double
%79 = load double, double* @CLOCKS_PER_SEC
%80 = fdiv double %78, %79
%81 = load double*, double** %6
%82 = getelementptr inbounds double, double* %81, i64 2
store double %80, double* %82
%83 = load i64*, i64** %9
%84 = call i32 @free(i64* %83)
ret void
}

LLVM IR (-O2):
@.str = [32 x i8] c"[%s]time to sort(%li): %4.10fs\0A\00"
@.str.1 = [12 x i8] c"bubble_sort\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.2 = [11 x i8] c"merge_sort\00"
@.str.3 = [11 x i8] c"quick_sort\00"
define void @sort_methods(i64* %0, double* nocapture writeonly %1, i32 %2, i64 %3) {
%5 = tail call i64 @calloc(i64 %3, i32 8)
%6 = inttoptr i64 %5 to i64*
%7 = tail call i32 @copy_vector(i64* %6, i64* %0, i64 %3)
%8 = tail call i64 (...) @clock()
%9 = tail call i32 @bubble_sort(i64* %6, i32 0, i64 %3)
%10 = tail call i64 (...) @clock()
%11 = sub nsw i64 %10, %8
%12 = sitofp i64 %11 to double
%13 = load double, double* @CLOCKS_PER_SEC
%14 = fdiv double %12, %13
%15 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i64 %3, double %14)
%16 = load double, double* @CLOCKS_PER_SEC
%17 = fdiv double %12, %16
store double %17, double* %1
%18 = tail call i32 @copy_vector(i64* %6, i64* %0, i64 %3)
%19 = tail call i64 (...) @clock()
%20 = tail call i32 @merge_sort(i64* %6, i32 0, i64 %3)
%21 = tail 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 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i64 %3, double %25)
%27 = load double, double* @CLOCKS_PER_SEC
%28 = fdiv double %23, %27
%29 = getelementptr inbounds double, double* %1, i64 1
store double %28, double* %29
%30 = tail call i32 @copy_vector(i64* %6, i64* %0, i64 %3)
%31 = tail call i64 (...) @clock()
%32 = tail call i32 @quick_sort(i64* %6, i32 0, i64 %3)
%33 = tail call i64 (...) @clock()
%34 = sub nsw i64 %33, %31
%35 = sitofp i64 %34 to double
%36 = load double, double* @CLOCKS_PER_SEC
%37 = fdiv double %35, %36
%38 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i64 %3, double %37)
%39 = load double, double* @CLOCKS_PER_SEC
%40 = fdiv double %35, %39
%41 = getelementptr inbounds double, double* %1, i64 2
store double %40, double* %41
%42 = tail call i32 @free(i64* %6)
ret void
}