#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 termios {
  int c_iflag;
  int c_lflag;
  int c_cflag;
  int /*<<< orphan*/ c_oflag;
};
typedef int pid_t;

/* Variables and functions */
int BRKINT;
int CS8;
int CSIZE;
int ECHO;
int ECHONL;
int ICANON;
int ICRNL;
int IEXTEN;
int IGNBRK;
int IGNCR;
int INLCR;
int ISIG;
int ISTRIP;
int IXON;
int /*<<< orphan*/ OPOST;
int PARENB;
int PARMRK;
int PATH_MAX;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ _exit(int);
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ execv(char *const, char *const *);
int fork();
int openpty(int *, int *, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
            int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, int);
char *strrchr(int /*<<< orphan*/, char);
int tcgetattr(int, struct termios *);
int tcsetattr(int, int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ ttyname(int);
int fork_xterm(pid_t *pid, int *fd) {
  int master, slave;
  struct termios term;
  if (openpty(&master, &slave, NULL, NULL, NULL) == -1)
    return -1;
  if (tcgetattr(master, &term) == -1) {
    int save = errno;
    close(master);
    close(slave);
    errno = save;
    return -1;
  }
  term.c_iflag &=
      ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
  term.c_oflag &= ~OPOST;
  term.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
  term.c_cflag &= ~(CSIZE | PARENB);
  term.c_cflag |= CS8;
  if (tcsetattr(master, TCSANOW, &term) == -1) {
    int save = errno;
    close(master);
    close(slave);
    errno = save;
    return -1;
  }
  *pid = fork();
  if (*pid == -1) {
    int save = errno;
    close(master);
    close(slave);
    errno = save;
    return -1;
  } else if (*pid == 0) {
    char ccn[PATH_MAX];
    sprintf(ccn, "-S%s/%d", strrchr(ttyname(slave), '/') + 1, slave);
    char *const args[] = {"/usr/bin/xterm", "-title", "Machine console",
                          "-samename",      ccn,      NULL};
    close(master);
    execv(args[0], args);
    perror("execv");
    _exit(1);
  }
  close(slave);
  *fd = master;
  return 0;
}


x86 assembly (clang, -O0):
<fork_xterm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x1c(%rbp),%rdi
lea    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   1060 <openpty@plt>
cmp    $0xffffffff,%eax
jne    11f0 <fork_xterm+0x40>
movl   $0xffffffff,-0x4(%rbp)
jmp    1492 <fork_xterm+0x2e2>
mov    -0x1c(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   1080 <tcgetattr@plt>
cmp    $0xffffffff,%eax
jne    1239 <fork_xterm+0x89>
mov    0x2d5c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
mov    -0x20(%rbp),%edi
call   1050 <close@plt>
mov    -0x34(%rbp),%ecx
mov    0x2d3d(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1492 <fork_xterm+0x2e2>
mov    0x2d10(%rip),%rax
mov    (%rax),%eax
mov    0x2d47(%rip),%rcx
or     (%rcx),%eax
mov    0x2d96(%rip),%rcx
or     (%rcx),%eax
mov    0x2d05(%rip),%rcx
or     (%rcx),%eax
mov    0x2d6c(%rip),%rcx
or     (%rcx),%eax
mov    0x2d5b(%rip),%rcx
or     (%rcx),%eax
mov    0x2d62(%rip),%rcx
or     (%rcx),%eax
mov    0x2d39(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d2f(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    0x2cfd(%rip),%rax
mov    (%rax),%eax
mov    0x2cac(%rip),%rcx
or     (%rcx),%eax
mov    0x2c93(%rip),%rcx
or     (%rcx),%eax
mov    0x2cda(%rip),%rcx
or     (%rcx),%eax
mov    0x2cb1(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2ca7(%rip),%rax
mov    (%rax),%eax
mov    0x2cce(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2c94(%rip),%rax
mov    (%rax),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2ca2(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1090 <tcsetattr@plt>
cmp    $0xffffffff,%eax
jne    134e <fork_xterm+0x19e>
mov    0x2c47(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
mov    -0x20(%rbp),%edi
call   1050 <close@plt>
mov    -0x38(%rbp),%ecx
mov    0x2c28(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1492 <fork_xterm+0x2e2>
mov    $0x0,%al
call   10d0 <fork@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
cmpl   $0xffffffff,(%rax)
jne    139e <fork_xterm+0x1ee>
mov    0x2bf7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
mov    -0x20(%rbp),%edi
call   1050 <close@plt>
mov    -0x3c(%rbp),%ecx
mov    0x2bd8(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1492 <fork_xterm+0x2e2>
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
jne    1475 <fork_xterm+0x2c5>
mov    0x2c3e(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x88(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x50(%rbp)
mov    -0x20(%rbp),%edi
call   1070 <ttyname@plt>
mov    %eax,%edi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    -0x88(%rbp),%rdi
mov    %rax,%rdx
add    $0x1,%rdx
mov    -0x20(%rbp),%ecx
lea    0xbfa(%rip),%rsi
call   10b0 <sprintf@plt>
mov    -0x88(%rbp),%rax
lea    0xbef(%rip),%rcx
mov    %rcx,-0x80(%rbp)
lea    0xbf3(%rip),%rcx
mov    %rcx,-0x78(%rbp)
lea    0xbef(%rip),%rcx
mov    %rcx,-0x70(%rbp)
lea    0xbf4(%rip),%rcx
mov    %rcx,-0x68(%rbp)
mov    %rax,-0x60(%rbp)
movq   $0x0,-0x58(%rbp)
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
mov    -0x80(%rbp),%rdi
lea    -0x80(%rbp),%rsi
call   10c0 <execv@plt>
lea    0xbd2(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>
jmp    147a <fork_xterm+0x2ca>
mov    -0x20(%rbp),%edi
call   1050 <close@plt>
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fork_xterm>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x50,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
lea    -0x24(%rbp),%rdi
lea    -0x28(%rbp),%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1060 <openpty@plt>
mov    $0xffffffff,%r12d
cmp    $0xffffffff,%eax
je     130a <fork_xterm+0x15a>
mov    -0x24(%rbp),%edi
lea    -0x38(%rbp),%rsi
call   1080 <tcgetattr@plt>
cmp    $0xffffffff,%eax
je     12ed <fork_xterm+0x13d>
mov    0x2d4c(%rip),%rax
mov    0x2d85(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2dd2(%rip),%rax
or     (%rax),%ecx
mov    0x2d41(%rip),%rax
or     (%rax),%ecx
mov    0x2da8(%rip),%rax
or     (%rax),%ecx
mov    0x2d97(%rip),%rax
or     (%rax),%ecx
mov    0x2d9e(%rip),%rax
or     (%rax),%ecx
mov    0x2d75(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,-0x38(%rbp)
mov    0x2d6f(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,-0x2c(%rbp)
mov    0x2d41(%rip),%rax
mov    0x2cf2(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2cd7(%rip),%rax
or     (%rax),%ecx
mov    0x2d1e(%rip),%rax
or     (%rax),%ecx
mov    0x2cf5(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,-0x34(%rbp)
mov    0x2cef(%rip),%rax
mov    0x2d18(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
not    %ecx
and    -0x30(%rbp),%ecx
mov    0x2ce0(%rip),%rax
or     (%rax),%ecx
mov    %ecx,-0x30(%rbp)
mov    -0x24(%rbp),%edi
mov    0x2cf1(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdx
call   1090 <tcsetattr@plt>
cmp    $0xffffffff,%eax
je     12ed <fork_xterm+0x13d>
xor    %eax,%eax
call   10d0 <fork@plt>
mov    %eax,(%r15)
cmp    $0xffffffff,%eax
je     12ed <fork_xterm+0x13d>
test   %eax,%eax
je     131a <fork_xterm+0x16a>
mov    -0x28(%rbp),%edi
call   1050 <close@plt>
mov    -0x24(%rbp),%eax
mov    %eax,(%r14)
xor    %r12d,%r12d
jmp    130a <fork_xterm+0x15a>
mov    0x2c74(%rip),%r14
mov    (%r14),%ebx
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
mov    -0x28(%rbp),%edi
call   1050 <close@plt>
mov    %ebx,(%r14)
mov    %r12d,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2ccf(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    -0x28(%rbp),%edi
call   1070 <ttyname@plt>
mov    %eax,%edi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
lea    0x1(%rax),%rdx
mov    -0x28(%rbp),%ecx
lea    0xcaa(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <sprintf@plt>
lea    0xca3(%rip),%r14
mov    %r14,-0x70(%rbp)
lea    0xca7(%rip),%rax
mov    %rax,-0x68(%rbp)
lea    0xca3(%rip),%rax
mov    %rax,-0x60(%rbp)
lea    0xca8(%rip),%rax
mov    %rax,-0x58(%rbp)
mov    %rbx,-0x50(%rbp)
movq   $0x0,-0x48(%rbp)
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
lea    -0x70(%rbp),%rsi
mov    %r14,%rdi
call   10c0 <execv@plt>
lea    0xc87(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
%struct.termios = type { i32, i32, i32, i32 }
@errno = global i32 0
@IGNBRK = global i32 0
@BRKINT = global i32 0
@PARMRK = global i32 0
@ISTRIP = global i32 0
@INLCR = global i32 0
@IGNCR = global i32 0
@ICRNL = global i32 0
@IXON = global i32 0
@OPOST = global i32 0
@ECHO = global i32 0
@ECHONL = global i32 0
@ICANON = global i32 0
@ISIG = global i32 0
@IEXTEN = global i32 0
@CSIZE = global i32 0
@PARENB = global i32 0
@CS8 = global i32 0
@TCSANOW = global i32 0
@PATH_MAX = global i32 0
@.str = [8 x i8] c"-S%s/%d\00"
@.str.1 = [15 x i8] c"/usr/bin/xterm\00"
@.str.2 = [7 x i8] c"-title\00"
@.str.3 = [16 x i8] c"Machine console\00"
@.str.4 = [10 x i8] c"-samename\00"
@.str.5 = [6 x i8] c"execv\00"
define i32 @fork_xterm(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.termios
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i64
%14 = alloca [6 x i8*]
store i32* %0, i32** %4
store i32* %1, i32** %5
%15 = call i32 @openpty(i32* %6, i32* %7, i32* null, i32* null, i32* null)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %18
17: ; preds = %2
store i32 -1, i32* %3
br label %137
18: ; preds = %2
%19 = load i32, i32* %6
%20 = call i32 @tcgetattr(i32 %19, %struct.termios* %8)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %29
22: ; preds = %18
%23 = load i32, i32* @errno
store i32 %23, i32* %9
%24 = load i32, i32* %6
%25 = call i32 @close(i32 %24)
%26 = load i32, i32* %7
%27 = call i32 @close(i32 %26)
%28 = load i32, i32* %9
store i32 %28, i32* @errno
store i32 -1, i32* %3
br label %137
29: ; preds = %18
%30 = load i32, i32* @IGNBRK
%31 = load i32, i32* @BRKINT
%32 = or i32 %30, %31
%33 = load i32, i32* @PARMRK
%34 = or i32 %32, %33
%35 = load i32, i32* @ISTRIP
%36 = or i32 %34, %35
%37 = load i32, i32* @INLCR
%38 = or i32 %36, %37
%39 = load i32, i32* @IGNCR
%40 = or i32 %38, %39
%41 = load i32, i32* @ICRNL
%42 = or i32 %40, %41
%43 = load i32, i32* @IXON
%44 = or i32 %42, %43
%45 = xor i32 %44, -1
%46 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
%47 = load i32, i32* %46
%48 = and i32 %47, %45
store i32 %48, i32* %46
%49 = load i32, i32* @OPOST
%50 = xor i32 %49, -1
%51 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 3
%52 = load i32, i32* %51
%53 = and i32 %52, %50
store i32 %53, i32* %51
%54 = load i32, i32* @ECHO
%55 = load i32, i32* @ECHONL
%56 = or i32 %54, %55
%57 = load i32, i32* @ICANON
%58 = or i32 %56, %57
%59 = load i32, i32* @ISIG
%60 = or i32 %58, %59
%61 = load i32, i32* @IEXTEN
%62 = or i32 %60, %61
%63 = xor i32 %62, -1
%64 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 1
%65 = load i32, i32* %64
%66 = and i32 %65, %63
store i32 %66, i32* %64
%67 = load i32, i32* @CSIZE
%68 = load i32, i32* @PARENB
%69 = or i32 %67, %68
%70 = xor i32 %69, -1
%71 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 2
%72 = load i32, i32* %71
%73 = and i32 %72, %70
store i32 %73, i32* %71
%74 = load i32, i32* @CS8
%75 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 2
%76 = load i32, i32* %75
%77 = or i32 %76, %74
store i32 %77, i32* %75
%78 = load i32, i32* %6
%79 = load i32, i32* @TCSANOW
%80 = call i32 @tcsetattr(i32 %78, i32 %79, %struct.termios* %8)
%81 = icmp eq i32 %80, -1
br i1 %81, label %82, label %89
82: ; preds = %29
%83 = load i32, i32* @errno
store i32 %83, i32* %10
%84 = load i32, i32* %6
%85 = call i32 @close(i32 %84)
%86 = load i32, i32* %7
%87 = call i32 @close(i32 %86)
%88 = load i32, i32* %10
store i32 %88, i32* @errno
store i32 -1, i32* %3
br label %137
89: ; preds = %29
%90 = call i32 (...) @fork()
%91 = load i32*, i32** %4
store i32 %90, i32* %91
%92 = load i32*, i32** %4
%93 = load i32, i32* %92
%94 = icmp eq i32 %93, -1
br i1 %94, label %95, label %102
95: ; preds = %89
%96 = load i32, i32* @errno
store i32 %96, i32* %11
%97 = load i32, i32* %6
%98 = call i32 @close(i32 %97)
%99 = load i32, i32* %7
%100 = call i32 @close(i32 %99)
%101 = load i32, i32* %11
store i32 %101, i32* @errno
store i32 -1, i32* %3
br label %137
102: ; preds = %89
%103 = load i32*, i32** %4
%104 = load i32, i32* %103
%105 = icmp eq i32 %104, 0
br i1 %105, label %106, label %131
106: ; preds = %102
%107 = load i32, i32* @PATH_MAX
%108 = zext i32 %107 to i64
%109 = call i8* @llvm.stacksave()
store i8* %109, i8** %12
%110 = alloca i8, i64 %108
store i64 %108, i64* %13
%111 = load i32, i32* %7
%112 = call i32 @ttyname(i32 %111)
%113 = call i8* @strrchr(i32 %112, i8 signext 47)
%114 = getelementptr inbounds i8, i8* %113, i64 1
%115 = load i32, i32* %7
%116 = call i32 @sprintf(i8* %110, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %114, i32 %115)
%117 = getelementptr inbounds [6 x i8*], [6 x i8*]* %14, i64 0, i64 0
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8** %117
%118 = getelementptr inbounds i8*, i8** %117, i64 1
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8** %118
%119 = getelementptr inbounds i8*, i8** %118, i64 1
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8** %119
%120 = getelementptr inbounds i8*, i8** %119, i64 1
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8** %120
%121 = getelementptr inbounds i8*, i8** %120, i64 1
store i8* %110, i8** %121
%122 = getelementptr inbounds i8*, i8** %121, i64 1
store i8* null, i8** %122
%123 = load i32, i32* %6
%124 = call i32 @close(i32 %123)
%125 = getelementptr inbounds [6 x i8*], [6 x i8*]* %14, i64 0, i64 0
%126 = load i8*, i8** %125
%127 = getelementptr inbounds [6 x i8*], [6 x i8*]* %14, i64 0, i64 0
%128 = call i32 @execv(i8* %126, i8** %127)
%129 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%130 = call i32 @_exit(i32 1)
unreachable
131: ; preds = %102
br label %132
132: ; preds = %131
%133 = load i32, i32* %7
%134 = call i32 @close(i32 %133)
%135 = load i32, i32* %6
%136 = load i32*, i32** %5
store i32 %135, i32* %136
store i32 0, i32* %3
br label %137
137: ; preds = %132, %95, %82, %22, %17
%138 = load i32, i32* %3
ret i32 %138
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i32, i32 }
@errno = global i32 0
@IGNBRK = global i32 0
@BRKINT = global i32 0
@PARMRK = global i32 0
@ISTRIP = global i32 0
@INLCR = global i32 0
@IGNCR = global i32 0
@ICRNL = global i32 0
@IXON = global i32 0
@OPOST = global i32 0
@ECHO = global i32 0
@ECHONL = global i32 0
@ICANON = global i32 0
@ISIG = global i32 0
@IEXTEN = global i32 0
@CSIZE = global i32 0
@PARENB = global i32 0
@CS8 = global i32 0
@TCSANOW = global i32 0
@PATH_MAX = global i32 0
@.str = [8 x i8] c"-S%s/%d\00"
@.str.1 = [15 x i8] c"/usr/bin/xterm\00"
@.str.2 = [7 x i8] c"-title\00"
@.str.3 = [16 x i8] c"Machine console\00"
@.str.4 = [10 x i8] c"-samename\00"
@.str.5 = [6 x i8] c"execv\00"
define i32 @fork_xterm(i32* nocapture writeonly %0, i32* nocapture writeonly %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.termios
%6 = alloca [6 x i8*]
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = bitcast %struct.termios* %5 to i8*
%10 = call i32 @openpty(i32* %3, i32* %4, i32* null, i32* null, i32* null)
%11 = icmp eq i32 %10, -1
br i1 %11, label %113, label %12
12: ; preds = %2
%13 = load i32, i32* %3
%14 = call i32 @tcgetattr(i32 %13, %struct.termios* %5)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %22
16: ; preds = %12
%17 = load i32, i32* @errno
%18 = load i32, i32* %3
%19 = call i32 @close(i32 %18)
%20 = load i32, i32* %4
%21 = call i32 @close(i32 %20)
store i32 %17, i32* @errno
br label %113
22: ; preds = %12
%23 = load i32, i32* @IGNBRK
%24 = load i32, i32* @BRKINT
%25 = or i32 %24, %23
%26 = load i32, i32* @PARMRK
%27 = or i32 %25, %26
%28 = load i32, i32* @ISTRIP
%29 = or i32 %27, %28
%30 = load i32, i32* @INLCR
%31 = or i32 %29, %30
%32 = load i32, i32* @IGNCR
%33 = or i32 %31, %32
%34 = load i32, i32* @ICRNL
%35 = or i32 %33, %34
%36 = load i32, i32* @IXON
%37 = or i32 %35, %36
%38 = xor i32 %37, -1
%39 = getelementptr inbounds %struct.termios, %struct.termios* %5, i64 0, i32 0
%40 = load i32, i32* %39
%41 = and i32 %40, %38
store i32 %41, i32* %39
%42 = load i32, i32* @OPOST
%43 = xor i32 %42, -1
%44 = getelementptr inbounds %struct.termios, %struct.termios* %5, i64 0, i32 3
%45 = load i32, i32* %44
%46 = and i32 %45, %43
store i32 %46, i32* %44
%47 = load i32, i32* @ECHO
%48 = load i32, i32* @ECHONL
%49 = or i32 %48, %47
%50 = load i32, i32* @ICANON
%51 = or i32 %49, %50
%52 = load i32, i32* @ISIG
%53 = or i32 %51, %52
%54 = load i32, i32* @IEXTEN
%55 = or i32 %53, %54
%56 = xor i32 %55, -1
%57 = getelementptr inbounds %struct.termios, %struct.termios* %5, i64 0, i32 1
%58 = load i32, i32* %57
%59 = and i32 %58, %56
store i32 %59, i32* %57
%60 = load i32, i32* @CSIZE
%61 = load i32, i32* @PARENB
%62 = or i32 %61, %60
%63 = xor i32 %62, -1
%64 = getelementptr inbounds %struct.termios, %struct.termios* %5, i64 0, i32 2
%65 = load i32, i32* %64
%66 = and i32 %65, %63
%67 = load i32, i32* @CS8
%68 = or i32 %67, %66
store i32 %68, i32* %64
%69 = load i32, i32* %3
%70 = load i32, i32* @TCSANOW
%71 = call i32 @tcsetattr(i32 %69, i32 %70, %struct.termios* %5)
%72 = icmp eq i32 %71, -1
br i1 %72, label %73, label %79
73: ; preds = %22
%74 = load i32, i32* @errno
%75 = load i32, i32* %3
%76 = call i32 @close(i32 %75)
%77 = load i32, i32* %4
%78 = call i32 @close(i32 %77)
store i32 %74, i32* @errno
br label %113
79: ; preds = %22
%80 = call i32 (...) @fork()
store i32 %80, i32* %0
switch i32 %80, label %109 [
i32 -1, label %81
i32 0, label %87
]
81: ; preds = %79
%82 = load i32, i32* @errno
%83 = load i32, i32* %3
%84 = call i32 @close(i32 %83)
%85 = load i32, i32* %4
%86 = call i32 @close(i32 %85)
store i32 %82, i32* @errno
br label %113
87: ; preds = %79
%88 = load i32, i32* @PATH_MAX
%89 = zext i32 %88 to i64
%90 = alloca i8, i64 %89
%91 = load i32, i32* %4
%92 = call i32 @ttyname(i32 %91)
%93 = call i8* @strrchr(i32 %92, i8 signext 47)
%94 = getelementptr inbounds i8, i8* %93, i64 1
%95 = load i32, i32* %4
%96 = call i32 @sprintf(i8* %90, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %94, i32 %95)
%97 = bitcast [6 x i8*]* %6 to i8*
%98 = getelementptr inbounds [6 x i8*], [6 x i8*]* %6, i64 0, i64 0
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8** %98
%99 = getelementptr inbounds [6 x i8*], [6 x i8*]* %6, i64 0, i64 1
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8** %99
%100 = getelementptr inbounds [6 x i8*], [6 x i8*]* %6, i64 0, i64 2
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8** %100
%101 = getelementptr inbounds [6 x i8*], [6 x i8*]* %6, i64 0, i64 3
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8** %101
%102 = getelementptr inbounds [6 x i8*], [6 x i8*]* %6, i64 0, i64 4
store i8* %90, i8** %102
%103 = getelementptr inbounds [6 x i8*], [6 x i8*]* %6, i64 0, i64 5
store i8* null, i8** %103
%104 = load i32, i32* %3
%105 = call i32 @close(i32 %104)
%106 = call i32 @execv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8** %98)
%107 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%108 = call i32 @_exit(i32 1)
unreachable
109: ; preds = %79
%110 = load i32, i32* %4
%111 = call i32 @close(i32 %110)
%112 = load i32, i32* %3
store i32 %112, i32* %1
br label %113
113: ; preds = %2, %109, %81, %73, %16
%114 = phi i32 [ -1, %16 ], [ -1, %73 ], [ -1, %81 ], [ 0, %109 ], [ -1, %2 ]
ret i32 %114
}