#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 uint64_t;
struct stat {
  size_t st_size;
};
typedef int int64_t;

/* Variables and functions */
char *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ PROT_READ;
int close(int);
int /*<<< orphan*/ free(struct stat *);
struct stat *malloc(size_t);
int /*<<< orphan*/ memcpy(char *, char *, size_t);
char *mmap(int /*<<< orphan*/, size_t, int /*<<< orphan*/, int /*<<< orphan*/,
           int, int /*<<< orphan*/);
int munmap(char *, size_t);
scalar_t__ open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ putchar(char);
int rdtsc();
int /*<<< orphan*/ stat(char *, struct stat *);
float *mmap_time(char *file) {
  struct stat *buf;
  int fd;
  float *result = (float *)malloc((sizeof(float) * 2) + 1);
  fd = (int)open(file, O_RDONLY);
  buf = malloc(sizeof(struct stat));
  stat(file, buf);
  size_t size = buf->st_size;
  free(buf);
  uint64_t start = rdtsc();
  char *m = mmap(0, size, PROT_READ, MAP_SHARED, fd, 0);
  uint64_t stop = rdtsc();
  unsigned int lo = start & (((uint64_t)2 << 32) - 1);
  unsigned int lo2 = stop & (((int64_t)2 << 32) - 1);
  int cycles = lo2 - lo;
  float t = ((float)(cycles));
  float factor = 3591338000.0 * .000001;
  t = t / factor;
  result[0] = t;
  char *destination = (char *)malloc(size + 1);
  uint64_t start1 = rdtsc();
  memcpy(destination, m, size);
  uint64_t stop1 = rdtsc();
  unsigned int lo1 = start1 & (((uint64_t)2 << 32) - 1);
  unsigned int lo3 = stop1 & (((int64_t)2 << 32) - 1);
  int cycles1 = lo3 - lo1;
  float tz = ((float)(cycles1));
  float fact = 3591338000.0 * .000001;
  tz = tz / fact;
  result[1] = tz;
  if (m == MAP_FAILED) {
    perror("mmap");
    return result;
  }
  if (close(fd) == -1) {
    perror("close");
    return result;
  }
  int len;
  int yo = size;
  for (len = 0; len < yo; len++)
    putchar(m[len]);
  if (munmap(m, size) == -1) {
    perror("munmap");
    return result;
  }
  return result;
}


