#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 winsize {
  int dummy;
};
struct termios {
  int dummy;
};
typedef int /*<<< orphan*/ status;
typedef int ssize_t;
typedef int pid_t;
typedef int /*<<< orphan*/ child_status;

/* Variables and functions */
int EIO;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ STDERR_FILENO;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ TIOCSWINSZ;
int /*<<< orphan*/ close(int);
scalar_t__ dup2(int, int /*<<< orphan*/);
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
scalar_t__ ioctl(int, int /*<<< orphan*/, struct winsize const *);
scalar_t__ pipe(int *);
int ptym_open(char *, size_t);
int ptys_open(char *);
int read(int, int *, int);
scalar_t__ setsid();
scalar_t__ tcsetattr(int, int /*<<< orphan*/, struct termios const *);
int /*<<< orphan*/ write(int, int *, int);
pid_t pty_fork(int *ptm_fd, char *pts_name, size_t pts_buff_len,
               const struct termios *slave_termios,
               const struct winsize *slave_winsize) {
  if ((*ptm_fd = ptym_open(pts_name, pts_buff_len)) < 0)
    return -1;
  pid_t pid;
  int pipefds[2];
  int child_status;
  int err_code;
  if (pipe(pipefds) < 0) {
    err_code = errno;
    goto errout;
  }
  if ((pid = fork()) < 0) {
    err_code = errno;
    goto pipeout1;
  }
  if (pid == 0) {
    int pts_fd = 0;
    int status = 0;
    close(pipefds[0]);
    close(*ptm_fd);
    if (setsid() < 0)
      goto childout;
    if ((pts_fd = ptys_open(pts_name)) < 0)
      goto childout;
    if (slave_termios != NULL)
      if (tcsetattr(pts_fd, 0, slave_termios) < 0)
        goto childout;
    if (slave_winsize != NULL)
      if (ioctl(pts_fd, TIOCSWINSZ, slave_winsize) < 0)
        goto childout;
    if (dup2(pts_fd, STDIN_FILENO) < 0)
      goto childout;
    if (dup2(pts_fd, STDOUT_FILENO) < 0)
      goto childout;
    if (dup2(pts_fd, STDERR_FILENO) < 0)
      goto childout;
    write(pipefds[1], &status, sizeof(status));
    close(pipefds[1]);
    close(pts_fd);
    return 0;
  childout:
    status = errno;
    write(pipefds[1], &status, sizeof(status));
    exit(EXIT_FAILURE);
  }
  close(pipefds[1]);
  ssize_t n;
  if ((n = read(pipefds[0], &child_status, sizeof(child_status))) !=
      sizeof(child_status)) {
    if (n >= 0)
      err_code = EIO;
    goto pipeout0;
  } else if (child_status != 0) {
    err_code = child_status;
    goto pipeout0;
  }
  close(pipefds[0]);
  return pid;
pipeout1:
  close(pipefds[1]);
pipeout0:
  close(pipefds[0]);
errout:
  close(*ptm_fd);
  errno = err_code;
  return -1;
}


