#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*/ mode_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int O_CREAT;
int O_RDWR;
int O_TRUNC;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, long double);
int lseek(int, int, int /*<<< orphan*/);
int *mmap(int /*<<< orphan*/, int, int, int /*<<< orphan*/, int,
          int /*<<< orphan*/);
int munmap(int *, int);
int open(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, long double);
unsigned long long rdtsc();
int write(int, char *, int);
int main(int argc, char *argv[]) {
  int i;
  int fd;
  int result;
  int *map;
  unsigned long long x;
  unsigned long long y;
  FILE *fp2;
  int iter = 0;
  for (iter; iter < 100; iter++) {
    fp2 = fopen("/home/george/Documents/C/pipe.txt", "a");
    fd = open("/home/george/Documents/C/mmapped.bin",
              O_RDWR | O_CREAT | O_TRUNC, (mode_t)0600);
    if (fd == -1) {
      perror("Error opening file for writing");
      exit(EXIT_FAILURE);
    }
    result = lseek(fd, ((4) * sizeof(int)) - 1, SEEK_SET);
    if (result == -1) {
      close(fd);
      perror("Error calling lseek() to 'stretch' the file");
      exit(EXIT_FAILURE);
    }
    result = write(fd, "", 1);
    if (result != 1) {
      close(fd);
      perror("Error writing last byte of the file");
      exit(EXIT_FAILURE);
    }
    map =
        mmap(0, ((4) * sizeof(int)), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
    if (map == MAP_FAILED) {
      close(fd);
      perror("Error mmapping the file");
      exit(EXIT_FAILURE);
    }
    x = rdtsc();
    for (i = 1; i <= (4); ++i) {
      map[i] = 1;
    }
    map = mmap(0, ((4) * sizeof(int)), PROT_READ, MAP_SHARED, fd, 0);
    if (map == MAP_FAILED) {
      close(fd);
      perror("Error mmapping the file");
      exit(EXIT_FAILURE);
    }
    for (i = 1; i <= (4) - 1; i = i + (4) / 2) {
      printf("%d ", map[i]);
    }
    map =
        mmap(0, ((4) * sizeof(int)), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
    if (map == MAP_FAILED) {
      close(fd);
      perror("Error mmapping the file");
      exit(EXIT_FAILURE);
    }
    map[0] = 6;
    map = mmap(0, ((4) * sizeof(int)), PROT_READ, MAP_SHARED, fd, 0);
    if (map == MAP_FAILED) {
      close(fd);
      perror("Error mmapping the file");
      exit(EXIT_FAILURE);
    }
    printf("%d ", map[0]);
    y = rdtsc();
    long double time = (long double)(y - x) / 2600000000;
    printf("It took this time to do the for-loop: %Lf \n", time);
    close(fd);
    fprintf(fp2, "%Lf\n", time);
    fflush(fp2);
    if (munmap(map, ((4) * sizeof(int))) == -1) {
      perror("Error un-mmapping the file");
    }
    fclose(fp2);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x44(%rbp)
cmpl   $0x64,-0x44(%rbp)
jge    15e2 <main+0x402>
lea    0xdfb(%rip),%rdi
lea    0xe16(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x40(%rbp)
mov    0x2da0(%rip),%rax
mov    (%rax),%esi
mov    0x2dc7(%rip),%rax
or     (%rax),%esi
mov    0x2db6(%rip),%rax
or     (%rax),%esi
lea    0xded(%rip),%rdi
mov    $0x180,%edx
call   10d0 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1274 <main+0x94>
lea    0xdf4(%rip),%rdi
call   10f0 <perror@plt>
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    -0x18(%rbp),%edi
mov    0x2d3a(%rip),%rax
mov    (%rax),%edx
mov    $0xf,%esi
call   1070 <lseek@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    12b9 <main+0xd9>
mov    -0x18(%rbp),%edi
call   1090 <close@plt>
lea    0xdce(%rip),%rdi
call   10f0 <perror@plt>
mov    0x2cfe(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    -0x18(%rbp),%edi
lea    0xe48(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
je     12fc <main+0x11c>
mov    -0x18(%rbp),%edi
call   1090 <close@plt>
lea    0xdb7(%rip),%rdi
call   10f0 <perror@plt>
mov    0x2cbb(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    0x2ce5(%rip),%rax
mov    (%rax),%edx
mov    0x2c9c(%rip),%rax
or     (%rax),%edx
mov    0x2cc3(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%r8d
xor    %r9d,%r9d
mov    $0x10,%esi
mov    %r9d,%edi
call   1050 <mmap@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2c66(%rip),%rcx
cmp    (%rcx),%rax
jne    1365 <main+0x185>
mov    -0x18(%rbp),%edi
call   1090 <close@plt>
lea    0xd72(%rip),%rdi
call   10f0 <perror@plt>
mov    0x2c52(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    $0x0,%al
call   1080 <rdtsc@plt>
mov    %rax,-0x30(%rbp)
movl   $0x1,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jg     139e <main+0x1be>
mov    -0x28(%rbp),%rax
movslq -0x14(%rbp),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1377 <main+0x197>
mov    0x2c43(%rip),%rax
mov    (%rax),%edx
mov    0x2c2a(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%r8d
xor    %r9d,%r9d
mov    $0x10,%esi
mov    %r9d,%edi
call   1050 <mmap@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2bcd(%rip),%rcx
cmp    (%rcx),%rax
jne    13fe <main+0x21e>
mov    -0x18(%rbp),%edi
call   1090 <close@plt>
lea    0xcd9(%rip),%rdi
call   10f0 <perror@plt>
mov    0x2bb9(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
movl   $0x1,-0x14(%rbp)
cmpl   $0x3,-0x14(%rbp)
jg     143f <main+0x25f>
mov    -0x28(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x70(%rbp)
fildl  -0x70(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
lea    0xcb0(%rip),%rdi
call   1060 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x14(%rbp)
jmp    1405 <main+0x225>
mov    0x2ba2(%rip),%rax
mov    (%rax),%edx
mov    0x2b59(%rip),%rax
or     (%rax),%edx
mov    0x2b80(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%r8d
xor    %r9d,%r9d
mov    $0x10,%esi
mov    %r9d,%edi
call   1050 <mmap@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2b23(%rip),%rcx
cmp    (%rcx),%rax
jne    14a8 <main+0x2c8>
mov    -0x18(%rbp),%edi
call   1090 <close@plt>
lea    0xc2f(%rip),%rdi
call   10f0 <perror@plt>
mov    0x2b0f(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    -0x28(%rbp),%rax
movl   $0x6,(%rax)
mov    0x2b2f(%rip),%rax
mov    (%rax),%edx
mov    0x2b16(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%r8d
xor    %r9d,%r9d
mov    $0x10,%esi
mov    %r9d,%edi
call   1050 <mmap@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2ab9(%rip),%rcx
cmp    (%rcx),%rax
jne    1512 <main+0x332>
mov    -0x18(%rbp),%edi
call   1090 <close@plt>
lea    0xbc5(%rip),%rdi
call   10f0 <perror@plt>
mov    0x2aa5(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
fildl  -0x6c(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
lea    0xbb2(%rip),%rdi
call   1060 <printf@plt>
xor    %eax,%eax
call   1080 <rdtsc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    -0x30(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x68(%rbp)
sets   %al
movzbl %al,%eax
mov    %eax,%ecx
fildll -0x68(%rbp)
lea    0xaa5(%rip),%rax
flds   (%rax,%rcx,4)
faddp  %st,%st(1)
flds   0xaa2(%rip)
fdivrp %st,%st(1)
fstpt  -0x60(%rbp)
fldt   -0x60(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
lea    0xb66(%rip),%rdi
call   1060 <printf@plt>
mov    -0x18(%rbp),%edi
call   1090 <close@plt>
mov    -0x40(%rbp),%rdi
fldt   -0x60(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
lea    0xb72(%rip),%rsi
call   10a0 <fprintf@plt>
mov    -0x40(%rbp),%rdi
call   10b0 <fflush@plt>
mov    -0x28(%rbp),%rdi
mov    $0x10,%esi
call   10c0 <munmap@plt>
cmp    $0xffffffff,%eax
jne    15cb <main+0x3eb>
lea    0xb4b(%rip),%rdi
call   10f0 <perror@plt>
mov    -0x40(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1200 <main+0x20>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    $0x64,%ebp
mov    0x2dee(%rip),%rbx
mov    0x2dd7(%rip),%r14
mov    0x2d98(%rip),%r13
jmp    122c <main+0x4c>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0x18(%rsp),%ebp
add    $0xffffffff,%ebp
mov    0x2dc2(%rip),%rbx
je     145c <main+0x27c>
lea    0xde9(%rip),%rdi
lea    0xe04(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,%r15
mov    0x2daf(%rip),%rax
mov    (%rax),%esi
mov    0x2d76(%rip),%rax
or     (%rax),%esi
mov    0x2d95(%rip),%rax
or     (%rax),%esi
lea    0xddc(%rip),%rdi
mov    $0x180,%edx
call   10d0 <open@plt>
cmp    $0xffffffff,%eax
je     147e <main+0x29e>
mov    %eax,%r12d
mov    0x2d37(%rip),%rax
mov    (%rax),%edx
mov    %r12d,%edi
mov    $0xf,%esi
call   1070 <lseek@plt>
cmp    $0xffffffff,%eax
je     1487 <main+0x2a7>
mov    %r15,0x38(%rsp)
mov    %r12d,%edi
lea    0xe73(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
jne    1498 <main+0x2b8>
mov    %ebp,0x18(%rsp)
mov    0x2ce2(%rip),%rax
mov    (%rax),%edx
or     (%rbx),%edx
mov    (%r14),%ecx
xor    %edi,%edi
mov    $0x10,%esi
mov    %r12d,%r8d
xor    %r9d,%r9d
call   1050 <mmap@plt>
cmp    0x0(%r13),%rax
je     146d <main+0x28d>
mov    %rax,%rbp
mov    %r13,%r15
xor    %eax,%eax
call   1080 <rdtsc@plt>
mov    %rax,0x28(%rsp)
movaps 0xcfe(%rip),%xmm0
movups %xmm0,0x4(%rbp)
mov    (%rbx),%edx
mov    (%r14),%ecx
xor    %edi,%edi
mov    $0x10,%esi
mov    %r12d,%r8d
xor    %r9d,%r9d
call   1050 <mmap@plt>
cmp    0x0(%r13),%rax
je     146d <main+0x28d>
mov    %rax,%rbp
mov    0x4(%rax),%eax
mov    %eax,0x20(%rsp)
fildl  0x20(%rsp)
fstpt  (%rsp)
lea    0xdad(%rip),%r13
mov    %r13,%rdi
call   1060 <printf@plt>
mov    0xc(%rbp),%eax
mov    %eax,0x24(%rsp)
fildl  0x24(%rsp)
fstpt  (%rsp)
mov    %r13,%rdi
call   1060 <printf@plt>
mov    0x2c44(%rip),%rax
mov    (%rax),%edx
or     (%rbx),%edx
mov    (%r14),%ecx
xor    %edi,%edi
mov    $0x10,%esi
mov    %r12d,%r8d
xor    %r9d,%r9d
call   1050 <mmap@plt>
cmp    (%r15),%rax
je     146d <main+0x28d>
movl   $0x6,(%rax)
mov    (%rbx),%edx
mov    (%r14),%ecx
xor    %edi,%edi
mov    $0x10,%esi
mov    %r12d,%r8d
xor    %r9d,%r9d
call   1050 <mmap@plt>
cmp    (%r15),%rax
je     146d <main+0x28d>
mov    %rax,%rbp
mov    %r15,%r13
mov    (%rax),%eax
mov    %eax,0x1c(%rsp)
fildl  0x1c(%rsp)
fstpt  (%rsp)
lea    0xd26(%rip),%rdi
call   1060 <printf@plt>
xor    %eax,%eax
call   1080 <rdtsc@plt>
xor    %ecx,%ecx
sub    0x28(%rsp),%rax
mov    %rax,0x40(%rsp)
sets   %cl
fildll 0x40(%rsp)
lea    0xc24(%rip),%rax
fadds  (%rax,%rcx,4)
fdivs  0xc23(%rip)
fld    %st(0)
fstpt  0x28(%rsp)
fstpt  (%rsp)
lea    0xceb(%rip),%rdi
call   1060 <printf@plt>
mov    %r12d,%edi
call   1090 <close@plt>
fldt   0x28(%rsp)
fstpt  (%rsp)
mov    0x38(%rsp),%rbx
mov    %rbx,%rdi
lea    0xcf4(%rip),%rsi
call   10a0 <fprintf@plt>
mov    %rbx,%rdi
call   10b0 <fflush@plt>
mov    %rbp,%rdi
mov    $0x10,%esi
call   10c0 <munmap@plt>
cmp    $0xffffffff,%eax
jne    1210 <main+0x30>
lea    0xccf(%rip),%rdi
call   10f0 <perror@plt>
jmp    1210 <main+0x30>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r12d,%edi
call   1090 <close@plt>
lea    0xc58(%rip),%rdi
jmp    14a7 <main+0x2c7>
lea    0xbe0(%rip),%rdi
jmp    14a7 <main+0x2c7>
mov    %r12d,%edi
call   1090 <close@plt>
lea    0xbee(%rip),%rdi
jmp    14a7 <main+0x2c7>
mov    %r12d,%edi
call   1090 <close@plt>
lea    0xc09(%rip),%rdi
call   10f0 <perror@plt>
mov    0x2afd(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>

LLVM IR (-O0):
@.str = [34 x i8] c"/home/george/Documents/C/pipe.txt\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [37 x i8] c"/home/george/Documents/C/mmapped.bin\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.3 = [31 x i8] c"Error opening file for writing\00"
@EXIT_FAILURE = global i32 0
@SEEK_SET = global i32 0
@.str.4 = [44 x i8] c"Error calling lseek() to 'stretch' the file\00"
@.str.5 = [1 x i8] zeroinitializer
@.str.6 = [36 x i8] c"Error writing last byte of the file\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i32* null
@.str.7 = [24 x i8] c"Error mmapping the file\00"
@.str.8 = [4 x i8] c"%d \00"
@.str.9 = [44 x i8] c"It took this time to do the for-loop: %Lf \0A\00"
@.str.10 = [5 x i8] c"%Lf\0A\00"
@.str.11 = [27 x i8] c"Error un-mmapping the file\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i64
%11 = alloca i64
%12 = alloca i32*
%13 = alloca i32
%14 = alloca x86_fp80
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %13
%15 = load i32, i32* %13
br label %16
16: ; preds = %175, %2
%17 = load i32, i32* %13
%18 = icmp slt i32 %17, 100
br i1 %18, label %19, label %178
19: ; preds = %16
%20 = call i32* @fopen(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %12
%21 = load i32, i32* @O_RDWR
%22 = load i32, i32* @O_CREAT
%23 = or i32 %21, %22
%24 = load i32, i32* @O_TRUNC
%25 = or i32 %23, %24
%26 = call i32 @open(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %25, i32 384)
store i32 %26, i32* %7
%27 = load i32, i32* %7
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %33
29: ; preds = %19
%30 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%31 = load i32, i32* @EXIT_FAILURE
%32 = call i32 @exit(i32 %31)
unreachable
33: ; preds = %19
%34 = load i32, i32* %7
%35 = load i32, i32* @SEEK_SET
%36 = call i32 @lseek(i32 %34, i32 15, i32 %35)
store i32 %36, i32* %8
%37 = load i32, i32* %8
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %45
39: ; preds = %33
%40 = load i32, i32* %7
%41 = call i32 @close(i32 %40)
%42 = call i32 @perror(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0))
%43 = load i32, i32* @EXIT_FAILURE
%44 = call i32 @exit(i32 %43)
unreachable
45: ; preds = %33
%46 = load i32, i32* %7
%47 = call i32 @write(i32 %46, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0), i32 1)
store i32 %47, i32* %8
%48 = load i32, i32* %8
%49 = icmp ne i32 %48, 1
br i1 %49, label %50, label %56
50: ; preds = %45
%51 = load i32, i32* %7
%52 = call i32 @close(i32 %51)
%53 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0))
%54 = load i32, i32* @EXIT_FAILURE
%55 = call i32 @exit(i32 %54)
unreachable
56: ; preds = %45
%57 = load i32, i32* @PROT_READ
%58 = load i32, i32* @PROT_WRITE
%59 = or i32 %57, %58
%60 = load i32, i32* @MAP_SHARED
%61 = load i32, i32* %7
%62 = call i32* @mmap(i32 0, i32 16, i32 %59, i32 %60, i32 %61, i32 0)
store i32* %62, i32** %9
%63 = load i32*, i32** %9
%64 = load i32*, i32** @MAP_FAILED
%65 = icmp eq i32* %63, %64
br i1 %65, label %66, label %72
66: ; preds = %56
%67 = load i32, i32* %7
%68 = call i32 @close(i32 %67)
%69 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0))
%70 = load i32, i32* @EXIT_FAILURE
%71 = call i32 @exit(i32 %70)
unreachable
72: ; preds = %56
%73 = call i64 (...) @rdtsc()
store i64 %73, i64* %10
store i32 1, i32* %6
br label %74
74: ; preds = %82, %72
%75 = load i32, i32* %6
%76 = icmp sle i32 %75, 4
br i1 %76, label %77, label %85
77: ; preds = %74
%78 = load i32*, i32** %9
%79 = load i32, i32* %6
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds i32, i32* %78, i64 %80
store i32 1, i32* %81
br label %82
82: ; preds = %77
%83 = load i32, i32* %6
%84 = add nsw i32 %83, 1
store i32 %84, i32* %6
br label %74
85: ; preds = %74
%86 = load i32, i32* @PROT_READ
%87 = load i32, i32* @MAP_SHARED
%88 = load i32, i32* %7
%89 = call i32* @mmap(i32 0, i32 16, i32 %86, i32 %87, i32 %88, i32 0)
store i32* %89, i32** %9
%90 = load i32*, i32** %9
%91 = load i32*, i32** @MAP_FAILED
%92 = icmp eq i32* %90, %91
br i1 %92, label %93, label %99
93: ; preds = %85
%94 = load i32, i32* %7
%95 = call i32 @close(i32 %94)
%96 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0))
%97 = load i32, i32* @EXIT_FAILURE
%98 = call i32 @exit(i32 %97)
unreachable
99: ; preds = %85
store i32 1, i32* %6
br label %100
100: ; preds = %111, %99
%101 = load i32, i32* %6
%102 = icmp sle i32 %101, 3
br i1 %102, label %103, label %114
103: ; preds = %100
%104 = load i32*, i32** %9
%105 = load i32, i32* %6
%106 = sext i32 %105 to i64
%107 = getelementptr inbounds i32, i32* %104, i64 %106
%108 = load i32, i32* %107
%109 = sitofp i32 %108 to x86_fp80
%110 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), x86_fp80 %109)
br label %111
111: ; preds = %103
%112 = load i32, i32* %6
%113 = add nsw i32 %112, 2
store i32 %113, i32* %6
br label %100
114: ; preds = %100
%115 = load i32, i32* @PROT_READ
%116 = load i32, i32* @PROT_WRITE
%117 = or i32 %115, %116
%118 = load i32, i32* @MAP_SHARED
%119 = load i32, i32* %7
%120 = call i32* @mmap(i32 0, i32 16, i32 %117, i32 %118, i32 %119, i32 0)
store i32* %120, i32** %9
%121 = load i32*, i32** %9
%122 = load i32*, i32** @MAP_FAILED
%123 = icmp eq i32* %121, %122
br i1 %123, label %124, label %130
124: ; preds = %114
%125 = load i32, i32* %7
%126 = call i32 @close(i32 %125)
%127 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0))
%128 = load i32, i32* @EXIT_FAILURE
%129 = call i32 @exit(i32 %128)
unreachable
130: ; preds = %114
%131 = load i32*, i32** %9
%132 = getelementptr inbounds i32, i32* %131, i64 0
store i32 6, i32* %132
%133 = load i32, i32* @PROT_READ
%134 = load i32, i32* @MAP_SHARED
%135 = load i32, i32* %7
%136 = call i32* @mmap(i32 0, i32 16, i32 %133, i32 %134, i32 %135, i32 0)
store i32* %136, i32** %9
%137 = load i32*, i32** %9
%138 = load i32*, i32** @MAP_FAILED
%139 = icmp eq i32* %137, %138
br i1 %139, label %140, label %146
140: ; preds = %130
%141 = load i32, i32* %7
%142 = call i32 @close(i32 %141)
%143 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0))
%144 = load i32, i32* @EXIT_FAILURE
%145 = call i32 @exit(i32 %144)
unreachable
146: ; preds = %130
%147 = load i32*, i32** %9
%148 = getelementptr inbounds i32, i32* %147, i64 0
%149 = load i32, i32* %148
%150 = sitofp i32 %149 to x86_fp80
%151 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), x86_fp80 %150)
%152 = call i64 (...) @rdtsc()
store i64 %152, i64* %11
%153 = load i64, i64* %11
%154 = load i64, i64* %10
%155 = sub i64 %153, %154
%156 = uitofp i64 %155 to x86_fp80
%157 = fdiv x86_fp80 %156, 0xK401E9AF8DA0000000000
store x86_fp80 %157, x86_fp80* %14
%158 = load x86_fp80, x86_fp80* %14
%159 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.9, i64 0, i64 0), x86_fp80 %158)
%160 = load i32, i32* %7
%161 = call i32 @close(i32 %160)
%162 = load i32*, i32** %12
%163 = load x86_fp80, x86_fp80* %14
%164 = call i32 @fprintf(i32* %162, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), x86_fp80 %163)
%165 = load i32*, i32** %12
%166 = call i32 @fflush(i32* %165)
%167 = load i32*, i32** %9
%168 = call i32 @munmap(i32* %167, i32 16)
%169 = icmp eq i32 %168, -1
br i1 %169, label %170, label %172
170: ; preds = %146
%171 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.11, i64 0, i64 0))
br label %172
172: ; preds = %170, %146
%173 = load i32*, i32** %12
%174 = call i32 @fclose(i32* %173)
br label %175
175: ; preds = %172
%176 = load i32, i32* %13
%177 = add nsw i32 %176, 1
store i32 %177, i32* %13
br label %16
178: ; preds = %16
ret i32 0
}

LLVM IR (-O2):
@.str = [34 x i8] c"/home/george/Documents/C/pipe.txt\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [37 x i8] c"/home/george/Documents/C/mmapped.bin\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.3 = [31 x i8] c"Error opening file for writing\00"
@EXIT_FAILURE = global i32 0
@SEEK_SET = global i32 0
@.str.4 = [44 x i8] c"Error calling lseek() to 'stretch' the file\00"
@.str.5 = [1 x i8] zeroinitializer
@.str.6 = [36 x i8] c"Error writing last byte of the file\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i32* null
@.str.7 = [24 x i8] c"Error mmapping the file\00"
@.str.8 = [4 x i8] c"%d \00"
@.str.9 = [44 x i8] c"It took this time to do the for-loop: %Lf \0A\00"
@.str.10 = [5 x i8] c"%Lf\0A\00"
@.str.11 = [27 x i8] c"Error un-mmapping the file\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
br label %3
3: ; preds = %2, %109
%4 = phi i32 [ 0, %2 ], [ %111, %109 ]
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = load i32, i32* @O_RDWR
%7 = load i32, i32* @O_CREAT
%8 = or i32 %7, %6
%9 = load i32, i32* @O_TRUNC
%10 = or i32 %8, %9
%11 = tail call i32 @open(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %10, i32 384)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %17
13: ; preds = %3
%14 = tail call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %3
%18 = load i32, i32* @SEEK_SET
%19 = tail call i32 @lseek(i32 %11, i32 15, i32 %18)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %26
21: ; preds = %17
%22 = tail call i32 @close(i32 %11)
%23 = tail call i32 @perror(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
%25 = tail call i32 @exit(i32 %24)
unreachable
26: ; preds = %17
%27 = tail call i32 @write(i32 %11, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0), i32 1)
%28 = icmp eq i32 %27, 1
br i1 %28, label %34, label %29
29: ; preds = %26
%30 = tail call i32 @close(i32 %11)
%31 = tail call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0))
%32 = load i32, i32* @EXIT_FAILURE
%33 = tail call i32 @exit(i32 %32)
unreachable
34: ; preds = %26
%35 = load i32, i32* @PROT_READ
%36 = load i32, i32* @PROT_WRITE
%37 = or i32 %36, %35
%38 = load i32, i32* @MAP_SHARED
%39 = tail call i32* @mmap(i32 0, i32 16, i32 %37, i32 %38, i32 %11, i32 0)
%40 = load i32*, i32** @MAP_FAILED
%41 = icmp eq i32* %39, %40
br i1 %41, label %42, label %47
42: ; preds = %34
%43 = tail call i32 @close(i32 %11)
%44 = tail call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0))
%45 = load i32, i32* @EXIT_FAILURE
%46 = tail call i32 @exit(i32 %45)
unreachable
47: ; preds = %34
%48 = tail call i64 (...) @rdtsc()
%49 = getelementptr inbounds i32, i32* %39, i64 1
%50 = bitcast i32* %49 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %50
%51 = load i32, i32* @PROT_READ
%52 = load i32, i32* @MAP_SHARED
%53 = tail call i32* @mmap(i32 0, i32 16, i32 %51, i32 %52, i32 %11, i32 0)
%54 = load i32*, i32** @MAP_FAILED
%55 = icmp eq i32* %53, %54
br i1 %55, label %72, label %56
56: ; preds = %47
%57 = getelementptr inbounds i32, i32* %53, i64 1
%58 = load i32, i32* %57
%59 = sitofp i32 %58 to x86_fp80
%60 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), x86_fp80 %59)
%61 = getelementptr inbounds i32, i32* %53, i64 3
%62 = load i32, i32* %61
%63 = sitofp i32 %62 to x86_fp80
%64 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), x86_fp80 %63)
%65 = load i32, i32* @PROT_READ
%66 = load i32, i32* @PROT_WRITE
%67 = or i32 %66, %65
%68 = load i32, i32* @MAP_SHARED
%69 = tail call i32* @mmap(i32 0, i32 16, i32 %67, i32 %68, i32 %11, i32 0)
%70 = load i32*, i32** @MAP_FAILED
%71 = icmp eq i32* %69, %70
br i1 %71, label %77, label %82
72: ; preds = %47
%73 = tail call i32 @close(i32 %11)
%74 = tail call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0))
%75 = load i32, i32* @EXIT_FAILURE
%76 = tail call i32 @exit(i32 %75)
unreachable
77: ; preds = %56
%78 = tail call i32 @close(i32 %11)
%79 = tail call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0))
%80 = load i32, i32* @EXIT_FAILURE
%81 = tail call i32 @exit(i32 %80)
unreachable
82: ; preds = %56
store i32 6, i32* %69
%83 = load i32, i32* @PROT_READ
%84 = load i32, i32* @MAP_SHARED
%85 = tail call i32* @mmap(i32 0, i32 16, i32 %83, i32 %84, i32 %11, i32 0)
%86 = load i32*, i32** @MAP_FAILED
%87 = icmp eq i32* %85, %86
br i1 %87, label %88, label %93
88: ; preds = %82
%89 = tail call i32 @close(i32 %11)
%90 = tail call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0))
%91 = load i32, i32* @EXIT_FAILURE
%92 = tail call i32 @exit(i32 %91)
unreachable
93: ; preds = %82
%94 = load i32, i32* %85
%95 = sitofp i32 %94 to x86_fp80
%96 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), x86_fp80 %95)
%97 = tail call i64 (...) @rdtsc()
%98 = sub i64 %97, %48
%99 = uitofp i64 %98 to x86_fp80
%100 = fdiv x86_fp80 %99, 0xK401E9AF8DA0000000000
%101 = tail call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.9, i64 0, i64 0), x86_fp80 %100)
%102 = tail call i32 @close(i32 %11)
%103 = tail call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), x86_fp80 %100)
%104 = tail call i32 @fflush(i32* %5)
%105 = tail call i32 @munmap(i32* %85, i32 16)
%106 = icmp eq i32 %105, -1
br i1 %106, label %107, label %109
107: ; preds = %93
%108 = tail call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.11, i64 0, i64 0))
br label %109
109: ; preds = %107, %93
%110 = tail call i32 @fclose(i32* %5)
%111 = add nuw nsw i32 %4, 1
%112 = icmp eq i32 %111, 100
br i1 %112, label %113, label %3
113: ; preds = %109
ret i32 0
}