#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 stat {
  int /*<<< orphan*/ member_0;
};

/* Variables and functions */
int O_CREAT;
int O_RDWR;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int fdatasync(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fstat(int, struct stat *);
int fsync(int);
int ftruncate(int, int /*<<< orphan*/);
int lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int memcmp(char *, char *, int /*<<< orphan*/);
int open(char *, int, int);
int read(int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int unlink(char *);
int write(int, char *, int /*<<< orphan*/);
int fd_based_fops_1(char *filename) {
  int fd = 0;
  int ret = -1;
  int result = 0;
  struct stat stbuf = {
      0,
  };
  char wstr[50] = {
      0,
  };
  char rstr[50] = {
      0,
  };
  fd = open(filename, O_RDWR | O_CREAT, 0666);
  if (fd < 0) {
    fprintf(stderr, "open failed : %s\n", strerror(errno));
    return ret;
  }
  ret = unlink(filename);
  if (ret < 0) {
    fprintf(stderr, "unlink failed : %s\n", strerror(errno));
    result |= ret;
  }
  strcpy(wstr, "This is my string\n");
  ret = write(fd, wstr, strlen(wstr));
  if (ret <= 0) {
    fprintf(stderr, "write failed: %s\n", strerror(errno));
    result |= ret;
  }
  ret = lseek(fd, 0, SEEK_SET);
  if (ret < 0) {
    fprintf(stderr, "lseek failed: %s\n", strerror(errno));
    result |= ret;
  }
  ret = read(fd, rstr, strlen(wstr));
  if (ret <= 0) {
    fprintf(stderr, "read failed: %s\n", strerror(errno));
    result |= ret;
  }
  ret = memcmp(rstr, wstr, strlen(wstr));
  if (ret != 0) {
    fprintf(stderr, "read returning junk\n");
    result |= ret;
  }
  ret = ftruncate(fd, 0);
  if (ret < 0) {
    fprintf(stderr, "ftruncate failed : %s\n", strerror(errno));
    result |= ret;
  }
  ret = fstat(fd, &stbuf);
  if (ret < 0) {
    fprintf(stderr, "fstat failed : %s\n", strerror(errno));
    result |= ret;
  }
  ret = fsync(fd);
  if (ret < 0) {
    fprintf(stderr, "fsync failed : %s\n", strerror(errno));
    result |= ret;
  }
  ret = fdatasync(fd);
  if (ret < 0) {
    fprintf(stderr, "fdatasync failed : %s\n", strerror(errno));
    result |= ret;
  }
  if (fd)
    close(fd);
  return result;
}


x86 assembly (clang, -O0):
<fd_based_fops_1>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0xffffffff,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   10a0 <memset@plt>
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x32,%edx
call   10a0 <memset@plt>
lea    -0xa0(%rbp),%rdi
xor    %esi,%esi
mov    $0x32,%edx
call   10a0 <memset@plt>
mov    -0x10(%rbp),%rdi
mov    0x2d7e(%rip),%rax
mov    (%rax),%esi
mov    0x2d8d(%rip),%rax
or     (%rax),%esi
mov    $0x1b6,%edx
call   1100 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    12c3 <fd_based_fops_1+0xc3>
mov    0x2d45(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xa4(%rbp)
mov    0x2d2e(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0xa4(%rbp),%edi
mov    %rax,%rdx
lea    0xd4f(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1646 <fd_based_fops_1+0x446>
mov    -0x10(%rbp),%rdi
call   1040 <unlink@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1316 <fd_based_fops_1+0x116>
mov    0x2cf0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xa8(%rbp)
mov    0x2cd9(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0xa8(%rbp),%edi
mov    %rax,%rdx
lea    0xd0c(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
mov    -0x18(%rbp),%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
lea    -0x60(%rbp),%rdi
lea    0xd05(%rip),%rsi
call   1050 <strcpy@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0xb4(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0xb0(%rbp)
lea    -0x60(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0xb4(%rbp),%edi
mov    -0xb0(%rbp),%rsi
mov    %eax,%edx
call   1060 <write@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jg     13a1 <fd_based_fops_1+0x1a1>
mov    0x2c65(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xb8(%rbp)
mov    0x2c4e(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0xb8(%rbp),%edi
mov    %rax,%rdx
lea    0xca8(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
mov    -0x18(%rbp),%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2c15(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <lseek@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    13fe <fd_based_fops_1+0x1fe>
mov    0x2c08(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xbc(%rbp)
mov    0x2bf1(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0xbc(%rbp),%edi
mov    %rax,%rdx
lea    0xc5d(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
mov    -0x18(%rbp),%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0xcc(%rbp)
lea    -0xa0(%rbp),%rax
mov    %rax,-0xc8(%rbp)
lea    -0x60(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0xcc(%rbp),%edi
mov    -0xc8(%rbp),%rsi
mov    %eax,%edx
call   10c0 <read@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jg     147c <fd_based_fops_1+0x27c>
mov    0x2b8a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xd0(%rbp)
mov    0x2b73(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0xd0(%rbp),%edi
mov    %rax,%rdx
lea    0xbf1(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
mov    -0x18(%rbp),%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
lea    -0xa0(%rbp),%rax
mov    %rax,-0xe0(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0xd8(%rbp)
lea    -0x60(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0xe0(%rbp),%rdi
mov    -0xd8(%rbp),%rsi
mov    %eax,%edx
call   10d0 <memcmp@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     14e0 <fd_based_fops_1+0x2e0>
mov    0x2b09(%rip),%rax
mov    (%rax),%edi
lea    0xb9e(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
mov    -0x18(%rbp),%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   1080 <ftruncate@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1534 <fd_based_fops_1+0x334>
mov    0x2ad2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xe4(%rbp)
mov    0x2abb(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0xe4(%rbp),%edi
mov    %rax,%rdx
lea    0xb5f(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
mov    -0x18(%rbp),%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1120 <fstat@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    158a <fd_based_fops_1+0x38a>
mov    0x2a7c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xe8(%rbp)
mov    0x2a65(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0xe8(%rbp),%edi
mov    %rax,%rdx
lea    0xb20(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
mov    -0x18(%rbp),%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
call   10f0 <fsync@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    15dc <fd_based_fops_1+0x3dc>
mov    0x2a2a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xec(%rbp)
mov    0x2a13(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0xec(%rbp),%edi
mov    %rax,%rdx
lea    0xae1(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
mov    -0x18(%rbp),%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <fdatasync@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    162e <fd_based_fops_1+0x42e>
mov    0x29d8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xf0(%rbp)
mov    0x29c1(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0xf0(%rbp),%edi
mov    %rax,%rdx
lea    0xaa2(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
mov    -0x18(%rbp),%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1640 <fd_based_fops_1+0x440>
mov    -0x14(%rbp),%edi
call   10b0 <close@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fd_based_fops_1>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x88,%rsp
mov    %rdi,%rbp
movl   $0x0,0x8(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movw   $0x0,0x40(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movw   $0x0,0x80(%rsp)
mov    0x2d9f(%rip),%rax
mov    0x2db0(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    $0x1b6,%edx
call   10f0 <open@plt>
test   %eax,%eax
js     1499 <fd_based_fops_1+0x2a9>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1040 <unlink@plt>
xor    %r14d,%r14d
test   %eax,%eax
jns    12a0 <fd_based_fops_1+0xb0>
mov    %eax,%ebp
mov    0x2d58(%rip),%rax
mov    (%rax),%r14d
mov    0x2d46(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xd82(%rip),%rsi
mov    %r14d,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    %ebp,%r14d
lea    0xd7f(%rip),%rsi
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
call   1050 <strcpy@plt>
mov    %rbp,%rdi
call   1070 <strlen@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1060 <write@plt>
test   %eax,%eax
jg     12fd <fd_based_fops_1+0x10d>
mov    %eax,%ebp
mov    0x2cfb(%rip),%rax
mov    (%rax),%r15d
mov    0x2ce9(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xd4c(%rip),%rsi
mov    %r15d,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10d0 <fprintf@plt>
or     %ebp,%r14d
mov    0x2cbc(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
xor    %esi,%esi
call   1090 <lseek@plt>
test   %eax,%eax
jns    1344 <fd_based_fops_1+0x154>
mov    %eax,%ebp
mov    0x2cb4(%rip),%rax
mov    (%rax),%r15d
mov    0x2ca2(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xd17(%rip),%rsi
mov    %r15d,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10d0 <fprintf@plt>
or     %ebp,%r14d
lea    0x10(%rsp),%rdi
call   1070 <strlen@plt>
lea    0x50(%rsp),%rsi
mov    %ebx,%edi
mov    %eax,%edx
call   10b0 <read@plt>
test   %eax,%eax
jg     1391 <fd_based_fops_1+0x1a1>
mov    %eax,%ebp
mov    0x2c67(%rip),%rax
mov    (%rax),%r15d
mov    0x2c55(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xcdc(%rip),%rsi
mov    %r15d,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10d0 <fprintf@plt>
or     %ebp,%r14d
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
call   1070 <strlen@plt>
lea    0x50(%rsp),%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   10c0 <memcmp@plt>
test   %eax,%eax
je     13cd <fd_based_fops_1+0x1dd>
mov    %eax,%ebp
mov    0x2c16(%rip),%rax
mov    (%rax),%edi
lea    0xcab(%rip),%rsi
xor    %eax,%eax
call   10d0 <fprintf@plt>
or     %ebp,%r14d
mov    %ebx,%edi
xor    %esi,%esi
call   1080 <ftruncate@plt>
test   %eax,%eax
jns    140b <fd_based_fops_1+0x21b>
mov    %eax,%ebp
mov    0x2bed(%rip),%rax
mov    (%rax),%r15d
mov    0x2bdb(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xc88(%rip),%rsi
mov    %r15d,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10d0 <fprintf@plt>
or     %ebp,%r14d
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
call   1110 <fstat@plt>
test   %eax,%eax
jns    144c <fd_based_fops_1+0x25c>
mov    %eax,%ebp
mov    0x2bac(%rip),%rax
mov    (%rax),%r15d
mov    0x2b9a(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xc5e(%rip),%rsi
mov    %r15d,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10d0 <fprintf@plt>
or     %ebp,%r14d
mov    %ebx,%edi
call   10e0 <fsync@plt>
test   %eax,%eax
jns    1488 <fd_based_fops_1+0x298>
mov    %eax,%ebp
mov    0x2b70(%rip),%rax
mov    (%rax),%r15d
mov    0x2b5e(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xc35(%rip),%rsi
mov    %r15d,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10d0 <fprintf@plt>
or     %ebp,%r14d
mov    %ebx,%edi
call   1030 <fdatasync@plt>
test   %eax,%eax
js     14cb <fd_based_fops_1+0x2db>
test   %ebx,%ebx
jne    1500 <fd_based_fops_1+0x310>
jmp    1507 <fd_based_fops_1+0x317>
mov    0x2b30(%rip),%rax
mov    (%rax),%ebx
mov    0x2b1f(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xb49(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    $0xffffffff,%r14d
jmp    1507 <fd_based_fops_1+0x317>
mov    %eax,%ebp
mov    0x2afc(%rip),%rax
mov    (%rax),%r15d
mov    0x2aea(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
lea    0xbd4(%rip),%rsi
mov    %r15d,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10d0 <fprintf@plt>
or     %ebp,%r14d
test   %ebx,%ebx
je     1507 <fd_based_fops_1+0x317>
mov    %ebx,%edi
call   10a0 <close@plt>
mov    %r14d,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@stderr = global i32 0
@.str = [18 x i8] c"open failed : %s\0A\00"
@errno = global i32 0
@.str.1 = [20 x i8] c"unlink failed : %s\0A\00"
@.str.2 = [19 x i8] c"This is my string\0A\00"
@.str.3 = [18 x i8] c"write failed: %s\0A\00"
@SEEK_SET = global i32 0
@.str.4 = [18 x i8] c"lseek failed: %s\0A\00"
@.str.5 = [17 x i8] c"read failed: %s\0A\00"
@.str.6 = [21 x i8] c"read returning junk\0A\00"
@.str.7 = [23 x i8] c"ftruncate failed : %s\0A\00"
@.str.8 = [19 x i8] c"fstat failed : %s\0A\00"
@.str.9 = [19 x i8] c"fsync failed : %s\0A\00"
@.str.10 = [23 x i8] c"fdatasync failed : %s\0A\00"
define i32 @fd_based_fops_1(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.stat
%8 = alloca [50 x i8]
%9 = alloca [50 x i8]
store i8* %0, i8** %3
store i32 0, i32* %4
store i32 -1, i32* %5
store i32 0, i32* %6
%10 = bitcast %struct.stat* %7 to i8*
%11 = bitcast [50 x i8]* %8 to i8*
%12 = bitcast [50 x i8]* %9 to i8*
%13 = load i8*, i8** %3
%14 = load i32, i32* @O_RDWR
%15 = load i32, i32* @O_CREAT
%16 = or i32 %14, %15
%17 = call i32 @open(i8* %13, i32 %16, i32 438)
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %1
%21 = load i32, i32* @stderr
%22 = load i32, i32* @errno
%23 = call i8* @strerror(i32 %22)
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %23)
%25 = load i32, i32* %5
store i32 %25, i32* %2
br label %161
26: ; preds = %1
%27 = load i8*, i8** %3
%28 = call i32 @unlink(i8* %27)
store i32 %28, i32* %5
%29 = load i32, i32* %5
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %39
31: ; preds = %26
%32 = load i32, i32* @stderr
%33 = load i32, i32* @errno
%34 = call i8* @strerror(i32 %33)
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %34)
%36 = load i32, i32* %5
%37 = load i32, i32* %6
%38 = or i32 %37, %36
store i32 %38, i32* %6
br label %39
39: ; preds = %31, %26
%40 = getelementptr inbounds [50 x i8], [50 x i8]* %8, i64 0, i64 0
%41 = call i32 @strcpy(i8* %40, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%42 = load i32, i32* %4
%43 = getelementptr inbounds [50 x i8], [50 x i8]* %8, i64 0, i64 0
%44 = getelementptr inbounds [50 x i8], [50 x i8]* %8, i64 0, i64 0
%45 = call i32 @strlen(i8* %44)
%46 = call i32 @write(i32 %42, i8* %43, i32 %45)
store i32 %46, i32* %5
%47 = load i32, i32* %5
%48 = icmp sle i32 %47, 0
br i1 %48, label %49, label %57
49: ; preds = %39
%50 = load i32, i32* @stderr
%51 = load i32, i32* @errno
%52 = call i8* @strerror(i32 %51)
%53 = call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %52)
%54 = load i32, i32* %5
%55 = load i32, i32* %6
%56 = or i32 %55, %54
store i32 %56, i32* %6
br label %57
57: ; preds = %49, %39
%58 = load i32, i32* %4
%59 = load i32, i32* @SEEK_SET
%60 = call i32 @lseek(i32 %58, i32 0, i32 %59)
store i32 %60, i32* %5
%61 = load i32, i32* %5
%62 = icmp slt i32 %61, 0
br i1 %62, label %63, label %71
63: ; preds = %57
%64 = load i32, i32* @stderr
%65 = load i32, i32* @errno
%66 = call i8* @strerror(i32 %65)
%67 = call i32 (i32, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %66)
%68 = load i32, i32* %5
%69 = load i32, i32* %6
%70 = or i32 %69, %68
store i32 %70, i32* %6
br label %71
71: ; preds = %63, %57
%72 = load i32, i32* %4
%73 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%74 = getelementptr inbounds [50 x i8], [50 x i8]* %8, i64 0, i64 0
%75 = call i32 @strlen(i8* %74)
%76 = call i32 @read(i32 %72, i8* %73, i32 %75)
store i32 %76, i32* %5
%77 = load i32, i32* %5
%78 = icmp sle i32 %77, 0
br i1 %78, label %79, label %87
79: ; preds = %71
%80 = load i32, i32* @stderr
%81 = load i32, i32* @errno
%82 = call i8* @strerror(i32 %81)
%83 = call i32 (i32, i8*, ...) @fprintf(i32 %80, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* %82)
%84 = load i32, i32* %5
%85 = load i32, i32* %6
%86 = or i32 %85, %84
store i32 %86, i32* %6
br label %87
87: ; preds = %79, %71
%88 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%89 = getelementptr inbounds [50 x i8], [50 x i8]* %8, i64 0, i64 0
%90 = getelementptr inbounds [50 x i8], [50 x i8]* %8, i64 0, i64 0
%91 = call i32 @strlen(i8* %90)
%92 = call i32 @memcmp(i8* %88, i8* %89, i32 %91)
store i32 %92, i32* %5
%93 = load i32, i32* %5
%94 = icmp ne i32 %93, 0
br i1 %94, label %95, label %101
95: ; preds = %87
%96 = load i32, i32* @stderr
%97 = call i32 (i32, i8*, ...) @fprintf(i32 %96, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
%98 = load i32, i32* %5
%99 = load i32, i32* %6
%100 = or i32 %99, %98
store i32 %100, i32* %6
br label %101
101: ; preds = %95, %87
%102 = load i32, i32* %4
%103 = call i32 @ftruncate(i32 %102, i32 0)
store i32 %103, i32* %5
%104 = load i32, i32* %5
%105 = icmp slt i32 %104, 0
br i1 %105, label %106, label %114
106: ; preds = %101
%107 = load i32, i32* @stderr
%108 = load i32, i32* @errno
%109 = call i8* @strerror(i32 %108)
%110 = call i32 (i32, i8*, ...) @fprintf(i32 %107, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i8* %109)
%111 = load i32, i32* %5
%112 = load i32, i32* %6
%113 = or i32 %112, %111
store i32 %113, i32* %6
br label %114
114: ; preds = %106, %101
%115 = load i32, i32* %4
%116 = call i32 @fstat(i32 %115, %struct.stat* %7)
store i32 %116, i32* %5
%117 = load i32, i32* %5
%118 = icmp slt i32 %117, 0
br i1 %118, label %119, label %127
119: ; preds = %114
%120 = load i32, i32* @stderr
%121 = load i32, i32* @errno
%122 = call i8* @strerror(i32 %121)
%123 = call i32 (i32, i8*, ...) @fprintf(i32 %120, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0), i8* %122)
%124 = load i32, i32* %5
%125 = load i32, i32* %6
%126 = or i32 %125, %124
store i32 %126, i32* %6
br label %127
127: ; preds = %119, %114
%128 = load i32, i32* %4
%129 = call i32 @fsync(i32 %128)
store i32 %129, i32* %5
%130 = load i32, i32* %5
%131 = icmp slt i32 %130, 0
br i1 %131, label %132, label %140
132: ; preds = %127
%133 = load i32, i32* @stderr
%134 = load i32, i32* @errno
%135 = call i8* @strerror(i32 %134)
%136 = call i32 (i32, i8*, ...) @fprintf(i32 %133, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0), i8* %135)
%137 = load i32, i32* %5
%138 = load i32, i32* %6
%139 = or i32 %138, %137
store i32 %139, i32* %6
br label %140
140: ; preds = %132, %127
%141 = load i32, i32* %4
%142 = call i32 @fdatasync(i32 %141)
store i32 %142, i32* %5
%143 = load i32, i32* %5
%144 = icmp slt i32 %143, 0
br i1 %144, label %145, label %153
145: ; preds = %140
%146 = load i32, i32* @stderr
%147 = load i32, i32* @errno
%148 = call i8* @strerror(i32 %147)
%149 = call i32 (i32, i8*, ...) @fprintf(i32 %146, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.10, i64 0, i64 0), i8* %148)
%150 = load i32, i32* %5
%151 = load i32, i32* %6
%152 = or i32 %151, %150
store i32 %152, i32* %6
br label %153
153: ; preds = %145, %140
%154 = load i32, i32* %4
%155 = icmp ne i32 %154, 0
br i1 %155, label %156, label %159
156: ; preds = %153
%157 = load i32, i32* %4
%158 = call i32 @close(i32 %157)
br label %159
159: ; preds = %156, %153
%160 = load i32, i32* %6
store i32 %160, i32* %2
br label %161
161: ; preds = %159, %20
%162 = load i32, i32* %2
ret i32 %162
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@stderr = global i32 0
@.str = [18 x i8] c"open failed : %s\0A\00"
@errno = global i32 0
@.str.1 = [20 x i8] c"unlink failed : %s\0A\00"
@.str.2 = [19 x i8] c"This is my string\0A\00"
@.str.3 = [18 x i8] c"write failed: %s\0A\00"
@SEEK_SET = global i32 0
@.str.4 = [18 x i8] c"lseek failed: %s\0A\00"
@.str.5 = [17 x i8] c"read failed: %s\0A\00"
@.str.6 = [21 x i8] c"read returning junk\0A\00"
@.str.7 = [23 x i8] c"ftruncate failed : %s\0A\00"
@.str.8 = [19 x i8] c"fstat failed : %s\0A\00"
@.str.9 = [19 x i8] c"fsync failed : %s\0A\00"
@.str.10 = [23 x i8] c"fdatasync failed : %s\0A\00"
define i32 @fd_based_fops_1(i8* nocapture %0) {
%2 = alloca %struct.stat
%3 = alloca [50 x i8]
%4 = alloca [50 x i8]
%5 = bitcast %struct.stat* %2 to i8*
%6 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
store i32 0, i32* %6
%7 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%9 = load i32, i32* @O_RDWR
%10 = load i32, i32* @O_CREAT
%11 = or i32 %10, %9
%12 = tail call i32 @open(i8* %0, i32 %11, i32 438)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %1
%15 = load i32, i32* @stderr
%16 = load i32, i32* @errno
%17 = tail call i8* @strerror(i32 %16)
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %17)
br label %115
19: ; preds = %1
%20 = tail call i32 @unlink(i8* %0)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %19
%23 = load i32, i32* @stderr
%24 = load i32, i32* @errno
%25 = tail call i8* @strerror(i32 %24)
%26 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %25)
br label %27
27: ; preds = %22, %19
%28 = phi i32 [ %20, %22 ], [ 0, %19 ]
%29 = call i32 @strcpy(i8* %7, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%30 = call i32 @strlen(i8* %7)
%31 = call i32 @write(i32 %12, i8* %7, i32 %30)
%32 = icmp slt i32 %31, 1
br i1 %32, label %33, label %39
33: ; preds = %27
%34 = load i32, i32* @stderr
%35 = load i32, i32* @errno
%36 = call i8* @strerror(i32 %35)
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %36)
%38 = or i32 %31, %28
br label %39
39: ; preds = %33, %27
%40 = phi i32 [ %38, %33 ], [ %28, %27 ]
%41 = load i32, i32* @SEEK_SET
%42 = call i32 @lseek(i32 %12, i32 0, i32 %41)
%43 = icmp slt i32 %42, 0
br i1 %43, label %44, label %50
44: ; preds = %39
%45 = load i32, i32* @stderr
%46 = load i32, i32* @errno
%47 = call i8* @strerror(i32 %46)
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %47)
%49 = or i32 %42, %40
br label %50
50: ; preds = %44, %39
%51 = phi i32 [ %49, %44 ], [ %40, %39 ]
%52 = call i32 @strlen(i8* %7)
%53 = call i32 @read(i32 %12, i8* %8, i32 %52)
%54 = icmp slt i32 %53, 1
br i1 %54, label %55, label %61
55: ; preds = %50
%56 = load i32, i32* @stderr
%57 = load i32, i32* @errno
%58 = call i8* @strerror(i32 %57)
%59 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* %58)
%60 = or i32 %53, %51
br label %61
61: ; preds = %55, %50
%62 = phi i32 [ %60, %55 ], [ %51, %50 ]
%63 = call i32 @strlen(i8* %7)
%64 = call i32 @memcmp(i8* %8, i8* %7, i32 %63)
%65 = icmp eq i32 %64, 0
br i1 %65, label %70, label %66
66: ; preds = %61
%67 = load i32, i32* @stderr
%68 = call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
%69 = or i32 %64, %62
br label %70
70: ; preds = %66, %61
%71 = phi i32 [ %69, %66 ], [ %62, %61 ]
%72 = call i32 @ftruncate(i32 %12, i32 0)
%73 = icmp slt i32 %72, 0
br i1 %73, label %74, label %80
74: ; preds = %70
%75 = load i32, i32* @stderr
%76 = load i32, i32* @errno
%77 = call i8* @strerror(i32 %76)
%78 = call i32 (i32, i8*, ...) @fprintf(i32 %75, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i8* %77)
%79 = or i32 %72, %71
br label %80
80: ; preds = %74, %70
%81 = phi i32 [ %79, %74 ], [ %71, %70 ]
%82 = call i32 @fstat(i32 %12, %struct.stat* %2)
%83 = icmp slt i32 %82, 0
br i1 %83, label %84, label %90
84: ; preds = %80
%85 = load i32, i32* @stderr
%86 = load i32, i32* @errno
%87 = call i8* @strerror(i32 %86)
%88 = call i32 (i32, i8*, ...) @fprintf(i32 %85, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0), i8* %87)
%89 = or i32 %82, %81
br label %90
90: ; preds = %84, %80
%91 = phi i32 [ %89, %84 ], [ %81, %80 ]
%92 = call i32 @fsync(i32 %12)
%93 = icmp slt i32 %92, 0
br i1 %93, label %94, label %100
94: ; preds = %90
%95 = load i32, i32* @stderr
%96 = load i32, i32* @errno
%97 = call i8* @strerror(i32 %96)
%98 = call i32 (i32, i8*, ...) @fprintf(i32 %95, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0), i8* %97)
%99 = or i32 %92, %91
br label %100
100: ; preds = %94, %90
%101 = phi i32 [ %99, %94 ], [ %91, %90 ]
%102 = call i32 @fdatasync(i32 %12)
%103 = icmp slt i32 %102, 0
br i1 %103, label %104, label %110
104: ; preds = %100
%105 = load i32, i32* @stderr
%106 = load i32, i32* @errno
%107 = call i8* @strerror(i32 %106)
%108 = call i32 (i32, i8*, ...) @fprintf(i32 %105, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.10, i64 0, i64 0), i8* %107)
%109 = or i32 %102, %101
br label %110
110: ; preds = %104, %100
%111 = phi i32 [ %109, %104 ], [ %101, %100 ]
%112 = icmp eq i32 %12, 0
br i1 %112, label %115, label %113
113: ; preds = %110
%114 = call i32 @close(i32 %12)
br label %115
115: ; preds = %110, %113, %14
%116 = phi i32 [ -1, %14 ], [ %111, %113 ], [ %111, %110 ]
ret i32 %116
}