#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 */
struct timeval {
  long long tv_sec;
  long long tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/);
int /*<<< orphan*/ icache_test(int, long);
int /*<<< orphan*/ icache_test2(int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  printf("[bytes]\t[us]\n");
  struct timeval now, tm;
  long long t;
  long MBs;
  long i;
  long step = 32;
  for (i = 0; step <= 2048; i++, step += 32) {
    long value;
    gettimeofday(&now, 0);
    icache_test(0x800000L, step);
    gettimeofday(&tm, 0);
    t = (tm.tv_sec * 1000000LL + tm.tv_usec) -
        (now.tv_sec * 1000000LL + now.tv_usec);
    printf("%6ld\t%lld\n", step * 32, t);
  }
  gettimeofday(&now, 0);
  icache_test2(0x800000L / 2048);
  gettimeofday(&tm, 0);
  t = (tm.tv_sec * 1000000LL + tm.tv_usec) -
      (now.tv_sec * 1000000LL + now.tv_usec);
  MBs = (8388608LL * 32 * 1000000) / (t * (1024 * 1024));
  printf("\n%6lld us\t%ld MB/s\n", t, MBs);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x20,-0x48(%rbp)
movq   $0x0,-0x40(%rbp)
cmpq   $0x800,-0x48(%rbp)
jg     11f5 <main+0xb5>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    -0x48(%rbp),%rsi
mov    $0x800000,%edi
call   1050 <icache_test@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
imul   $0xf4240,-0x28(%rbp),%rax
add    -0x20(%rbp),%rax
imul   $0xf4240,-0x18(%rbp),%rcx
add    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x48(%rbp),%rsi
shl    $0x5,%rsi
mov    -0x30(%rbp),%rdx
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
mov    -0x48(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x48(%rbp)
jmp    116d <main+0x2d>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    $0x1000,%edi
call   1060 <icache_test2@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
imul   $0xf4240,-0x28(%rbp),%rax
add    -0x20(%rbp),%rax
imul   $0xf4240,-0x18(%rbp),%rcx
add    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rcx
shl    $0x14,%rcx
movabs $0xf42400000000,%rax
cqto
idiv   %rcx
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
lea    0xdbb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
lea    0xebb(%rip),%rdi
call   1030 <puts@plt>
mov    $0x400,%r13d
lea    0x10(%rsp),%r14
mov    %rsp,%r15
lea    0xe82(%rip),%r12
xor    %ebx,%ebx
add    $0x20,%rbx
mov    %r14,%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    $0x800000,%edi
mov    %rbx,%rsi
call   1060 <icache_test@plt>
mov    %r15,%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    (%rsp),%rax
mov    0x8(%rsp),%rdx
sub    0x10(%rsp),%rax
imul   $0xf4240,%rax,%rax
sub    0x18(%rsp),%rdx
add    %rax,%rdx
mov    %r12,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x400,%r13
cmp    $0x7e1,%rbx
jb     1180 <main+0x30>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    $0x1000,%edi
call   1070 <icache_test2@plt>
mov    %rsp,%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    (%rsp),%rax
mov    0x8(%rsp),%rsi
sub    0x10(%rsp),%rax
imul   $0xf4240,%rax,%rax
sub    0x18(%rsp),%rsi
add    %rax,%rsi
mov    %rsi,%rcx
shl    $0x14,%rcx
movabs $0xf42400000000,%rax
xor    %edx,%edx
idiv   %rcx
lea    0xdd2(%rip),%rdi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
@.str = [14 x i8] c"[bytes]\09[us]\0A\00"
@.str.1 = [11 x i8] c"%6ld\09%lld\0A\00"
@.str.2 = [20 x i8] c"\0A%6lld us\09%ld MB/s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.timeval
%3 = alloca %struct.timeval
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
store i32 0, i32* %1
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i64 32, i64* %7
store i64 0, i64* %6
br label %10
10: ; preds = %35, %0
%11 = load i64, i64* %7
%12 = icmp sle i64 %11, 2048
br i1 %12, label %13, label %40
13: ; preds = %10
%14 = call i32 @gettimeofday(%struct.timeval* %2, i32 0)
%15 = load i64, i64* %7
%16 = call i32 @icache_test(i32 8388608, i64 %15)
%17 = call i32 @gettimeofday(%struct.timeval* %3, i32 0)
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%19 = load i64, i64* %18
%20 = mul nsw i64 %19, 1000000
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%22 = load i64, i64* %21
%23 = add nsw i64 %20, %22
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%25 = load i64, i64* %24
%26 = mul nsw i64 %25, 1000000
%27 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 1
%28 = load i64, i64* %27
%29 = add nsw i64 %26, %28
%30 = sub nsw i64 %23, %29
store i64 %30, i64* %4
%31 = load i64, i64* %7
%32 = mul nsw i64 %31, 32
%33 = load i64, i64* %4
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i64 %32, i64 %33)
br label %35
35: ; preds = %13
%36 = load i64, i64* %6
%37 = add nsw i64 %36, 1
store i64 %37, i64* %6
%38 = load i64, i64* %7
%39 = add nsw i64 %38, 32
store i64 %39, i64* %7
br label %10
40: ; preds = %10
%41 = call i32 @gettimeofday(%struct.timeval* %2, i32 0)
%42 = call i32 @icache_test2(i32 4096)
%43 = call i32 @gettimeofday(%struct.timeval* %3, i32 0)
%44 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%45 = load i64, i64* %44
%46 = mul nsw i64 %45, 1000000
%47 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%48 = load i64, i64* %47
%49 = add nsw i64 %46, %48
%50 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%51 = load i64, i64* %50
%52 = mul nsw i64 %51, 1000000
%53 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 1
%54 = load i64, i64* %53
%55 = add nsw i64 %52, %54
%56 = sub nsw i64 %49, %55
store i64 %56, i64* %4
%57 = load i64, i64* %4
%58 = mul nsw i64 %57, 1048576
%59 = sdiv i64 268435456000000, %58
store i64 %59, i64* %5
%60 = load i64, i64* %4
%61 = load i64, i64* %5
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i64 %60, i64 %61)
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
@.str.1 = [11 x i8] c"%6ld\09%lld\0A\00"
@.str.2 = [20 x i8] c"\0A%6lld us\09%ld MB/s\0A\00"
@str = [13 x i8] c"[bytes]\09[us]\00"
define i32 @main() {
%1 = alloca %struct.timeval
%2 = alloca %struct.timeval
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%4 = bitcast %struct.timeval* %1 to i8*
%5 = bitcast %struct.timeval* %2 to i8*
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
br label %10
10: ; preds = %0, %10
%11 = phi i64 [ 32, %0 ], [ %25, %10 ]
%12 = call i32 @gettimeofday(%struct.timeval* %1, i32 0)
%13 = call i32 @icache_test(i32 8388608, i64 %11)
%14 = call i32 @gettimeofday(%struct.timeval* %2, i32 0)
%15 = load i64, i64* %6
%16 = load i64, i64* %7
%17 = load i64, i64* %8
%18 = load i64, i64* %9
%19 = sub i64 %15, %17
%20 = mul i64 %19, 1000000
%21 = sub i64 %16, %18
%22 = add i64 %21, %20
%23 = shl nuw nsw i64 %11, 5
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i64 %23, i64 %22)
%25 = add nuw nsw i64 %11, 32
%26 = icmp ult i64 %11, 2017
br i1 %26, label %10, label %27
27: ; preds = %10
%28 = call i32 @gettimeofday(%struct.timeval* %1, i32 0)
%29 = call i32 @icache_test2(i32 4096)
%30 = call i32 @gettimeofday(%struct.timeval* %2, i32 0)
%31 = load i64, i64* %6
%32 = load i64, i64* %7
%33 = load i64, i64* %8
%34 = load i64, i64* %9
%35 = sub i64 %31, %33
%36 = mul i64 %35, 1000000
%37 = sub i64 %32, %34
%38 = add i64 %37, %36
%39 = shl nsw i64 %38, 20
%40 = sdiv i64 268435456000000, %39
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i64 %38, i64 %40)
ret i32 0
}