#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);
int /*<<< orphan*/ printf(char *, unsigned long);
unsigned long rdtsc();
int main() {
  int ***q = make_array(2);
  free(q);
  unsigned long total_diff = 0;
  unsigned long start = 0;
  unsigned long end = 0;
  int j;
  int **p;
  unsigned long diff = 0;
  int ***head;
  int i = 1;
  while (i <= 28) {
    total_diff = 0;
    head = make_array(i);
    p = (int **)head;
    j = 0;
    start = rdtsc();
    while (j < 100000000) {
      p = (int **)*p;
      j++;
      total_diff += diff;
    }
    end = rdtsc();
    diff = end - start;
    free(head);
    if (diff < 100000000000) {
      i++;
      printf("%lu\n", diff);
    } else {
      continue;
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x2,%edi
call   1060 <make_array@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x40(%rbp)
movl   $0x1,-0x4c(%rbp)
cmpl   $0x1c,-0x4c(%rbp)
jg     1253 <main+0x113>
movq   $0x0,-0x18(%rbp)
mov    -0x4c(%rbp),%edi
call   1060 <make_array@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    $0x0,%al
call   1050 <rdtsc@plt>
mov    %rax,-0x20(%rbp)
cmpl   $0x5f5e100,-0x2c(%rbp)
jge    11f7 <main+0xb7>
mov    -0x38(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x40(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    11c5 <main+0x85>
mov    $0x0,%al
call   1050 <rdtsc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
sub    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
movabs $0x174876e800,%rax
cmp    %rax,-0x40(%rbp)
jae    1249 <main+0x109>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
mov    -0x40(%rbp),%rsi
lea    0xdc1(%rip),%rdi
call   1040 <printf@plt>
jmp    124e <main+0x10e>
jmp    118d <main+0x4d>
jmp    118d <main+0x4d>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0x2,%edi
call   1060 <make_array@plt>
mov    %rax,%rdi
call   1030 <free@plt>
mov    $0x1,%r15d
lea    0xe99(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    %r15d,%edi
call   1060 <make_array@plt>
mov    %rax,%r12
xor    %eax,%eax
call   1050 <rdtsc@plt>
mov    %rax,%rbp
xor    %eax,%eax
call   1050 <rdtsc@plt>
mov    %rax,%rbx
sub    %rbp,%rbx
mov    %r12,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
shr    $0xb,%rax
cmp    $0x2e90edc,%rax
ja     1170 <main+0x30>
add    $0x1,%r15d
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
cmp    $0x1d,%r15d
jne    1170 <main+0x30>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%lu\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32***
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32**
%8 = alloca i64
%9 = alloca i32***
%10 = alloca i32
store i32 0, i32* %1
%11 = call i32*** @make_array(i32 2)
store i32*** %11, i32**** %2
%12 = load i32***, i32**** %2
%13 = call i32 @free(i32*** %12)
store i64 0, i64* %3
store i64 0, i64* %4
store i64 0, i64* %5
store i64 0, i64* %8
store i32 1, i32* %10
br label %14
14: ; preds = %50, %49, %0
%15 = load i32, i32* %10
%16 = icmp sle i32 %15, 28
br i1 %16, label %17, label %51
17: ; preds = %14
store i64 0, i64* %3
%18 = load i32, i32* %10
%19 = call i32*** @make_array(i32 %18)
store i32*** %19, i32**** %9
%20 = load i32***, i32**** %9
%21 = bitcast i32*** %20 to i32**
store i32** %21, i32*** %7
store i32 0, i32* %6
%22 = call i64 (...) @rdtsc()
store i64 %22, i64* %4
br label %23
23: ; preds = %26, %17
%24 = load i32, i32* %6
%25 = icmp slt i32 %24, 100000000
br i1 %25, label %26, label %35
26: ; preds = %23
%27 = load i32**, i32*** %7
%28 = load i32*, i32** %27
%29 = bitcast i32* %28 to i32**
store i32** %29, i32*** %7
%30 = load i32, i32* %6
%31 = add nsw i32 %30, 1
store i32 %31, i32* %6
%32 = load i64, i64* %8
%33 = load i64, i64* %3
%34 = add i64 %33, %32
store i64 %34, i64* %3
br label %23
35: ; preds = %23
%36 = call i64 (...) @rdtsc()
store i64 %36, i64* %5
%37 = load i64, i64* %5
%38 = load i64, i64* %4
%39 = sub i64 %37, %38
store i64 %39, i64* %8
%40 = load i32***, i32**** %9
%41 = call i32 @free(i32*** %40)
%42 = load i64, i64* %8
%43 = icmp ult i64 %42, 100000000000
br i1 %43, label %44, label %49
44: ; preds = %35
%45 = load i32, i32* %10
%46 = add nsw i32 %45, 1
store i32 %46, i32* %10
%47 = load i64, i64* %8
%48 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %47)
br label %50
49: ; preds = %35
br label %14
50: ; preds = %44
br label %14
51: ; preds = %14
%52 = load i32, i32* %1
ret i32 %52
}

LLVM IR (-O2):
@.str = [5 x i8] c"%lu\0A\00"
define i32 @main() {
%1 = tail call i32*** @make_array(i32 2)
%2 = tail call i32 @free(i32*** %1)
br label %3
3: ; preds = %0, %12
%4 = phi i32 [ 1, %0 ], [ %13, %12 ]
br label %5
5: ; preds = %3, %5
%6 = tail call i32*** @make_array(i32 %4)
%7 = tail call i64 (...) @rdtsc()
%8 = tail call i64 (...) @rdtsc()
%9 = sub i64 %8, %7
%10 = tail call i32 @free(i32*** %6)
%11 = icmp ult i64 %9, 100000000000
br i1 %11, label %12, label %5
12: ; preds = %5
%13 = add nuw nsw i32 %4, 1
%14 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %9)
%15 = icmp eq i32 %13, 29
br i1 %15, label %16, label %3
16: ; preds = %12
ret i32 0
}