#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 *, unsigned 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_write(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_write\n");
    return 1;
  }
  fd = open("/dev/urandom", O_RDONLY);
  if (fd < 0) {
    fprintf(stderr, "ERROR: unable to open /dev/urandom in file_write\n");
    return 1;
  }
  read(fd, data, N);
  close(fd);
  warmupsize = 10000;
  if (warmupsize > N)
    warmupsize = N;
  for (i = 0; i < 100; i++) {
    sprintf(name, "warmup_%d", i);
    fd = open(name, O_CREAT | O_WRONLY | O_TRUNC, 0644);
    if (fd < 0) {
      fprintf(stderr,
              "ERROR: unable to open warmup file for writing in file_write\n");
      return 1;
    }
    write(fd, data, warmupsize);
    close(fd);
  }
  while (N >= 10000) {
    N = N / 2;
    size = size * 2;
  }
  while (N >= 1) {
    sprintf(titlebuffer, "file_write: %d files of %d bytes", N, size);
    clock_gettime(CLOCK_MONOTONIC, &start);
    reps = 128 / N;
    if (reps == 0)
      reps = 1;
    for (j = 0; j < reps; j++) {
      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_write\n");
          return 1;
        }
        write(fd, data, size);
        fsync(fd);
        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;
  }
  for (i = 0; i < 100; i++) {
    sprintf(name, "warmup_%d", i);
    unlink(name);
  }
  free(data);
  fflush(stdout);
  return 0;
}


