#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 */
struct timespec {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC;
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ elapsed_time_hr(struct timespec, struct timespec, char *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ fsync(int);
unsigned char *malloc(unsigned int);
int open(char *, int, ...);
int /*<<< orphan*/ read(int, unsigned char *, int);
int /*<<< orphan*/ sprintf(char *, char *, int, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ unlink(char *);
int /*<<< orphan*/ write(int, unsigned char *, int);
int file_read(unsigned int N) {
  struct timespec start, end;
  char name[100];
  int size = 1;
  int i, j;
  unsigned char *data;
  int warmupsize;
  char titlebuffer[500];
  int fd;
  int reps;
  data = malloc(N);
  if (!data) {
    fprintf(stderr, "ERROR: out of memory in file_read\n");
    return 1;
  }
  fd = open("/dev/urandom", O_RDONLY);
  if (fd < 0) {
    fprintf(stderr, "ERROR: unable to open /dev/urandom in file_read\n");
    return 1;
  }
  read(fd, data, N);
  close(fd);
  while (N >= 10000) {
    N = N / 2;
    size = size * 2;
  }
  while (N >= 1) {
    sprintf(titlebuffer, "file_read: %d files of %d bytes", N, size);
    for (i = 0; i < N; i++) {
      sprintf(name, "testfile_%d", i);
      fd = open(name, O_CREAT | O_WRONLY | O_TRUNC, 0644);
      if (fd < 0) {
        fprintf(stderr,
                "ERROR: unable to open test file for writing in file_read\n");
        return 1;
      }
      write(fd, data, size);
      fsync(fd);
      close(fd);
    }
    reps = 32768 / N;
    if (reps == 0)
      reps = 1;
    clock_gettime(CLOCK_MONOTONIC, &start);
    for (j = 0; j < reps; j++) {
      for (i = 0; i < N; i++) {
        sprintf(name, "testfile_%d", i);
        fd = open(name, O_RDONLY);
        if (fd < 0) {
          fprintf(stderr,
                  "ERROR: unable to open test file for reading in file_read\n");
          return 1;
        }
        read(fd, data, size);
        close(fd);
      }
    }
    clock_gettime(CLOCK_MONOTONIC, &end);
    elapsed_time_hr(start, end, titlebuffer);
    for (i = 0; i < N; i++) {
      sprintf(name, "testfile_%d", i);
      unlink(name);
    }
    N = N / 2;
    size = size * 2;
  }
  free(data);
  fflush(stdout);
  return 0;
}


x86 assembly (clang, -O0):
<file_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2a0,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x1,-0x84(%rbp)
mov    -0x8(%rbp),%edi
call   10b0 <malloc@plt>
mov    %rax,-0x98(%rbp)
cmpq   $0x0,-0x98(%rbp)
jne    1226 <file_read+0x56>
mov    0x2db4(%rip),%rax
mov    (%rax),%edi
lea    0xdeb(%rip),%rsi
call   10a0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1588 <file_read+0x3b8>
mov    0x2dab(%rip),%rax
mov    (%rax),%esi
lea    0xded(%rip),%rdi
mov    $0x0,%al
call   10e0 <open@plt>
mov    %eax,-0x294(%rbp)
cmpl   $0x0,-0x294(%rbp)
jge    1271 <file_read+0xa1>
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
lea    0xdd0(%rip),%rsi
call   10a0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1588 <file_read+0x3b8>
mov    -0x294(%rbp),%edi
mov    -0x98(%rbp),%rsi
mov    -0x8(%rbp),%edx
call   1090 <read@plt>
mov    -0x294(%rbp),%edi
call   1080 <close@plt>
cmpl   $0x2710,-0x8(%rbp)
jb     12bb <file_read+0xeb>
mov    -0x8(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x84(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    1291 <file_read+0xc1>
jmp    12c0 <file_read+0xf0>
cmpl   $0x1,-0x8(%rbp)
jb     1567 <file_read+0x397>
lea    -0x290(%rbp),%rdi
mov    -0x8(%rbp),%edx
mov    -0x84(%rbp),%ecx
lea    0xd80(%rip),%rsi
mov    $0x0,%al
call   10f0 <sprintf@plt>
movl   $0x0,-0x88(%rbp)
mov    -0x88(%rbp),%eax
cmp    -0x8(%rbp),%eax
jae    13ba <file_read+0x1ea>
lea    -0x80(%rbp),%rdi
mov    -0x88(%rbp),%edx
lea    0xd6f(%rip),%rsi
mov    $0x0,%al
call   10f0 <sprintf@plt>
lea    -0x80(%rbp),%rdi
mov    0x2cd4(%rip),%rax
mov    (%rax),%esi
mov    0x2c7b(%rip),%rax
or     (%rax),%esi
mov    0x2cba(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
mov    $0x0,%al
call   10e0 <open@plt>
mov    %eax,-0x294(%rbp)
cmpl   $0x0,-0x294(%rbp)
jge    1378 <file_read+0x1a8>
mov    0x2c62(%rip),%rax
mov    (%rax),%edi
lea    0xd26(%rip),%rsi
call   10a0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1588 <file_read+0x3b8>
mov    -0x294(%rbp),%edi
mov    -0x98(%rbp),%rsi
mov    -0x84(%rbp),%edx
call   1070 <write@plt>
mov    -0x294(%rbp),%edi
call   10d0 <fsync@plt>
mov    -0x294(%rbp),%edi
call   1080 <close@plt>
mov    -0x88(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x88(%rbp)
jmp    12f2 <file_read+0x122>
mov    $0x8000,%eax
xor    %edx,%edx
divl   -0x8(%rbp)
mov    %eax,-0x298(%rbp)
cmpl   $0x0,-0x298(%rbp)
jne    13e1 <file_read+0x211>
movl   $0x1,-0x298(%rbp)
mov    0x2be8(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1060 <clock_gettime@plt>
movl   $0x0,-0x8c(%rbp)
mov    -0x8c(%rbp),%eax
cmp    -0x298(%rbp),%eax
jge    14d8 <file_read+0x308>
movl   $0x0,-0x88(%rbp)
mov    -0x88(%rbp),%eax
cmp    -0x8(%rbp),%eax
jae    14bf <file_read+0x2ef>
lea    -0x80(%rbp),%rdi
mov    -0x88(%rbp),%edx
lea    0xc48(%rip),%rsi
mov    $0x0,%al
call   10f0 <sprintf@plt>
lea    -0x80(%rbp),%rdi
mov    0x2b8d(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   10e0 <open@plt>
mov    %eax,-0x294(%rbp)
cmpl   $0x0,-0x294(%rbp)
jge    1488 <file_read+0x2b8>
mov    0x2b52(%rip),%rax
mov    (%rax),%edi
lea    0xc50(%rip),%rsi
call   10a0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1588 <file_read+0x3b8>
mov    -0x294(%rbp),%edi
mov    -0x98(%rbp),%rsi
mov    -0x84(%rbp),%edx
call   1090 <read@plt>
mov    -0x294(%rbp),%edi
call   1080 <close@plt>
mov    -0x88(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x88(%rbp)
jmp    1419 <file_read+0x249>
jmp    14c4 <file_read+0x2f4>
mov    -0x8c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8c(%rbp)
jmp    13fd <file_read+0x22d>
mov    0x2af1(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1060 <clock_gettime@plt>
lea    -0x290(%rbp),%rdx
mov    -0x10(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1030 <elapsed_time_hr@plt>
movl   $0x0,-0x88(%rbp)
mov    -0x88(%rbp),%eax
cmp    -0x8(%rbp),%eax
jae    154a <file_read+0x37a>
lea    -0x80(%rbp),%rdi
mov    -0x88(%rbp),%edx
lea    0xb5b(%rip),%rsi
mov    $0x0,%al
call   10f0 <sprintf@plt>
lea    -0x80(%rbp),%rdi
call   1050 <unlink@plt>
mov    -0x88(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x88(%rbp)
jmp    1506 <file_read+0x336>
mov    -0x8(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x84(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    12c0 <file_read+0xf0>
mov    -0x98(%rbp),%rdi
call   1040 <free@plt>
mov    0x2a3e(%rip),%rax
mov    (%rax),%edi
call   10c0 <fflush@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_read>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x288,%rsp
mov    %edi,%ebx
call   10b0 <malloc@plt>
test   %rax,%rax
je     125b <file_read+0x8b>
mov    %rax,0x8(%rsp)
mov    0x2ddf(%rip),%rax
mov    (%rax),%esi
lea    0xe21(%rip),%rdi
xor    %eax,%eax
call   10e0 <open@plt>
test   %eax,%eax
js     1270 <file_read+0xa0>
mov    %eax,%ebp
mov    %eax,%edi
mov    0x8(%rsp),%rsi
mov    %ebx,%edx
call   1090 <read@plt>
mov    %ebp,%edi
call   1080 <close@plt>
mov    $0x1,%r14d
cmp    $0x2710,%ebx
jb     1285 <file_read+0xb5>
mov    $0x1,%r14d
mov    %ebx,%r12d
nopl   0x0(%rax,%rax,1)
shr    %r12d
add    %r14d,%r14d
cmp    $0x4e1f,%ebx
mov    %r12d,%ebx
ja     1240 <file_read+0x70>
test   %r12d,%r12d
jne    1291 <file_read+0xc1>
jmp    1480 <file_read+0x2b0>
mov    0x2d5e(%rip),%rax
mov    (%rax),%edi
lea    0xd95(%rip),%rsi
jmp    14ac <file_read+0x2dc>
mov    0x2d49(%rip),%rax
mov    (%rax),%edi
lea    0xdb0(%rip),%rsi
jmp    14ac <file_read+0x2dc>
mov    %ebx,%r12d
test   %r12d,%r12d
je     1480 <file_read+0x2b0>
lea    0xdc9(%rip),%rsi
lea    0x90(%rsp),%rdi
lea    0x20(%rsp),%rbp
mov    %r12d,%edx
mov    %r14d,%ecx
xor    %eax,%eax
call   10f0 <sprintf@plt>
cmp    $0x2,%r12d
mov    $0x1,%eax
cmovae %r12d,%eax
mov    %eax,0x4(%rsp)
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbp,%rdi
lea    0xda7(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   10f0 <sprintf@plt>
mov    0x2cbe(%rip),%rax
mov    (%rax),%esi
mov    0x2d05(%rip),%rax
or     (%rax),%esi
mov    0x2cf4(%rip),%rax
or     (%rax),%esi
mov    %rbp,%r15
mov    %rbp,%rdi
mov    $0x1a4,%edx
xor    %eax,%eax
call   10e0 <open@plt>
test   %eax,%eax
js     146e <file_read+0x29e>
mov    %eax,%r13d
mov    %eax,%edi
mov    0x8(%rsp),%rsi
mov    %r14d,%edx
call   1070 <write@plt>
mov    %r13d,%edi
call   10d0 <fsync@plt>
mov    %r13d,%edi
call   1080 <close@plt>
add    $0x1,%ebx
cmp    %ebx,0x4(%rsp)
mov    %r15,%rbp
jne    12d0 <file_read+0x100>
mov    0x2c83(%rip),%rax
mov    (%rax),%edi
lea    0x18(%rsp),%rsi
call   1060 <clock_gettime@plt>
cmp    $0x8000,%r12d
jbe    13e8 <file_read+0x218>
mov    0x2c63(%rip),%rax
mov    (%rax),%edi
lea    0x10(%rsp),%rsi
call   1060 <clock_gettime@plt>
mov    0x18(%rsp),%edi
mov    0x10(%rsp),%esi
lea    0x90(%rsp),%rdx
call   1030 <elapsed_time_hr@plt>
xor    %ebx,%ebx
lea    0xcea(%rip),%r13
mov    %r15,%rbp
mov    0x4(%rsp),%r15d
nop
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   10f0 <sprintf@plt>
mov    %rbp,%rdi
call   1050 <unlink@plt>
add    $0x1,%ebx
cmp    %ebx,%r15d
jne    13a0 <file_read+0x1d0>
mov    %r12d,%eax
shr    %eax
add    %r14d,%r14d
cmp    $0x1,%r12d
mov    %eax,%r12d
lea    0xc8c(%rip),%rsi
lea    0x90(%rsp),%rdi
ja     12a5 <file_read+0xd5>
jmp    1480 <file_read+0x2b0>
xor    %r13d,%r13d
mov    $0x8000,%eax
xor    %edx,%edx
div    %r12d
mov    %eax,%ecx
cmp    $0x2,%eax
mov    $0x1,%eax
cmovb  %eax,%ecx
mov    %ecx,0x1c(%rsp)
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %r15,%rbp
mov    %r15,%rdi
lea    0xc64(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   10f0 <sprintf@plt>
mov    0x2bab(%rip),%rax
mov    (%rax),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   10e0 <open@plt>
test   %eax,%eax
js     149c <file_read+0x2cc>
mov    %eax,%ebp
mov    %eax,%edi
mov    0x8(%rsp),%rsi
mov    %r14d,%edx
call   1090 <read@plt>
mov    %ebp,%edi
call   1080 <close@plt>
add    $0x1,%ebx
cmp    %ebx,0x4(%rsp)
jne    1410 <file_read+0x240>
add    $0x1,%r13d
cmp    0x1c(%rsp),%r13d
jne    1406 <file_read+0x236>
jmp    1366 <file_read+0x196>
mov    0x2b4b(%rip),%rax
mov    (%rax),%edi
lea    0xc0f(%rip),%rsi
jmp    14ac <file_read+0x2dc>
mov    0x8(%rsp),%rdi
call   1040 <free@plt>
mov    0x2b27(%rip),%rax
mov    (%rax),%edi
call   10c0 <fflush@plt>
xor    %eax,%eax
jmp    14b6 <file_read+0x2e6>
mov    0x2b1d(%rip),%rax
mov    (%rax),%edi
lea    0xc1b(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%eax
add    $0x288,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { i32 }
@stderr = global i32 0
@.str = [35 x i8] c"ERROR: out of memory in file_read\0A\00"
@.str.1 = [13 x i8] c"/dev/urandom\00"
@O_RDONLY = global i32 0
@.str.2 = [49 x i8] c"ERROR: unable to open /dev/urandom in file_read\0A\00"
@.str.3 = [32 x i8] c"file_read: %d files of %d bytes\00"
@.str.4 = [12 x i8] c"testfile_%d\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@.str.5 = [58 x i8] c"ERROR: unable to open test file for writing in file_read\0A\00"
@CLOCK_MONOTONIC = global i32 0
@.str.6 = [58 x i8] c"ERROR: unable to open test file for reading in file_read\0A\00"
@stdout = global i32 0
define i32 @file_read(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.timespec
%5 = alloca %struct.timespec
%6 = alloca [100 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca [500 x i8]
%13 = alloca i32
%14 = alloca i32
store i32 %0, i32* %3
store i32 1, i32* %7
%15 = load i32, i32* %3
%16 = call i8* @malloc(i32 %15)
store i8* %16, i8** %10
%17 = load i8*, i8** %10
%18 = icmp ne i8* %17, null
br i1 %18, label %22, label %19
19: ; preds = %1
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %2
br label %162
22: ; preds = %1
%23 = load i32, i32* @O_RDONLY
%24 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %23)
store i32 %24, i32* %13
%25 = load i32, i32* %13
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %22
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %2
br label %162
30: ; preds = %22
%31 = load i32, i32* %13
%32 = load i8*, i8** %10
%33 = load i32, i32* %3
%34 = call i32 @read(i32 %31, i8* %32, i32 %33)
%35 = load i32, i32* %13
%36 = call i32 @close(i32 %35)
br label %37
37: ; preds = %40, %30
%38 = load i32, i32* %3
%39 = icmp uge i32 %38, 10000
br i1 %39, label %40, label %45
40: ; preds = %37
%41 = load i32, i32* %3
%42 = udiv i32 %41, 2
store i32 %42, i32* %3
%43 = load i32, i32* %7
%44 = mul nsw i32 %43, 2
store i32 %44, i32* %7
br label %37
45: ; preds = %37
br label %46
46: ; preds = %152, %45
%47 = load i32, i32* %3
%48 = icmp uge i32 %47, 1
br i1 %48, label %49, label %157
49: ; preds = %46
%50 = getelementptr inbounds [500 x i8], [500 x i8]* %12, i64 0, i64 0
%51 = load i32, i32* %3
%52 = load i32, i32* %7
%53 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %50, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %51, i32 %52)
store i32 0, i32* %8
br label %54
54: ; preds = %83, %49
%55 = load i32, i32* %8
%56 = load i32, i32* %3
%57 = icmp ult i32 %55, %56
br i1 %57, label %58, label %86
58: ; preds = %54
%59 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%60 = load i32, i32* %8
%61 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %59, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %60)
%62 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%63 = load i32, i32* @O_CREAT
%64 = load i32, i32* @O_WRONLY
%65 = or i32 %63, %64
%66 = load i32, i32* @O_TRUNC
%67 = or i32 %65, %66
%68 = call i32 (i8*, i32, ...) @open(i8* %62, i32 %67, i32 420)
store i32 %68, i32* %13
%69 = load i32, i32* %13
%70 = icmp slt i32 %69, 0
br i1 %70, label %71, label %74
71: ; preds = %58
%72 = load i32, i32* @stderr
%73 = call i32 @fprintf(i32 %72, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %2
br label %162
74: ; preds = %58
%75 = load i32, i32* %13
%76 = load i8*, i8** %10
%77 = load i32, i32* %7
%78 = call i32 @write(i32 %75, i8* %76, i32 %77)
%79 = load i32, i32* %13
%80 = call i32 @fsync(i32 %79)
%81 = load i32, i32* %13
%82 = call i32 @close(i32 %81)
br label %83
83: ; preds = %74
%84 = load i32, i32* %8
%85 = add nsw i32 %84, 1
store i32 %85, i32* %8
br label %54
86: ; preds = %54
%87 = load i32, i32* %3
%88 = udiv i32 32768, %87
store i32 %88, i32* %14
%89 = load i32, i32* %14
%90 = icmp eq i32 %89, 0
br i1 %90, label %91, label %92
91: ; preds = %86
store i32 1, i32* %14
br label %92
92: ; preds = %91, %86
%93 = load i32, i32* @CLOCK_MONOTONIC
%94 = call i32 @clock_gettime(i32 %93, %struct.timespec* %4)
store i32 0, i32* %9
br label %95
95: ; preds = %127, %92
%96 = load i32, i32* %9
%97 = load i32, i32* %14
%98 = icmp slt i32 %96, %97
br i1 %98, label %99, label %130
99: ; preds = %95
store i32 0, i32* %8
br label %100
100: ; preds = %123, %99
%101 = load i32, i32* %8
%102 = load i32, i32* %3
%103 = icmp ult i32 %101, %102
br i1 %103, label %104, label %126
104: ; preds = %100
%105 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%106 = load i32, i32* %8
%107 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %105, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %106)
%108 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%109 = load i32, i32* @O_RDONLY
%110 = call i32 (i8*, i32, ...) @open(i8* %108, i32 %109)
store i32 %110, i32* %13
%111 = load i32, i32* %13
%112 = icmp slt i32 %111, 0
br i1 %112, label %113, label %116
113: ; preds = %104
%114 = load i32, i32* @stderr
%115 = call i32 @fprintf(i32 %114, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %2
br label %162
116: ; preds = %104
%117 = load i32, i32* %13
%118 = load i8*, i8** %10
%119 = load i32, i32* %7
%120 = call i32 @read(i32 %117, i8* %118, i32 %119)
%121 = load i32, i32* %13
%122 = call i32 @close(i32 %121)
br label %123
123: ; preds = %116
%124 = load i32, i32* %8
%125 = add nsw i32 %124, 1
store i32 %125, i32* %8
br label %100
126: ; preds = %100
br label %127
127: ; preds = %126
%128 = load i32, i32* %9
%129 = add nsw i32 %128, 1
store i32 %129, i32* %9
br label %95
130: ; preds = %95
%131 = load i32, i32* @CLOCK_MONOTONIC
%132 = call i32 @clock_gettime(i32 %131, %struct.timespec* %5)
%133 = getelementptr inbounds [500 x i8], [500 x i8]* %12, i64 0, i64 0
%134 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
%135 = load i32, i32* %134
%136 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 0
%137 = load i32, i32* %136
%138 = call i32 @elapsed_time_hr(i32 %135, i32 %137, i8* %133)
store i32 0, i32* %8
br label %139
139: ; preds = %149, %130
%140 = load i32, i32* %8
%141 = load i32, i32* %3
%142 = icmp ult i32 %140, %141
br i1 %142, label %143, label %152
143: ; preds = %139
%144 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%145 = load i32, i32* %8
%146 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %144, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %145)
%147 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%148 = call i32 @unlink(i8* %147)
br label %149
149: ; preds = %143
%150 = load i32, i32* %8
%151 = add nsw i32 %150, 1
store i32 %151, i32* %8
br label %139
152: ; preds = %139
%153 = load i32, i32* %3
%154 = udiv i32 %153, 2
store i32 %154, i32* %3
%155 = load i32, i32* %7
%156 = mul nsw i32 %155, 2
store i32 %156, i32* %7
br label %46
157: ; preds = %46
%158 = load i8*, i8** %10
%159 = call i32 @free(i8* %158)
%160 = load i32, i32* @stdout
%161 = call i32 @fflush(i32 %160)
store i32 0, i32* %2
br label %162
162: ; preds = %157, %113, %71, %27, %19
%163 = load i32, i32* %2
ret i32 %163
}

LLVM IR (-O2):
%struct.timespec = type { i32 }
@stderr = global i32 0
@.str = [35 x i8] c"ERROR: out of memory in file_read\0A\00"
@.str.1 = [13 x i8] c"/dev/urandom\00"
@O_RDONLY = global i32 0
@.str.2 = [49 x i8] c"ERROR: unable to open /dev/urandom in file_read\0A\00"
@.str.3 = [32 x i8] c"file_read: %d files of %d bytes\00"
@.str.4 = [12 x i8] c"testfile_%d\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@.str.5 = [58 x i8] c"ERROR: unable to open test file for writing in file_read\0A\00"
@CLOCK_MONOTONIC = global i32 0
@.str.6 = [58 x i8] c"ERROR: unable to open test file for reading in file_read\0A\00"
@stdout = global i32 0
define i32 @file_read(i32 %0) {
%2 = alloca %struct.timespec
%3 = alloca %struct.timespec
%4 = alloca [100 x i8]
%5 = alloca [500 x i8]
%6 = bitcast %struct.timespec* %2 to i8*
%7 = bitcast %struct.timespec* %3 to i8*
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [500 x i8], [500 x i8]* %5, i64 0, i64 0
%10 = tail call i8* @malloc(i32 %0)
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
br label %109
15: ; preds = %1
%16 = load i32, i32* @O_RDONLY
%17 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = load i32, i32* @stderr
%21 = tail call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0))
br label %109
22: ; preds = %15
%23 = tail call i32 @read(i32 %17, i8* %10, i32 %0)
%24 = tail call i32 @close(i32 %17)
%25 = icmp ugt i32 %0, 9999
br i1 %25, label %33, label %26
26: ; preds = %33, %22
%27 = phi i32 [ 1, %22 ], [ %37, %33 ]
%28 = phi i32 [ %0, %22 ], [ %36, %33 ]
%29 = icmp eq i32 %28, 0
br i1 %29, label %105, label %30
30: ; preds = %26
%31 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
%32 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
br label %39
33: ; preds = %22, %33
%34 = phi i32 [ %36, %33 ], [ %0, %22 ]
%35 = phi i32 [ %37, %33 ], [ 1, %22 ]
%36 = lshr i32 %34, 1
%37 = shl nsw i32 %35, 1
%38 = icmp ugt i32 %34, 19999
br i1 %38, label %33, label %26
39: ; preds = %30, %101
%40 = phi i32 [ %28, %30 ], [ %102, %101 ]
%41 = phi i32 [ %27, %30 ], [ %103, %101 ]
%42 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %40, i32 %41)
%43 = call i32 @llvm.umax.i32(i32 %40, i32 1)
br label %44
44: ; preds = %39, %57
%45 = phi i32 [ 0, %39 ], [ %61, %57 ]
%46 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %45)
%47 = load i32, i32* @O_CREAT
%48 = load i32, i32* @O_WRONLY
%49 = or i32 %48, %47
%50 = load i32, i32* @O_TRUNC
%51 = or i32 %49, %50
%52 = call i32 (i8*, i32, ...) @open(i8* %8, i32 %51, i32 420)
%53 = icmp slt i32 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %44
%55 = load i32, i32* @stderr
%56 = call i32 @fprintf(i32 %55, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.5, i64 0, i64 0))
br label %109
57: ; preds = %44
%58 = call i32 @write(i32 %52, i8* %10, i32 %41)
%59 = call i32 @fsync(i32 %52)
%60 = call i32 @close(i32 %52)
%61 = add nuw i32 %45, 1
%62 = icmp eq i32 %61, %43
br i1 %62, label %63, label %44
63: ; preds = %57
%64 = load i32, i32* @CLOCK_MONOTONIC
%65 = call i32 @clock_gettime(i32 %64, %struct.timespec* %2)
%66 = icmp ugt i32 %40, 32768
br i1 %66, label %89, label %67
67: ; preds = %63
%68 = udiv i32 32768, %40
%69 = call i32 @llvm.umax.i32(i32 %68, i32 1)
br label %70
70: ; preds = %67, %86
%71 = phi i32 [ %87, %86 ], [ 0, %67 ]
br label %72
72: ; preds = %70, %81
%73 = phi i32 [ 0, %70 ], [ %84, %81 ]
%74 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %73)
%75 = load i32, i32* @O_RDONLY
%76 = call i32 (i8*, i32, ...) @open(i8* %8, i32 %75)
%77 = icmp slt i32 %76, 0
br i1 %77, label %78, label %81
78: ; preds = %72
%79 = load i32, i32* @stderr
%80 = call i32 @fprintf(i32 %79, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.6, i64 0, i64 0))
br label %109
81: ; preds = %72
%82 = call i32 @read(i32 %76, i8* %10, i32 %41)
%83 = call i32 @close(i32 %76)
%84 = add nuw i32 %73, 1
%85 = icmp eq i32 %84, %43
br i1 %85, label %86, label %72
86: ; preds = %81
%87 = add nuw nsw i32 %71, 1
%88 = icmp eq i32 %87, %69
br i1 %88, label %89, label %70
89: ; preds = %86, %63
%90 = load i32, i32* @CLOCK_MONOTONIC
%91 = call i32 @clock_gettime(i32 %90, %struct.timespec* %3)
%92 = load i32, i32* %31
%93 = load i32, i32* %32
%94 = call i32 @elapsed_time_hr(i32 %92, i32 %93, i8* %9)
br label %95
95: ; preds = %89, %95
%96 = phi i32 [ 0, %89 ], [ %99, %95 ]
%97 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %96)
%98 = call i32 @unlink(i8* %8)
%99 = add nuw i32 %96, 1
%100 = icmp eq i32 %99, %43
br i1 %100, label %101, label %95
101: ; preds = %95
%102 = lshr i32 %40, 1
%103 = shl nsw i32 %41, 1
%104 = icmp ult i32 %40, 2
br i1 %104, label %105, label %39
105: ; preds = %101, %26
%106 = call i32 @free(i8* %10)
%107 = load i32, i32* @stdout
%108 = call i32 @fflush(i32 %107)
br label %109
109: ; preds = %105, %78, %54, %19, %12
%110 = phi i32 [ 1, %19 ], [ 1, %54 ], [ 1, %78 ], [ 0, %105 ], [ 1, %12 ]
ret i32 %110
}