#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 */

/* Variables and functions */
int /*<<< orphan*/ free(int *);
int *make_array(int);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, double);
int rand();
unsigned long rdtsc();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  unsigned long total_diff = 0;
  unsigned long start = 0;
  unsigned long end = 0;
  int j, p;
  unsigned long diff = 0;
  int *head;
  int i = 1;
  int *indices = (int *)malloc(sizeof(int) * 1000000);
  srand(time(NULL));
  while (i <= 30) {
    total_diff = 0;
    head = make_array(i);
    int h;
    for (h = 0; h < 1000000; h++) {
      indices[h] = rand() % (1 << i);
    }
    j = 0;
    start = rdtsc();
    while (j < 1000000) {
      p = head[indices[j]];
      j++;
    }
    end = rdtsc();
    total_diff = end - start;
    free(head);
    if (total_diff < 10000000000000) {
      printf("%lf\n", (double)total_diff / 1000000);
      i++;
    } else {
      continue;
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    $0x3d0900,%edi
call   1080 <malloc@plt>
mov    %rax,-0x48(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
cmpl   $0x1e,-0x3c(%rbp)
jg     1303 <main+0x183>
movq   $0x0,-0x10(%rbp)
mov    -0x3c(%rbp),%edi
call   10a0 <make_array@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x4c(%rbp)
cmpl   $0xf4240,-0x4c(%rbp)
jge    1235 <main+0xb5>
mov    $0x0,%al
call   1090 <rand@plt>
mov    -0x3c(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
cltd
idiv   %ecx
mov    -0x48(%rbp),%rax
movslq -0x4c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    11f9 <main+0x79>
movl   $0x0,-0x24(%rbp)
mov    $0x0,%al
call   1050 <rdtsc@plt>
mov    %rax,-0x18(%rbp)
cmpl   $0xf4240,-0x24(%rbp)
jge    1278 <main+0xf8>
mov    -0x38(%rbp),%rax
mov    -0x48(%rbp),%rcx
movslq -0x24(%rbp),%rdx
movslq (%rcx,%rdx,4),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1247 <main+0xc7>
mov    $0x0,%al
call   1050 <rdtsc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
sub    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movabs $0x9184e72a000,%rax
cmp    %rax,-0x10(%rbp)
jae    12f9 <main+0x179>
movaps 0xd5d(%rip),%xmm1
movq   -0x10(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xd5c(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  0xd25(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xd4a(%rip),%rdi
call   1040 <printf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    12fe <main+0x17e>
jmp    11d4 <main+0x54>
jmp    11d4 <main+0x54>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x3d0900,%edi
call   1080 <malloc@plt>
mov    %rax,%r14
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
mov    $0x1,%r12d
jmp    11ba <main+0x3a>
xchg   %ax,%ax
cmp    $0x1f,%r12d
jge    1267 <main+0xe7>
mov    %r12d,%edi
call   10a0 <make_array@plt>
mov    %rax,%r15
mov    $0x1,%ebp
mov    %r12d,%ecx
shl    %cl,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1090 <rand@plt>
cltd
idiv   %ebp
mov    %edx,(%r14,%rbx,4)
add    $0x1,%rbx
cmp    $0xf4240,%rbx
jne    11e0 <main+0x60>
xor    %eax,%eax
call   1050 <rdtsc@plt>
mov    %rax,%r13
xor    %eax,%eax
call   1050 <rdtsc@plt>
mov    %rax,%rbp
sub    %r13,%rbp
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbp,%rax
shr    $0xd,%rax
cmp    $0x48c27394,%rax
ja     11b0 <main+0x30>
movq   %rbp,%xmm1
punpckldq 0xdca(%rip),%xmm1
subpd  0xdd2(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
divsd  0xdce(%rip),%xmm0
lea    0xdcf(%rip),%rdi
call   1040 <printf@plt>
add    $0x1,%r12d
jmp    11b0 <main+0x30>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%lf\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32
store i32 0, i32* %1
store i64 0, i64* %2
store i64 0, i64* %3
store i64 0, i64* %4
store i64 0, i64* %7
store i32 1, i32* %9
%12 = call i64 @malloc(i32 4000000)
%13 = inttoptr i64 %12 to i32*
store i32* %13, i32** %10
%14 = call i32 @time(i32* null)
%15 = call i32 @srand(i32 %14)
br label %16
16: ; preds = %71, %70, %0
%17 = load i32, i32* %9
%18 = icmp sle i32 %17, 30
br i1 %18, label %19, label %72
19: ; preds = %16
store i64 0, i64* %2
%20 = load i32, i32* %9
%21 = call i32* @make_array(i32 %20)
store i32* %21, i32** %8
store i32 0, i32* %11
br label %22
22: ; preds = %34, %19
%23 = load i32, i32* %11
%24 = icmp slt i32 %23, 1000000
br i1 %24, label %25, label %37
25: ; preds = %22
%26 = call i32 (...) @rand()
%27 = load i32, i32* %9
%28 = shl i32 1, %27
%29 = srem i32 %26, %28
%30 = load i32*, i32** %10
%31 = load i32, i32* %11
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %30, i64 %32
store i32 %29, i32* %33
br label %34
34: ; preds = %25
%35 = load i32, i32* %11
%36 = add nsw i32 %35, 1
store i32 %36, i32* %11
br label %22
37: ; preds = %22
store i32 0, i32* %5
%38 = call i64 (...) @rdtsc()
store i64 %38, i64* %3
br label %39
39: ; preds = %42, %37
%40 = load i32, i32* %5
%41 = icmp slt i32 %40, 1000000
br i1 %41, label %42, label %54
42: ; preds = %39
%43 = load i32*, i32** %8
%44 = load i32*, i32** %10
%45 = load i32, i32* %5
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i32, i32* %44, i64 %46
%48 = load i32, i32* %47
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i32, i32* %43, i64 %49
%51 = load i32, i32* %50
store i32 %51, i32* %6
%52 = load i32, i32* %5
%53 = add nsw i32 %52, 1
store i32 %53, i32* %5
br label %39
54: ; preds = %39
%55 = call i64 (...) @rdtsc()
store i64 %55, i64* %4
%56 = load i64, i64* %4
%57 = load i64, i64* %3
%58 = sub i64 %56, %57
store i64 %58, i64* %2
%59 = load i32*, i32** %8
%60 = call i32 @free(i32* %59)
%61 = load i64, i64* %2
%62 = icmp ult i64 %61, 10000000000000
br i1 %62, label %63, label %70
63: ; preds = %54
%64 = load i64, i64* %2
%65 = uitofp i64 %64 to double
%66 = fdiv double %65, 1.000000e+06
%67 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %66)
%68 = load i32, i32* %9
%69 = add nsw i32 %68, 1
store i32 %69, i32* %9
br label %71
70: ; preds = %54
br label %16
71: ; preds = %63
br label %16
72: ; preds = %16
%73 = load i32, i32* %1
ret i32 %73
}

LLVM IR (-O2):
@.str = [5 x i8] c"%lf\0A\00"
define i32 @main() {
%1 = tail call i64 @malloc(i32 4000000)
%2 = inttoptr i64 %1 to i32*
%3 = tail call i32 @time(i32* null)
%4 = tail call i32 @srand(i32 %3)
br label %5
5: ; preds = %0, %27
%6 = phi i32 [ 1, %0 ], [ %28, %27 ]
%7 = tail call i32* @make_array(i32 %6)
%8 = shl nuw nsw i32 1, %6
br label %9
9: ; preds = %5, %9
%10 = phi i64 [ 0, %5 ], [ %14, %9 ]
%11 = tail call i32 (...) @rand()
%12 = srem i32 %11, %8
%13 = getelementptr inbounds i32, i32* %2, i64 %10
store i32 %12, i32* %13
%14 = add nuw nsw i64 %10, 1
%15 = icmp eq i64 %14, 1000000
br i1 %15, label %16, label %9
16: ; preds = %9
%17 = tail call i64 (...) @rdtsc()
%18 = tail call i64 (...) @rdtsc()
%19 = sub i64 %18, %17
%20 = tail call i32 @free(i32* %7)
%21 = icmp ult i64 %19, 10000000000000
br i1 %21, label %22, label %27
22: ; preds = %16
%23 = uitofp i64 %19 to double
%24 = fdiv double %23, 1.000000e+06
%25 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), double %24)
%26 = add nsw i32 %6, 1
br label %27
27: ; preds = %16, %22
%28 = phi i32 [ %26, %22 ], [ %6, %16 ]
%29 = icmp slt i32 %28, 31
br i1 %29, label %5, label %30
30: ; preds = %27
ret i32 0
}