#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;
scalar_t__ clock();
int /*<<< orphan*/ insertionSort(int *);
int /*<<< orphan*/ printf(char *, double);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  int array[10000] = {0};
  srand(time(NULL));
  for (int i = 0; i < 10000; ++i) {
    array[i] = rand();
  }
  clock_t begin = clock();
  insertionSort(array);
  clock_t end = clock();
  double timeSpent = (double)(end - begin) / CLOCKS_PER_SEC;
  printf("Took to sort: %f\n", timeSpent);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x9c70,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x9c50(%rbp),%rdi
xor    %esi,%esi
mov    $0x9c40,%edx
call   1050 <memset@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
movl   $0x0,-0x9c54(%rbp)
cmpl   $0x2710,-0x9c54(%rbp)
jge    11ea <main+0x7a>
mov    $0x0,%al
call   1090 <rand@plt>
mov    %eax,%ecx
movslq -0x9c54(%rbp),%rax
mov    %ecx,-0x9c50(%rbp,%rax,4)
mov    -0x9c54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c54(%rbp)
jmp    11af <main+0x3f>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x9c60(%rbp)
lea    -0x9c50(%rbp),%rdi
call   1080 <insertionSort@plt>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x9c68(%rbp)
mov    -0x9c68(%rbp),%rax
sub    -0x9c60(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2dbc(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x9c70(%rbp)
ff
movsd  -0x9c70(%rbp),%xmm0
ff
lea    0xdb9(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x9c70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x9c40,%rsp
mov    %rsp,%rdi
mov    $0x9c40,%edx
xor    %esi,%esi
call   1050 <memset@plt>
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1090 <rand@plt>
mov    %eax,(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0x2710,%rbx
jne    11a0 <main+0x30>
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%rbx
mov    %rsp,%rdi
call   1080 <insertionSort@plt>
xor    %eax,%eax
call   1030 <clock@plt>
sub    %rbx,%rax
cvtsi2sd %rax,%xmm0
mov    0x2e09(%rip),%rax
divsd  (%rax),%xmm0
lea    0xe16(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x9c40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str = [18 x i8] c"Took to sort: %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10000 x i32]
%3 = alloca i32
%4 = alloca i64
%5 = alloca i64
%6 = alloca double
store i32 0, i32* %1
%7 = bitcast [10000 x i32]* %2 to i8*
%8 = call i32 @time(i32* null)
%9 = call i32 @srand(i32 %8)
store i32 0, i32* %3
br label %10
10: ; preds = %18, %0
%11 = load i32, i32* %3
%12 = icmp slt i32 %11, 10000
br i1 %12, label %13, label %21
13: ; preds = %10
%14 = call i32 (...) @rand()
%15 = load i32, i32* %3
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [10000 x i32], [10000 x i32]* %2, i64 0, i64 %16
store i32 %14, i32* %17
br label %18
18: ; preds = %13
%19 = load i32, i32* %3
%20 = add nsw i32 %19, 1
store i32 %20, i32* %3
br label %10
21: ; preds = %10
%22 = call i64 (...) @clock()
store i64 %22, i64* %4
%23 = getelementptr inbounds [10000 x i32], [10000 x i32]* %2, i64 0, i64 0
%24 = call i32 @insertionSort(i32* %23)
%25 = call i64 (...) @clock()
store i64 %25, i64* %5
%26 = load i64, i64* %5
%27 = load i64, i64* %4
%28 = sub nsw i64 %26, %27
%29 = sitofp i64 %28 to double
%30 = load double, double* @CLOCKS_PER_SEC
%31 = fdiv double %29, %30
store double %31, double* %6
%32 = load double, double* %6
%33 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), double %32)
ret i32 0
}

LLVM IR (-O2):
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str = [18 x i8] c"Took to sort: %f\0A\00"
define i32 @main() {
%1 = alloca [10000 x i32]
%2 = bitcast [10000 x i32]* %1 to i8*
%3 = tail call i32 @time(i32* null)
%4 = tail call i32 @srand(i32 %3)
br label %15
5: ; preds = %15
%6 = tail call i64 (...) @clock()
%7 = getelementptr inbounds [10000 x i32], [10000 x i32]* %1, i64 0, i64 0
%8 = call i32 @insertionSort(i32* %7)
%9 = call i64 (...) @clock()
%10 = sub nsw i64 %9, %6
%11 = sitofp i64 %10 to double
%12 = load double, double* @CLOCKS_PER_SEC
%13 = fdiv double %11, %12
%14 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), double %13)
ret i32 0
15: ; preds = %0, %15
%16 = phi i64 [ 0, %0 ], [ %19, %15 ]
%17 = tail call i32 (...) @rand()
%18 = getelementptr inbounds [10000 x i32], [10000 x i32]* %1, i64 0, i64 %16
store i32 %17, i32* %18
%19 = add nuw nsw i64 %16, 1
%20 = icmp eq i64 %19, 10000
br i1 %20, label %5, label %15
}