#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 st_size;
  int /*<<< orphan*/ st_mode;
};
typedef int mode_t;

/* Variables and functions */
int EXIT_FAILURE;
int O_CREAT;
int O_RDWR;
int /*<<< orphan*/ SEEK_SET;
int S_IRWXG;
int S_IRWXO;
int S_IRWXU;
int /*<<< orphan*/ S_ISREG(int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int fstat(int, struct stat *);
int lseek(int, int, int /*<<< orphan*/);
int open(char *, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int write(int, char *, int);
int ipc_open(char *fname, int size) {
  int fd;
  struct stat sb;
  mode_t mode = S_IRWXO | S_IRWXG | S_IRWXU;
  int result;
  fd = open(fname, O_RDWR | O_CREAT, mode);
  if (fd == -1)
    do {
      perror("open");
      exit(EXIT_FAILURE);
    } while (0);
  if (fstat(fd, &sb) == -1)
    do {
      perror("fstat");
      exit(EXIT_FAILURE);
    } while (0);
  if (!S_ISREG(sb.st_mode)) {
    fprintf(stderr, "%s is not a file\n", fname);
    exit(1);
  }
  if (sb.st_size < size) {
    result = lseek(fd, size - 1, SEEK_SET);
    if (result == -1) {
      close(fd);
      perror("Error calling lseek() to 'stretch' the file");
      exit(EXIT_FAILURE);
    }
    result = write(fd, "", 1);
    if (result != 1) {
      close(fd);
      perror("Error writing last byte of the file");
      exit(EXIT_FAILURE);
    }
    if (fstat(fd, &sb) == -1)
      do {
        perror("fstat");
        exit(EXIT_FAILURE);
      } while (0);
    if (!S_ISREG(sb.st_mode)) {
      fprintf(stderr, "%s is not a file\n", fname);
      exit(1);
    }
    close(fd);
    fd = open(fname, O_RDWR | O_CREAT, mode);
    if (fd == -1)
      do {
        perror("RDWR open");
        exit(EXIT_FAILURE);
      } while (0);
    if (fstat(fd, &sb) == -1)
      do {
        perror("RDWR fstat");
        exit(EXIT_FAILURE);
      } while (0);
    if (!S_ISREG(sb.st_mode)) {
      fprintf(stderr, "%s is not a file\n", fname);
      exit(1);
    }
    fd = open(fname, O_RDWR | O_CREAT, mode);
    if (fd == -1)
      do {
        perror("RDWR open");
        exit(EXIT_FAILURE);
      } while (0);
    if (fstat(fd, &sb) == -1)
      do {
        perror("RDWR fstat");
        exit(EXIT_FAILURE);
      } while (0);
    if (!S_ISREG(sb.st_mode)) {
      fprintf(stderr, "%s is not a file\n", fname);
      exit(1);
    }
  }
  return fd;
}


x86 assembly (clang, -O0):
<ipc_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0x2e42(%rip),%rax
mov    (%rax),%eax
mov    0x2e19(%rip),%rcx
or     (%rcx),%eax
mov    0x2e20(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e08(%rip),%rax
mov    (%rax),%esi
mov    0x2e27(%rip),%rax
or     (%rax),%esi
mov    -0x1c(%rbp),%edx
call   1080 <open@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    1207 <ipc_open+0x77>
jmp    11ed <ipc_open+0x5d>
lea    0xe73(%rip),%rdi
call   1090 <perror@plt>
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   10b0 <fstat@plt>
cmp    $0xffffffff,%eax
jne    123b <ipc_open+0xab>
jmp    1221 <ipc_open+0x91>
lea    0xe49(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d74(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x14(%rbp),%edi
call   1070 <S_ISREG@plt>
cmp    $0x0,%eax
jne    126f <ipc_open+0xdf>
mov    0x2d65(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xda0(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    14dd <ipc_open+0x34d>
mov    -0x10(%rbp),%edi
mov    -0xc(%rbp),%esi
sub    $0x1,%esi
mov    0x2d25(%rip),%rax
mov    (%rax),%edx
call   1040 <lseek@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    12c1 <ipc_open+0x131>
mov    -0x10(%rbp),%edi
call   1050 <close@plt>
lea    0xd64(%rip),%rdi
call   1090 <perror@plt>
mov    0x2cee(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%edi
lea    0xd46(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x1,-0x20(%rbp)
je     1304 <ipc_open+0x174>
mov    -0x10(%rbp),%edi
call   1050 <close@plt>
lea    0xd4d(%rip),%rdi
call   1090 <perror@plt>
mov    0x2cab(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   10b0 <fstat@plt>
cmp    $0xffffffff,%eax
jne    1338 <ipc_open+0x1a8>
jmp    131e <ipc_open+0x18e>
lea    0xd4c(%rip),%rdi
call   1090 <perror@plt>
mov    0x2c77(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x14(%rbp),%edi
call   1070 <S_ISREG@plt>
cmp    $0x0,%eax
jne    136c <ipc_open+0x1dc>
mov    0x2c68(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xca3(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%edi
call   1050 <close@plt>
mov    -0x8(%rbp),%rdi
mov    0x2c51(%rip),%rax
mov    (%rax),%esi
mov    0x2c70(%rip),%rax
or     (%rax),%esi
mov    -0x1c(%rbp),%edx
call   1080 <open@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    13be <ipc_open+0x22e>
jmp    13a4 <ipc_open+0x214>
lea    0xcb7(%rip),%rdi
call   1090 <perror@plt>
mov    0x2bf1(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   10b0 <fstat@plt>
cmp    $0xffffffff,%eax
jne    13f2 <ipc_open+0x262>
jmp    13d8 <ipc_open+0x248>
lea    0xc8d(%rip),%rdi
call   1090 <perror@plt>
mov    0x2bbd(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x14(%rbp),%edi
call   1070 <S_ISREG@plt>
cmp    $0x0,%eax
jne    1426 <ipc_open+0x296>
mov    0x2bae(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xbe9(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%rdi
mov    0x2b9f(%rip),%rax
mov    (%rax),%esi
mov    0x2bbe(%rip),%rax
or     (%rax),%esi
mov    -0x1c(%rbp),%edx
call   1080 <open@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    1470 <ipc_open+0x2e0>
jmp    1456 <ipc_open+0x2c6>
lea    0xc05(%rip),%rdi
call   1090 <perror@plt>
mov    0x2b3f(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   10b0 <fstat@plt>
cmp    $0xffffffff,%eax
jne    14a4 <ipc_open+0x314>
jmp    148a <ipc_open+0x2fa>
lea    0xbdb(%rip),%rdi
call   1090 <perror@plt>
mov    0x2b0b(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x14(%rbp),%edi
call   1070 <S_ISREG@plt>
cmp    $0x0,%eax
jne    14d8 <ipc_open+0x348>
mov    0x2afc(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xb37(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    14dd <ipc_open+0x34d>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ipc_open>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%r14
mov    0x2e41(%rip),%rax
mov    0x2e1a(%rip),%rcx
mov    (%rcx),%r15d
or     (%rax),%r15d
mov    0x2e1d(%rip),%rax
or     (%rax),%r15d
mov    0x2e0b(%rip),%r12
mov    0x2e2c(%rip),%r13
mov    0x0(%r13),%esi
or     (%r12),%esi
mov    %r15d,%edx
call   1080 <open@plt>
cmp    $0xffffffff,%eax
je     1327 <ipc_open+0x197>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
call   10b0 <fstat@plt>
cmp    $0xffffffff,%eax
je     131e <ipc_open+0x18e>
mov    0x4(%rsp),%edi
call   1070 <S_ISREG@plt>
test   %eax,%eax
je     12fc <ipc_open+0x16c>
cmp    %ebp,(%rsp)
jge    12eb <ipc_open+0x15b>
add    $0xffffffff,%ebp
mov    0x2d92(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    %ebp,%esi
call   1040 <lseek@plt>
cmp    $0xffffffff,%eax
je     1342 <ipc_open+0x1b2>
lea    0xdd8(%rip),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
jne    1352 <ipc_open+0x1c2>
mov    %rsp,%rsi
mov    %ebx,%edi
call   10b0 <fstat@plt>
cmp    $0xffffffff,%eax
je     131e <ipc_open+0x18e>
mov    0x4(%rsp),%edi
call   1070 <S_ISREG@plt>
test   %eax,%eax
je     12fc <ipc_open+0x16c>
mov    %ebx,%edi
call   1050 <close@plt>
mov    0x0(%r13),%esi
or     (%r12),%esi
mov    %r14,%rdi
mov    %r15d,%edx
call   1080 <open@plt>
cmp    $0xffffffff,%eax
je     1330 <ipc_open+0x1a0>
mov    %rsp,%rsi
mov    %eax,%edi
call   10b0 <fstat@plt>
cmp    $0xffffffff,%eax
je     1339 <ipc_open+0x1a9>
mov    0x4(%rsp),%edi
call   1070 <S_ISREG@plt>
test   %eax,%eax
je     12fc <ipc_open+0x16c>
mov    0x0(%r13),%esi
or     (%r12),%esi
mov    %r14,%rdi
mov    %r15d,%edx
call   1080 <open@plt>
cmp    $0xffffffff,%eax
je     1330 <ipc_open+0x1a0>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
call   10b0 <fstat@plt>
cmp    $0xffffffff,%eax
je     1339 <ipc_open+0x1a9>
mov    0x4(%rsp),%edi
call   1070 <S_ISREG@plt>
test   %eax,%eax
je     12fc <ipc_open+0x16c>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cb5(%rip),%rax
mov    (%rax),%edi
lea    0xcf4(%rip),%rsi
mov    %r14,%rdx
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xd4c(%rip),%rdi
jmp    1360 <ipc_open+0x1d0>
lea    0xd39(%rip),%rdi
jmp    1360 <ipc_open+0x1d0>
lea    0xd2b(%rip),%rdi
jmp    1360 <ipc_open+0x1d0>
lea    0xd2c(%rip),%rdi
jmp    1360 <ipc_open+0x1d0>
mov    %ebx,%edi
call   1050 <close@plt>
lea    0xcc2(%rip),%rdi
jmp    1360 <ipc_open+0x1d0>
mov    %ebx,%edi
call   1050 <close@plt>
lea    0xcde(%rip),%rdi
call   1090 <perror@plt>
mov    0x2c3c(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32, i32 }
@S_IRWXO = global i32 0
@S_IRWXG = global i32 0
@S_IRWXU = global i32 0
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str = [5 x i8] c"open\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [6 x i8] c"fstat\00"
@stderr = global i32 0
@.str.2 = [18 x i8] c"%s is not a file\0A\00"
@SEEK_SET = global i32 0
@.str.3 = [44 x i8] c"Error calling lseek() to 'stretch' the file\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [36 x i8] c"Error writing last byte of the file\00"
@.str.6 = [10 x i8] c"RDWR open\00"
@.str.7 = [11 x i8] c"RDWR fstat\00"
define i32 @ipc_open(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.stat
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%9 = load i32, i32* @S_IRWXO
%10 = load i32, i32* @S_IRWXG
%11 = or i32 %9, %10
%12 = load i32, i32* @S_IRWXU
%13 = or i32 %11, %12
store i32 %13, i32* %7
%14 = load i8*, i8** %3
%15 = load i32, i32* @O_RDWR
%16 = load i32, i32* @O_CREAT
%17 = or i32 %15, %16
%18 = load i32, i32* %7
%19 = call i32 @open(i8* %14, i32 %17, i32 %18)
store i32 %19, i32* %5
%20 = load i32, i32* %5
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %28
22: ; preds = %2
br label %23
23: ; preds = %22
%24 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; No predecessors!
br label %28
28: ; preds = %27, %2
%29 = load i32, i32* %5
%30 = call i32 @fstat(i32 %29, %struct.stat* %6)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %38
32: ; preds = %28
br label %33
33: ; preds = %32
%34 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%35 = load i32, i32* @EXIT_FAILURE
%36 = call i32 @exit(i32 %35)
unreachable
37: ; No predecessors!
br label %38
38: ; preds = %37, %28
%39 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 1
%40 = load i32, i32* %39
%41 = call i32 @S_ISREG(i32 %40)
%42 = icmp ne i32 %41, 0
br i1 %42, label %48, label %43
43: ; preds = %38
%44 = load i32, i32* @stderr
%45 = load i8*, i8** %3
%46 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %45)
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %38
%49 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%50 = load i32, i32* %49
%51 = load i32, i32* %4
%52 = icmp slt i32 %50, %51
br i1 %52, label %53, label %171
53: ; preds = %48
%54 = load i32, i32* %5
%55 = load i32, i32* %4
%56 = sub nsw i32 %55, 1
%57 = load i32, i32* @SEEK_SET
%58 = call i32 @lseek(i32 %54, i32 %56, i32 %57)
store i32 %58, i32* %8
%59 = load i32, i32* %8
%60 = icmp eq i32 %59, -1
br i1 %60, label %61, label %67
61: ; preds = %53
%62 = load i32, i32* %5
%63 = call i32 @close(i32 %62)
%64 = call i32 @perror(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0))
%65 = load i32, i32* @EXIT_FAILURE
%66 = call i32 @exit(i32 %65)
unreachable
67: ; preds = %53
%68 = load i32, i32* %5
%69 = call i32 @write(i32 %68, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0), i32 1)
store i32 %69, i32* %8
%70 = load i32, i32* %8
%71 = icmp ne i32 %70, 1
br i1 %71, label %72, label %78
72: ; preds = %67
%73 = load i32, i32* %5
%74 = call i32 @close(i32 %73)
%75 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0))
%76 = load i32, i32* @EXIT_FAILURE
%77 = call i32 @exit(i32 %76)
unreachable
78: ; preds = %67
%79 = load i32, i32* %5
%80 = call i32 @fstat(i32 %79, %struct.stat* %6)
%81 = icmp eq i32 %80, -1
br i1 %81, label %82, label %88
82: ; preds = %78
br label %83
83: ; preds = %82
%84 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%85 = load i32, i32* @EXIT_FAILURE
%86 = call i32 @exit(i32 %85)
unreachable
87: ; No predecessors!
br label %88
88: ; preds = %87, %78
%89 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 1
%90 = load i32, i32* %89
%91 = call i32 @S_ISREG(i32 %90)
%92 = icmp ne i32 %91, 0
br i1 %92, label %98, label %93
93: ; preds = %88
%94 = load i32, i32* @stderr
%95 = load i8*, i8** %3
%96 = call i32 @fprintf(i32 %94, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %95)
%97 = call i32 @exit(i32 1)
unreachable
98: ; preds = %88
%99 = load i32, i32* %5
%100 = call i32 @close(i32 %99)
%101 = load i8*, i8** %3
%102 = load i32, i32* @O_RDWR
%103 = load i32, i32* @O_CREAT
%104 = or i32 %102, %103
%105 = load i32, i32* %7
%106 = call i32 @open(i8* %101, i32 %104, i32 %105)
store i32 %106, i32* %5
%107 = load i32, i32* %5
%108 = icmp eq i32 %107, -1
br i1 %108, label %109, label %115
109: ; preds = %98
br label %110
110: ; preds = %109
%111 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
%112 = load i32, i32* @EXIT_FAILURE
%113 = call i32 @exit(i32 %112)
unreachable
114: ; No predecessors!
br label %115
115: ; preds = %114, %98
%116 = load i32, i32* %5
%117 = call i32 @fstat(i32 %116, %struct.stat* %6)
%118 = icmp eq i32 %117, -1
br i1 %118, label %119, label %125
119: ; preds = %115
br label %120
120: ; preds = %119
%121 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
%122 = load i32, i32* @EXIT_FAILURE
%123 = call i32 @exit(i32 %122)
unreachable
124: ; No predecessors!
br label %125
125: ; preds = %124, %115
%126 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 1
%127 = load i32, i32* %126
%128 = call i32 @S_ISREG(i32 %127)
%129 = icmp ne i32 %128, 0
br i1 %129, label %135, label %130
130: ; preds = %125
%131 = load i32, i32* @stderr
%132 = load i8*, i8** %3
%133 = call i32 @fprintf(i32 %131, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %132)
%134 = call i32 @exit(i32 1)
unreachable
135: ; preds = %125
%136 = load i8*, i8** %3
%137 = load i32, i32* @O_RDWR
%138 = load i32, i32* @O_CREAT
%139 = or i32 %137, %138
%140 = load i32, i32* %7
%141 = call i32 @open(i8* %136, i32 %139, i32 %140)
store i32 %141, i32* %5
%142 = load i32, i32* %5
%143 = icmp eq i32 %142, -1
br i1 %143, label %144, label %150
144: ; preds = %135
br label %145
145: ; preds = %144
%146 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
%147 = load i32, i32* @EXIT_FAILURE
%148 = call i32 @exit(i32 %147)
unreachable
149: ; No predecessors!
br label %150
150: ; preds = %149, %135
%151 = load i32, i32* %5
%152 = call i32 @fstat(i32 %151, %struct.stat* %6)
%153 = icmp eq i32 %152, -1
br i1 %153, label %154, label %160
154: ; preds = %150
br label %155
155: ; preds = %154
%156 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
%157 = load i32, i32* @EXIT_FAILURE
%158 = call i32 @exit(i32 %157)
unreachable
159: ; No predecessors!
br label %160
160: ; preds = %159, %150
%161 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 1
%162 = load i32, i32* %161
%163 = call i32 @S_ISREG(i32 %162)
%164 = icmp ne i32 %163, 0
br i1 %164, label %170, label %165
165: ; preds = %160
%166 = load i32, i32* @stderr
%167 = load i8*, i8** %3
%168 = call i32 @fprintf(i32 %166, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %167)
%169 = call i32 @exit(i32 1)
unreachable
170: ; preds = %160
br label %171
171: ; preds = %170, %48
%172 = load i32, i32* %5
ret i32 %172
}

LLVM IR (-O2):
%struct.stat = type { i32, i32 }
@S_IRWXO = global i32 0
@S_IRWXG = global i32 0
@S_IRWXU = global i32 0
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@.str = [5 x i8] c"open\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [6 x i8] c"fstat\00"
@stderr = global i32 0
@.str.2 = [18 x i8] c"%s is not a file\0A\00"
@SEEK_SET = global i32 0
@.str.3 = [44 x i8] c"Error calling lseek() to 'stretch' the file\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [36 x i8] c"Error writing last byte of the file\00"
@.str.6 = [10 x i8] c"RDWR open\00"
@.str.7 = [11 x i8] c"RDWR fstat\00"
define i32 @ipc_open(i8* %0, i32 %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = load i32, i32* @S_IRWXO
%6 = load i32, i32* @S_IRWXG
%7 = or i32 %6, %5
%8 = load i32, i32* @S_IRWXU
%9 = or i32 %7, %8
%10 = load i32, i32* @O_RDWR
%11 = load i32, i32* @O_CREAT
%12 = or i32 %11, %10
%13 = tail call i32 @open(i8* %0, i32 %12, i32 %9)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = tail call i32 @exit(i32 %17)
unreachable
19: ; preds = %2
%20 = call i32 @fstat(i32 %13, %struct.stat* %3)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
%25 = tail call i32 @exit(i32 %24)
unreachable
26: ; preds = %19
%27 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
%28 = load i32, i32* %27
%29 = tail call i32 @S_ISREG(i32 %28)
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %26
%32 = load i32, i32* @stderr
%33 = tail call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%34 = tail call i32 @exit(i32 1)
unreachable
35: ; preds = %26
%36 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%37 = load i32, i32* %36
%38 = icmp slt i32 %37, %1
br i1 %38, label %39, label %123
39: ; preds = %35
%40 = add nsw i32 %1, -1
%41 = load i32, i32* @SEEK_SET
%42 = tail call i32 @lseek(i32 %13, i32 %40, i32 %41)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %49
44: ; preds = %39
%45 = tail call i32 @close(i32 %13)
%46 = tail call i32 @perror(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0))
%47 = load i32, i32* @EXIT_FAILURE
%48 = tail call i32 @exit(i32 %47)
unreachable
49: ; preds = %39
%50 = tail call i32 @write(i32 %13, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0), i32 1)
%51 = icmp eq i32 %50, 1
br i1 %51, label %57, label %52
52: ; preds = %49
%53 = tail call i32 @close(i32 %13)
%54 = tail call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0))
%55 = load i32, i32* @EXIT_FAILURE
%56 = tail call i32 @exit(i32 %55)
unreachable
57: ; preds = %49
%58 = call i32 @fstat(i32 %13, %struct.stat* %3)
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %64
60: ; preds = %57
%61 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%62 = load i32, i32* @EXIT_FAILURE
%63 = tail call i32 @exit(i32 %62)
unreachable
64: ; preds = %57
%65 = load i32, i32* %27
%66 = tail call i32 @S_ISREG(i32 %65)
%67 = icmp eq i32 %66, 0
br i1 %67, label %68, label %72
68: ; preds = %64
%69 = load i32, i32* @stderr
%70 = tail call i32 @fprintf(i32 %69, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%71 = tail call i32 @exit(i32 1)
unreachable
72: ; preds = %64
%73 = tail call i32 @close(i32 %13)
%74 = load i32, i32* @O_RDWR
%75 = load i32, i32* @O_CREAT
%76 = or i32 %75, %74
%77 = tail call i32 @open(i8* %0, i32 %76, i32 %9)
%78 = icmp eq i32 %77, -1
br i1 %78, label %79, label %83
79: ; preds = %72
%80 = tail call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
%81 = load i32, i32* @EXIT_FAILURE
%82 = tail call i32 @exit(i32 %81)
unreachable
83: ; preds = %72
%84 = call i32 @fstat(i32 %77, %struct.stat* %3)
%85 = icmp eq i32 %84, -1
br i1 %85, label %86, label %90
86: ; preds = %83
%87 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
%88 = load i32, i32* @EXIT_FAILURE
%89 = tail call i32 @exit(i32 %88)
unreachable
90: ; preds = %83
%91 = load i32, i32* %27
%92 = tail call i32 @S_ISREG(i32 %91)
%93 = icmp eq i32 %92, 0
br i1 %93, label %94, label %98
94: ; preds = %90
%95 = load i32, i32* @stderr
%96 = tail call i32 @fprintf(i32 %95, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%97 = tail call i32 @exit(i32 1)
unreachable
98: ; preds = %90
%99 = load i32, i32* @O_RDWR
%100 = load i32, i32* @O_CREAT
%101 = or i32 %100, %99
%102 = tail call i32 @open(i8* %0, i32 %101, i32 %9)
%103 = icmp eq i32 %102, -1
br i1 %103, label %104, label %108
104: ; preds = %98
%105 = tail call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
%106 = load i32, i32* @EXIT_FAILURE
%107 = tail call i32 @exit(i32 %106)
unreachable
108: ; preds = %98
%109 = call i32 @fstat(i32 %102, %struct.stat* %3)
%110 = icmp eq i32 %109, -1
br i1 %110, label %111, label %115
111: ; preds = %108
%112 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
%113 = load i32, i32* @EXIT_FAILURE
%114 = tail call i32 @exit(i32 %113)
unreachable
115: ; preds = %108
%116 = load i32, i32* %27
%117 = tail call i32 @S_ISREG(i32 %116)
%118 = icmp eq i32 %117, 0
br i1 %118, label %119, label %123
119: ; preds = %115
%120 = load i32, i32* @stderr
%121 = tail call i32 @fprintf(i32 %120, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%122 = tail call i32 @exit(i32 1)
unreachable
123: ; preds = %115, %35
%124 = phi i32 [ %102, %115 ], [ %13, %35 ]
ret i32 %124
}