x86 assembly (clang, -O0):
<mmap_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x9,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e00(%rip),%rax
mov    (%rax),%esi
call   10c0 <open@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x8,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <stat@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    $0x0,%al
call   1060 <rdtsc@plt>
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rsi
mov    0x2dd2(%rip),%rax
mov    (%rax),%edx
mov    0x2db9(%rip),%rax
mov    (%rax),%ecx
mov    -0x1c(%rbp),%r8d
xor    %r9d,%r9d
mov    %r9d,%edi
call   1050 <mmap@plt>
mov    %rax,-0x40(%rbp)
mov    $0x0,%al
call   1060 <rdtsc@plt>
mov    %eax,-0x44(%rbp)
and    -0x34(%rbp),%eax
mov    %eax,-0x48(%rbp)
and    -0x44(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
sub    -0x48(%rbp),%eax
mov    %eax,-0x50(%rbp)
cvtsi2ssl -0x50(%rbp),%xmm0
movss  %xmm0,-0x54(%rbp)
movss  0xd8b(%rip),%xmm0
movss  %xmm0,-0x58(%rbp)
movss  -0x54(%rbp),%xmm0
divss  -0x58(%rbp),%xmm0
movss  %xmm0,-0x54(%rbp)
movss  -0x54(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movss  %xmm0,(%rax)
mov    -0x30(%rbp),%rdi
add    $0x1,%rdi
call   10a0 <malloc@plt>
mov    %rax,-0x60(%rbp)
mov    $0x0,%al
call   1060 <rdtsc@plt>
mov    %eax,-0x64(%rbp)
mov    -0x60(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1090 <memcpy@plt>
mov    $0x0,%al
call   1060 <rdtsc@plt>
mov    %eax,-0x68(%rbp)
and    -0x64(%rbp),%eax
mov    %eax,-0x6c(%rbp)
and    -0x68(%rbp),%eax
mov    %eax,-0x70(%rbp)
mov    -0x70(%rbp),%eax
sub    -0x6c(%rbp),%eax
mov    %eax,-0x74(%rbp)
cvtsi2ssl -0x74(%rbp),%xmm0
movss  %xmm0,-0x78(%rbp)
movss  0xd0d(%rip),%xmm0
movss  %xmm0,-0x7c(%rbp)
movss  -0x78(%rbp),%xmm0
divss  -0x7c(%rbp),%xmm0
movss  %xmm0,-0x78(%rbp)
movss  -0x78(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movss  %xmm0,0x4(%rax)
mov    -0x40(%rbp),%rax
mov    0x2ca8(%rip),%rcx
cmp    (%rcx),%rax
jne    1342 <mmap_time+0x192>
lea    0xcd4(%rip),%rdi
call   10d0 <perror@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    13e2 <mmap_time+0x232>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
cmp    $0xffffffff,%eax
jne    136c <mmap_time+0x1bc>
lea    0xcaf(%rip),%rdi
call   10d0 <perror@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    13e2 <mmap_time+0x232>
mov    -0x30(%rbp),%rax
mov    %eax,-0x84(%rbp)
movl   $0x0,-0x80(%rbp)
mov    -0x80(%rbp),%eax
cmp    -0x84(%rbp),%eax
jge    13ab <mmap_time+0x1fb>
mov    -0x40(%rbp),%rax
movslq -0x80(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <putchar@plt>
mov    -0x80(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x80(%rbp)
jmp    137d <mmap_time+0x1cd>
mov    -0x40(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   10b0 <munmap@plt>
cmp    $0xffffffff,%eax
jne    13da <mmap_time+0x22a>
lea    0xc47(%rip),%rdi
call   10d0 <perror@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    13e2 <mmap_time+0x232>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mmap_time>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r12
mov    $0x9,%edi
call   10a0 <malloc@plt>
mov    %rax,%rbp
mov    0x2e06(%rip),%rax
mov    (%rax),%esi
mov    %r12,%rdi
call   10c0 <open@plt>
mov    %rax,%r15
mov    $0x8,%edi
call   10a0 <malloc@plt>
mov    %rax,%rbx
mov    %r12,%rdi
mov    %rax,%rsi
call   1080 <stat@plt>
mov    (%rbx),%r12
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
call   1060 <rdtsc@plt>
mov    0x2de8(%rip),%rax
mov    (%rax),%edx
mov    0x2dcf(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %r12,%rsi
mov    %r15d,%r8d
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1060 <rdtsc@plt>
lea    0x1(%r12),%rdi
call   10a0 <malloc@plt>
mov    %rax,%r13
xor    %eax,%eax
call   1060 <rdtsc@plt>
mov    %r13,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1090 <memcpy@plt>
xor    %eax,%eax
call   1060 <rdtsc@plt>
mov    0x2d63(%rip),%rax
cmp    (%rax),%r14
je     12c8 <mmap_time+0x118>
mov    %r15d,%edi
call   1070 <close@plt>
cmp    $0xffffffff,%eax
je     12d1 <mmap_time+0x121>
mov    %rbp,%r15
test   %r12d,%r12d
jle    12a3 <mmap_time+0xf3>
mov    %r12d,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl (%r14,%rbp,1),%edi
call   1040 <putchar@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1290 <mmap_time+0xe0>
mov    %r14,%rdi
mov    %r12,%rsi
call   10b0 <munmap@plt>
cmp    $0xffffffff,%eax
mov    %r15,%rbp
je     12da <mmap_time+0x12a>
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd31(%rip),%rdi
jmp    12e1 <mmap_time+0x131>
lea    0xd2d(%rip),%rdi
jmp    12e1 <mmap_time+0x131>
lea    0xd2a(%rip),%rdi
call   10d0 <perror@plt>
jmp    12b6 <mmap_time+0x106>

LLVM IR (-O0):
%struct.stat = type { i64 }
@O_RDONLY = global i32 0
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str = [5 x i8] c"mmap\00"
@.str.1 = [6 x i8] c"close\00"
@.str.2 = [7 x i8] c"munmap\00"
define float* @mmap_time(i8* %0) {
%2 = alloca float*
%3 = alloca i8*
%4 = alloca %struct.stat*
%5 = alloca i32
%6 = alloca float*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca float
%15 = alloca float
%16 = alloca i8*
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca float
%23 = alloca float
%24 = alloca i32
%25 = alloca i32
store i8* %0, i8** %3
%26 = call %struct.stat* @malloc(i64 9)
%27 = bitcast %struct.stat* %26 to float*
store float* %27, float** %6
%28 = load i8*, i8** %3
%29 = load i32, i32* @O_RDONLY
%30 = call i64 @open(i8* %28, i32 %29)
%31 = trunc i64 %30 to i32
store i32 %31, i32* %5
%32 = call %struct.stat* @malloc(i64 8)
store %struct.stat* %32, %struct.stat** %4
%33 = load i8*, i8** %3
%34 = load %struct.stat*, %struct.stat** %4
%35 = call i32 @stat(i8* %33, %struct.stat* %34)
%36 = load %struct.stat*, %struct.stat** %4
%37 = getelementptr inbounds %struct.stat, %struct.stat* %36, i32 0, i32 0
%38 = load i64, i64* %37
store i64 %38, i64* %7
%39 = load %struct.stat*, %struct.stat** %4
%40 = call i32 @free(%struct.stat* %39)
%41 = call i32 (...) @rdtsc()
store i32 %41, i32* %8
%42 = load i64, i64* %7
%43 = load i32, i32* @PROT_READ
%44 = load i32, i32* @MAP_SHARED
%45 = load i32, i32* %5
%46 = call i8* @mmap(i32 0, i64 %42, i32 %43, i32 %44, i32 %45, i32 0)
store i8* %46, i8** %9
%47 = call i32 (...) @rdtsc()
store i32 %47, i32* %10
%48 = load i32, i32* %8
%49 = and i32 %48, poison
store i32 %49, i32* %11
%50 = load i32, i32* %10
%51 = and i32 %50, poison
store i32 %51, i32* %12
%52 = load i32, i32* %12
%53 = load i32, i32* %11
%54 = sub i32 %52, %53
store i32 %54, i32* %13
%55 = load i32, i32* %13
%56 = sitofp i32 %55 to float
store float %56, float* %14
store float 0x40AC0EAD00000000, float* %15
%57 = load float, float* %14
%58 = load float, float* %15
%59 = fdiv float %57, %58
store float %59, float* %14
%60 = load float, float* %14
%61 = load float*, float** %6
%62 = getelementptr inbounds float, float* %61, i64 0
store float %60, float* %62
%63 = load i64, i64* %7
%64 = add i64 %63, 1
%65 = call %struct.stat* @malloc(i64 %64)
%66 = bitcast %struct.stat* %65 to i8*
store i8* %66, i8** %16
%67 = call i32 (...) @rdtsc()
store i32 %67, i32* %17
%68 = load i8*, i8** %16
%69 = load i8*, i8** %9
%70 = load i64, i64* %7
%71 = call i32 @memcpy(i8* %68, i8* %69, i64 %70)
%72 = call i32 (...) @rdtsc()
store i32 %72, i32* %18
%73 = load i32, i32* %17
%74 = and i32 %73, poison
store i32 %74, i32* %19
%75 = load i32, i32* %18
%76 = and i32 %75, poison
store i32 %76, i32* %20
%77 = load i32, i32* %20
%78 = load i32, i32* %19
%79 = sub i32 %77, %78
store i32 %79, i32* %21
%80 = load i32, i32* %21
%81 = sitofp i32 %80 to float
store float %81, float* %22
store float 0x40AC0EAD00000000, float* %23
%82 = load float, float* %22
%83 = load float, float* %23
%84 = fdiv float %82, %83
store float %84, float* %22
%85 = load float, float* %22
%86 = load float*, float** %6
%87 = getelementptr inbounds float, float* %86, i64 1
store float %85, float* %87
%88 = load i8*, i8** %9
%89 = load i8*, i8** @MAP_FAILED
%90 = icmp eq i8* %88, %89
br i1 %90, label %91, label %94
91: ; preds = %1
%92 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%93 = load float*, float** %6
store float* %93, float** %2
br label %128
94: ; preds = %1
%95 = load i32, i32* %5
%96 = call i32 @close(i32 %95)
%97 = icmp eq i32 %96, -1
br i1 %97, label %98, label %101
98: ; preds = %94
%99 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%100 = load float*, float** %6
store float* %100, float** %2
br label %128
101: ; preds = %94
%102 = load i64, i64* %7
%103 = trunc i64 %102 to i32
store i32 %103, i32* %25
store i32 0, i32* %24
br label %104
104: ; preds = %115, %101
%105 = load i32, i32* %24
%106 = load i32, i32* %25
%107 = icmp slt i32 %105, %106
br i1 %107, label %108, label %118
108: ; preds = %104
%109 = load i8*, i8** %9
%110 = load i32, i32* %24
%111 = sext i32 %110 to i64
%112 = getelementptr inbounds i8, i8* %109, i64 %111
%113 = load i8, i8* %112
%114 = call i32 @putchar(i8 signext %113)
br label %115
115: ; preds = %108
%116 = load i32, i32* %24
%117 = add nsw i32 %116, 1
store i32 %117, i32* %24
br label %104
118: ; preds = %104
%119 = load i8*, i8** %9
%120 = load i64, i64* %7
%121 = call i32 @munmap(i8* %119, i64 %120)
%122 = icmp eq i32 %121, -1
br i1 %122, label %123, label %126
123: ; preds = %118
%124 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%125 = load float*, float** %6
store float* %125, float** %2
br label %128
126: ; preds = %118
%127 = load float*, float** %6
store float* %127, float** %2
br label %128
128: ; preds = %126, %123, %98, %91
%129 = load float*, float** %2
ret float* %129
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@O_RDONLY = global i32 0
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str = [5 x i8] c"mmap\00"
@.str.1 = [6 x i8] c"close\00"
@.str.2 = [7 x i8] c"munmap\00"
define noalias float* @mmap_time(i8* nocapture %0) {
%2 = tail call %struct.stat* @malloc(i64 9)
%3 = load i32, i32* @O_RDONLY
%4 = tail call i64 @open(i8* %0, i32 %3)
%5 = trunc i64 %4 to i32
%6 = tail call %struct.stat* @malloc(i64 8)
%7 = tail call i32 @stat(i8* %0, %struct.stat* %6)
%8 = getelementptr inbounds %struct.stat, %struct.stat* %6, i64 0, i32 0
%9 = load i64, i64* %8
%10 = tail call i32 @free(%struct.stat* %6)
%11 = tail call i32 (...) @rdtsc()
%12 = load i32, i32* @PROT_READ
%13 = load i32, i32* @MAP_SHARED
%14 = tail call i8* @mmap(i32 0, i64 %9, i32 %12, i32 %13, i32 %5, i32 0)
%15 = tail call i32 (...) @rdtsc()
%16 = add i64 %9, 1
%17 = tail call %struct.stat* @malloc(i64 %16)
%18 = bitcast %struct.stat* %17 to i8*
%19 = tail call i32 (...) @rdtsc()
%20 = tail call i32 @memcpy(i8* %18, i8* %14, i64 %9)
%21 = tail call i32 (...) @rdtsc()
%22 = load i8*, i8** @MAP_FAILED
%23 = icmp eq i8* %14, %22
br i1 %23, label %42, label %24
24: ; preds = %1
%25 = tail call i32 @close(i32 %5)
%26 = icmp eq i32 %25, -1
br i1 %26, label %42, label %27
27: ; preds = %24
%28 = trunc i64 %9 to i32
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %39
30: ; preds = %27
%31 = and i64 %9, 4294967295
br label %32
32: ; preds = %30, %32
%33 = phi i64 [ 0, %30 ], [ %37, %32 ]
%34 = getelementptr inbounds i8, i8* %14, i64 %33
%35 = load i8, i8* %34
%36 = tail call i32 @putchar(i8 signext %35)
%37 = add nuw nsw i64 %33, 1
%38 = icmp eq i64 %37, %31
br i1 %38, label %39, label %32
39: ; preds = %32, %27
%40 = tail call i32 @munmap(i8* %14, i64 %9)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %45
42: ; preds = %39, %24, %1
%43 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), %24 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), %39 ]
%44 = tail call i32 @perror(i8* %43)
br label %45
45: ; preds = %42, %39
%46 = bitcast %struct.stat* %2 to float*
ret float* %46
}