#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 */

/* Variables and functions */
int FD_CLOEXEC;
int /*<<< orphan*/ F_DUPFD_CLOEXEC;
int /*<<< orphan*/ F_GETFD;
int O_CLOEXEC;
int O_CREAT;
int O_RDWR;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int dup2(int, int);
int /*<<< orphan*/ err_sys(char *, ...);
int fcntl(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ strlen(char const *);
int /*<<< orphan*/ write(int, char const *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int fd = open("file.dup", O_RDWR | O_CREAT | O_CLOEXEC, 0644);
  if (fd == -1)
    err_sys("open file.dup");
  int val = 0;
  printf("fd = %d\n", fd);
  if ((val = fcntl(fd, F_GETFD, 0)) < 0)
    err_sys("fcntl error for fd %d", fd);
  if (val & FD_CLOEXEC)
    printf("fd %d: close_on_exec\n", fd);
  int fd2 = 0;
  if ((fd2 = dup2(fd, 100)) < 0)
    err_sys("dup2 error for fd %d", fd);
  printf("fd2 = %d\n", fd2);
  if ((val = fcntl(fd2, F_GETFD, 0)) < 0)
    err_sys("fcntl error for fd %d", fd2);
  if (val & FD_CLOEXEC)
    printf("fd2 %d: close_on_exec\n", fd2);
  int fd3 = 0;
  if ((fd3 = fcntl(fd, F_DUPFD_CLOEXEC, 100)) < 0)
    err_sys("fcntl dup error for fd %d", fd3);
  printf("fd3 = %d\n", fd3);
  if ((val = fcntl(fd3, F_GETFD, 0)) < 0)
    err_sys("fcntl error for fd %d", fd3);
  if (val & FD_CLOEXEC)
    printf("fd3 %d: close_on_exec\n", fd3);
  char const *ptr = "hello world!";
  write(fd, ptr, strlen(ptr));
  printf("open & write to fd %d\n", fd);
  lseek(fd2, 0, SEEK_SET);
  printf("seek to begin on fd %d\n", fd2);
  char arg[128] = {0};
  read(fd3, arg, 127);
  printf("read '%s' on fd %d\n", arg, fd3);
  close(fd);
  close(fd2);
  close(fd3);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e10(%rip),%rax
mov    (%rax),%esi
mov    0x2e1f(%rip),%rax
or     (%rax),%esi
mov    0x2dc6(%rip),%rax
or     (%rax),%esi
lea    0xe1a(%rip),%rdi
mov    $0x1a4,%edx
call   10d0 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1210 <main+0x60>
lea    0xdf7(%rip),%rdi
mov    $0x0,%al
call   1030 <err_sys@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x14(%rbp),%esi
lea    0xded(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x14(%rbp),%edi
mov    0x2d86(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1040 <fcntl@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    1258 <main+0xa8>
mov    -0x14(%rbp),%esi
lea    0xdc6(%rip),%rdi
mov    $0x0,%al
call   1030 <err_sys@plt>
mov    -0x18(%rbp),%eax
mov    0x2d66(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     127e <main+0xce>
mov    -0x14(%rbp),%esi
lea    0xdb6(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
mov    $0x64,%esi
call   1070 <dup2@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    12af <main+0xff>
mov    -0x14(%rbp),%esi
lea    0xd9b(%rip),%rdi
mov    $0x0,%al
call   1030 <err_sys@plt>
mov    -0x1c(%rbp),%esi
lea    0xd9f(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x1c(%rbp),%edi
mov    0x2cee(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1040 <fcntl@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    12f0 <main+0x140>
mov    -0x1c(%rbp),%esi
lea    0xd2e(%rip),%rdi
mov    $0x0,%al
call   1030 <err_sys@plt>
mov    -0x18(%rbp),%eax
mov    0x2cce(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1316 <main+0x166>
mov    -0x1c(%rbp),%esi
lea    0xd53(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2cb1(%rip),%rax
mov    (%rax),%esi
mov    $0x64,%edx
call   1040 <fcntl@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jge    1350 <main+0x1a0>
mov    -0x20(%rbp),%esi
lea    0xd30(%rip),%rdi
mov    $0x0,%al
call   1030 <err_sys@plt>
mov    -0x20(%rbp),%esi
lea    0xd39(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x20(%rbp),%edi
mov    0x2c4d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1040 <fcntl@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    1391 <main+0x1e1>
mov    -0x20(%rbp),%esi
lea    0xc8d(%rip),%rdi
mov    $0x0,%al
call   1030 <err_sys@plt>
mov    -0x18(%rbp),%eax
mov    0x2c2d(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     13b7 <main+0x207>
mov    -0x20(%rbp),%esi
lea    0xced(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    0xcf6(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0xbc(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0xb8(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0xbc(%rbp),%edi
mov    -0xb8(%rbp),%rsi
mov    %eax,%edx
call   1050 <write@plt>
mov    -0x14(%rbp),%esi
lea    0xcc4(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x1c(%rbp),%edi
mov    0x2bb2(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <lseek@plt>
mov    -0x1c(%rbp),%esi
lea    0xcb7(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0xb0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   10a0 <memset@plt>
mov    -0x20(%rbp),%edi
lea    -0xb0(%rbp),%rsi
mov    $0x7f,%edx
call   10c0 <read@plt>
lea    -0xb0(%rbp),%rsi
mov    -0x20(%rbp),%edx
lea    0xc90(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x14(%rbp),%edi
call   10b0 <close@plt>
mov    -0x1c(%rbp),%edi
call   10b0 <close@plt>
mov    -0x20(%rbp),%edi
call   10b0 <close@plt>
xor    %eax,%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x80,%rsp
mov    0x2e2a(%rip),%rax
mov    0x2e3b(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2de0(%rip),%rax
or     (%rax),%esi
lea    0xe34(%rip),%rdi
mov    $0x1a4,%edx
call   10c0 <open@plt>
mov    %eax,%r15d
cmp    $0xffffffff,%eax
jne    11f1 <main+0x51>
lea    0xe16(%rip),%rdi
xor    %eax,%eax
call   1030 <err_sys@plt>
lea    0xe16(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x2daf(%rip),%rbx
mov    (%rbx),%esi
mov    %r15d,%edi
xor    %edx,%edx
call   1040 <fcntl@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    122c <main+0x8c>
lea    0xdf5(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1030 <err_sys@plt>
mov    0x2d95(%rip),%r12
test   %ebp,(%r12)
je     124a <main+0xaa>
lea    0xded(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r15d,%edi
mov    $0x64,%esi
call   1070 <dup2@plt>
mov    %eax,%r14d
test   %eax,%eax
jns    126f <main+0xcf>
lea    0xdde(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1030 <err_sys@plt>
lea    0xde2(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    (%rbx),%esi
mov    %r14d,%edi
xor    %edx,%edx
call   1040 <fcntl@plt>
mov    %eax,%ebp
test   %eax,%eax
js     13dd <main+0x23d>
test   %ebp,(%r12)
je     12ad <main+0x10d>
lea    0xdbf(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x2d24(%rip),%rax
mov    (%rax),%esi
mov    %r15d,%edi
mov    $0x64,%edx
call   1040 <fcntl@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    12d9 <main+0x139>
lea    0xda9(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <err_sys@plt>
lea    0xdb3(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    (%rbx),%esi
mov    %ebp,%edi
xor    %edx,%edx
call   1040 <fcntl@plt>
mov    %eax,%ebx
test   %eax,%eax
js     13fd <main+0x25d>
test   %ebx,(%r12)
je     1314 <main+0x174>
lea    0xd92(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xd99(%rip),%rbx
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <write@plt>
lea    0xd8a(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x2c78(%rip),%rax
mov    (%rax),%edx
mov    %r14d,%edi
xor    %esi,%esi
call   1090 <lseek@plt>
lea    0xd7d(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1080 <printf@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    %rsp,%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x7f,%edx
call   10b0 <read@plt>
lea    0xd48(%rip),%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r15d,%edi
call   10a0 <close@plt>
mov    %r14d,%edi
call   10a0 <close@plt>
mov    %ebp,%edi
call   10a0 <close@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc33(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1030 <err_sys@plt>
test   %ebp,(%r12)
jne    129c <main+0xfc>
jmp    12ad <main+0x10d>
lea    0xc13(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <err_sys@plt>
test   %ebx,(%r12)
jne    1304 <main+0x164>
jmp    1314 <main+0x174>

LLVM IR (-O0):
@.str = [9 x i8] c"file.dup\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_CLOEXEC = global i32 0
@.str.1 = [14 x i8] c"open file.dup\00"
@.str.2 = [9 x i8] c"fd = %d\0A\00"
@F_GETFD = global i32 0
@.str.3 = [22 x i8] c"fcntl error for fd %d\00"
@FD_CLOEXEC = global i32 0
@.str.4 = [22 x i8] c"fd %d: close_on_exec\0A\00"
@.str.5 = [21 x i8] c"dup2 error for fd %d\00"
@.str.6 = [10 x i8] c"fd2 = %d\0A\00"
@.str.7 = [23 x i8] c"fd2 %d: close_on_exec\0A\00"
@F_DUPFD_CLOEXEC = global i32 0
@.str.8 = [26 x i8] c"fcntl dup error for fd %d\00"
@.str.9 = [10 x i8] c"fd3 = %d\0A\00"
@.str.10 = [23 x i8] c"fd3 %d: close_on_exec\0A\00"
@.str.11 = [13 x i8] c"hello world!\00"
@.str.12 = [23 x i8] c"open & write to fd %d\0A\00"
@SEEK_SET = global i32 0
@.str.13 = [24 x i8] c"seek to begin on fd %d\0A\00"
@.str.14 = [20 x i8] c"read '%s' on fd %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca [128 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* @O_RDWR
%13 = load i32, i32* @O_CREAT
%14 = or i32 %12, %13
%15 = load i32, i32* @O_CLOEXEC
%16 = or i32 %14, %15
%17 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %16, i32 420)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %2
%21 = call i32 (i8*, ...) @err_sys(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %2
store i32 0, i32* %7
%23 = load i32, i32* %6
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %23)
%25 = load i32, i32* %6
%26 = load i32, i32* @F_GETFD
%27 = call i32 @fcntl(i32 %25, i32 %26, i32 0)
store i32 %27, i32* %7
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %22
%30 = load i32, i32* %6
%31 = call i32 (i8*, ...) @err_sys(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %29, %22
%33 = load i32, i32* %7
%34 = load i32, i32* @FD_CLOEXEC
%35 = and i32 %33, %34
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %32
%38 = load i32, i32* %6
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 %38)
br label %40
40: ; preds = %37, %32
store i32 0, i32* %8
%41 = load i32, i32* %6
%42 = call i32 @dup2(i32 %41, i32 100)
store i32 %42, i32* %8
%43 = icmp slt i32 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %40
%45 = load i32, i32* %6
%46 = call i32 (i8*, ...) @err_sys(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %45)
br label %47
47: ; preds = %44, %40
%48 = load i32, i32* %8
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i32 %48)
%50 = load i32, i32* %8
%51 = load i32, i32* @F_GETFD
%52 = call i32 @fcntl(i32 %50, i32 %51, i32 0)
store i32 %52, i32* %7
%53 = icmp slt i32 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %47
%55 = load i32, i32* %8
%56 = call i32 (i8*, ...) @err_sys(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %55)
br label %57
57: ; preds = %54, %47
%58 = load i32, i32* %7
%59 = load i32, i32* @FD_CLOEXEC
%60 = and i32 %58, %59
%61 = icmp ne i32 %60, 0
br i1 %61, label %62, label %65
62: ; preds = %57
%63 = load i32, i32* %8
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i32 %63)
br label %65
65: ; preds = %62, %57
store i32 0, i32* %9
%66 = load i32, i32* %6
%67 = load i32, i32* @F_DUPFD_CLOEXEC
%68 = call i32 @fcntl(i32 %66, i32 %67, i32 100)
store i32 %68, i32* %9
%69 = icmp slt i32 %68, 0
br i1 %69, label %70, label %73
70: ; preds = %65
%71 = load i32, i32* %9
%72 = call i32 (i8*, ...) @err_sys(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i32 %71)
br label %73
73: ; preds = %70, %65
%74 = load i32, i32* %9
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0), i32 %74)
%76 = load i32, i32* %9
%77 = load i32, i32* @F_GETFD
%78 = call i32 @fcntl(i32 %76, i32 %77, i32 0)
store i32 %78, i32* %7
%79 = icmp slt i32 %78, 0
br i1 %79, label %80, label %83
80: ; preds = %73
%81 = load i32, i32* %9
%82 = call i32 (i8*, ...) @err_sys(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %81)
br label %83
83: ; preds = %80, %73
%84 = load i32, i32* %7
%85 = load i32, i32* @FD_CLOEXEC
%86 = and i32 %84, %85
%87 = icmp ne i32 %86, 0
br i1 %87, label %88, label %91
88: ; preds = %83
%89 = load i32, i32* %9
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.10, i64 0, i64 0), i32 %89)
br label %91
91: ; preds = %88, %83
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.11, i64 0, i64 0), i8** %10
%92 = load i32, i32* %6
%93 = load i8*, i8** %10
%94 = load i8*, i8** %10
%95 = call i32 @strlen(i8* %94)
%96 = call i32 @write(i32 %92, i8* %93, i32 %95)
%97 = load i32, i32* %6
%98 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.12, i64 0, i64 0), i32 %97)
%99 = load i32, i32* %8
%100 = load i32, i32* @SEEK_SET
%101 = call i32 @lseek(i32 %99, i32 0, i32 %100)
%102 = load i32, i32* %8
%103 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.13, i64 0, i64 0), i32 %102)
%104 = bitcast [128 x i8]* %11 to i8*
%105 = load i32, i32* %9
%106 = getelementptr inbounds [128 x i8], [128 x i8]* %11, i64 0, i64 0
%107 = call i32 @read(i32 %105, i8* %106, i32 127)
%108 = getelementptr inbounds [128 x i8], [128 x i8]* %11, i64 0, i64 0
%109 = load i32, i32* %9
%110 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.14, i64 0, i64 0), i8* %108, i32 %109)
%111 = load i32, i32* %6
%112 = call i32 @close(i32 %111)
%113 = load i32, i32* %8
%114 = call i32 @close(i32 %113)
%115 = load i32, i32* %9
%116 = call i32 @close(i32 %115)
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"file.dup\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_CLOEXEC = global i32 0
@.str.1 = [14 x i8] c"open file.dup\00"
@.str.2 = [9 x i8] c"fd = %d\0A\00"
@F_GETFD = global i32 0
@.str.3 = [22 x i8] c"fcntl error for fd %d\00"
@FD_CLOEXEC = global i32 0
@.str.4 = [22 x i8] c"fd %d: close_on_exec\0A\00"
@.str.5 = [21 x i8] c"dup2 error for fd %d\00"
@.str.6 = [10 x i8] c"fd2 = %d\0A\00"
@.str.7 = [23 x i8] c"fd2 %d: close_on_exec\0A\00"
@F_DUPFD_CLOEXEC = global i32 0
@.str.8 = [26 x i8] c"fcntl dup error for fd %d\00"
@.str.9 = [10 x i8] c"fd3 = %d\0A\00"
@.str.10 = [23 x i8] c"fd3 %d: close_on_exec\0A\00"
@.str.11 = [13 x i8] c"hello world!\00"
@.str.12 = [23 x i8] c"open & write to fd %d\0A\00"
@SEEK_SET = global i32 0
@.str.13 = [24 x i8] c"seek to begin on fd %d\0A\00"
@.str.14 = [20 x i8] c"read '%s' on fd %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [128 x i8]
%4 = load i32, i32* @O_RDWR
%5 = load i32, i32* @O_CREAT
%6 = or i32 %5, %4
%7 = load i32, i32* @O_CLOEXEC
%8 = or i32 %6, %7
%9 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %8, i32 420)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = tail call i32 (i8*, ...) @err_sys(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %11, %2
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%15 = load i32, i32* @F_GETFD
%16 = tail call i32 @fcntl(i32 %9, i32 %15, i32 0)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = tail call i32 (i8*, ...) @err_sys(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %9)
br label %20
20: ; preds = %18, %13
%21 = load i32, i32* @FD_CLOEXEC
%22 = and i32 %21, %16
%23 = icmp eq i32 %22, 0
br i1 %23, label %26, label %24
24: ; preds = %20
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 %9)
br label %26
26: ; preds = %24, %20
%27 = tail call i32 @dup2(i32 %9, i32 100)
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = tail call i32 (i8*, ...) @err_sys(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %9)
br label %31
31: ; preds = %29, %26
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i32 %27)
%33 = load i32, i32* @F_GETFD
%34 = tail call i32 @fcntl(i32 %27, i32 %33, i32 0)
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %31
%37 = tail call i32 (i8*, ...) @err_sys(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %27)
br label %38
38: ; preds = %36, %31
%39 = load i32, i32* @FD_CLOEXEC
%40 = and i32 %39, %34
%41 = icmp eq i32 %40, 0
br i1 %41, label %44, label %42
42: ; preds = %38
%43 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i32 %27)
br label %44
44: ; preds = %42, %38
%45 = load i32, i32* @F_DUPFD_CLOEXEC
%46 = tail call i32 @fcntl(i32 %9, i32 %45, i32 100)
%47 = icmp slt i32 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %44
%49 = tail call i32 (i8*, ...) @err_sys(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0), i32 %46)
br label %50
50: ; preds = %48, %44
%51 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0), i32 %46)
%52 = load i32, i32* @F_GETFD
%53 = tail call i32 @fcntl(i32 %46, i32 %52, i32 0)
%54 = icmp slt i32 %53, 0
br i1 %54, label %55, label %57
55: ; preds = %50
%56 = tail call i32 (i8*, ...) @err_sys(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %46)
br label %57
57: ; preds = %55, %50
%58 = load i32, i32* @FD_CLOEXEC
%59 = and i32 %58, %53
%60 = icmp eq i32 %59, 0
br i1 %60, label %63, label %61
61: ; preds = %57
%62 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.10, i64 0, i64 0), i32 %46)
br label %63
63: ; preds = %61, %57
%64 = tail call i32 @strlen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.11, i64 0, i64 0))
%65 = tail call i32 @write(i32 %9, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.11, i64 0, i64 0), i32 %64)
%66 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.12, i64 0, i64 0), i32 %9)
%67 = load i32, i32* @SEEK_SET
%68 = tail call i32 @lseek(i32 %27, i32 0, i32 %67)
%69 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.13, i64 0, i64 0), i32 %27)
%70 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%71 = call i32 @read(i32 %46, i8* %70, i32 127)
%72 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.14, i64 0, i64 0), i8* %70, i32 %46)
%73 = call i32 @close(i32 %9)
%74 = call i32 @close(i32 %27)
%75 = call i32 @close(i32 %46)
ret i32 0
}