#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef unsigned long long uint64_t;

/* Variables and functions */
int O_APPEND;
int O_CREAT;
int O_RDWR;
int O_TRUNC;
int PATH_MAX;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWGRP;
int S_IWOTH;
int S_IWUSR;
int S_IXGRP;
int S_IXOTH;
int S_IXUSR;
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *,
                           unsigned long long, ...);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(unsigned long long);
int /*<<< orphan*/ memset(char *, char, unsigned long long);
int open64(char *, int, int);
int pwrite(int, char *, unsigned long long, unsigned long long);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int);
int /*<<< orphan*/ unlink(char *);
int prep_file(char *file_name, uint64_t size, uint64_t chunksize, int keep) {
  int fd = -1, fdt = -1, ret = 0;
  unsigned long long offset = 0, write_size = 0;
  char tmp_path[PATH_MAX];
  char *pattern = NULL;
  int open_rw_flags = O_CREAT | O_RDWR | O_APPEND | O_TRUNC;
  pattern = (char *)malloc(chunksize);
  fd = open64(file_name, open_rw_flags,
              (S_IRUSR | S_IWUSR | S_IXUSR | S_IROTH | S_IWOTH | S_IXOTH |
               S_IRGRP | S_IWGRP | S_IXGRP));
  if (fd < 0) {
    ret = fd;
    fd = errno;
    fprintf(stderr, "create file %s failed:%d:%s\n", file_name, fd,
            strerror(fd));
    goto bail;
  }
  memset(pattern, 'a', chunksize);
  snprintf(tmp_path, PATH_MAX, "%s-tmp-file", file_name);
  fdt = open64(tmp_path, open_rw_flags,
               (S_IRUSR | S_IWUSR | S_IXUSR | S_IROTH | S_IWOTH | S_IXOTH |
                S_IRGRP | S_IWGRP | S_IXGRP));
  if (fdt < 0) {
    ret = fdt;
    fdt = errno;
    fprintf(stderr, "create file %s failed:%d:%s\n", tmp_path, fdt,
            strerror(fdt));
    goto bail;
  }
  if (!keep)
    unlink(tmp_path);
  while (offset < size) {
    if ((offset + chunksize) > size)
      write_size = size - offset;
    else
      write_size = chunksize;
    ret = pwrite(fd, pattern, write_size, offset);
    if (ret < 0) {
      ret = errno;
      fprintf(stderr,
              "pwrite on %s failed at "
              "%llu:%d:%s\n",
              file_name, offset, ret, strerror(ret));
      goto bail;
    }
    ret = pwrite(fdt, pattern, write_size, offset);
    if (ret < 0) {
      ret = errno;
      fprintf(stderr,
              "pwrite on %s failed at "
              "%llu:%d:%s\n",
              tmp_path, offset, ret, strerror(ret));
      goto bail;
    }
    offset += write_size;
  }
bail:
  if (pattern)
    free(pattern);
  if (fdt > 0)
    close(fdt);
  if (fd > 0)
    close(fd);
  return ret;
}