x86 assembly (clang, -O0):
<file_write>:
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_write+0x56>
mov    0x2db4(%rip),%rax
mov    (%rax),%edi
lea    0xdeb(%rip),%rsi
call   10a0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1610 <file_write+0x440>
mov    0x2dab(%rip),%rax
mov    (%rax),%esi
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   10e0 <open@plt>
mov    %eax,-0x294(%rbp)
cmpl   $0x0,-0x294(%rbp)
jge    1271 <file_write+0xa1>
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
lea    0xdd1(%rip),%rsi
call   10a0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1610 <file_write+0x440>
mov    -0x294(%rbp),%edi
mov    -0x98(%rbp),%rsi
mov    -0x8(%rbp),%edx
call   1090 <read@plt>
mov    -0x294(%rbp),%edi
call   1080 <close@plt>
movl   $0x2710,-0x9c(%rbp)
mov    -0x9c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jbe    12b3 <file_write+0xe3>
mov    -0x8(%rbp),%eax
mov    %eax,-0x9c(%rbp)
movl   $0x0,-0x88(%rbp)
cmpl   $0x64,-0x88(%rbp)
jge    1378 <file_write+0x1a8>
lea    -0x80(%rbp),%rdi
mov    -0x88(%rbp),%edx
lea    0xd88(%rip),%rsi
mov    $0x0,%al
call   10f0 <sprintf@plt>
lea    -0x80(%rbp),%rdi
mov    0x2d0b(%rip),%rax
mov    (%rax),%esi
mov    0x2cb2(%rip),%rax
or     (%rax),%esi
mov    0x2cf1(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
mov    $0x0,%al
call   10e0 <open@plt>
mov    %eax,-0x294(%rbp)
cmpl   $0x0,-0x294(%rbp)
jge    1341 <file_write+0x171>
mov    0x2c99(%rip),%rax
mov    (%rax),%edi
lea    0xd3d(%rip),%rsi
call   10a0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1610 <file_write+0x440>
mov    -0x294(%rbp),%edi
mov    -0x98(%rbp),%rsi
mov    -0x9c(%rbp),%edx
call   1070 <write@plt>
mov    -0x294(%rbp),%edi
call   1080 <close@plt>
mov    -0x88(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x88(%rbp)
jmp    12bd <file_write+0xed>
jmp    137d <file_write+0x1ad>
cmpl   $0x2710,-0x8(%rbp)
jb     13a7 <file_write+0x1d7>
mov    -0x8(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x84(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    137d <file_write+0x1ad>
jmp    13ac <file_write+0x1dc>
cmpl   $0x1,-0x8(%rbp)
jb     15a3 <file_write+0x3d3>
lea    -0x290(%rbp),%rdi
mov    -0x8(%rbp),%edx
mov    -0x84(%rbp),%ecx
lea    0xcdd(%rip),%rsi
mov    $0x0,%al
call   10f0 <sprintf@plt>
mov    0x2bf5(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1060 <clock_gettime@plt>
mov    $0x80,%eax
xor    %edx,%edx
divl   -0x8(%rbp)
mov    %eax,-0x298(%rbp)
cmpl   $0x0,-0x298(%rbp)
jne    140d <file_write+0x23d>
movl   $0x1,-0x298(%rbp)
movl   $0x0,-0x8c(%rbp)
mov    -0x8c(%rbp),%eax
cmp    -0x298(%rbp),%eax
jge    1514 <file_write+0x344>
movl   $0x0,-0x88(%rbp)
mov    -0x88(%rbp),%eax
cmp    -0x8(%rbp),%eax
jae    14fb <file_write+0x32b>
lea    -0x80(%rbp),%rdi
mov    -0x88(%rbp),%edx
lea    0xc78(%rip),%rsi
mov    $0x0,%al
call   10f0 <sprintf@plt>
lea    -0x80(%rbp),%rdi
mov    0x2b93(%rip),%rax
mov    (%rax),%esi
mov    0x2b3a(%rip),%rax
or     (%rax),%esi
mov    0x2b79(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
mov    $0x0,%al
call   10e0 <open@plt>
mov    %eax,-0x294(%rbp)
cmpl   $0x0,-0x294(%rbp)
jge    14b9 <file_write+0x2e9>
mov    0x2b21(%rip),%rax
mov    (%rax),%edi
lea    0xc2f(%rip),%rsi
call   10a0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1610 <file_write+0x440>
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    1433 <file_write+0x263>
jmp    1500 <file_write+0x330>
mov    -0x8c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8c(%rbp)
jmp    1417 <file_write+0x247>
mov    0x2ab5(%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    1586 <file_write+0x3b6>
lea    -0x80(%rbp),%rdi
mov    -0x88(%rbp),%edx
lea    0xb69(%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    1542 <file_write+0x372>
mov    -0x8(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x84(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    13ac <file_write+0x1dc>
movl   $0x0,-0x88(%rbp)
cmpl   $0x64,-0x88(%rbp)
jge    15ef <file_write+0x41f>
lea    -0x80(%rbp),%rdi
mov    -0x88(%rbp),%edx
lea    0xa98(%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    15ad <file_write+0x3dd>
mov    -0x98(%rbp),%rdi
call   1040 <free@plt>
mov    0x29b6(%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_write>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x288,%rsp
mov    %edi,%ebp
call   10b0 <malloc@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     12e8 <file_write+0x118>
mov    0x2ddb(%rip),%rax
mov    (%rax),%esi
lea    0xe1e(%rip),%rdi
xor    %eax,%eax
call   10e0 <open@plt>
test   %eax,%eax
js     12fd <file_write+0x12d>
mov    %eax,%ebx
mov    %eax,%edi
mov    0x8(%rsp),%rsi
mov    %ebp,%edx
call   1090 <read@plt>
mov    %ebx,%edi
call   1080 <close@plt>
cmp    $0x2710,%ebp
mov    $0x2710,%r13d
cmovb  %ebp,%r13d
lea    0xe20(%rip),%r15
lea    0x20(%rsp),%r12
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   10f0 <sprintf@plt>
mov    0x2d42(%rip),%rax
mov    (%rax),%esi
mov    0x2d89(%rip),%rax
or     (%rax),%esi
mov    0x2d78(%rip),%rax
or     (%rax),%esi
mov    %r12,%rdi
mov    $0x1a4,%edx
xor    %eax,%eax
call   10e0 <open@plt>
test   %eax,%eax
js     1312 <file_write+0x142>
mov    %eax,%r14d
mov    %eax,%edi
mov    0x8(%rsp),%rsi
mov    %r13d,%edx
call   1070 <write@plt>
mov    %r14d,%edi
call   1080 <close@plt>
add    $0x1,%ebx
cmp    $0x64,%ebx
jne    1250 <file_write+0x80>
mov    $0x1,%r12d
cmp    $0x2710,%ebp
jb     1327 <file_write+0x157>
mov    $0x1,%r12d
mov    %ebp,%ebx
nopl   0x0(%rax)
shr    %ebx
add    %r12d,%r12d
cmp    $0x4e1f,%ebp
mov    %ebx,%ebp
ja     12d0 <file_write+0x100>
test   %ebx,%ebx
jne    1331 <file_write+0x161>
jmp    14b0 <file_write+0x2e0>
mov    0x2cd1(%rip),%rax
mov    (%rax),%edi
lea    0xd08(%rip),%rsi
jmp    150b <file_write+0x33b>
mov    0x2cbc(%rip),%rax
mov    (%rax),%edi
lea    0xd24(%rip),%rsi
jmp    150b <file_write+0x33b>
mov    0x2ca7(%rip),%rax
mov    (%rax),%edi
lea    0xd4b(%rip),%rsi
jmp    150b <file_write+0x33b>
mov    %ebp,%ebx
test   %ebx,%ebx
je     14b0 <file_write+0x2e0>
lea    0xd72(%rip),%rsi
lea    0x90(%rsp),%rdi
mov    0x2c89(%rip),%rbp
mov    %rsp,%r14
mov    $0x1,%r15d
lea    0x20(%rsp),%r13
mov    %ebx,%edx
mov    %r12d,%ecx
xor    %eax,%eax
call   10f0 <sprintf@plt>
mov    0x0(%rbp),%edi
mov    %r14,%rsi
call   1060 <clock_gettime@plt>
mov    $0x80,%eax
xor    %edx,%edx
div    %ebx
cmp    $0x81,%ebx
cmovae %r15d,%eax
cmp    $0x2,%ebx
mov    $0x1,%r14d
cmovae %ebx,%r14d
mov    %eax,0x18(%rsp)
test   %eax,%eax
lea    0xd32(%rip),%rsi
je     1430 <file_write+0x260>
xor    %eax,%eax
mov    %eax,0x1c(%rsp)
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   10f0 <sprintf@plt>
mov    0x2be5(%rip),%rax
mov    (%rax),%esi
mov    0x2c2c(%rip),%rax
or     (%rax),%esi
mov    0x2c1b(%rip),%rax
or     (%rax),%esi
mov    %r13,%rdi
mov    $0x1a4,%edx
xor    %eax,%eax
call   10e0 <open@plt>
test   %eax,%eax
js     14fb <file_write+0x32b>
mov    %eax,%r15d
mov    %eax,%edi
mov    0x8(%rsp),%rsi
mov    %r12d,%edx
call   1070 <write@plt>
mov    %r15d,%edi
call   10d0 <fsync@plt>
mov    %r15d,%edi
call   1080 <close@plt>
add    $0x1,%ebp
cmp    %ebp,%r14d
lea    0xcae(%rip),%rsi
jne    13b0 <file_write+0x1e0>
mov    0x1c(%rsp),%eax
add    $0x1,%eax
cmp    0x18(%rsp),%eax
jne    13a1 <file_write+0x1d1>
mov    0x2b99(%rip),%rax
mov    (%rax),%edi
lea    0x10(%rsp),%rsi
call   1060 <clock_gettime@plt>
mov    (%rsp),%edi
mov    0x10(%rsp),%esi
lea    0x90(%rsp),%rdx
lea    0xc72(%rip),%r15
call   1030 <elapsed_time_hr@plt>
xor    %ebp,%ebp
mov    %r13,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   10f0 <sprintf@plt>
mov    %r13,%rdi
call   1050 <unlink@plt>
add    $0x1,%ebp
cmp    %ebp,%r14d
jne    1460 <file_write+0x290>
mov    %ebx,%eax
shr    %eax
add    %r12d,%r12d
cmp    $0x1,%ebx
mov    %eax,%ebx
lea    0xc18(%rip),%rsi
mov    0x2b37(%rip),%rbp
mov    %rsp,%r14
mov    $0x1,%r15d
lea    0x90(%rsp),%rdi
ja     1355 <file_write+0x185>
lea    0xbac(%rip),%r15
lea    0x20(%rsp),%rbp
xor    %ebx,%ebx
xchg   %ax,%ax
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   10f0 <sprintf@plt>
mov    %rbp,%rdi
call   1050 <unlink@plt>
add    $0x1,%ebx
cmp    $0x64,%ebx
jne    14c0 <file_write+0x2f0>
mov    0x8(%rsp),%rdi
call   1040 <free@plt>
mov    0x2ac8(%rip),%rax
mov    (%rax),%edi
call   10c0 <fflush@plt>
xor    %eax,%eax
jmp    1515 <file_write+0x345>
mov    0x2abe(%rip),%rax
mov    (%rax),%edi
lea    0xbcc(%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 = [36 x i8] c"ERROR: out of memory in file_write\0A\00"
@.str.1 = [13 x i8] c"/dev/urandom\00"
@O_RDONLY = global i32 0
@.str.2 = [50 x i8] c"ERROR: unable to open /dev/urandom in file_write\0A\00"
@.str.3 = [10 x i8] c"warmup_%d\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@.str.4 = [61 x i8] c"ERROR: unable to open warmup file for writing in file_write\0A\00"
@.str.5 = [33 x i8] c"file_write: %d files of %d bytes\00"
@CLOCK_MONOTONIC = global i32 0
@.str.6 = [12 x i8] c"testfile_%d\00"
@.str.7 = [59 x i8] c"ERROR: unable to open test file for writing in file_write\0A\00"
@stdout = global i32 0
define i32 @file_write(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 ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %2
br label %184
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 ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %2
br label %184
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)
store i32 10000, i32* %11
%37 = load i32, i32* %11
%38 = load i32, i32* %3
%39 = icmp ugt i32 %37, %38
br i1 %39, label %40, label %42
40: ; preds = %30
%41 = load i32, i32* %3
store i32 %41, i32* %11
br label %42
42: ; preds = %40, %30
store i32 0, i32* %8
br label %43
43: ; preds = %69, %42
%44 = load i32, i32* %8
%45 = icmp slt i32 %44, 100
br i1 %45, label %46, label %72
46: ; preds = %43
%47 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%48 = load i32, i32* %8
%49 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %47, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %48)
%50 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%51 = load i32, i32* @O_CREAT
%52 = load i32, i32* @O_WRONLY
%53 = or i32 %51, %52
%54 = load i32, i32* @O_TRUNC
%55 = or i32 %53, %54
%56 = call i32 (i8*, i32, ...) @open(i8* %50, i32 %55, i32 420)
store i32 %56, i32* %13
%57 = load i32, i32* %13
%58 = icmp slt i32 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %46
%60 = load i32, i32* @stderr
%61 = call i32 @fprintf(i32 %60, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %2
br label %184
62: ; preds = %46
%63 = load i32, i32* %13
%64 = load i8*, i8** %10
%65 = load i32, i32* %11
%66 = call i32 @write(i32 %63, i8* %64, i32 %65)
%67 = load i32, i32* %13
%68 = call i32 @close(i32 %67)
br label %69
69: ; preds = %62
%70 = load i32, i32* %8
%71 = add nsw i32 %70, 1
store i32 %71, i32* %8
br label %43
72: ; preds = %43
br label %73
73: ; preds = %76, %72
%74 = load i32, i32* %3
%75 = icmp uge i32 %74, 10000
br i1 %75, label %76, label %81
76: ; preds = %73
%77 = load i32, i32* %3
%78 = udiv i32 %77, 2
store i32 %78, i32* %3
%79 = load i32, i32* %7
%80 = mul nsw i32 %79, 2
store i32 %80, i32* %7
br label %73
81: ; preds = %73
br label %82
82: ; preds = %161, %81
%83 = load i32, i32* %3
%84 = icmp uge i32 %83, 1
br i1 %84, label %85, label %166
85: ; preds = %82
%86 = getelementptr inbounds [500 x i8], [500 x i8]* %12, i64 0, i64 0
%87 = load i32, i32* %3
%88 = load i32, i32* %7
%89 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %86, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i32 %87, i32 %88)
%90 = load i32, i32* @CLOCK_MONOTONIC
%91 = call i32 @clock_gettime(i32 %90, %struct.timespec* %4)
%92 = load i32, i32* %3
%93 = udiv i32 128, %92
store i32 %93, i32* %14
%94 = load i32, i32* %14
%95 = icmp eq i32 %94, 0
br i1 %95, label %96, label %97
96: ; preds = %85
store i32 1, i32* %14
br label %97
97: ; preds = %96, %85
store i32 0, i32* %9
br label %98
98: ; preds = %136, %97
%99 = load i32, i32* %9
%100 = load i32, i32* %14
%101 = icmp slt i32 %99, %100
br i1 %101, label %102, label %139
102: ; preds = %98
store i32 0, i32* %8
br label %103
103: ; preds = %132, %102
%104 = load i32, i32* %8
%105 = load i32, i32* %3
%106 = icmp ult i32 %104, %105
br i1 %106, label %107, label %135
107: ; preds = %103
%108 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%109 = load i32, i32* %8
%110 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %108, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 %109)
%111 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%112 = load i32, i32* @O_CREAT
%113 = load i32, i32* @O_WRONLY
%114 = or i32 %112, %113
%115 = load i32, i32* @O_TRUNC
%116 = or i32 %114, %115
%117 = call i32 (i8*, i32, ...) @open(i8* %111, i32 %116, i32 420)
store i32 %117, i32* %13
%118 = load i32, i32* %13
%119 = icmp slt i32 %118, 0
br i1 %119, label %120, label %123
120: ; preds = %107
%121 = load i32, i32* @stderr
%122 = call i32 @fprintf(i32 %121, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %2
br label %184
123: ; preds = %107
%124 = load i32, i32* %13
%125 = load i8*, i8** %10
%126 = load i32, i32* %7
%127 = call i32 @write(i32 %124, i8* %125, i32 %126)
%128 = load i32, i32* %13
%129 = call i32 @fsync(i32 %128)
%130 = load i32, i32* %13
%131 = call i32 @close(i32 %130)
br label %132
132: ; preds = %123
%133 = load i32, i32* %8
%134 = add nsw i32 %133, 1
store i32 %134, i32* %8
br label %103
135: ; preds = %103
br label %136
136: ; preds = %135
%137 = load i32, i32* %9
%138 = add nsw i32 %137, 1
store i32 %138, i32* %9
br label %98
139: ; preds = %98
%140 = load i32, i32* @CLOCK_MONOTONIC
%141 = call i32 @clock_gettime(i32 %140, %struct.timespec* %5)
%142 = getelementptr inbounds [500 x i8], [500 x i8]* %12, i64 0, i64 0
%143 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
%144 = load i32, i32* %143
%145 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 0
%146 = load i32, i32* %145
%147 = call i32 @elapsed_time_hr(i32 %144, i32 %146, i8* %142)
store i32 0, i32* %8
br label %148
148: ; preds = %158, %139
%149 = load i32, i32* %8
%150 = load i32, i32* %3
%151 = icmp ult i32 %149, %150
br i1 %151, label %152, label %161
152: ; preds = %148
%153 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%154 = load i32, i32* %8
%155 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %153, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 %154)
%156 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%157 = call i32 @unlink(i8* %156)
br label %158
158: ; preds = %152
%159 = load i32, i32* %8
%160 = add nsw i32 %159, 1
store i32 %160, i32* %8
br label %148
161: ; preds = %148
%162 = load i32, i32* %3
%163 = udiv i32 %162, 2
store i32 %163, i32* %3
%164 = load i32, i32* %7
%165 = mul nsw i32 %164, 2
store i32 %165, i32* %7
br label %82
166: ; preds = %82
store i32 0, i32* %8
br label %167
167: ; preds = %176, %166
%168 = load i32, i32* %8
%169 = icmp slt i32 %168, 100
br i1 %169, label %170, label %179
170: ; preds = %167
%171 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%172 = load i32, i32* %8
%173 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %171, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %172)
%174 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%175 = call i32 @unlink(i8* %174)
br label %176
176: ; preds = %170
%177 = load i32, i32* %8
%178 = add nsw i32 %177, 1
store i32 %178, i32* %8
br label %167
179: ; preds = %167
%180 = load i8*, i8** %10
%181 = call i32 @free(i8* %180)
%182 = load i32, i32* @stdout
%183 = call i32 @fflush(i32 %182)
store i32 0, i32* %2
br label %184
184: ; preds = %179, %120, %59, %27, %19
%185 = load i32, i32* %2
ret i32 %185
}

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