#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__ int64_t;

/* Variables and functions */
int do_data(int, scalar_t__ *);
int /*<<< orphan*/ printf(char *, ...);
int do_data_compare() {
  const double thresh = 1.3;
  int ret = 0;
  double ratio;
  int64_t cache_time = 0, uncache_time = 0;
  printf("Timing cached pages...\n");
  ret = do_data(0, &cache_time);
  if (ret != 0)
    goto out;
  printf("Timing uncached pages...\n");
  ret = do_data(1, &uncache_time);
  if (ret != 0)
    goto out;
  ratio = (double)uncache_time / (double)cache_time;
  printf("Uncached/Cached Ratio: %f\n", ratio);
  if (ratio < thresh) {
    printf("Ratio is unexpectedly small (< %f)! "
           " Uncache broken? Are you on kvm?\n",
           thresh);
    ret = -1;
  }
out:
  return ret;
}


x86 assembly (clang, -O0):
<do_data_compare>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  0xed0(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
lea    -0x20(%rbp),%rsi
call   1030 <do_data@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1177 <do_data_compare+0x57>
jmp    1202 <do_data_compare+0xe2>
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
lea    -0x28(%rbp),%rsi
call   1030 <do_data@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11a5 <do_data_compare+0x85>
jmp    1202 <do_data_compare+0xe2>
cvtsi2sdq -0x28(%rbp),%xmm0
cvtsi2sdq -0x20(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
lea    0xe74(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  0xe2b(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    11fd <do_data_compare+0xdd>
lea    0xe6e(%rip),%rdi
movsd  0xe11(%rip),%xmm0
mov    $0x1,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0xc(%rbp)
jmp    1202 <do_data_compare+0xe2>
mov    -0xc(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_data_compare>:
sub    $0x18,%rsp
movq   $0x0,0x8(%rsp)
movq   $0x0,(%rsp)
lea    0xf1d(%rip),%rdi
call   1030 <puts@plt>
lea    0x8(%rsp),%rsi
xor    %edi,%edi
call   1040 <do_data@plt>
test   %eax,%eax
je     1166 <do_data_compare+0x36>
add    $0x18,%rsp
ret
lea    0xf13(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rsi
mov    $0x1,%edi
call   1040 <do_data@plt>
test   %eax,%eax
jne    1161 <do_data_compare+0x31>
cvtsi2sdq (%rsp),%xmm0
cvtsi2sdq 0x8(%rsp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,0x10(%rsp)
lea    0xe67(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
movsd  0xe4e(%rip),%xmm0
ucomisd 0x10(%rsp),%xmm0
jbe    1161 <do_data_compare+0x31>
lea    0xe62(%rip),%rdi
movsd  0xe37(%rip),%xmm0
mov    $0x1,%al
call   1050 <printf@plt>
mov    $0xffffffff,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Timing cached pages...\0A\00"
@.str.1 = [26 x i8] c"Timing uncached pages...\0A\00"
@.str.2 = [27 x i8] c"Uncached/Cached Ratio: %f\0A\00"
@.str.3 = [70 x i8] c"Ratio is unexpectedly small (< %f)! Uncache broken? Are you on kvm?\0A\00"
define i32 @do_data_compare() {
%1 = alloca double
%2 = alloca i32
%3 = alloca double
%4 = alloca i64
%5 = alloca i64
store double 1.300000e+00, double* %1
store i32 0, i32* %2
store i64 0, i64* %4
store i64 0, i64* %5
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @do_data(i32 0, i64* %4)
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %0
br label %30
11: ; preds = %0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @do_data(i32 1, i64* %5)
store i32 %13, i32* %2
%14 = load i32, i32* %2
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %11
br label %30
17: ; preds = %11
%18 = load i64, i64* %5
%19 = sitofp i64 %18 to double
%20 = load i64, i64* %4
%21 = sitofp i64 %20 to double
%22 = fdiv double %19, %21
store double %22, double* %3
%23 = load double, double* %3
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), double %23)
%25 = load double, double* %3
%26 = fcmp olt double %25, 1.300000e+00
br i1 %26, label %27, label %29
27: ; preds = %17
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.3, i64 0, i64 0), double 1.300000e+00)
store i32 -1, i32* %2
br label %29
29: ; preds = %27, %17
br label %30
30: ; preds = %29, %16, %10
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
@.str.2 = [27 x i8] c"Uncached/Cached Ratio: %f\0A\00"
@.str.3 = [70 x i8] c"Ratio is unexpectedly small (< %f)! Uncache broken? Are you on kvm?\0A\00"
@str = [23 x i8] c"Timing cached pages...\00"
@str.4 = [25 x i8] c"Timing uncached pages...\00"
define i32 @do_data_compare() {
%1 = alloca i64
%2 = alloca i64
%3 = bitcast i64* %1 to i8*
store i64 0, i64* %1
%4 = bitcast i64* %2 to i8*
store i64 0, i64* %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%6 = call i32 @do_data(i32 0, i64* %1)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %22
8: ; preds = %0
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.4, i64 0, i64 0))
%10 = call i32 @do_data(i32 1, i64* %2)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %22
12: ; preds = %8
%13 = load i64, i64* %2
%14 = sitofp i64 %13 to double
%15 = load i64, i64* %1
%16 = sitofp i64 %15 to double
%17 = fdiv double %14, %16
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), double %17)
%19 = fcmp olt double %17, 1.300000e+00
br i1 %19, label %20, label %22
20: ; preds = %12
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([70 x i8], [70 x i8]* @.str.3, i64 0, i64 0), double 1.300000e+00)
br label %22
22: ; preds = %12, %20, %8, %0
%23 = phi i32 [ %6, %0 ], [ %10, %8 ], [ -1, %20 ], [ 0, %12 ]
ret i32 %23
}