#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*/ fprintf(int /*<<< orphan*/, char *, float, double, double);
unsigned char *malloc(int);
long long rdtsc();
int /*<<< orphan*/ stdout;
int check_cache() {
  int i = 0;
  int j = 0;
  double stride = 1024;
  int stride_inc = 4096;
  unsigned char *huge = malloc(2000000000);
  long long int a, b, c;
  float size = 0;
  double time_seconds;
  int freq = 3166000;
  double old_time = 0;
  double factor = 0;
  int count = 0;
  while (stride < 2000000000) {
    a = rdtsc();
    count = 0;
    for (i = 0; i < stride; i++) {
      huge[i]++;
      count++;
    }
    b = rdtsc();
    c = b - a;
    old_time = time_seconds;
    time_seconds = (double)c / freq;
    size = (float)stride / 1024;
    factor = time_seconds / old_time;
    fprintf(stdout, "Size: %0.3fKB,\tTime: %lf ms,\tpercent: %lf\n", size,
            time_seconds, stride / 2000000000);
    stride *= 2;
  }
  return 0;
}


x86 assembly (clang, -O0):
<check_cache>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movsd  0xeb2(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x1000,-0x14(%rbp)
mov    $0x77359400,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x3c(%rbp)
movl   $0x304f30,-0x4c(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x60(%rbp)
movl   $0x0,-0x64(%rbp)
movsd  0xe72(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    129b <check_cache+0x16b>
mov    $0x0,%al
call   1030 <rdtsc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x64(%rbp)
movl   $0x0,-0x4(%rbp)
cvtsi2sdl -0x4(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11f6 <check_cache+0xc6>
mov    -0x20(%rbp),%rax
movslq -0x4(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
add    $0x1,%dl
mov    %dl,(%rax,%rcx,1)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11ba <check_cache+0x8a>
mov    $0x0,%al
call   1030 <rdtsc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
sub    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
cvtsi2sdq -0x38(%rbp),%xmm0
cvtsi2sdl -0x4c(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x10(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  0xddc(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x3c(%rbp)
movsd  -0x48(%rbp),%xmm0
divsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    0x2d85(%rip),%rax
mov    (%rax),%edi
movss  -0x3c(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm2
movsd  0xd94(%rip),%xmm3
divsd  %xmm3,%xmm2
lea    0xd9d(%rip),%rsi
call   1040 <fprintf@plt>
movsd  0xd84(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    118e <check_cache+0x5e>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_cache>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    $0x77359400,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
movsd  0xeb3(%rip),%xmm0
mov    0x2e8c(%rip),%r12
lea    0xec9(%rip),%r14
jmp    11bf <check_cache+0x8f>
nopl   (%rax)
xor    %eax,%eax
call   1030 <rdtsc@plt>
sub    %r15,%rax
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
movsd  (%rsp),%xmm0
cvtsd2ss %xmm0,%xmm0
divsd  0xe85(%rip),%xmm1
mulss  0xe95(%rip),%xmm0
mov    (%r12),%edi
movsd  (%rsp),%xmm2
movsd  0xe74(%rip),%xmm3
divsd  %xmm3,%xmm2
mov    %r14,%rsi
call   1040 <fprintf@plt>
movsd  (%rsp),%xmm0
addsd  %xmm0,%xmm0
movsd  0xe57(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    11fa <check_cache+0xca>
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1030 <rdtsc@plt>
movsd  (%rsp),%xmm1
mov    %rax,%r15
ucomisd 0xe3d(%rip),%xmm1
jbe    1160 <check_cache+0x30>
xor    %eax,%eax
nop
addb   $0x1,(%rbx,%rax,1)
add    $0x1,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
ucomisd %xmm0,%xmm1
ja     11e0 <check_cache+0xb0>
jmp    1160 <check_cache+0x30>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [43 x i8] c"Size: %0.3fKB,\09Time: %lf ms,\09percent: %lf\0A\00"
define i32 @check_cache() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca double
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca float
%10 = alloca double
%11 = alloca i32
%12 = alloca double
%13 = alloca double
%14 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store double 1.024000e+03, double* %3
store i32 4096, i32* %4
%15 = call i8* @malloc(i32 2000000000)
store i8* %15, i8** %5
store float 0.000000e+00, float* %9
store i32 3166000, i32* %11
store double 0.000000e+00, double* %12
store double 0.000000e+00, double* %13
store i32 0, i32* %14
br label %16
16: ; preds = %38, %0
%17 = load double, double* %3
%18 = fcmp olt double %17, 2.000000e+09
br i1 %18, label %19, label %63
19: ; preds = %16
%20 = call i64 (...) @rdtsc()
store i64 %20, i64* %6
store i32 0, i32* %14
store i32 0, i32* %1
br label %21
21: ; preds = %35, %19
%22 = load i32, i32* %1
%23 = sitofp i32 %22 to double
%24 = load double, double* %3
%25 = fcmp olt double %23, %24
br i1 %25, label %26, label %38
26: ; preds = %21
%27 = load i8*, i8** %5
%28 = load i32, i32* %1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = add i8 %31, 1
store i8 %32, i8* %30
%33 = load i32, i32* %14
%34 = add nsw i32 %33, 1
store i32 %34, i32* %14
br label %35
35: ; preds = %26
%36 = load i32, i32* %1
%37 = add nsw i32 %36, 1
store i32 %37, i32* %1
br label %21
38: ; preds = %21
%39 = call i64 (...) @rdtsc()
store i64 %39, i64* %7
%40 = load i64, i64* %7
%41 = load i64, i64* %6
%42 = sub nsw i64 %40, %41
store i64 %42, i64* %8
%43 = load double, double* %10
store double %43, double* %12
%44 = load i64, i64* %8
%45 = sitofp i64 %44 to double
%46 = load i32, i32* %11
%47 = sitofp i32 %46 to double
%48 = fdiv double %45, %47
store double %48, double* %10
%49 = load double, double* %3
%50 = fptrunc double %49 to float
%51 = fdiv float %50, 1.024000e+03
store float %51, float* %9
%52 = load double, double* %10
%53 = load double, double* %12
%54 = fdiv double %52, %53
store double %54, double* %13
%55 = load i32, i32* @stdout
%56 = load float, float* %9
%57 = load double, double* %10
%58 = load double, double* %3
%59 = fdiv double %58, 2.000000e+09
%60 = call i32 @fprintf(i32 %55, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), float %56, double %57, double %59)
%61 = load double, double* %3
%62 = fmul double %61, 2.000000e+00
store double %62, double* %3
br label %16
63: ; preds = %16
ret i32 0
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [43 x i8] c"Size: %0.3fKB,\09Time: %lf ms,\09percent: %lf\0A\00"
define i32 @check_cache() {
%1 = tail call dereferenceable_or_null(2000000000) i8* @malloc(i32 2000000000)
br label %2
2: ; preds = %0, %15
%3 = phi double [ 1.024000e+03, %0 ], [ %25, %15 ]
%4 = tail call i64 (...) @rdtsc()
%5 = fcmp ogt double %3, 0.000000e+00
br i1 %5, label %6, label %15
6: ; preds = %2, %6
%7 = phi i64 [ %11, %6 ], [ 0, %2 ]
%8 = getelementptr inbounds i8, i8* %1, i64 %7
%9 = load i8, i8* %8
%10 = add i8 %9, 1
store i8 %10, i8* %8
%11 = add nuw i64 %7, 1
%12 = trunc i64 %11 to i32
%13 = sitofp i32 %12 to double
%14 = fcmp ogt double %3, %13
br i1 %14, label %6, label %15
15: ; preds = %6, %2
%16 = tail call i64 (...) @rdtsc()
%17 = sub nsw i64 %16, %4
%18 = sitofp i64 %17 to double
%19 = fdiv double %18, 3.166000e+06
%20 = fptrunc double %3 to float
%21 = fmul float %20, 0x3F50000000000000
%22 = load i32, i32* @stdout
%23 = fdiv double %3, 2.000000e+09
%24 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), float %21, double %19, double %23)
%25 = fmul double %3, 2.000000e+00
%26 = fcmp olt double %25, 2.000000e+09
br i1 %26, label %2, label %27
27: ; preds = %15
ret i32 0
}