#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*/ SEEK_SET;
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);
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
unsigned char *malloc(unsigned int);
int open(char *, int, ...);
unsigned int rand();
int /*<<< orphan*/ read(int, unsigned char *, int);
int /*<<< orphan*/ sprintf(char *, char *, unsigned int, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ unlink(char *);
int /*<<< orphan*/ write(int, unsigned char *, unsigned int);
int file_read_random(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 block;
  int reps;
  data = malloc(N);
  if (!data) {
    fprintf(stderr, "ERROR: out of memory in file_read_random\n");
    return 1;
  }
  fd = open("/dev/urandom", O_RDONLY);
  if (fd < 0) {
    fprintf(stderr, "ERROR: unable to open /dev/urandom in file_read_random\n");
    return 1;
  }
  read(fd, data, N);
  close(fd);
  fd = open("testfile_1", O_CREAT | O_WRONLY | O_TRUNC, 0644);
  if (fd < 0) {
    fprintf(
        stderr,
        "ERROR: unable to open test file for writing in file_read_random\n");
    return 1;
  }
  write(fd, data, N);
  fsync(fd);
  close(fd);
  while (N >= 10000) {
    N = N / 2;
    size = size * 2;
  }
  while (N >= 1) {
    sprintf(titlebuffer, "file_read_random: %d blocks of %d bytes", N, size);
    reps = 65536 / N;
    if (reps == 0)
      reps = 1;
    clock_gettime(CLOCK_MONOTONIC, &start);
    for (j = 0; j < reps; j++) {
      for (i = 0; i < N; i++) {
        fd = open("testfile_1", O_RDONLY);
        if (fd < 0) {
          fprintf(stderr, "ERROR: unable to open test file for reading in "
                          "file_read_random\n");
          return 1;
        }
        block = rand() % N;
        lseek(fd, block * size, SEEK_SET);
        read(fd, data, size);
        close(fd);
      }
    }
    clock_gettime(CLOCK_MONOTONIC, &end);
    elapsed_time_hr(start, end, titlebuffer);
    N = N / 2;
    size = size * 2;
  }
  unlink("testfile_1");
  free(data);
  fflush(stdout);
  return 0;
}


x86 assembly (clang, -O0):
<file_read_random>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2a0,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x1,-0x84(%rbp)
mov    -0x8(%rbp),%edi
call   10c0 <malloc@plt>
mov    %rax,-0x98(%rbp)
cmpq   $0x0,-0x98(%rbp)
jne    1246 <file_read_random+0x56>
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
lea    0xdcb(%rip),%rsi
call   10b0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    153d <file_read_random+0x34d>
mov    0x2d8b(%rip),%rax
mov    (%rax),%esi
lea    0xdd4(%rip),%rdi
mov    $0x0,%al
call   10f0 <open@plt>
mov    %eax,-0x294(%rbp)
cmpl   $0x0,-0x294(%rbp)
jge    1291 <file_read_random+0xa1>
mov    0x2d49(%rip),%rax
mov    (%rax),%edi
lea    0xdb7(%rip),%rsi
call   10b0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    153d <file_read_random+0x34d>
mov    -0x294(%rbp),%edi
mov    -0x98(%rbp),%rsi
mov    -0x8(%rbp),%edx
call   10a0 <read@plt>
mov    -0x294(%rbp),%edi
call   1090 <close@plt>
mov    0x2d40(%rip),%rax
mov    (%rax),%esi
mov    0x2cdf(%rip),%rax
or     (%rax),%esi
mov    0x2d26(%rip),%rax
or     (%rax),%esi
lea    0xd9c(%rip),%rdi
mov    $0x1a4,%edx
mov    $0x0,%al
call   10f0 <open@plt>
mov    %eax,-0x294(%rbp)
cmpl   $0x0,-0x294(%rbp)
jge    1313 <file_read_random+0x123>
mov    0x2cc7(%rip),%rax
mov    (%rax),%edi
lea    0xd78(%rip),%rsi
call   10b0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    153d <file_read_random+0x34d>
mov    -0x294(%rbp),%edi
mov    -0x98(%rbp),%rsi
mov    -0x8(%rbp),%edx
call   1070 <write@plt>
mov    -0x294(%rbp),%edi
call   10e0 <fsync@plt>
mov    -0x294(%rbp),%edi
call   1090 <close@plt>
cmpl   $0x2710,-0x8(%rbp)
jb     1368 <file_read_random+0x178>
mov    -0x8(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x84(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    133e <file_read_random+0x14e>
jmp    136d <file_read_random+0x17d>
cmpl   $0x1,-0x8(%rbp)
jb     1510 <file_read_random+0x320>
lea    -0x290(%rbp),%rdi
mov    -0x8(%rbp),%edx
mov    -0x84(%rbp),%ecx
lea    0xd2d(%rip),%rsi
call   1100 <sprintf@plt>
mov    $0x10000,%eax
xor    %edx,%edx
divl   -0x8(%rbp)
mov    %eax,-0x29c(%rbp)
cmpl   $0x0,-0x29c(%rbp)
jne    13ba <file_read_random+0x1ca>
movl   $0x1,-0x29c(%rbp)
mov    0x2c0f(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1060 <clock_gettime@plt>
movl   $0x0,-0x8c(%rbp)
mov    -0x8c(%rbp),%eax
cmp    -0x29c(%rbp),%eax
jge    14cf <file_read_random+0x2df>
movl   $0x0,-0x88(%rbp)
mov    -0x88(%rbp),%eax
cmp    -0x8(%rbp),%eax
jae    14b6 <file_read_random+0x2c6>
mov    0x2bd0(%rip),%rax
mov    (%rax),%esi
lea    0xc5e(%rip),%rdi
mov    $0x0,%al
call   10f0 <open@plt>
mov    %eax,-0x294(%rbp)
cmpl   $0x0,-0x294(%rbp)
jge    144c <file_read_random+0x25c>
mov    0x2b8e(%rip),%rax
mov    (%rax),%edi
lea    0xca8(%rip),%rsi
call   10b0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    153d <file_read_random+0x34d>
mov    $0x0,%al
call   1110 <rand@plt>
xor    %edx,%edx
divl   -0x8(%rbp)
mov    %edx,-0x298(%rbp)
mov    -0x294(%rbp),%edi
mov    -0x298(%rbp),%esi
imul   -0x84(%rbp),%esi
mov    0x2b40(%rip),%rax
mov    (%rax),%edx
call   1080 <lseek@plt>
mov    -0x294(%rbp),%edi
mov    -0x98(%rbp),%rsi
mov    -0x84(%rbp),%edx
call   10a0 <read@plt>
mov    -0x294(%rbp),%edi
call   1090 <close@plt>
mov    -0x88(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x88(%rbp)
jmp    13f2 <file_read_random+0x202>
jmp    14bb <file_read_random+0x2cb>
mov    -0x8c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8c(%rbp)
jmp    13d6 <file_read_random+0x1e6>
mov    0x2afa(%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>
mov    -0x8(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x84(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    136d <file_read_random+0x17d>
lea    0xb58(%rip),%rdi
call   1050 <unlink@plt>
mov    -0x98(%rbp),%rdi
call   1040 <free@plt>
mov    0x2a81(%rip),%rax
mov    (%rax),%edi
call   10d0 <fflush@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_read_random>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
mov    %edi,%r15d
call   10c0 <malloc@plt>
test   %rax,%rax
je     12c9 <file_read_random+0xd9>
mov    %rax,%r14
mov    0x2dbc(%rip),%rax
mov    (%rax),%esi
lea    0xe05(%rip),%rdi
xor    %eax,%eax
call   10f0 <open@plt>
test   %eax,%eax
js     12de <file_read_random+0xee>
mov    %eax,%ebx
mov    %eax,%edi
mov    %r14,%rsi
mov    %r15d,%edx
call   10a0 <read@plt>
mov    %ebx,%edi
call   1090 <close@plt>
mov    0x2da7(%rip),%rax
mov    0x2d48(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2d8d(%rip),%rax
or     (%rax),%esi
lea    0xe03(%rip),%rdi
mov    $0x1a4,%edx
xor    %eax,%eax
call   10f0 <open@plt>
test   %eax,%eax
js     12f3 <file_read_random+0x103>
mov    %eax,%ebx
mov    %eax,%edi
mov    %r14,%rsi
mov    %r15d,%edx
call   1070 <write@plt>
mov    %ebx,%edi
call   10e0 <fsync@plt>
mov    %ebx,%edi
call   1090 <close@plt>
mov    $0x1,%ebp
cmp    $0x2710,%r15d
jb     1308 <file_read_random+0x118>
mov    $0x1,%ebp
mov    %r15d,%ebx
nop
shr    %ebx
add    %ebp,%ebp
cmp    $0x4e1f,%r15d
mov    %ebx,%r15d
ja     12b0 <file_read_random+0xc0>
test   %ebx,%ebx
jne    1313 <file_read_random+0x123>
jmp    147a <file_read_random+0x28a>
mov    0x2cf0(%rip),%rax
mov    (%rax),%edi
lea    0xd27(%rip),%rsi
jmp    145e <file_read_random+0x26e>
mov    0x2cdb(%rip),%rax
mov    (%rax),%edi
lea    0xd49(%rip),%rsi
jmp    145e <file_read_random+0x26e>
mov    0x2cc6(%rip),%rax
mov    (%rax),%edi
lea    0xd77(%rip),%rsi
jmp    145e <file_read_random+0x26e>
mov    %r15d,%ebx
test   %ebx,%ebx
je     147a <file_read_random+0x28a>
lea    0xda1(%rip),%r15
mov    0x2caf(%rip),%r12
lea    0x8(%rsp),%r13
lea    0x20(%rsp),%rdi
mov    %r15,%rsi
mov    %ebx,%edx
mov    %ebp,%ecx
call   1100 <sprintf@plt>
mov    (%r12),%edi
mov    %r13,%rsi
call   1060 <clock_gettime@plt>
cmp    $0x10000,%ebx
jbe    1389 <file_read_random+0x199>
mov    0x2c7e(%rip),%r12
mov    (%r12),%edi
lea    0x10(%rsp),%rsi
call   1060 <clock_gettime@plt>
mov    0x8(%rsp),%edi
mov    0x10(%rsp),%esi
lea    0x20(%rsp),%rdx
call   1030 <elapsed_time_hr@plt>
mov    %ebx,%eax
shr    %eax
add    %ebp,%ebp
cmp    $0x1,%ebx
mov    %eax,%ebx
lea    0x8(%rsp),%r13
ja     1326 <file_read_random+0x136>
jmp    147a <file_read_random+0x28a>
movl   $0x0,0xc(%rsp)
mov    $0x10000,%eax
xor    %edx,%edx
div    %ebx
mov    %eax,%ecx
cmp    $0x2,%ebx
mov    $0x1,%r13d
cmovae %ebx,%r13d
cmp    $0x2,%eax
mov    $0x1,%eax
cmovb  %eax,%ecx
mov    %ecx,0x1c(%rsp)
mov    %r13d,0x18(%rsp)
lea    0xcab(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x2c01(%rip),%rax
mov    (%rax),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   10f0 <open@plt>
test   %eax,%eax
js     144e <file_read_random+0x25e>
mov    %eax,%r12d
xor    %eax,%eax
call   1110 <rand@plt>
xor    %edx,%edx
div    %ebx
imul   %ebp,%edx
mov    0x2bb9(%rip),%rax
mov    (%rax),%eax
mov    %r12d,%edi
mov    %edx,%esi
mov    %eax,%edx
call   1080 <lseek@plt>
mov    %r12d,%edi
mov    %r14,%rsi
mov    %ebp,%edx
call   10a0 <read@plt>
mov    %r12d,%edi
call   1090 <close@plt>
add    $0xffffffff,%r13d
jne    13d0 <file_read_random+0x1e0>
mov    0xc(%rsp),%eax
add    $0x1,%eax
mov    %eax,0xc(%rsp)
cmp    0x1c(%rsp),%eax
lea    0xc7d(%rip),%r15
mov    0x18(%rsp),%r13d
jne    13bd <file_read_random+0x1cd>
jmp    134b <file_read_random+0x15b>
mov    0x2b6b(%rip),%rax
mov    (%rax),%edi
lea    0xc85(%rip),%rsi
call   10b0 <fprintf@plt>
mov    $0x1,%eax
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xbee(%rip),%rdi
call   1050 <unlink@plt>
mov    %r14,%rdi
call   1040 <free@plt>
mov    0x2b1b(%rip),%rax
mov    (%rax),%edi
call   10d0 <fflush@plt>
xor    %eax,%eax
jmp    1468 <file_read_random+0x278>

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

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