#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 int /*<<< orphan*/ caddr_t;

/* Variables and functions */
int /*<<< orphan*/ MAP_SHARED;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ PROT_READ;
int getpagesize();
char *mmap(int /*<<< orphan*/, int, int /*<<< orphan*/, int /*<<< orphan*/, int,
           int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, unsigned long long);
unsigned long long rdtsc();
int main() {
  unsigned long long coldstart, start, end;
  int descriptor = open("testfile", O_RDONLY);
  int page_size = getpagesize();
  char *data;
  char p = ' ';
  coldstart = rdtsc();
  start = rdtsc();
  data = mmap((caddr_t)0, page_size, PROT_READ, MAP_SHARED, descriptor,
              10 * page_size);
  p = data[2];
  end = rdtsc();
  printf("%llu", end - start);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
lea    0xe91(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1070 <getpagesize@plt>
mov    %eax,-0x28(%rbp)
movb   $0x20,-0x31(%rbp)
mov    $0x0,%al
call   1050 <rdtsc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1050 <rdtsc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%esi
mov    0x2e53(%rip),%rax
mov    (%rax),%edx
mov    0x2e3a(%rip),%rax
mov    (%rax),%ecx
mov    -0x24(%rbp),%r8d
imul   $0xa,-0x28(%rbp),%r9d
xor    %edi,%edi
call   1030 <mmap@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    0x2(%rax),%al
mov    %al,-0x31(%rbp)
mov    $0x0,%al
call   1050 <rdtsc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
sub    -0x18(%rbp),%rsi
lea    0xe21(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    0x2e7d(%rip),%rax
mov    (%rax),%esi
lea    0xe9c(%rip),%rdi
call   1060 <open@plt>
mov    %eax,%r14d
xor    %eax,%eax
call   1070 <getpagesize@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <rdtsc@plt>
xor    %eax,%eax
call   1050 <rdtsc@plt>
mov    %rax,%rbp
mov    0x2e6b(%rip),%rax
mov    (%rax),%edx
mov    0x2e52(%rip),%rax
mov    (%rax),%ecx
lea    (%rbx,%rbx,1),%eax
lea    (%rax,%rax,4),%r9d
xor    %edi,%edi
mov    %ebx,%esi
mov    %r14d,%r8d
call   1030 <mmap@plt>
xor    %eax,%eax
call   1050 <rdtsc@plt>
sub    %rbp,%rax
lea    0xe4d(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"testfile\00"
@O_RDONLY = global i32 0
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@.str.1 = [5 x i8] c"%llu\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8
store i32 0, i32* %1
%9 = load i32, i32* @O_RDONLY
%10 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %9)
store i32 %10, i32* %5
%11 = call i32 (...) @getpagesize()
store i32 %11, i32* %6
store i8 32, i8* %8
%12 = call i64 (...) @rdtsc()
store i64 %12, i64* %2
%13 = call i64 (...) @rdtsc()
store i64 %13, i64* %3
%14 = load i32, i32* %6
%15 = load i32, i32* @PROT_READ
%16 = load i32, i32* @MAP_SHARED
%17 = load i32, i32* %5
%18 = load i32, i32* %6
%19 = mul nsw i32 10, %18
%20 = call i8* @mmap(i32 0, i32 %14, i32 %15, i32 %16, i32 %17, i32 %19)
store i8* %20, i8** %7
%21 = load i8*, i8** %7
%22 = getelementptr inbounds i8, i8* %21, i64 2
%23 = load i8, i8* %22
store i8 %23, i8* %8
%24 = call i64 (...) @rdtsc()
store i64 %24, i64* %4
%25 = load i64, i64* %4
%26 = load i64, i64* %3
%27 = sub i64 %25, %26
%28 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %27)
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"testfile\00"
@O_RDONLY = global i32 0
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@.str.1 = [5 x i8] c"%llu\00"
define i32 @main() {
%1 = load i32, i32* @O_RDONLY
%2 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = tail call i32 (...) @getpagesize()
%4 = tail call i64 (...) @rdtsc()
%5 = tail call i64 (...) @rdtsc()
%6 = load i32, i32* @PROT_READ
%7 = load i32, i32* @MAP_SHARED
%8 = mul nsw i32 %3, 10
%9 = tail call i8* @mmap(i32 0, i32 %3, i32 %6, i32 %7, i32 %2, i32 %8)
%10 = tail call i64 (...) @rdtsc()
%11 = sub i64 %10, %5
%12 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %11)
ret i32 0
}