#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 */
typedef scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int STDIN_FILENO;
int STDOUT_FILENO;
scalar_t__ close(int);
scalar_t__ dup2(int, int);
int errno;
scalar_t__ execlp(char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ perror(char *);
scalar_t__ pipe(int *);
int do_driver(char *driver) {
  int pty_to_driver[2];
  int driver_to_pty[2];
  int err_code;
  if (pipe(pty_to_driver) < 0)
    return -1;
  if (pipe(driver_to_pty) < 0) {
    err_code = errno;
    goto ptdout;
  }
  pid_t pid;
  if ((pid = fork()) < 0) {
    err_code = errno;
    goto dtpout;
  }
  if (pid == 0) {
    if (close(pty_to_driver[1]) < 0) {
      perror("Error closing pty_to_driver write channel on driver child");
      exit(EXIT_FAILURE);
    }
    if (close(driver_to_pty[0]) < 0) {
      perror("Error closing driver_to_pty read channel on driver child");
      exit(EXIT_FAILURE);
    }
    if (dup2(pty_to_driver[0], STDIN_FILENO) < 0) {
      perror("Error duplicating pty_to_driver read channel to stdin on driver "
             "child");
      exit(EXIT_FAILURE);
    }
    if (pty_to_driver[0] != STDIN_FILENO) {
      if (close(pty_to_driver[0]) < 0) {
        perror("Error closing pty_to_driver read channel after successfully "
               "duplicating it to stdin");
        exit(EXIT_FAILURE);
      }
    }
    if (dup2(driver_to_pty[1], STDOUT_FILENO) < 0) {
      perror("Error duplicating driver_to_pty write channel to stdout on "
             "driver child");
      exit(EXIT_FAILURE);
    }
    if (driver_to_pty[1] != STDOUT_FILENO) {
      if (close(driver_to_pty[1]) < 0) {
        perror("Error closing driver_to_pty write channel after successfully "
               "duplicating it to stdout");
        exit(EXIT_FAILURE);
      }
    }
    if (execlp(driver, driver, NULL) < 0) {
      perror("execl(2) error");
      exit(EXIT_FAILURE);
    }
  }
  if (close(driver_to_pty[1]) < 0) {
    err_code = errno;
    goto dtpout;
  }
  if (close(pty_to_driver[0]) < 0) {
    err_code = errno;
    goto dtpout;
  }
  if (dup2(pty_to_driver[1], STDOUT_FILENO) < 0) {
    err_code = errno;
    goto dtpout;
  }
  if (pty_to_driver[1] != STDOUT_FILENO) {
    if (close(pty_to_driver[1]) < 0) {
      err_code = errno;
      goto dtpout;
    }
  }
  if (dup2(driver_to_pty[0], STDIN_FILENO) < 0) {
    err_code = errno;
    goto dtpout;
  }
  if (driver_to_pty[0] != STDIN_FILENO) {
    if (close(driver_to_pty[0]) < 0) {
      err_code = errno;
      goto dtpout;
    }
  }
  return 0;
dtpout:
  close(driver_to_pty[0]);
  close(driver_to_pty[1]);
ptdout:
  close(pty_to_driver[0]);
  close(pty_to_driver[1]);
  errno = err_code;
  return -1;
}


x86 assembly (clang, -O0):
<do_driver>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
call   1050 <pipe@plt>
cmp    $0x0,%rax
jge    119b <do_driver+0x2b>
movl   $0xffffffff,-0x4(%rbp)
jmp    14c3 <do_driver+0x353>
lea    -0x20(%rbp),%rdi
call   1050 <pipe@plt>
cmp    $0x0,%rax
jge    11bf <do_driver+0x4f>
mov    0x2e23(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
jmp    14a0 <do_driver+0x330>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jge    11e5 <do_driver+0x75>
mov    0x2dfd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
jmp    1490 <do_driver+0x320>
cmpq   $0x0,-0x30(%rbp)
jne    1372 <do_driver+0x202>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
cmp    $0x0,%rax
jge    121c <do_driver+0xac>
lea    0xdf7(%rip),%rdi
call   1060 <perror@plt>
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x20(%rbp),%edi
call   1040 <close@plt>
cmp    $0x0,%rax
jge    1248 <do_driver+0xd8>
lea    0xe05(%rip),%rdi
call   1060 <perror@plt>
mov    0x2d8f(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%edi
mov    0x2d76(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
cmp    $0x0,%rax
jge    127d <do_driver+0x10d>
lea    0xe09(%rip),%rdi
call   1060 <perror@plt>
mov    0x2d5a(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%eax
mov    0x2d41(%rip),%rcx
cmp    (%rcx),%eax
je     12c0 <do_driver+0x150>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
cmp    $0x0,%rax
jge    12bb <do_driver+0x14b>
lea    0xe11(%rip),%rdi
call   1060 <perror@plt>
mov    0x2d1c(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
jmp    12c0 <do_driver+0x150>
mov    -0x1c(%rbp),%edi
mov    0x2d26(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
cmp    $0x0,%rax
jge    12f5 <do_driver+0x185>
lea    0xe2b(%rip),%rdi
call   1060 <perror@plt>
mov    0x2ce2(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x1c(%rbp),%eax
mov    0x2cf1(%rip),%rcx
cmp    (%rcx),%eax
je     1338 <do_driver+0x1c8>
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
cmp    $0x0,%rax
jge    1333 <do_driver+0x1c3>
lea    0xe35(%rip),%rdi
call   1060 <perror@plt>
mov    0x2ca4(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
jmp    1338 <do_driver+0x1c8>
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1080 <execlp@plt>
cmp    $0x0,%rax
jge    136d <do_driver+0x1fd>
lea    0xe51(%rip),%rdi
call   1060 <perror@plt>
mov    0x2c6a(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
jmp    1372 <do_driver+0x202>
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
cmp    $0x0,%rax
jge    1395 <do_driver+0x225>
mov    0x2c4d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
jmp    1490 <do_driver+0x320>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
cmp    $0x0,%rax
jge    13b8 <do_driver+0x248>
mov    0x2c2a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
jmp    1490 <do_driver+0x320>
mov    -0x14(%rbp),%edi
mov    0x2c2e(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
cmp    $0x0,%rax
jge    13e4 <do_driver+0x274>
mov    0x2bfe(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
jmp    1490 <do_driver+0x320>
mov    -0x14(%rbp),%eax
mov    0x2c02(%rip),%rcx
cmp    (%rcx),%eax
je     141e <do_driver+0x2ae>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
cmp    $0x0,%rax
jge    1419 <do_driver+0x2a9>
mov    0x2bc9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
jmp    1490 <do_driver+0x320>
jmp    141e <do_driver+0x2ae>
mov    -0x20(%rbp),%edi
mov    0x2ba0(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
cmp    $0x0,%rax
jge    144a <do_driver+0x2da>
mov    0x2b98(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
jmp    1490 <do_driver+0x320>
mov    -0x20(%rbp),%eax
mov    0x2b74(%rip),%rcx
cmp    (%rcx),%eax
je     1484 <do_driver+0x314>
mov    -0x20(%rbp),%edi
call   1040 <close@plt>
cmp    $0x0,%rax
jge    147f <do_driver+0x30f>
mov    0x2b63(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
jmp    1490 <do_driver+0x320>
jmp    1484 <do_driver+0x314>
movl   $0x0,-0x4(%rbp)
jmp    14c3 <do_driver+0x353>
mov    -0x20(%rbp),%edi
call   1040 <close@plt>
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x24(%rbp),%ecx
mov    0x2b1e(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_driver>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
lea    0x10(%rsp),%rdi
call   1050 <pipe@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
js     1310 <do_driver+0x1a0>
lea    0x8(%rsp),%rdi
call   1050 <pipe@plt>
test   %rax,%rax
js     12e7 <do_driver+0x177>
xor    %eax,%eax
call   1090 <fork@plt>
test   %rax,%rax
js     12ca <do_driver+0x15a>
jne    125a <do_driver+0xea>
mov    0x14(%rsp),%edi
call   1040 <close@plt>
test   %rax,%rax
js     1319 <do_driver+0x1a9>
mov    0x8(%rsp),%edi
call   1040 <close@plt>
test   %rax,%rax
js     1322 <do_driver+0x1b2>
mov    0x10(%rsp),%edi
mov    0x2ddf(%rip),%rbp
mov    0x0(%rbp),%esi
call   1030 <dup2@plt>
test   %rax,%rax
js     132b <do_driver+0x1bb>
mov    0x10(%rsp),%edi
cmp    0x0(%rbp),%edi
je     1211 <do_driver+0xa1>
call   1040 <close@plt>
test   %rax,%rax
js     1346 <do_driver+0x1d6>
mov    0xc(%rsp),%edi
mov    0x2dd4(%rip),%rbp
mov    0x0(%rbp),%esi
call   1030 <dup2@plt>
test   %rax,%rax
js     1334 <do_driver+0x1c4>
mov    0xc(%rsp),%edi
cmp    0x0(%rbp),%edi
je     1244 <do_driver+0xd4>
call   1040 <close@plt>
test   %rax,%rax
js     134f <do_driver+0x1df>
mov    %rbx,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   1080 <execlp@plt>
test   %rax,%rax
js     133d <do_driver+0x1cd>
mov    0xc(%rsp),%edi
call   1040 <close@plt>
test   %rax,%rax
js     12ca <do_driver+0x15a>
mov    0x10(%rsp),%edi
call   1040 <close@plt>
test   %rax,%rax
js     12ca <do_driver+0x15a>
mov    0x14(%rsp),%edi
mov    0x2d6f(%rip),%rbx
mov    (%rbx),%esi
call   1030 <dup2@plt>
test   %rax,%rax
js     12ca <do_driver+0x15a>
mov    0x14(%rsp),%edi
cmp    (%rbx),%edi
je     129f <do_driver+0x12f>
call   1040 <close@plt>
test   %rax,%rax
js     12ca <do_driver+0x15a>
mov    0x8(%rsp),%edi
mov    0x2d1e(%rip),%rbx
mov    (%rbx),%esi
call   1030 <dup2@plt>
test   %rax,%rax
js     12ca <do_driver+0x15a>
mov    0x8(%rsp),%edi
xor    %ebp,%ebp
cmp    (%rbx),%edi
je     1310 <do_driver+0x1a0>
call   1040 <close@plt>
test   %rax,%rax
jns    1310 <do_driver+0x1a0>
mov    0x2d07(%rip),%rax
mov    (%rax),%ebx
mov    0x8(%rsp),%edi
call   1040 <close@plt>
mov    0xc(%rsp),%edi
call   1040 <close@plt>
jmp    12f0 <do_driver+0x180>
mov    0x2cea(%rip),%rax
mov    (%rax),%ebx
mov    0x10(%rsp),%edi
call   1040 <close@plt>
mov    0x14(%rsp),%edi
call   1040 <close@plt>
mov    0x2ccf(%rip),%rax
mov    %ebx,(%rax)
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xce0(%rip),%rdi
jmp    1356 <do_driver+0x1e6>
lea    0xd11(%rip),%rdi
jmp    1356 <do_driver+0x1e6>
lea    0xd41(%rip),%rdi
jmp    1356 <do_driver+0x1e6>
lea    0xdd2(%rip),%rdi
jmp    1356 <do_driver+0x1e6>
lea    0xe67(%rip),%rdi
jmp    1356 <do_driver+0x1e6>
lea    0xd6c(%rip),%rdi
jmp    1356 <do_driver+0x1e6>
lea    0xdff(%rip),%rdi
call   1060 <perror@plt>
mov    0x2c6e(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@errno = global i32 0
@.str = [58 x i8] c"Error closing pty_to_driver write channel on driver child\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [57 x i8] c"Error closing driver_to_pty read channel on driver child\00"
@STDIN_FILENO = global i32 0
@.str.2 = [70 x i8] c"Error duplicating pty_to_driver read channel to stdin on driver child\00"
@.str.3 = [84 x i8] c"Error closing pty_to_driver read channel after successfully duplicating it to stdin\00"
@STDOUT_FILENO = global i32 0
@.str.4 = [72 x i8] c"Error duplicating driver_to_pty write channel to stdout on driver child\00"
@.str.5 = [86 x i8] c"Error closing driver_to_pty write channel after successfully duplicating it to stdout\00"
@.str.6 = [15 x i8] c"execl(2) error\00"
define i32 @do_driver(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [2 x i32]
%5 = alloca [2 x i32]
%6 = alloca i32
%7 = alloca i64
store i8* %0, i8** %3
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%9 = call i64 @pipe(i32* %8)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 -1, i32* %2
br label %176
12: ; preds = %1
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%14 = call i64 @pipe(i32* %13)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = load i32, i32* @errno
store i32 %17, i32* %6
br label %168
18: ; preds = %12
%19 = call i64 (...) @fork()
store i64 %19, i64* %7
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = load i32, i32* @errno
store i32 %22, i32* %6
br label %161
23: ; preds = %18
%24 = load i64, i64* %7
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %104
26: ; preds = %23
%27 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%28 = load i32, i32* %27
%29 = call i64 @close(i32 %28)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %26
%32 = call i32 @perror(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0))
%33 = load i32, i32* @EXIT_FAILURE
%34 = call i32 @exit(i32 %33)
unreachable
35: ; preds = %26
%36 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%37 = load i32, i32* %36
%38 = call i64 @close(i32 %37)
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %44
40: ; preds = %35
%41 = call i32 @perror(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0))
%42 = load i32, i32* @EXIT_FAILURE
%43 = call i32 @exit(i32 %42)
unreachable
44: ; preds = %35
%45 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%46 = load i32, i32* %45
%47 = load i32, i32* @STDIN_FILENO
%48 = call i64 @dup2(i32 %46, i32 %47)
%49 = icmp slt i64 %48, 0
br i1 %49, label %50, label %54
50: ; preds = %44
%51 = call i32 @perror(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.2, i64 0, i64 0))
%52 = load i32, i32* @EXIT_FAILURE
%53 = call i32 @exit(i32 %52)
unreachable
54: ; preds = %44
%55 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%56 = load i32, i32* %55
%57 = load i32, i32* @STDIN_FILENO
%58 = icmp ne i32 %56, %57
br i1 %58, label %59, label %69
59: ; preds = %54
%60 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%61 = load i32, i32* %60
%62 = call i64 @close(i32 %61)
%63 = icmp slt i64 %62, 0
br i1 %63, label %64, label %68
64: ; preds = %59
%65 = call i32 @perror(i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.3, i64 0, i64 0))
%66 = load i32, i32* @EXIT_FAILURE
%67 = call i32 @exit(i32 %66)
unreachable
68: ; preds = %59
br label %69
69: ; preds = %68, %54
%70 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%71 = load i32, i32* %70
%72 = load i32, i32* @STDOUT_FILENO
%73 = call i64 @dup2(i32 %71, i32 %72)
%74 = icmp slt i64 %73, 0
br i1 %74, label %75, label %79
75: ; preds = %69
%76 = call i32 @perror(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.4, i64 0, i64 0))
%77 = load i32, i32* @EXIT_FAILURE
%78 = call i32 @exit(i32 %77)
unreachable
79: ; preds = %69
%80 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%81 = load i32, i32* %80
%82 = load i32, i32* @STDOUT_FILENO
%83 = icmp ne i32 %81, %82
br i1 %83, label %84, label %94
84: ; preds = %79
%85 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%86 = load i32, i32* %85
%87 = call i64 @close(i32 %86)
%88 = icmp slt i64 %87, 0
br i1 %88, label %89, label %93
89: ; preds = %84
%90 = call i32 @perror(i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str.5, i64 0, i64 0))
%91 = load i32, i32* @EXIT_FAILURE
%92 = call i32 @exit(i32 %91)
unreachable
93: ; preds = %84
br label %94
94: ; preds = %93, %79
%95 = load i8*, i8** %3
%96 = load i8*, i8** %3
%97 = call i64 @execlp(i8* %95, i8* %96, i32* null)
%98 = icmp slt i64 %97, 0
br i1 %98, label %99, label %103
99: ; preds = %94
%100 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
%101 = load i32, i32* @EXIT_FAILURE
%102 = call i32 @exit(i32 %101)
unreachable
103: ; preds = %94
br label %104
104: ; preds = %103, %23
%105 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%106 = load i32, i32* %105
%107 = call i64 @close(i32 %106)
%108 = icmp slt i64 %107, 0
br i1 %108, label %109, label %111
109: ; preds = %104
%110 = load i32, i32* @errno
store i32 %110, i32* %6
br label %161
111: ; preds = %104
%112 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%113 = load i32, i32* %112
%114 = call i64 @close(i32 %113)
%115 = icmp slt i64 %114, 0
br i1 %115, label %116, label %118
116: ; preds = %111
%117 = load i32, i32* @errno
store i32 %117, i32* %6
br label %161
118: ; preds = %111
%119 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%120 = load i32, i32* %119
%121 = load i32, i32* @STDOUT_FILENO
%122 = call i64 @dup2(i32 %120, i32 %121)
%123 = icmp slt i64 %122, 0
br i1 %123, label %124, label %126
124: ; preds = %118
%125 = load i32, i32* @errno
store i32 %125, i32* %6
br label %161
126: ; preds = %118
%127 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%128 = load i32, i32* %127
%129 = load i32, i32* @STDOUT_FILENO
%130 = icmp ne i32 %128, %129
br i1 %130, label %131, label %139
131: ; preds = %126
%132 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%133 = load i32, i32* %132
%134 = call i64 @close(i32 %133)
%135 = icmp slt i64 %134, 0
br i1 %135, label %136, label %138
136: ; preds = %131
%137 = load i32, i32* @errno
store i32 %137, i32* %6
br label %161
138: ; preds = %131
br label %139
139: ; preds = %138, %126
%140 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%141 = load i32, i32* %140
%142 = load i32, i32* @STDIN_FILENO
%143 = call i64 @dup2(i32 %141, i32 %142)
%144 = icmp slt i64 %143, 0
br i1 %144, label %145, label %147
145: ; preds = %139
%146 = load i32, i32* @errno
store i32 %146, i32* %6
br label %161
147: ; preds = %139
%148 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%149 = load i32, i32* %148
%150 = load i32, i32* @STDIN_FILENO
%151 = icmp ne i32 %149, %150
br i1 %151, label %152, label %160
152: ; preds = %147
%153 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%154 = load i32, i32* %153
%155 = call i64 @close(i32 %154)
%156 = icmp slt i64 %155, 0
br i1 %156, label %157, label %159
157: ; preds = %152
%158 = load i32, i32* @errno
store i32 %158, i32* %6
br label %161
159: ; preds = %152
br label %160
160: ; preds = %159, %147
store i32 0, i32* %2
br label %176
161: ; preds = %157, %145, %136, %124, %116, %109, %21
%162 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%163 = load i32, i32* %162
%164 = call i64 @close(i32 %163)
%165 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%166 = load i32, i32* %165
%167 = call i64 @close(i32 %166)
br label %168
168: ; preds = %161, %16
%169 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%170 = load i32, i32* %169
%171 = call i64 @close(i32 %170)
%172 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%173 = load i32, i32* %172
%174 = call i64 @close(i32 %173)
%175 = load i32, i32* %6
store i32 %175, i32* @errno
store i32 -1, i32* %2
br label %176
176: ; preds = %168, %160, %11
%177 = load i32, i32* %2
ret i32 %177
}

LLVM IR (-O2):
@errno = global i32 0
@.str = [58 x i8] c"Error closing pty_to_driver write channel on driver child\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [57 x i8] c"Error closing driver_to_pty read channel on driver child\00"
@STDIN_FILENO = global i32 0
@.str.2 = [70 x i8] c"Error duplicating pty_to_driver read channel to stdin on driver child\00"
@.str.3 = [84 x i8] c"Error closing pty_to_driver read channel after successfully duplicating it to stdin\00"
@STDOUT_FILENO = global i32 0
@.str.4 = [72 x i8] c"Error duplicating driver_to_pty write channel to stdout on driver child\00"
@.str.5 = [86 x i8] c"Error closing driver_to_pty write channel after successfully duplicating it to stdout\00"
@.str.6 = [15 x i8] c"execl(2) error\00"
define i32 @do_driver(i8* %0) {
%2 = alloca [2 x i32]
%3 = alloca [2 x i32]
%4 = bitcast [2 x i32]* %2 to i8*
%5 = bitcast [2 x i32]* %3 to i8*
%6 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%7 = call i64 @pipe(i32* %6)
%8 = icmp slt i64 %7, 0
br i1 %8, label %133, label %9
9: ; preds = %1
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%11 = call i64 @pipe(i32* %10)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = load i32, i32* @errno
br label %126
15: ; preds = %9
%16 = call i64 (...) @fork()
%17 = icmp slt i64 %16, 0
br i1 %17, label %119, label %18
18: ; preds = %15
%19 = icmp eq i64 %16, 0
br i1 %19, label %20, label %85
20: ; preds = %18
%21 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%22 = load i32, i32* %21
%23 = call i64 @close(i32 %22)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %20
%26 = call i32 @perror(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0))
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %20
%30 = load i32, i32* %10
%31 = call i64 @close(i32 %30)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %29
%34 = call i32 @perror(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0))
%35 = load i32, i32* @EXIT_FAILURE
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %29
%38 = load i32, i32* %6
%39 = load i32, i32* @STDIN_FILENO
%40 = call i64 @dup2(i32 %38, i32 %39)
%41 = icmp slt i64 %40, 0
br i1 %41, label %42, label %46
42: ; preds = %37
%43 = call i32 @perror(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.2, i64 0, i64 0))
%44 = load i32, i32* @EXIT_FAILURE
%45 = call i32 @exit(i32 %44)
unreachable
46: ; preds = %37
%47 = load i32, i32* %6
%48 = load i32, i32* @STDIN_FILENO
%49 = icmp eq i32 %47, %48
br i1 %49, label %57, label %50
50: ; preds = %46
%51 = call i64 @close(i32 %47)
%52 = icmp slt i64 %51, 0
br i1 %52, label %53, label %57
53: ; preds = %50
%54 = call i32 @perror(i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.3, i64 0, i64 0))
%55 = load i32, i32* @EXIT_FAILURE
%56 = call i32 @exit(i32 %55)
unreachable
57: ; preds = %50, %46
%58 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%59 = load i32, i32* %58
%60 = load i32, i32* @STDOUT_FILENO
%61 = call i64 @dup2(i32 %59, i32 %60)
%62 = icmp slt i64 %61, 0
br i1 %62, label %63, label %67
63: ; preds = %57
%64 = call i32 @perror(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.4, i64 0, i64 0))
%65 = load i32, i32* @EXIT_FAILURE
%66 = call i32 @exit(i32 %65)
unreachable
67: ; preds = %57
%68 = load i32, i32* %58
%69 = load i32, i32* @STDOUT_FILENO
%70 = icmp eq i32 %68, %69
br i1 %70, label %78, label %71
71: ; preds = %67
%72 = call i64 @close(i32 %68)
%73 = icmp slt i64 %72, 0
br i1 %73, label %74, label %78
74: ; preds = %71
%75 = call i32 @perror(i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str.5, i64 0, i64 0))
%76 = load i32, i32* @EXIT_FAILURE
%77 = call i32 @exit(i32 %76)
unreachable
78: ; preds = %71, %67
%79 = call i64 @execlp(i8* %0, i8* %0, i32* null)
%80 = icmp slt i64 %79, 0
br i1 %80, label %81, label %85
81: ; preds = %78
%82 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
%83 = load i32, i32* @EXIT_FAILURE
%84 = call i32 @exit(i32 %83)
unreachable
85: ; preds = %78, %18
%86 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%87 = load i32, i32* %86
%88 = call i64 @close(i32 %87)
%89 = icmp slt i64 %88, 0
br i1 %89, label %119, label %90
90: ; preds = %85
%91 = load i32, i32* %6
%92 = call i64 @close(i32 %91)
%93 = icmp slt i64 %92, 0
br i1 %93, label %119, label %94
94: ; preds = %90
%95 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%96 = load i32, i32* %95
%97 = load i32, i32* @STDOUT_FILENO
%98 = call i64 @dup2(i32 %96, i32 %97)
%99 = icmp slt i64 %98, 0
br i1 %99, label %119, label %100
100: ; preds = %94
%101 = load i32, i32* %95
%102 = load i32, i32* @STDOUT_FILENO
%103 = icmp eq i32 %101, %102
br i1 %103, label %107, label %104
104: ; preds = %100
%105 = call i64 @close(i32 %101)
%106 = icmp slt i64 %105, 0
br i1 %106, label %119, label %107
107: ; preds = %104, %100
%108 = load i32, i32* %10
%109 = load i32, i32* @STDIN_FILENO
%110 = call i64 @dup2(i32 %108, i32 %109)
%111 = icmp slt i64 %110, 0
br i1 %111, label %119, label %112
112: ; preds = %107
%113 = load i32, i32* %10
%114 = load i32, i32* @STDIN_FILENO
%115 = icmp eq i32 %113, %114
br i1 %115, label %133, label %116
116: ; preds = %112
%117 = call i64 @close(i32 %113)
%118 = icmp slt i64 %117, 0
br i1 %118, label %119, label %133
119: ; preds = %116, %107, %104, %94, %90, %85, %15
%120 = load i32, i32* @errno
%121 = load i32, i32* %10
%122 = call i64 @close(i32 %121)
%123 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%124 = load i32, i32* %123
%125 = call i64 @close(i32 %124)
br label %126
126: ; preds = %119, %13
%127 = phi i32 [ %14, %13 ], [ %120, %119 ]
%128 = load i32, i32* %6
%129 = call i64 @close(i32 %128)
%130 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%131 = load i32, i32* %130
%132 = call i64 @close(i32 %131)
store i32 %127, i32* @errno
br label %133
133: ; preds = %112, %116, %1, %126
%134 = phi i32 [ -1, %126 ], [ -1, %1 ], [ 0, %116 ], [ 0, %112 ]
ret i32 %134
}