#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 timeval {
  int tv_sec;
  long long tv_usec;
};
typedef scalar_t__ off_t;

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fsync(int);
int /*<<< orphan*/ get_timer(struct timeval *);
scalar_t__ lseek(int, scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, char *, long, long, int, int, int,
                          long, long long, long long, long, long);
long rand();
scalar_t__ read(int, char *, long);
int /*<<< orphan*/ srand(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ timersub(struct timeval *, struct timeval *,
                            struct timeval *);
scalar_t__ write(int, char *, long);
int run_random_one(char *label, int writeops, int fd, long fsize, char *buf,
                   long msize, int alignment, int direct, int max_seconds,
                   int timeofday_latency, long iosize) {
  off_t pos;
  struct timeval tvstart, tvend, tvdiff;
  long long num_iterations;
  long long usecs;
  int rw;
  srand(1);
  lseek(fd, 0, SEEK_SET);
  fsync(fd);
  fprintf(stderr, "RND %s iosize=%ld\r",
          writeops ? (writeops == 2 ? "RDWR" : "WRONLY") : "RDONLY", iosize);
  if (!get_timer(&tvstart))
    return (0);
  num_iterations = 0;
  rw = (writeops == 2) ? 1 : writeops;
  do {
    pos = (off_t)((rand() % ((fsize - iosize) / iosize)) * iosize);
    if (lseek(fd, pos, SEEK_SET) < 0) {
      fprintf(stderr, "seek error for ofs=%ld (errno %d)\n", (long)pos, errno);
      return (0);
    }
    if (writeops == 2)
      rw = rw ? 0 : 1;
    if ((rw ? write(fd, buf, iosize) : read(fd, buf, iosize)) < 0) {
      fprintf(stderr, "cannot %s file (errno %d)\n",
              writeops ? "write" : "read", errno);
      return (0);
    }
    if (rw && !direct)
      fsync(fd);
    if (!get_timer(&tvend))
      return (0);
    num_iterations++;
    timersub(&tvend, &tvstart, &tvdiff);
  } while (tvdiff.tv_sec < max_seconds);
  usecs = ((tvdiff.tv_sec * 1000000LL) + tvdiff.tv_usec) -
          (((long long)num_iterations * timeofday_latency) / 100000);
  if (usecs < 1)
    usecs = 1;
  printf("%s,RND,%s,%ld,%ld,%d,%d,%d,%ld,%lld,%lld,%ld,%ld\n", label,
         writeops ? (writeops == 2 ? "RDWR" : "WRONLY") : "RDONLY", fsize,
         msize, alignment, direct, max_seconds, iosize, num_iterations, usecs,
         (long)(1000000LL / (usecs / num_iterations)),
         (long)(usecs / num_iterations));
  return (1);
}


x86 assembly (clang, -O0):
<run_random_one>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x100,%rsp
mov    0x30(%rbp),%rax
mov    0x28(%rbp),%eax
mov    0x20(%rbp),%eax
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %rdi,-0x30(%rbp)
mov    %esi,-0x34(%rbp)
mov    %edx,-0x38(%rbp)
mov    %rcx,-0x40(%rbp)
mov    %r8,-0x48(%rbp)
mov    %r9,-0x50(%rbp)
mov    $0x1,%edi
call   1070 <srand@plt>
mov    -0x38(%rbp),%edi
mov    0x2de4(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1050 <lseek@plt>
mov    -0x38(%rbp),%edi
call   10a0 <fsync@plt>
mov    0x2dda(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xa0(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     123c <run_random_one+0x9c>
mov    -0x34(%rbp),%edx
lea    0xdf6(%rip),%rax
lea    0xdea(%rip),%rcx
cmp    $0x2,%edx
cmove  %rcx,%rax
mov    %rax,-0xa8(%rbp)
jmp    124f <run_random_one+0xaf>
lea    0xddc(%rip),%rax
mov    %rax,-0xa8(%rbp)
jmp    124f <run_random_one+0xaf>
mov    -0xa0(%rbp),%edi
mov    -0xa8(%rbp),%rdx
mov    0x30(%rbp),%rcx
lea    0xd99(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
lea    -0x68(%rbp),%rdi
call   1090 <get_timer@plt>
cmp    $0x0,%eax
jne    128c <run_random_one+0xec>
movl   $0x0,-0x24(%rbp)
jmp    15c5 <run_random_one+0x425>
movq   $0x0,-0x90(%rbp)
cmpl   $0x2,-0x34(%rbp)
jne    12b1 <run_random_one+0x111>
mov    $0x1,%eax
mov    %eax,-0xac(%rbp)
jmp    12ba <run_random_one+0x11a>
mov    -0x34(%rbp),%eax
mov    %eax,-0xac(%rbp)
mov    -0xac(%rbp),%eax
mov    %eax,-0x9c(%rbp)
mov    $0x0,%al
call   10c0 <rand@plt>
mov    %rax,-0xb8(%rbp)
mov    -0x40(%rbp),%rax
sub    0x30(%rbp),%rax
cqto
idivq  0x30(%rbp)
mov    %rax,%rcx
mov    -0xb8(%rbp),%rax
cqto
idiv   %rcx
imul   0x30(%rbp),%rdx
mov    %rdx,-0x58(%rbp)
mov    -0x38(%rbp),%edi
mov    -0x58(%rbp),%rsi
mov    0x2cc8(%rip),%rax
mov    (%rax),%edx
call   1050 <lseek@plt>
cmp    $0x0,%rax
jge    1349 <run_random_one+0x1a9>
mov    0x2cc0(%rip),%rax
mov    (%rax),%edi
mov    -0x58(%rbp),%rdx
mov    0x2cab(%rip),%rax
mov    (%rax),%ecx
lea    0xcf0(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x0,-0x24(%rbp)
jmp    15c5 <run_random_one+0x425>
cmpl   $0x2,-0x34(%rbp)
jne    136c <run_random_one+0x1cc>
mov    -0x9c(%rbp),%edx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x9c(%rbp)
cmpl   $0x0,-0x9c(%rbp)
je     1395 <run_random_one+0x1f5>
mov    -0x38(%rbp),%edi
mov    -0x48(%rbp),%rsi
mov    0x30(%rbp),%rdx
call   1030 <write@plt>
mov    %rax,-0xc0(%rbp)
jmp    13ac <run_random_one+0x20c>
mov    -0x38(%rbp),%edi
mov    -0x48(%rbp),%rsi
mov    0x30(%rbp),%rdx
call   1060 <read@plt>
mov    %rax,-0xc0(%rbp)
mov    -0xc0(%rbp),%rax
cmp    $0x0,%rax
jge    1401 <run_random_one+0x261>
mov    0x2c1c(%rip),%rax
mov    (%rax),%edi
mov    -0x34(%rbp),%ecx
lea    0xc9a(%rip),%rdx
lea    0xc8d(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdx
mov    0x2bf3(%rip),%rax
mov    (%rax),%ecx
lea    0xc5b(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x0,-0x24(%rbp)
jmp    15c5 <run_random_one+0x425>
cmpl   $0x0,-0x9c(%rbp)
je     1420 <run_random_one+0x280>
cmpl   $0x0,0x18(%rbp)
jne    1420 <run_random_one+0x280>
mov    -0x38(%rbp),%edi
call   10a0 <fsync@plt>
lea    -0x78(%rbp),%rdi
call   1090 <get_timer@plt>
cmp    $0x0,%eax
jne    143e <run_random_one+0x29e>
movl   $0x0,-0x24(%rbp)
jmp    15c5 <run_random_one+0x425>
mov    -0x90(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x90(%rbp)
lea    -0x78(%rbp),%rdi
lea    -0x68(%rbp),%rsi
lea    -0x88(%rbp),%rdx
call   10b0 <timersub@plt>
mov    -0x88(%rbp),%eax
cmp    0x20(%rbp),%eax
jl     12c6 <run_random_one+0x126>
movslq -0x88(%rbp),%rax
imul   $0xf4240,%rax,%rax
add    -0x80(%rbp),%rax
mov    %rax,-0xc8(%rbp)
mov    -0x90(%rbp),%rax
movslq 0x28(%rbp),%rcx
imul   %rcx,%rax
mov    $0x186a0,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0xc8(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x98(%rbp)
cmpq   $0x1,-0x98(%rbp)
01
jge    14d2 <run_random_one+0x332>
movq   $0x1,-0x98(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0xd0(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     150b <run_random_one+0x36b>
mov    -0x34(%rbp),%edx
lea    0xb27(%rip),%rax
lea    0xb1b(%rip),%rcx
cmp    $0x2,%edx
cmove  %rcx,%rax
mov    %rax,-0xd8(%rbp)
jmp    151e <run_random_one+0x37e>
lea    0xb0d(%rip),%rax
mov    %rax,-0xd8(%rbp)
jmp    151e <run_random_one+0x37e>
mov    -0xd0(%rbp),%rsi
mov    -0xd8(%rbp),%rax
mov    %rax,-0xe0(%rbp)
mov    -0x40(%rbp),%rcx
mov    -0x50(%rbp),%r8
mov    0x10(%rbp),%r9d
mov    0x18(%rbp),%r12d
mov    0x20(%rbp),%r15d
mov    0x30(%rbp),%r14
mov    -0x90(%rbp),%rbx
mov    -0x98(%rbp),%r11
mov    -0x98(%rbp),%rax
cqto
idivq  -0x90(%rbp)
mov    %rax,%rdi
mov    $0xf4240,%eax
cqto
idiv   %rdi
mov    %rax,%r10
mov    -0x98(%rbp),%rax
cqto
idivq  -0x90(%rbp)
mov    -0xe0(%rbp),%rdx
lea    0xad8(%rip),%rdi
mov    %r12d,(%rsp)
mov    %r15d,0x8(%rsp)
mov    %r14,0x10(%rsp)
mov    %rbx,0x18(%rsp)
mov    %r11,0x20(%rsp)
mov    %r10,0x28(%rsp)
mov    %rax,0x30(%rsp)
call   1040 <printf@plt>
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x100,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_random_one>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %r9,0x30(%rsp)
mov    %r8,0x20(%rsp)
mov    %rcx,%rbx
mov    %edx,%r13d
mov    %esi,%r12d
mov    %rdi,0x18(%rsp)
mov    0xd0(%rsp),%rbp
mov    $0x1,%r14d
mov    $0x1,%edi
call   1070 <srand@plt>
mov    0x2deb(%rip),%rax
mov    (%rax),%edx
xor    %r15d,%r15d
mov    %r13d,%edi
xor    %esi,%esi
call   1050 <lseek@plt>
mov    %r13d,0x8(%rsp)
mov    %r13d,%edi
call   10a0 <fsync@plt>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
cmp    $0x2,%r12d
lea    0xdfe(%rip),%rax
lea    0xdfc(%rip),%rcx
cmove  %rax,%rcx
test   %r12d,%r12d
lea    0xdf5(%rip),%rdx
cmovne %rcx,%rdx
lea    0xdcb(%rip),%rsi
mov    %rdx,0x10(%rsp)
mov    %rbp,%rcx
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    0x68(%rsp),%rdi
call   1090 <get_timer@plt>
test   %eax,%eax
je     1501 <run_random_one+0x361>
cmp    $0x2,%r12d
mov    %r12d,0xc(%rsp)
cmovne %r12d,%r14d
mov    %rbx,0x28(%rsp)
sub    %rbp,%rbx
movslq 0xc8(%rsp),%rax
mov    %rax,0x40(%rsp)
xor    %r13d,%r13d
xor    %r12d,%r12d
mov    %rbx,0x38(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   10c0 <rand@plt>
mov    %rax,%rcx
mov    %rbx,%rax
or     %rbp,%rax
shr    $0x20,%rax
je     12c0 <run_random_one+0x120>
mov    %rbx,%rax
cqto
idiv   %rbp
mov    %rax,%rsi
jmp    12c8 <run_random_one+0x128>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebx,%eax
xor    %edx,%edx
div    %ebp
mov    %eax,%esi
mov    %rcx,%rax
or     %rsi,%rax
shr    $0x20,%rax
je     12f0 <run_random_one+0x150>
mov    %rcx,%rax
cqto
idiv   %rsi
mov    %rdx,%rbp
jmp    12f8 <run_random_one+0x158>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ecx,%eax
xor    %edx,%edx
div    %esi
mov    %edx,%ebp
imul   0xd0(%rsp),%rbp
mov    0x2cc8(%rip),%rax
mov    (%rax),%edx
mov    0x8(%rsp),%edi
mov    %rbp,%rsi
call   1050 <lseek@plt>
test   %rax,%rax
js     142b <run_random_one+0x28b>
xor    %eax,%eax
test   %r14d,%r14d
sete   %al
cmpl   $0x2,0xc(%rsp)
cmove  %eax,%r14d
test   %r14d,%r14d
je     1350 <run_random_one+0x1b0>
mov    0x8(%rsp),%edi
mov    0x20(%rsp),%rsi
mov    0xd0(%rsp),%rbp
mov    %rbp,%rdx
call   1030 <write@plt>
jmp    1369 <run_random_one+0x1c9>
mov    0x8(%rsp),%edi
mov    0x20(%rsp),%rsi
mov    0xd0(%rsp),%rbp
mov    %rbp,%rdx
call   1060 <read@plt>
lea    0x58(%rsp),%r15
test   %rax,%rax
js     144c <run_random_one+0x2ac>
mov    0xb8(%rsp),%eax
test   %eax,%eax
jne    1395 <run_random_one+0x1f5>
test   %r14d,%r14d
je     1395 <run_random_one+0x1f5>
mov    0x8(%rsp),%edi
call   10a0 <fsync@plt>
lea    0x58(%rsp),%r15
mov    %r15,%rdi
call   1090 <get_timer@plt>
test   %eax,%eax
je     1488 <run_random_one+0x2e8>
add    $0x1,%r12
mov    %r15,%rdi
lea    0x68(%rsp),%rsi
lea    0x48(%rsp),%rdx
call   10b0 <timersub@plt>
movslq 0x48(%rsp),%rax
add    0x40(%rsp),%r13
mov    0xc0(%rsp),%ecx
cmp    %ecx,%eax
mov    0x38(%rsp),%rbx
jl     1290 <run_random_one+0xf0>
imul   $0xf4240,%rax,%rcx
movabs $0xd60e94ee392e1ef7,%rdx
94 0e d6
mov    %r13,%rax
imul   %rdx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0xe,%rdx
add    %rax,%rdx
add    %rcx,%rdx
add    0x50(%rsp),%rdx
test   %rdx,%rdx
mov    $0x1,%ebp
cmovg  %rdx,%rbp
mov    %rbp,%rax
or     %r12,%rax
shr    $0x20,%rax
je     148d <run_random_one+0x2ed>
mov    %rbp,%rax
xor    %edx,%edx
div    %r12
mov    %rax,%r10
jmp    1497 <run_random_one+0x2f7>
mov    0x2bae(%rip),%rax
mov    (%rax),%edi
mov    0x2b9d(%rip),%rax
mov    (%rax),%ecx
lea    0xbe2(%rip),%rsi
xor    %r15d,%r15d
mov    %rbp,%rdx
jmp    147f <run_random_one+0x2df>
cmpl   $0x0,0xc(%rsp)
mov    0x2b88(%rip),%rax
mov    (%rax),%edi
lea    0xc09(%rip),%rax
lea    0xbfc(%rip),%rdx
cmove  %rax,%rdx
mov    0x2b65(%rip),%rax
mov    (%rax),%ecx
lea    0xbcd(%rip),%rsi
xor    %r15d,%r15d
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    1501 <run_random_one+0x361>
xor    %r15d,%r15d
jmp    1501 <run_random_one+0x361>
mov    %ebp,%eax
xor    %edx,%edx
div    %r12d
mov    %eax,%r10d
mov    0x18(%rsp),%rsi
cmp    $0xf4240,%r10
ja     14b1 <run_random_one+0x311>
mov    $0xf4240,%eax
xor    %edx,%edx
div    %r10d
jmp    14b3 <run_random_one+0x313>
xor    %eax,%eax
mov    0x10(%rsp),%rdx
sub    $0x8,%rsp
lea    0xbac(%rip),%rdi
mov    0x30(%rsp),%rcx
mov    0x38(%rsp),%r8
mov    0xb8(%rsp),%r9d
push   %r10
push   %rax
push   %rbp
push   %r12
push   0xf8(%rsp)
mov    0xf0(%rsp),%eax
push   %rax
mov    0xf0(%rsp),%eax
push   %rax
call   1040 <printf@plt>
add    $0x40,%rsp
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
@SEEK_SET = global i32 0
@stderr = global i32 0
@.str = [19 x i8] c"RND %s iosize=%ld\0D\00"
@.str.1 = [5 x i8] c"RDWR\00"
@.str.2 = [7 x i8] c"WRONLY\00"
@.str.3 = [7 x i8] c"RDONLY\00"
@.str.4 = [35 x i8] c"seek error for ofs=%ld (errno %d)\0A\00"
@errno = global i32 0
@.str.5 = [27 x i8] c"cannot %s file (errno %d)\0A\00"
@.str.6 = [6 x i8] c"write\00"
@.str.7 = [5 x i8] c"read\00"
@.str.8 = [50 x i8] c"%s,RND,%s,%ld,%ld,%d,%d,%d,%ld,%lld,%lld,%ld,%ld\0A\00"
define i32 @run_random_one(i8* %0, i32 %1, i32 %2, i64 %3, i8* %4, i64 %5, i32 %6, i32 %7, i32 %8, i32 %9, i64 %10) {
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i64
%17 = alloca i8*
%18 = alloca i64
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i64
%24 = alloca i64
%25 = alloca %struct.timeval
%26 = alloca %struct.timeval
%27 = alloca %struct.timeval
%28 = alloca i64
%29 = alloca i64
%30 = alloca i32
store i8* %0, i8** %13
store i32 %1, i32* %14
store i32 %2, i32* %15
store i64 %3, i64* %16
store i8* %4, i8** %17
store i64 %5, i64* %18
store i32 %6, i32* %19
store i32 %7, i32* %20
store i32 %8, i32* %21
store i32 %9, i32* %22
store i64 %10, i64* %23
%31 = call i32 @srand(i32 1)
%32 = load i32, i32* %15
%33 = load i32, i32* @SEEK_SET
%34 = call i64 @lseek(i32 %32, i64 0, i32 %33)
%35 = load i32, i32* %15
%36 = call i32 @fsync(i32 %35)
%37 = load i32, i32* @stderr
%38 = load i32, i32* %14
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %45
40: ; preds = %11
%41 = load i32, i32* %14
%42 = icmp eq i32 %41, 2
%43 = zext i1 %42 to i64
%44 = select i1 %42, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0)
br label %46
45: ; preds = %11
br label %46
46: ; preds = %45, %40
%47 = phi i8* [ %44, %40 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), %45 ]
%48 = load i64, i64* %23
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %47, i64 %48)
%50 = call i32 @get_timer(%struct.timeval* %25)
%51 = icmp ne i32 %50, 0
br i1 %51, label %53, label %52
52: ; preds = %46
store i32 0, i32* %12
br label %180
53: ; preds = %46
store i64 0, i64* %28
%54 = load i32, i32* %14
%55 = icmp eq i32 %54, 2
br i1 %55, label %56, label %57
56: ; preds = %53
br label %59
57: ; preds = %53
%58 = load i32, i32* %14
br label %59
59: ; preds = %57, %56
%60 = phi i32 [ 1, %56 ], [ %58, %57 ]
store i32 %60, i32* %30
br label %61
61: ; preds = %130, %59
%62 = call i64 (...) @rand()
%63 = load i64, i64* %16
%64 = load i64, i64* %23
%65 = sub nsw i64 %63, %64
%66 = load i64, i64* %23
%67 = sdiv i64 %65, %66
%68 = srem i64 %62, %67
%69 = load i64, i64* %23
%70 = mul nsw i64 %68, %69
store i64 %70, i64* %24
%71 = load i32, i32* %15
%72 = load i64, i64* %24
%73 = load i32, i32* @SEEK_SET
%74 = call i64 @lseek(i32 %71, i64 %72, i32 %73)
%75 = icmp slt i64 %74, 0
br i1 %75, label %76, label %81
76: ; preds = %61
%77 = load i32, i32* @stderr
%78 = load i64, i64* %24
%79 = load i32, i32* @errno
%80 = call i32 (i32, i8*, ...) @fprintf(i32 %77, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i64 %78, i32 %79)
store i32 0, i32* %12
br label %180
81: ; preds = %61
%82 = load i32, i32* %14
%83 = icmp eq i32 %82, 2
br i1 %83, label %84, label %89
84: ; preds = %81
%85 = load i32, i32* %30
%86 = icmp ne i32 %85, 0
%87 = zext i1 %86 to i64
%88 = select i1 %86, i32 0, i32 1
store i32 %88, i32* %30
br label %89
89: ; preds = %84, %81
%90 = load i32, i32* %30
%91 = icmp ne i32 %90, 0
br i1 %91, label %92, label %97
92: ; preds = %89
%93 = load i32, i32* %15
%94 = load i8*, i8** %17
%95 = load i64, i64* %23
%96 = call i64 @write(i32 %93, i8* %94, i64 %95)
br label %102
97: ; preds = %89
%98 = load i32, i32* %15
%99 = load i8*, i8** %17
%100 = load i64, i64* %23
%101 = call i64 @read(i32 %98, i8* %99, i64 %100)
br label %102
102: ; preds = %97, %92
%103 = phi i64 [ %96, %92 ], [ %101, %97 ]
%104 = icmp slt i64 %103, 0
br i1 %104, label %105, label %113
105: ; preds = %102
%106 = load i32, i32* @stderr
%107 = load i32, i32* %14
%108 = icmp ne i32 %107, 0
%109 = zext i1 %108 to i64
%110 = select i1 %108, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0)
%111 = load i32, i32* @errno
%112 = call i32 (i32, i8*, ...) @fprintf(i32 %106, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i8* %110, i32 %111)
store i32 0, i32* %12
br label %180
113: ; preds = %102
%114 = load i32, i32* %30
%115 = icmp ne i32 %114, 0
br i1 %115, label %116, label %122
116: ; preds = %113
%117 = load i32, i32* %20
%118 = icmp ne i32 %117, 0
br i1 %118, label %122, label %119
119: ; preds = %116
%120 = load i32, i32* %15
%121 = call i32 @fsync(i32 %120)
br label %122
122: ; preds = %119, %116, %113
%123 = call i32 @get_timer(%struct.timeval* %26)
%124 = icmp ne i32 %123, 0
br i1 %124, label %126, label %125
125: ; preds = %122
store i32 0, i32* %12
br label %180
126: ; preds = %122
%127 = load i64, i64* %28
%128 = add nsw i64 %127, 1
store i64 %128, i64* %28
%129 = call i32 @timersub(%struct.timeval* %26, %struct.timeval* %25, %struct.timeval* %27)
br label %130
130: ; preds = %126
%131 = getelementptr inbounds %struct.timeval, %struct.timeval* %27, i32 0, i32 0
%132 = load i32, i32* %131
%133 = load i32, i32* %21
%134 = icmp slt i32 %132, %133
br i1 %134, label %61, label %135
135: ; preds = %130
%136 = getelementptr inbounds %struct.timeval, %struct.timeval* %27, i32 0, i32 0
%137 = load i32, i32* %136
%138 = sext i32 %137 to i64
%139 = mul nsw i64 %138, 1000000
%140 = getelementptr inbounds %struct.timeval, %struct.timeval* %27, i32 0, i32 1
%141 = load i64, i64* %140
%142 = add nsw i64 %139, %141
%143 = load i64, i64* %28
%144 = load i32, i32* %22
%145 = sext i32 %144 to i64
%146 = mul nsw i64 %143, %145
%147 = sdiv i64 %146, 100000
%148 = sub nsw i64 %142, %147
store i64 %148, i64* %29
%149 = load i64, i64* %29
%150 = icmp slt i64 %149, 1
br i1 %150, label %151, label %152
151: ; preds = %135
store i64 1, i64* %29
br label %152
152: ; preds = %151, %135
%153 = load i8*, i8** %13
%154 = load i32, i32* %14
%155 = icmp ne i32 %154, 0
br i1 %155, label %156, label %161
156: ; preds = %152
%157 = load i32, i32* %14
%158 = icmp eq i32 %157, 2
%159 = zext i1 %158 to i64
%160 = select i1 %158, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0)
br label %162
161: ; preds = %152
br label %162
162: ; preds = %161, %156
%163 = phi i8* [ %160, %156 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), %161 ]
%164 = load i64, i64* %16
%165 = load i64, i64* %18
%166 = load i32, i32* %19
%167 = load i32, i32* %20
%168 = load i32, i32* %21
%169 = load i64, i64* %23
%170 = load i64, i64* %28
%171 = load i64, i64* %29
%172 = load i64, i64* %29
%173 = load i64, i64* %28
%174 = sdiv i64 %172, %173
%175 = sdiv i64 1000000, %174
%176 = load i64, i64* %29
%177 = load i64, i64* %28
%178 = sdiv i64 %176, %177
%179 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.8, i64 0, i64 0), i8* %153, i8* %163, i64 %164, i64 %165, i32 %166, i32 %167, i32 %168, i64 %169, i64 %170, i64 %171, i64 %175, i64 %178)
store i32 1, i32* %12
br label %180
180: ; preds = %162, %125, %105, %76, %52
%181 = load i32, i32* %12
ret i32 %181
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
@SEEK_SET = global i32 0
@stderr = global i32 0
@.str = [19 x i8] c"RND %s iosize=%ld\0D\00"
@.str.1 = [5 x i8] c"RDWR\00"
@.str.2 = [7 x i8] c"WRONLY\00"
@.str.3 = [7 x i8] c"RDONLY\00"
@.str.4 = [35 x i8] c"seek error for ofs=%ld (errno %d)\0A\00"
@errno = global i32 0
@.str.5 = [27 x i8] c"cannot %s file (errno %d)\0A\00"
@.str.6 = [6 x i8] c"write\00"
@.str.7 = [5 x i8] c"read\00"
@.str.8 = [50 x i8] c"%s,RND,%s,%ld,%ld,%d,%d,%d,%ld,%lld,%lld,%ld,%ld\0A\00"
define i32 @run_random_one(i8* %0, i32 %1, i32 %2, i64 %3, i8* nocapture %4, i64 %5, i32 %6, i32 %7, i32 %8, i32 %9, i64 %10) {
%12 = alloca %struct.timeval
%13 = alloca %struct.timeval
%14 = alloca %struct.timeval
%15 = bitcast %struct.timeval* %12 to i8*
%16 = bitcast %struct.timeval* %13 to i8*
%17 = bitcast %struct.timeval* %14 to i8*
%18 = tail call i32 @srand(i32 1)
%19 = load i32, i32* @SEEK_SET
%20 = tail call i64 @lseek(i32 %2, i64 0, i32 %19)
%21 = tail call i32 @fsync(i32 %2)
%22 = load i32, i32* @stderr
%23 = icmp eq i32 %1, 0
%24 = icmp eq i32 %1, 2
%25 = select i1 %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0)
%26 = select i1 %23, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %25
%27 = tail call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %26, i64 %10)
%28 = call i32 @get_timer(%struct.timeval* %12)
%29 = icmp eq i32 %28, 0
br i1 %29, label %93, label %30
30: ; preds = %11
%31 = select i1 %24, i32 1, i32 %1
%32 = sub nsw i64 %3, %10
%33 = icmp ne i32 %7, 0
%34 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i64 0, i32 0
br label %35
35: ; preds = %73, %30
%36 = phi i64 [ 0, %30 ], [ %74, %73 ]
%37 = phi i32 [ %31, %30 ], [ %52, %73 ]
%38 = call i64 (...) @rand()
%39 = sdiv i64 %32, %10
%40 = srem i64 %38, %39
%41 = mul nsw i64 %40, %10
%42 = load i32, i32* @SEEK_SET
%43 = call i64 @lseek(i32 %2, i64 %41, i32 %42)
%44 = icmp slt i64 %43, 0
br i1 %44, label %45, label %49
45: ; preds = %35
%46 = load i32, i32* @stderr
%47 = load i32, i32* @errno
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i64 %41, i32 %47)
br label %93
49: ; preds = %35
%50 = icmp eq i32 %37, 0
%51 = zext i1 %50 to i32
%52 = select i1 %24, i32 %51, i32 %37
%53 = icmp eq i32 %52, 0
br i1 %53, label %56, label %54
54: ; preds = %49
%55 = call i64 @write(i32 %2, i8* %4, i64 %10)
br label %58
56: ; preds = %49
%57 = call i64 @read(i32 %2, i8* %4, i64 %10)
br label %58
58: ; preds = %56, %54
%59 = phi i64 [ %55, %54 ], [ %57, %56 ]
%60 = icmp slt i64 %59, 0
br i1 %60, label %61, label %66
61: ; preds = %58
%62 = load i32, i32* @stderr
%63 = select i1 %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0)
%64 = load i32, i32* @errno
%65 = call i32 (i32, i8*, ...) @fprintf(i32 %62, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i8* %63, i32 %64)
br label %93
66: ; preds = %58
%67 = or i1 %33, %53
br i1 %67, label %70, label %68
68: ; preds = %66
%69 = call i32 @fsync(i32 %2)
br label %70
70: ; preds = %68, %66
%71 = call i32 @get_timer(%struct.timeval* %13)
%72 = icmp eq i32 %71, 0
br i1 %72, label %93, label %73
73: ; preds = %70
%74 = add nuw nsw i64 %36, 1
%75 = call i32 @timersub(%struct.timeval* %13, %struct.timeval* %12, %struct.timeval* %14)
%76 = load i32, i32* %34
%77 = icmp slt i32 %76, %8
br i1 %77, label %35, label %78
78: ; preds = %73
%79 = sext i32 %76 to i64
%80 = mul nsw i64 %79, 1000000
%81 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i64 0, i32 1
%82 = load i64, i64* %81
%83 = sext i32 %9 to i64
%84 = mul nsw i64 %74, %83
%85 = sdiv i64 %84, -100000
%86 = add nsw i64 %80, %85
%87 = add i64 %86, %82
%88 = icmp sgt i64 %87, 1
%89 = select i1 %88, i64 %87, i64 1
%90 = udiv i64 %89, %74
%91 = udiv i64 1000000, %90
%92 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.8, i64 0, i64 0), i8* %0, i8* %26, i64 %3, i64 %5, i32 %6, i32 %7, i32 %8, i64 %10, i64 %74, i64 %89, i64 %91, i64 %90)
br label %93
93: ; preds = %70, %11, %78, %61, %45
%94 = phi i32 [ 0, %45 ], [ 0, %61 ], [ 1, %78 ], [ 0, %11 ], [ 0, %70 ]
ret i32 %94
}