x86 assembly (clang, -O0):
<pty_fork>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10b0 <ptym_open@plt>
mov    -0x10(%rbp),%rcx
mov    %eax,(%rcx)
cmp    $0x0,%eax
jge    1204 <pty_fork+0x44>
movl   $0xffffffff,-0x4(%rbp)
jmp    145e <pty_fork+0x29e>
lea    -0x3c(%rbp),%rdi
call   1070 <pipe@plt>
cmp    $0x0,%rax
jge    1228 <pty_fork+0x68>
mov    0x2daa(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
jmp    1440 <pty_fork+0x280>
mov    $0x0,%al
call   10e0 <fork@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jge    124c <pty_fork+0x8c>
mov    0x2d86(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
jmp    1430 <pty_fork+0x270>
cmpl   $0x0,-0x34(%rbp)
jne    13c0 <pty_fork+0x200>
movl   $0x0,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
mov    -0x3c(%rbp),%edi
call   1060 <close@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1060 <close@plt>
mov    $0x0,%al
call   1080 <setsid@plt>
cmp    $0x0,%rax
jge    128d <pty_fork+0xcd>
jmp    1395 <pty_fork+0x1d5>
mov    -0x18(%rbp),%rdi
call   10d0 <ptys_open@plt>
mov    %eax,-0x48(%rbp)
cmp    $0x0,%eax
jge    12a7 <pty_fork+0xe7>
jmp    1395 <pty_fork+0x1d5>
cmpq   $0x0,-0x28(%rbp)
je     12d4 <pty_fork+0x114>
mov    -0x48(%rbp),%edi
mov    -0x28(%rbp),%rdx
xor    %esi,%esi
call   10a0 <tcsetattr@plt>
cmp    $0x0,%rax
jge    12cf <pty_fork+0x10f>
jmp    1395 <pty_fork+0x1d5>
jmp    12d4 <pty_fork+0x114>
cmpq   $0x0,-0x30(%rbp)
je     1308 <pty_fork+0x148>
mov    -0x48(%rbp),%edi
mov    0x2cf7(%rip),%rax
mov    (%rax),%esi
mov    -0x30(%rbp),%rdx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
jge    1303 <pty_fork+0x143>
jmp    1395 <pty_fork+0x1d5>
jmp    1308 <pty_fork+0x148>
mov    -0x48(%rbp),%edi
mov    0x2c9e(%rip),%rax
mov    (%rax),%esi
call   1040 <dup2@plt>
cmp    $0x0,%rax
jge    1328 <pty_fork+0x168>
jmp    1395 <pty_fork+0x1d5>
mov    -0x48(%rbp),%edi
mov    0x2cbe(%rip),%rax
mov    (%rax),%esi
call   1040 <dup2@plt>
cmp    $0x0,%rax
jge    1348 <pty_fork+0x188>
jmp    1395 <pty_fork+0x1d5>
mov    -0x48(%rbp),%edi
mov    0x2c6e(%rip),%rax
mov    (%rax),%esi
call   1040 <dup2@plt>
cmp    $0x0,%rax
jge    1368 <pty_fork+0x1a8>
jmp    1395 <pty_fork+0x1d5>
mov    -0x38(%rbp),%edi
lea    -0x4c(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    -0x38(%rbp),%edi
call   1060 <close@plt>
mov    -0x48(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
jmp    145e <pty_fork+0x29e>
mov    0x2c2c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x38(%rbp),%edi
lea    -0x4c(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    0x2bff(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x38(%rbp),%edi
call   1060 <close@plt>
mov    -0x3c(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x4,%edx
call   1090 <read@plt>
mov    %eax,-0x50(%rbp)
cltq
cmp    $0x4,%rax
je     1403 <pty_fork+0x243>
cmpl   $0x0,-0x50(%rbp)
jl     13fe <pty_fork+0x23e>
mov    0x2bd7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
jmp    1438 <pty_fork+0x278>
cmpl   $0x0,-0x40(%rbp)
je     1418 <pty_fork+0x258>
mov    -0x40(%rbp),%eax
mov    %eax,-0x44(%rbp)
jmp    1438 <pty_fork+0x278>
jmp    141d <pty_fork+0x25d>
mov    -0x3c(%rbp),%edi
call   1060 <close@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    145e <pty_fork+0x29e>
mov    -0x38(%rbp),%edi
call   1060 <close@plt>
mov    -0x3c(%rbp),%edi
call   1060 <close@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1060 <close@plt>
mov    -0x44(%rbp),%ecx
mov    0x2b73(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pty_fork>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %r8,%r14
mov    %rcx,%r15
mov    %rsi,%rbx
mov    %rdi,%r12
mov    %rsi,%rdi
mov    %rdx,%rsi
call   10b0 <ptym_open@plt>
mov    %eax,(%r12)
test   %eax,%eax
js     1376 <pty_fork+0x1b6>
lea    0x8(%rsp),%rdi
call   1070 <pipe@plt>
test   %rax,%rax
js     124c <pty_fork+0x8c>
xor    %eax,%eax
call   10e0 <fork@plt>
test   %eax,%eax
js     125a <pty_fork+0x9a>
je     1271 <pty_fork+0xb1>
mov    %eax,%ebp
mov    0xc(%rsp),%edi
call   1060 <close@plt>
mov    0x8(%rsp),%edi
lea    0x4(%rsp),%rsi
mov    $0x4,%edx
call   1090 <read@plt>
cmp    $0x4,%eax
jne    1352 <pty_fork+0x192>
mov    0x4(%rsp),%ebx
test   %ebx,%ebx
jne    135b <pty_fork+0x19b>
mov    0x8(%rsp),%edi
call   1060 <close@plt>
jmp    137b <pty_fork+0x1bb>
mov    0x2d75(%rip),%rax
mov    (%rax),%ebx
jmp    1364 <pty_fork+0x1a4>
mov    0x2d67(%rip),%rax
mov    (%rax),%ebx
mov    0xc(%rsp),%edi
call   1060 <close@plt>
jmp    135b <pty_fork+0x19b>
movl   $0x0,0x4(%rsp)
mov    0x8(%rsp),%edi
call   1060 <close@plt>
mov    (%r12),%edi
call   1060 <close@plt>
xor    %eax,%eax
call   1080 <setsid@plt>
test   %rax,%rax
js     138a <pty_fork+0x1ca>
mov    %rbx,%rdi
call   10d0 <ptys_open@plt>
test   %eax,%eax
js     138a <pty_fork+0x1ca>
mov    %eax,%ebx
test   %r15,%r15
je     12c7 <pty_fork+0x107>
mov    %ebx,%edi
xor    %esi,%esi
mov    %r15,%rdx
call   10a0 <tcsetattr@plt>
test   %rax,%rax
js     138a <pty_fork+0x1ca>
test   %r14,%r14
je     12e8 <pty_fork+0x128>
mov    0x2d0d(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1050 <ioctl@plt>
test   %rax,%rax
js     138a <pty_fork+0x1ca>
mov    0x2cc1(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1040 <dup2@plt>
test   %rax,%rax
js     138a <pty_fork+0x1ca>
mov    0x2ce8(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1040 <dup2@plt>
test   %rax,%rax
js     138a <pty_fork+0x1ca>
mov    0x2ca3(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1040 <dup2@plt>
test   %rax,%rax
js     138a <pty_fork+0x1ca>
mov    0xc(%rsp),%edi
lea    0x4(%rsp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    0xc(%rsp),%edi
call   1060 <close@plt>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %ebp,%ebp
jmp    137b <pty_fork+0x1bb>
mov    0x2c77(%rip),%rax
mov    (%rax),%ebx
mov    0x8(%rsp),%edi
call   1060 <close@plt>
mov    (%r12),%edi
call   1060 <close@plt>
mov    0x2c54(%rip),%rax
mov    %ebx,(%rax)
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c37(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    0xc(%rsp),%edi
lea    0x4(%rsp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    0x2c07(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.termios = type { i32 }
%struct.winsize = type { i32 }
@errno = global i32 0
@TIOCSWINSZ = global i32 0
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
@EXIT_FAILURE = global i32 0
@EIO = global i32 0
define i32 @pty_fork(i32* %0, i8* %1, i64 %2, %struct.termios* %3, %struct.winsize* %4) {
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca %struct.termios*
%11 = alloca %struct.winsize*
%12 = alloca i32
%13 = alloca [2 x i32]
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
store i32* %0, i32** %7
store i8* %1, i8** %8
store i64 %2, i64* %9
store %struct.termios* %3, %struct.termios** %10
store %struct.winsize* %4, %struct.winsize** %11
%19 = load i8*, i8** %8
%20 = load i64, i64* %9
%21 = call i32 @ptym_open(i8* %19, i64 %20)
%22 = load i32*, i32** %7
store i32 %21, i32* %22
%23 = icmp slt i32 %21, 0
br i1 %23, label %24, label %25
24: ; preds = %5
store i32 -1, i32* %6
br label %148
25: ; preds = %5
%26 = getelementptr inbounds [2 x i32], [2 x i32]* %13, i64 0, i64 0
%27 = call i64 @pipe(i32* %26)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = load i32, i32* @errno
store i32 %30, i32* %15
br label %143
31: ; preds = %25
%32 = call i32 (...) @fork()
store i32 %32, i32* %12
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %31
%35 = load i32, i32* @errno
store i32 %35, i32* %15
br label %135
36: ; preds = %31
%37 = load i32, i32* %12
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %109
39: ; preds = %36
store i32 0, i32* %16
store i32 0, i32* %17
%40 = getelementptr inbounds [2 x i32], [2 x i32]* %13, i64 0, i64 0
%41 = load i32, i32* %40
%42 = call i32 @close(i32 %41)
%43 = load i32*, i32** %7
%44 = load i32, i32* %43
%45 = call i32 @close(i32 %44)
%46 = call i64 (...) @setsid()
%47 = icmp slt i64 %46, 0
br i1 %47, label %48, label %49
48: ; preds = %39
br label %102
49: ; preds = %39
%50 = load i8*, i8** %8
%51 = call i32 @ptys_open(i8* %50)
store i32 %51, i32* %16
%52 = icmp slt i32 %51, 0
br i1 %52, label %53, label %54
53: ; preds = %49
br label %102
54: ; preds = %49
%55 = load %struct.termios*, %struct.termios** %10
%56 = icmp ne %struct.termios* %55, null
br i1 %56, label %57, label %64
57: ; preds = %54
%58 = load i32, i32* %16
%59 = load %struct.termios*, %struct.termios** %10
%60 = call i64 @tcsetattr(i32 %58, i32 0, %struct.termios* %59)
%61 = icmp slt i64 %60, 0
br i1 %61, label %62, label %63
62: ; preds = %57
br label %102
63: ; preds = %57
br label %64
64: ; preds = %63, %54
%65 = load %struct.winsize*, %struct.winsize** %11
%66 = icmp ne %struct.winsize* %65, null
br i1 %66, label %67, label %75
67: ; preds = %64
%68 = load i32, i32* %16
%69 = load i32, i32* @TIOCSWINSZ
%70 = load %struct.winsize*, %struct.winsize** %11
%71 = call i64 @ioctl(i32 %68, i32 %69, %struct.winsize* %70)
%72 = icmp slt i64 %71, 0
br i1 %72, label %73, label %74
73: ; preds = %67
br label %102
74: ; preds = %67
br label %75
75: ; preds = %74, %64
%76 = load i32, i32* %16
%77 = load i32, i32* @STDIN_FILENO
%78 = call i64 @dup2(i32 %76, i32 %77)
%79 = icmp slt i64 %78, 0
br i1 %79, label %80, label %81
80: ; preds = %75
br label %102
81: ; preds = %75
%82 = load i32, i32* %16
%83 = load i32, i32* @STDOUT_FILENO
%84 = call i64 @dup2(i32 %82, i32 %83)
%85 = icmp slt i64 %84, 0
br i1 %85, label %86, label %87
86: ; preds = %81
br label %102
87: ; preds = %81
%88 = load i32, i32* %16
%89 = load i32, i32* @STDERR_FILENO
%90 = call i64 @dup2(i32 %88, i32 %89)
%91 = icmp slt i64 %90, 0
br i1 %91, label %92, label %93
92: ; preds = %87
br label %102
93: ; preds = %87
%94 = getelementptr inbounds [2 x i32], [2 x i32]* %13, i64 0, i64 1
%95 = load i32, i32* %94
%96 = call i32 @write(i32 %95, i32* %17, i32 4)
%97 = getelementptr inbounds [2 x i32], [2 x i32]* %13, i64 0, i64 1
%98 = load i32, i32* %97
%99 = call i32 @close(i32 %98)
%100 = load i32, i32* %16
%101 = call i32 @close(i32 %100)
store i32 0, i32* %6
br label %148
102: ; preds = %92, %86, %80, %73, %62, %53, %48
%103 = load i32, i32* @errno
store i32 %103, i32* %17
%104 = getelementptr inbounds [2 x i32], [2 x i32]* %13, i64 0, i64 1
%105 = load i32, i32* %104
%106 = call i32 @write(i32 %105, i32* %17, i32 4)
%107 = load i32, i32* @EXIT_FAILURE
%108 = call i32 @exit(i32 %107)
unreachable
109: ; preds = %36
%110 = getelementptr inbounds [2 x i32], [2 x i32]* %13, i64 0, i64 1
%111 = load i32, i32* %110
%112 = call i32 @close(i32 %111)
%113 = getelementptr inbounds [2 x i32], [2 x i32]* %13, i64 0, i64 0
%114 = load i32, i32* %113
%115 = call i32 @read(i32 %114, i32* %14, i32 4)
store i32 %115, i32* %18
%116 = sext i32 %115 to i64
%117 = icmp ne i64 %116, 4
br i1 %117, label %118, label %124
118: ; preds = %109
%119 = load i32, i32* %18
%120 = icmp sge i32 %119, 0
br i1 %120, label %121, label %123
121: ; preds = %118
%122 = load i32, i32* @EIO
store i32 %122, i32* %15
br label %123
123: ; preds = %121, %118
br label %139
124: ; preds = %109
%125 = load i32, i32* %14
%126 = icmp ne i32 %125, 0
br i1 %126, label %127, label %129
127: ; preds = %124
%128 = load i32, i32* %14
store i32 %128, i32* %15
br label %139
129: ; preds = %124
br label %130
130: ; preds = %129
%131 = getelementptr inbounds [2 x i32], [2 x i32]* %13, i64 0, i64 0
%132 = load i32, i32* %131
%133 = call i32 @close(i32 %132)
%134 = load i32, i32* %12
store i32 %134, i32* %6
br label %148
135: ; preds = %34
%136 = getelementptr inbounds [2 x i32], [2 x i32]* %13, i64 0, i64 1
%137 = load i32, i32* %136
%138 = call i32 @close(i32 %137)
br label %139
139: ; preds = %135, %127, %123
%140 = getelementptr inbounds [2 x i32], [2 x i32]* %13, i64 0, i64 0
%141 = load i32, i32* %140
%142 = call i32 @close(i32 %141)
br label %143
143: ; preds = %139, %29
%144 = load i32*, i32** %7
%145 = load i32, i32* %144
%146 = call i32 @close(i32 %145)
%147 = load i32, i32* %15
store i32 %147, i32* @errno
store i32 -1, i32* %6
br label %148
148: ; preds = %143, %130, %93, %24
%149 = load i32, i32* %6
ret i32 %149
}

LLVM IR (-O2):
%struct.termios = type { i32 }
%struct.winsize = type { i32 }
@errno = global i32 0
@TIOCSWINSZ = global i32 0
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
@EXIT_FAILURE = global i32 0
@EIO = global i32 0
define i32 @pty_fork(i32* nocapture %0, i8* %1, i64 %2, %struct.termios* %3, %struct.winsize* %4) {
%6 = alloca [2 x i32]
%7 = alloca i32
%8 = alloca i32
%9 = tail call i32 @ptym_open(i8* %1, i64 %2)
store i32 %9, i32* %0
%10 = icmp slt i32 %9, 0
br i1 %10, label %104, label %11
11: ; preds = %5
%12 = bitcast [2 x i32]* %6 to i8*
%13 = bitcast i32* %7 to i8*
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%15 = call i64 @pipe(i32* %14)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %11
%18 = load i32, i32* @errno
br label %98
19: ; preds = %11
%20 = call i32 (...) @fork()
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %19
%23 = load i32, i32* @errno
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%25 = load i32, i32* %24
%26 = call i32 @close(i32 %25)
br label %94
27: ; preds = %19
%28 = icmp eq i32 %20, 0
br i1 %28, label %29, label %77
29: ; preds = %27
%30 = bitcast i32* %8 to i8*
store i32 0, i32* %8
%31 = load i32, i32* %14
%32 = call i32 @close(i32 %31)
%33 = load i32, i32* %0
%34 = call i32 @close(i32 %33)
%35 = call i64 (...) @setsid()
%36 = icmp slt i64 %35, 0
br i1 %36, label %70, label %37
37: ; preds = %29
%38 = call i32 @ptys_open(i8* %1)
%39 = icmp slt i32 %38, 0
br i1 %39, label %70, label %40
40: ; preds = %37
%41 = icmp eq %struct.termios* %3, null
br i1 %41, label %45, label %42
42: ; preds = %40
%43 = call i64 @tcsetattr(i32 %38, i32 0, %struct.termios* %3)
%44 = icmp slt i64 %43, 0
br i1 %44, label %70, label %45
45: ; preds = %42, %40
%46 = icmp eq %struct.winsize* %4, null
br i1 %46, label %51, label %47
47: ; preds = %45
%48 = load i32, i32* @TIOCSWINSZ
%49 = call i64 @ioctl(i32 %38, i32 %48, %struct.winsize* %4)
%50 = icmp slt i64 %49, 0
br i1 %50, label %70, label %51
51: ; preds = %47, %45
%52 = load i32, i32* @STDIN_FILENO
%53 = call i64 @dup2(i32 %38, i32 %52)
%54 = icmp slt i64 %53, 0
br i1 %54, label %70, label %55
55: ; preds = %51
%56 = load i32, i32* @STDOUT_FILENO
%57 = call i64 @dup2(i32 %38, i32 %56)
%58 = icmp slt i64 %57, 0
br i1 %58, label %70, label %59
59: ; preds = %55
%60 = load i32, i32* @STDERR_FILENO
%61 = call i64 @dup2(i32 %38, i32 %60)
%62 = icmp slt i64 %61, 0
br i1 %62, label %70, label %63
63: ; preds = %59
%64 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%65 = load i32, i32* %64
%66 = call i32 @write(i32 %65, i32* %8, i32 4)
%67 = load i32, i32* %64
%68 = call i32 @close(i32 %67)
%69 = call i32 @close(i32 %38)
br label %102
70: ; preds = %59, %55, %51, %47, %42, %37, %29
%71 = load i32, i32* @errno
store i32 %71, i32* %8
%72 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%73 = load i32, i32* %72
%74 = call i32 @write(i32 %73, i32* %8, i32 4)
%75 = load i32, i32* @EXIT_FAILURE
%76 = call i32 @exit(i32 %75)
unreachable
77: ; preds = %27
%78 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%79 = load i32, i32* %78
%80 = call i32 @close(i32 %79)
%81 = load i32, i32* %14
%82 = call i32 @read(i32 %81, i32* %7, i32 4)
%83 = icmp eq i32 %82, 4
br i1 %83, label %88, label %84
84: ; preds = %77
%85 = icmp sgt i32 %82, -1
%86 = load i32, i32* @EIO
%87 = select i1 %85, i32 %86, i32 undef
br label %94
88: ; preds = %77
%89 = load i32, i32* %7
%90 = icmp eq i32 %89, 0
br i1 %90, label %91, label %94
91: ; preds = %88
%92 = load i32, i32* %14
%93 = call i32 @close(i32 %92)
br label %102
94: ; preds = %84, %88, %22
%95 = phi i32 [ %23, %22 ], [ %87, %84 ], [ %89, %88 ]
%96 = load i32, i32* %14
%97 = call i32 @close(i32 %96)
br label %98
98: ; preds = %94, %17
%99 = phi i32 [ %18, %17 ], [ %95, %94 ]
%100 = load i32, i32* %0
%101 = call i32 @close(i32 %100)
store i32 %99, i32* @errno
br label %102
102: ; preds = %98, %91, %63
%103 = phi i32 [ -1, %98 ], [ 0, %63 ], [ %20, %91 ]
br label %104
104: ; preds = %5, %102
%105 = phi i32 [ %103, %102 ], [ -1, %5 ]
ret i32 %105
}