x86 assembly (clang, -O0):
<prep_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0xffffffff,-0x20(%rbp)
movl   $0xffffffff,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    0x2dfa(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x60(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
mov    0x2dde(%rip),%rax
mov    (%rax),%eax
mov    0x2dad(%rip),%rcx
or     (%rcx),%eax
mov    0x2d3c(%rip),%rcx
or     (%rcx),%eax
mov    0x2dbb(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x54(%rbp)
mov    -0x18(%rbp),%rdi
call   1090 <malloc@plt>
mov    %rax,-0x50(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x54(%rbp),%esi
mov    0x2d23(%rip),%rax
mov    (%rax),%edx
mov    0x2d52(%rip),%rax
or     (%rax),%edx
mov    0x2d59(%rip),%rax
or     (%rax),%edx
mov    0x2d10(%rip),%rax
or     (%rax),%edx
mov    0x2ce7(%rip),%rax
or     (%rax),%edx
mov    0x2d46(%rip),%rax
or     (%rax),%edx
mov    0x2cfd(%rip),%rax
or     (%rax),%edx
mov    0x2d24(%rip),%rax
or     (%rax),%edx
mov    0x2d0b(%rip),%rax
or     (%rax),%edx
call   10b0 <open64@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1308 <prep_file+0x168>
mov    -0x20(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2cd2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2cce(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x74(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x70(%rbp)
movslq -0x20(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x20(%rbp),%edi
call   10c0 <strerror@plt>
mov    -0x74(%rbp),%edi
mov    -0x70(%rbp),%rdx
mov    -0x68(%rbp),%rcx
mov    %rax,%r8
lea    0xd04(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    1577 <prep_file+0x3d7>
mov    -0x50(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x61,%esi
call   1060 <memset@plt>
mov    -0x60(%rbp),%rdi
mov    0x2cbb(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%rcx
lea    0xceb(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x60(%rbp),%rdi
mov    -0x54(%rbp),%esi
mov    0x2c33(%rip),%rax
mov    (%rax),%edx
mov    0x2c62(%rip),%rax
or     (%rax),%edx
mov    0x2c69(%rip),%rax
or     (%rax),%edx
mov    0x2c20(%rip),%rax
or     (%rax),%edx
mov    0x2bf7(%rip),%rax
or     (%rax),%edx
mov    0x2c56(%rip),%rax
or     (%rax),%edx
mov    0x2c0d(%rip),%rax
or     (%rax),%edx
mov    0x2c34(%rip),%rax
or     (%rax),%edx
mov    0x2c1b(%rip),%rax
or     (%rax),%edx
call   10b0 <open64@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    13f6 <prep_file+0x256>
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2be2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2bde(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x84(%rbp)
movslq -0x24(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x24(%rbp),%edi
call   10c0 <strerror@plt>
mov    -0x84(%rbp),%edi
mov    -0x60(%rbp),%rdx
mov    -0x80(%rbp),%rcx
mov    %rax,%r8
lea    0xc16(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    1577 <prep_file+0x3d7>
cmpl   $0x0,-0x1c(%rbp)
jne    1409 <prep_file+0x269>
mov    -0x60(%rbp),%rdi
call   1040 <unlink@plt>
jmp    140e <prep_file+0x26e>
mov    -0x30(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1572 <prep_file+0x3d2>
mov    -0x30(%rbp),%rax
add    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jbe    143f <prep_file+0x29f>
mov    -0x10(%rbp),%rax
sub    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    1447 <prep_file+0x2a7>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x50(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x30(%rbp),%rcx
call   10a0 <pwrite@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    14db <prep_file+0x33b>
mov    0x2b21(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2b1d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x9c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x98(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x88(%rbp)
mov    -0x28(%rbp),%edi
call   10c0 <strerror@plt>
mov    -0x9c(%rbp),%edi
mov    -0x98(%rbp),%rdx
mov    -0x90(%rbp),%rcx
mov    -0x88(%rbp),%r8d
mov    %rax,%r9
lea    0xb5a(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    1577 <prep_file+0x3d7>
mov    -0x24(%rbp),%edi
mov    -0x50(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x30(%rbp),%rcx
call   10a0 <pwrite@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    1561 <prep_file+0x3c1>
mov    0x2a8d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2a89(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xac(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0xa8(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0xa0(%rbp)
mov    -0x28(%rbp),%edi
call   10c0 <strerror@plt>
mov    -0xac(%rbp),%edi
mov    -0x60(%rbp),%rdx
mov    -0xa8(%rbp),%rcx
mov    -0xa0(%rbp),%r8d
mov    %rax,%r9
lea    0xad4(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    1577 <prep_file+0x3d7>
mov    -0x38(%rbp),%rax
add    -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    140e <prep_file+0x26e>
jmp    1577 <prep_file+0x3d7>
cmpq   $0x0,-0x50(%rbp)
je     158b <prep_file+0x3eb>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x24(%rbp)
jle    159d <prep_file+0x3fd>
mov    -0x24(%rbp),%edi
call   1070 <close@plt>
cmpl   $0x0,-0x20(%rbp)
jle    15af <prep_file+0x40f>
mov    -0x20(%rbp),%edi
call   1070 <close@plt>
mov    -0x28(%rbp),%eax
mov    -0x40(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prep_file>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %ecx,-0x2c(%rbp)
mov    %rsi,%r12
mov    %rdi,%r13
mov    0x2e1f(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r15
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    0x2e1d(%rip),%rax
mov    0x2dee(%rip),%rcx
mov    (%rcx),%ebx
or     (%rax),%ebx
mov    0x2d7b(%rip),%rax
or     (%rax),%ebx
mov    0x2dfa(%rip),%rax
or     (%rax),%ebx
mov    %rdx,-0x40(%rbp)
mov    %rdx,%rdi
call   1090 <malloc@plt>
mov    0x2d6d(%rip),%rcx
mov    0x2d9e(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    0x2da3(%rip),%rcx
or     (%rcx),%edx
mov    0x2d5a(%rip),%rcx
or     (%rcx),%edx
mov    0x2d31(%rip),%rcx
or     (%rcx),%edx
mov    0x2d90(%rip),%rcx
or     (%rcx),%edx
mov    0x2d47(%rip),%rcx
or     (%rcx),%edx
mov    0x2d6e(%rip),%rcx
or     (%rcx),%edx
mov    %rax,%r14
mov    0x2d52(%rip),%rax
or     (%rax),%edx
mov    %r13,-0x38(%rbp)
mov    %r13,%rdi
mov    %ebx,%esi
call   10b0 <open64@plt>
mov    %eax,%r13d
test   %eax,%eax
mov    %r14,-0x48(%rbp)
js     138a <prep_file+0x1ea>
mov    %r13d,-0x30(%rbp)
mov    %r14,%rdi
mov    $0x61,%esi
mov    -0x40(%rbp),%rdx
call   1060 <memset@plt>
mov    0x2d4f(%rip),%rax
mov    (%rax),%esi
lea    0xd83(%rip),%rdx
mov    %r15,%rdi
mov    -0x38(%rbp),%rcx
call   1050 <snprintf@plt>
mov    0x2d03(%rip),%rax
mov    (%rax),%edx
mov    0x2cc2(%rip),%rax
or     (%rax),%edx
mov    0x2d01(%rip),%rax
or     (%rax),%edx
mov    0x2cb8(%rip),%rax
or     (%rax),%edx
mov    0x2c8f(%rip),%rax
or     (%rax),%edx
mov    0x2cee(%rip),%rax
or     (%rax),%edx
mov    0x2ca5(%rip),%rax
or     (%rax),%edx
mov    0x2ccc(%rip),%rax
or     (%rax),%edx
mov    0x2cb3(%rip),%rax
or     (%rax),%edx
mov    %r15,%rdi
mov    %ebx,%esi
call   10b0 <open64@plt>
mov    %eax,%r14d
test   %eax,%eax
mov    %r15,%r13
js     13d1 <prep_file+0x231>
cmpl   $0x0,-0x2c(%rbp)
je     141b <prep_file+0x27b>
test   %r12,%r12
je     142c <prep_file+0x28c>
mov    %r14d,-0x2c(%rbp)
mov    %r13,%r15
xor    %r13d,%r13d
nopl   0x0(%rax)
mov    -0x40(%rbp),%rcx
lea    (%rcx,%r13,1),%rax
mov    %r12,%r14
sub    %r13,%r14
cmp    %r12,%rax
cmovbe %rcx,%r14
mov    -0x30(%rbp),%edi
mov    -0x48(%rbp),%rbx
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %r13,%rcx
call   10a0 <pwrite@plt>
test   %eax,%eax
js     1434 <prep_file+0x294>
mov    -0x2c(%rbp),%edi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %r13,%rcx
call   10a0 <pwrite@plt>
test   %eax,%eax
js     145e <prep_file+0x2be>
mov    %eax,%ebx
add    %r14,%r13
cmp    %r12,%r13
jb     1330 <prep_file+0x190>
jmp    1495 <prep_file+0x2f5>
mov    0x2bff(%rip),%rax
mov    (%rax),%r15d
mov    0x2bfd(%rip),%rax
mov    (%rax),%r14d
movslq %r15d,%rbx
mov    %ebx,%edi
call   10c0 <strerror@plt>
lea    0xc51(%rip),%rsi
mov    %r14d,%edi
mov    -0x38(%rbp),%rdx
mov    %rbx,%rcx
mov    %rax,%r8
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0xffffffff,%r14d
mov    %r13d,%ebx
jmp    149d <prep_file+0x2fd>
mov    0x2bb8(%rip),%rax
mov    (%rax),%r15d
mov    0x2bb6(%rip),%rax
mov    %r14d,%r12d
mov    (%rax),%r14d
movslq %r15d,%rbx
mov    %ebx,%edi
call   10c0 <strerror@plt>
lea    0xc07(%rip),%rsi
mov    %r14d,%edi
mov    %r13,%rdx
mov    %rbx,%rcx
mov    %rax,%r8
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %r12d,%ebx
mov    %r15d,%r14d
mov    -0x30(%rbp),%r15d
jmp    149d <prep_file+0x2fd>
mov    %r13,%rdi
call   1040 <unlink@plt>
test   %r12,%r12
jne    1322 <prep_file+0x182>
xor    %ebx,%ebx
mov    -0x30(%rbp),%r15d
jmp    149d <prep_file+0x2fd>
mov    0x2b55(%rip),%rax
mov    (%rax),%ebx
mov    0x2b54(%rip),%rax
mov    (%rax),%r14d
mov    %ebx,%edi
call   10c0 <strerror@plt>
lea    0xbd4(%rip),%rsi
mov    %r14d,%edi
mov    -0x38(%rbp),%rdx
jmp    1485 <prep_file+0x2e5>
mov    0x2b2b(%rip),%rax
mov    (%rax),%ebx
mov    0x2b2a(%rip),%rax
mov    (%rax),%r14d
mov    %ebx,%edi
call   10c0 <strerror@plt>
lea    0xbaa(%rip),%rsi
mov    %r14d,%edi
mov    %r15,%rdx
mov    %r13,%rcx
mov    %ebx,%r8d
mov    %rax,%r9
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    -0x30(%rbp),%r15d
mov    -0x2c(%rbp),%r14d
mov    -0x48(%rbp),%rdi
test   %rdi,%rdi
je     14ab <prep_file+0x30b>
call   1030 <free@plt>
test   %r14d,%r14d
jle    14b8 <prep_file+0x318>
mov    %r14d,%edi
call   1070 <close@plt>
test   %r15d,%r15d
jle    14c5 <prep_file+0x325>
mov    %r15d,%edi
call   1070 <close@plt>
mov    %ebx,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@O_APPEND = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IXUSR = global i32 0
@S_IROTH = global i32 0
@S_IWOTH = global i32 0
@S_IXOTH = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@S_IXGRP = global i32 0
@errno = global i32 0
@stderr = global i32 0
@.str = [29 x i8] c"create file %s failed:%d:%s\0A\00"
@.str.1 = [12 x i8] c"%s-tmp-file\00"
@.str.2 = [35 x i8] c"pwrite on %s failed at %llu:%d:%s\0A\00"
define i32 @prep_file(i8* %0, i64 %1, i64 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i64
%13 = alloca i64
%14 = alloca i8*
%15 = alloca i64
%16 = alloca i8*
%17 = alloca i32
store i8* %0, i8** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
store i32 %3, i32* %8
store i32 -1, i32* %9
store i32 -1, i32* %10
store i32 0, i32* %11
store i64 0, i64* %12
store i64 0, i64* %13
%18 = load i32, i32* @PATH_MAX
%19 = zext i32 %18 to i64
%20 = call i8* @llvm.stacksave()
store i8* %20, i8** %14
%21 = alloca i8, i64 %19
store i64 %19, i64* %15
store i8* null, i8** %16
%22 = load i32, i32* @O_CREAT
%23 = load i32, i32* @O_RDWR
%24 = or i32 %22, %23
%25 = load i32, i32* @O_APPEND
%26 = or i32 %24, %25
%27 = load i32, i32* @O_TRUNC
%28 = or i32 %26, %27
store i32 %28, i32* %17
%29 = load i64, i64* %7
%30 = call i64 @malloc(i64 %29)
%31 = inttoptr i64 %30 to i8*
store i8* %31, i8** %16
%32 = load i8*, i8** %5
%33 = load i32, i32* %17
%34 = load i32, i32* @S_IRUSR
%35 = load i32, i32* @S_IWUSR
%36 = or i32 %34, %35
%37 = load i32, i32* @S_IXUSR
%38 = or i32 %36, %37
%39 = load i32, i32* @S_IROTH
%40 = or i32 %38, %39
%41 = load i32, i32* @S_IWOTH
%42 = or i32 %40, %41
%43 = load i32, i32* @S_IXOTH
%44 = or i32 %42, %43
%45 = load i32, i32* @S_IRGRP
%46 = or i32 %44, %45
%47 = load i32, i32* @S_IWGRP
%48 = or i32 %46, %47
%49 = load i32, i32* @S_IXGRP
%50 = or i32 %48, %49
%51 = call i32 @open64(i8* %32, i32 %33, i32 %50)
store i32 %51, i32* %9
%52 = load i32, i32* %9
%53 = icmp slt i32 %52, 0
br i1 %53, label %54, label %64
54: ; preds = %4
%55 = load i32, i32* %9
store i32 %55, i32* %11
%56 = load i32, i32* @errno
store i32 %56, i32* %9
%57 = load i32, i32* @stderr
%58 = load i8*, i8** %5
%59 = load i32, i32* %9
%60 = sext i32 %59 to i64
%61 = load i32, i32* %9
%62 = call i8* @strerror(i32 %61)
%63 = call i32 (i32, i8*, i8*, i64, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %58, i64 %60, i8* %62)
br label %161
64: ; preds = %4
%65 = load i8*, i8** %16
%66 = load i64, i64* %7
%67 = call i32 @memset(i8* %65, i8 signext 97, i64 %66)
%68 = load i32, i32* @PATH_MAX
%69 = load i8*, i8** %5
%70 = call i32 @snprintf(i8* %21, i32 %68, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %69)
%71 = load i32, i32* %17
%72 = load i32, i32* @S_IRUSR
%73 = load i32, i32* @S_IWUSR
%74 = or i32 %72, %73
%75 = load i32, i32* @S_IXUSR
%76 = or i32 %74, %75
%77 = load i32, i32* @S_IROTH
%78 = or i32 %76, %77
%79 = load i32, i32* @S_IWOTH
%80 = or i32 %78, %79
%81 = load i32, i32* @S_IXOTH
%82 = or i32 %80, %81
%83 = load i32, i32* @S_IRGRP
%84 = or i32 %82, %83
%85 = load i32, i32* @S_IWGRP
%86 = or i32 %84, %85
%87 = load i32, i32* @S_IXGRP
%88 = or i32 %86, %87
%89 = call i32 @open64(i8* %21, i32 %71, i32 %88)
store i32 %89, i32* %10
%90 = load i32, i32* %10
%91 = icmp slt i32 %90, 0
br i1 %91, label %92, label %101
92: ; preds = %64
%93 = load i32, i32* %10
store i32 %93, i32* %11
%94 = load i32, i32* @errno
store i32 %94, i32* %10
%95 = load i32, i32* @stderr
%96 = load i32, i32* %10
%97 = sext i32 %96 to i64
%98 = load i32, i32* %10
%99 = call i8* @strerror(i32 %98)
%100 = call i32 (i32, i8*, i8*, i64, ...) @fprintf(i32 %95, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %21, i64 %97, i8* %99)
br label %161
101: ; preds = %64
%102 = load i32, i32* %8
%103 = icmp ne i32 %102, 0
br i1 %103, label %106, label %104
104: ; preds = %101
%105 = call i32 @unlink(i8* %21)
br label %106
106: ; preds = %104, %101
br label %107
107: ; preds = %156, %106
%108 = load i64, i64* %12
%109 = load i64, i64* %6
%110 = icmp ult i64 %108, %109
br i1 %110, label %111, label %160
111: ; preds = %107
%112 = load i64, i64* %12
%113 = load i64, i64* %7
%114 = add i64 %112, %113
%115 = load i64, i64* %6
%116 = icmp ugt i64 %114, %115
br i1 %116, label %117, label %121
117: ; preds = %111
%118 = load i64, i64* %6
%119 = load i64, i64* %12
%120 = sub i64 %118, %119
store i64 %120, i64* %13
br label %123
121: ; preds = %111
%122 = load i64, i64* %7
store i64 %122, i64* %13
br label %123
123: ; preds = %121, %117
%124 = load i32, i32* %9
%125 = load i8*, i8** %16
%126 = load i64, i64* %13
%127 = load i64, i64* %12
%128 = call i32 @pwrite(i32 %124, i8* %125, i64 %126, i64 %127)
store i32 %128, i32* %11
%129 = load i32, i32* %11
%130 = icmp slt i32 %129, 0
br i1 %130, label %131, label %140
131: ; preds = %123
%132 = load i32, i32* @errno
store i32 %132, i32* %11
%133 = load i32, i32* @stderr
%134 = load i8*, i8** %5
%135 = load i64, i64* %12
%136 = load i32, i32* %11
%137 = load i32, i32* %11
%138 = call i8* @strerror(i32 %137)
%139 = call i32 (i32, i8*, i8*, i64, ...) @fprintf(i32 %133, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %134, i64 %135, i32 %136, i8* %138)
br label %161
140: ; preds = %123
%141 = load i32, i32* %10
%142 = load i8*, i8** %16
%143 = load i64, i64* %13
%144 = load i64, i64* %12
%145 = call i32 @pwrite(i32 %141, i8* %142, i64 %143, i64 %144)
store i32 %145, i32* %11
%146 = load i32, i32* %11
%147 = icmp slt i32 %146, 0
br i1 %147, label %148, label %156
148: ; preds = %140
%149 = load i32, i32* @errno
store i32 %149, i32* %11
%150 = load i32, i32* @stderr
%151 = load i64, i64* %12
%152 = load i32, i32* %11
%153 = load i32, i32* %11
%154 = call i8* @strerror(i32 %153)
%155 = call i32 (i32, i8*, i8*, i64, ...) @fprintf(i32 %150, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %21, i64 %151, i32 %152, i8* %154)
br label %161
156: ; preds = %140
%157 = load i64, i64* %13
%158 = load i64, i64* %12
%159 = add i64 %158, %157
store i64 %159, i64* %12
br label %107
160: ; preds = %107
br label %161
161: ; preds = %160, %148, %131, %92, %54
%162 = load i8*, i8** %16
%163 = icmp ne i8* %162, null
br i1 %163, label %164, label %167
164: ; preds = %161
%165 = load i8*, i8** %16
%166 = call i32 @free(i8* %165)
br label %167
167: ; preds = %164, %161
%168 = load i32, i32* %10
%169 = icmp sgt i32 %168, 0
br i1 %169, label %170, label %173
170: ; preds = %167
%171 = load i32, i32* %10
%172 = call i32 @close(i32 %171)
br label %173
173: ; preds = %170, %167
%174 = load i32, i32* %9
%175 = icmp sgt i32 %174, 0
br i1 %175, label %176, label %179
176: ; preds = %173
%177 = load i32, i32* %9
%178 = call i32 @close(i32 %177)
br label %179
179: ; preds = %176, %173
%180 = load i32, i32* %11
%181 = load i8*, i8** %14
ret i32 %180
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@O_APPEND = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IXUSR = global i32 0
@S_IROTH = global i32 0
@S_IWOTH = global i32 0
@S_IXOTH = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@S_IXGRP = global i32 0
@errno = global i32 0
@stderr = global i32 0
@.str = [29 x i8] c"create file %s failed:%d:%s\0A\00"
@.str.1 = [12 x i8] c"%s-tmp-file\00"
@.str.2 = [35 x i8] c"pwrite on %s failed at %llu:%d:%s\0A\00"
define i32 @prep_file(i8* %0, i64 %1, i64 %2, i32 %3) {
%5 = load i32, i32* @PATH_MAX
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = load i32, i32* @O_CREAT
%9 = load i32, i32* @O_RDWR
%10 = or i32 %9, %8
%11 = load i32, i32* @O_APPEND
%12 = or i32 %10, %11
%13 = load i32, i32* @O_TRUNC
%14 = or i32 %12, %13
%15 = tail call i64 @malloc(i64 %2)
%16 = inttoptr i64 %15 to i8*
%17 = load i32, i32* @S_IRUSR
%18 = load i32, i32* @S_IWUSR
%19 = or i32 %18, %17
%20 = load i32, i32* @S_IXUSR
%21 = or i32 %19, %20
%22 = load i32, i32* @S_IROTH
%23 = or i32 %21, %22
%24 = load i32, i32* @S_IWOTH
%25 = or i32 %23, %24
%26 = load i32, i32* @S_IXOTH
%27 = or i32 %25, %26
%28 = load i32, i32* @S_IRGRP
%29 = or i32 %27, %28
%30 = load i32, i32* @S_IWGRP
%31 = or i32 %29, %30
%32 = load i32, i32* @S_IXGRP
%33 = or i32 %31, %32
%34 = tail call i32 @open64(i8* %0, i32 %14, i32 %33)
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %42
36: ; preds = %4
%37 = load i32, i32* @errno
%38 = load i32, i32* @stderr
%39 = sext i32 %37 to i64
%40 = tail call i8* @strerror(i32 %37)
%41 = tail call i32 (i32, i8*, i8*, i64, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %0, i64 %39, i8* %40)
br label %101
42: ; preds = %4
%43 = tail call i32 @memset(i8* %16, i8 signext 97, i64 %2)
%44 = load i32, i32* @PATH_MAX
%45 = call i32 @snprintf(i8* %7, i32 %44, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%46 = load i32, i32* @S_IRUSR
%47 = load i32, i32* @S_IWUSR
%48 = or i32 %47, %46
%49 = load i32, i32* @S_IXUSR
%50 = or i32 %48, %49
%51 = load i32, i32* @S_IROTH
%52 = or i32 %50, %51
%53 = load i32, i32* @S_IWOTH
%54 = or i32 %52, %53
%55 = load i32, i32* @S_IXOTH
%56 = or i32 %54, %55
%57 = load i32, i32* @S_IRGRP
%58 = or i32 %56, %57
%59 = load i32, i32* @S_IWGRP
%60 = or i32 %58, %59
%61 = load i32, i32* @S_IXGRP
%62 = or i32 %60, %61
%63 = call i32 @open64(i8* %7, i32 %14, i32 %62)
%64 = icmp slt i32 %63, 0
br i1 %64, label %65, label %71
65: ; preds = %42
%66 = load i32, i32* @errno
%67 = load i32, i32* @stderr
%68 = sext i32 %66 to i64
%69 = call i8* @strerror(i32 %66)
%70 = call i32 (i32, i8*, i8*, i64, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %7, i64 %68, i8* %69)
br label %101
71: ; preds = %42
%72 = icmp eq i32 %3, 0
br i1 %72, label %73, label %75
73: ; preds = %71
%74 = call i32 @unlink(i8* %7)
br label %75
75: ; preds = %73, %71
%76 = icmp eq i64 %1, 0
br i1 %76, label %101, label %79
77: ; preds = %92
%78 = icmp ult i64 %95, %1
br i1 %78, label %79, label %101
79: ; preds = %75, %77
%80 = phi i64 [ %95, %77 ], [ 0, %75 ]
%81 = add i64 %80, %2
%82 = icmp ugt i64 %81, %1
%83 = sub i64 %1, %80
%84 = select i1 %82, i64 %83, i64 %2
%85 = call i32 @pwrite(i32 %34, i8* %16, i64 %84, i64 %80)
%86 = icmp slt i32 %85, 0
br i1 %86, label %87, label %92
87: ; preds = %79
%88 = load i32, i32* @errno
%89 = load i32, i32* @stderr
%90 = call i8* @strerror(i32 %88)
%91 = call i32 (i32, i8*, i8*, i64, ...) @fprintf(i32 %89, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %0, i64 %80, i32 %88, i8* %90)
br label %101
92: ; preds = %79
%93 = call i32 @pwrite(i32 %63, i8* %16, i64 %84, i64 %80)
%94 = icmp slt i32 %93, 0
%95 = add i64 %84, %80
br i1 %94, label %96, label %77
96: ; preds = %92
%97 = load i32, i32* @errno
%98 = load i32, i32* @stderr
%99 = call i8* @strerror(i32 %97)
%100 = call i32 (i32, i8*, i8*, i64, ...) @fprintf(i32 %98, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %7, i64 %80, i32 %97, i8* %99)
br label %101
101: ; preds = %77, %75, %96, %87, %65, %36
%102 = phi i32 [ %34, %36 ], [ %63, %65 ], [ %88, %87 ], [ %97, %96 ], [ 0, %75 ], [ %93, %77 ]
%103 = phi i32 [ -1, %36 ], [ %66, %65 ], [ %63, %87 ], [ %63, %96 ], [ %63, %75 ], [ %63, %77 ]
%104 = phi i32 [ %37, %36 ], [ %34, %65 ], [ %34, %87 ], [ %34, %96 ], [ %34, %75 ], [ %34, %77 ]
%105 = icmp eq i64 %15, 0
br i1 %105, label %108, label %106
106: ; preds = %101
%107 = call i32 @free(i8* %16)
br label %108
108: ; preds = %106, %101
%109 = icmp sgt i32 %103, 0
br i1 %109, label %110, label %112
110: ; preds = %108
%111 = call i32 @close(i32 %103)
br label %112
112: ; preds = %110, %108
%113 = icmp sgt i32 %104, 0
br i1 %113, label %114, label %116
114: ; preds = %112
%115 = call i32 @close(i32 %104)
br label %116
116: ; preds = %114, %112
ret i32 %102
}