#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*/ F_DUPFD_CLOEXEC;
int O_CLOEXEC;
int O_RDONLY;
int O_RDWR;
int /*<<< orphan*/ TIOCNOTTY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dprintf(int, char *, char *, char *, ...);
int /*<<< orphan*/ dup2(int, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ execvp(char *, char **);
int fcntl(int, int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/);
int isatty(int);
int open(char *, int);
int /*<<< orphan*/ pipe2(int *, int);
scalar_t__ read(int, int *, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  if (argc < 2) {
    fprintf(stderr, "Usage: %s command [arg]...\n", argv[0]);
    return 2;
  }
  int errtty = isatty(2);
  int pipefd[2];
  pipe2(pipefd, O_CLOEXEC);
  pid_t pid = fork();
  if (pid < 0) {
    fprintf(stderr, "%s: fork: %s\n", argv[0], strerror(errno));
    return 1;
  } else if (pid == 0) {
    close(pipefd[0]);
    int ttyfd = open("/dev/tty", O_RDONLY | O_CLOEXEC);
    if (ttyfd >= 0) {
      ioctl(ttyfd, TIOCNOTTY);
      close(ttyfd);
    }
    int errfd;
    if (errtty)
      errfd = fcntl(2, F_DUPFD_CLOEXEC);
    else
      errfd = 2;
    int nullfd = open("/dev/null", O_RDWR | O_CLOEXEC);
    if (nullfd < 0) {
      dprintf(errfd, "%s: couldn't open /dev/null: %s\n", argv[0],
              strerror(errno));
      if (isatty(0))
        close(0);
      if (isatty(1))
        close(1);
      if (errtty)
        close(2);
    } else {
      if (isatty(0))
        dup2(nullfd, 0);
      if (isatty(1))
        dup2(nullfd, 1);
      if (errtty)
        dup2(nullfd, 2);
    }
    execvp(argv[1], argv + 1);
    dprintf(errfd, "%s: %s: %s\n", argv[0], argv[1], strerror(errno));
    write(pipefd[1], "", 1);
    close(pipefd[1]);
    return 1;
  } else {
    close(pipefd[1]);
    if (read(pipefd[0], &pipefd[1], 1) > 0) {
      return 1;
    } else {
      return 0;
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    122a <main+0x4a>
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xde9(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    14ee <main+0x30e>
mov    $0x2,%edi
call   1030 <isatty@plt>
mov    %eax,-0x14(%rbp)
lea    -0x1c(%rbp),%rdi
mov    0x2d66(%rip),%rax
mov    (%rax),%esi
call   10e0 <pipe2@plt>
mov    $0x0,%al
call   1100 <fork@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jge    12a8 <main+0xc8>
mov    0x2d5a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    0x2d3b(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rdx
mov    %rax,%rcx
lea    0xd87(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14ee <main+0x30e>
cmpq   $0x0,-0x28(%rbp)
jne    14b4 <main+0x2d4>
mov    -0x1c(%rbp),%edi
call   1080 <close@plt>
mov    0x2d16(%rip),%rax
mov    (%rax),%esi
mov    0x2cdd(%rip),%rax
or     (%rax),%esi
lea    0xd56(%rip),%rdi
call   10c0 <open@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jl     12ff <main+0x11f>
mov    -0x2c(%rbp),%edi
mov    0x2d00(%rip),%rax
mov    (%rax),%esi
call   1070 <ioctl@plt>
mov    -0x2c(%rbp),%edi
call   1080 <close@plt>
cmpl   $0x0,-0x14(%rbp)
je     1324 <main+0x144>
mov    0x2cc0(%rip),%rax
mov    (%rax),%esi
mov    $0x2,%edi
call   1040 <fcntl@plt>
mov    %eax,-0x30(%rbp)
jmp    132b <main+0x14b>
movl   $0x2,-0x30(%rbp)
mov    0x2cae(%rip),%rax
mov    (%rax),%esi
mov    0x2c6d(%rip),%rax
or     (%rax),%esi
lea    0xcef(%rip),%rdi
call   10c0 <open@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    13da <main+0x1fa>
mov    -0x30(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x50(%rbp)
mov    0x2c4a(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x54(%rbp),%edi
mov    -0x50(%rbp),%rdx
mov    %rax,%rcx
lea    0xcb7(%rip),%rsi
mov    $0x0,%al
call   1090 <dprintf@plt>
xor    %edi,%edi
call   1030 <isatty@plt>
cmp    $0x0,%eax
je     13a4 <main+0x1c4>
xor    %edi,%edi
call   1080 <close@plt>
mov    $0x1,%edi
call   1030 <isatty@plt>
cmp    $0x0,%eax
je     13c1 <main+0x1e1>
mov    $0x1,%edi
call   1080 <close@plt>
cmpl   $0x0,-0x14(%rbp)
je     13d5 <main+0x1f5>
mov    $0x2,%edi
call   1080 <close@plt>
jmp    1430 <main+0x250>
xor    %edi,%edi
call   1030 <isatty@plt>
cmp    $0x0,%eax
je     13f4 <main+0x214>
mov    -0x34(%rbp),%edi
xor    %esi,%esi
call   1060 <dup2@plt>
mov    $0x1,%edi
call   1030 <isatty@plt>
cmp    $0x0,%eax
je     1414 <main+0x234>
mov    -0x34(%rbp),%edi
mov    $0x1,%esi
call   1060 <dup2@plt>
cmpl   $0x0,-0x14(%rbp)
je     142b <main+0x24b>
mov    -0x34(%rbp),%edi
mov    $0x2,%esi
call   1060 <dup2@plt>
jmp    1430 <main+0x250>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
call   10d0 <execvp@plt>
mov    -0x30(%rbp),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x68(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x60(%rbp)
mov    0x2b4f(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
mov    -0x6c(%rbp),%edi
mov    -0x68(%rbp),%rdx
mov    -0x60(%rbp),%rcx
mov    %rax,%r8
lea    0xbd9(%rip),%rsi
mov    $0x0,%al
call   1090 <dprintf@plt>
mov    -0x18(%rbp),%edi
lea    0xb85(%rip),%rsi
mov    $0x1,%edx
call   1050 <write@plt>
mov    -0x18(%rbp),%edi
call   1080 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    14ee <main+0x30e>
mov    -0x18(%rbp),%edi
call   1080 <close@plt>
mov    -0x1c(%rbp),%edi
lea    -0x1c(%rbp),%rsi
add    $0x4,%rsi
mov    $0x1,%edx
call   10a0 <read@plt>
cmp    $0x0,%rax
jle    14e7 <main+0x307>
movl   $0x1,-0x4(%rbp)
jmp    14ee <main+0x30e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
cmp    $0x1,%edi
jg     1218 <main+0x38>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xdf9(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0x2,%ebx
jmp    1430 <main+0x250>
mov    $0x2,%edi
call   1030 <isatty@plt>
mov    %eax,%r15d
mov    0x2d7c(%rip),%r12
mov    (%r12),%esi
lea    0x8(%rsp),%rdi
call   10e0 <pipe2@plt>
xor    %eax,%eax
call   1100 <fork@plt>
test   %rax,%rax
js     1274 <main+0x94>
je     12ae <main+0xce>
lea    0xc(%rsp),%rbx
mov    0xc(%rsp),%edi
call   1080 <close@plt>
mov    0x8(%rsp),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   10a0 <read@plt>
xor    %ebx,%ebx
test   %rax,%rax
setg   %bl
jmp    1430 <main+0x250>
mov    0x2d45(%rip),%rax
mov    (%rax),%ebp
mov    (%rbx),%rbx
mov    0x2d31(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
lea    0xd87(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0x1,%ebx
jmp    1430 <main+0x250>
mov    0x8(%rsp),%edi
call   1080 <close@plt>
mov    0x2d1a(%rip),%rax
mov    (%r12),%esi
or     (%rax),%esi
lea    0xd5f(%rip),%rdi
call   10c0 <open@plt>
test   %eax,%eax
js     12ed <main+0x10d>
mov    %eax,%ebp
mov    0x2d13(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   1070 <ioctl@plt>
mov    %ebp,%edi
call   1080 <close@plt>
test   %r15d,%r15d
je     130a <main+0x12a>
mov    0x2cd7(%rip),%rax
mov    (%rax),%esi
mov    $0x2,%edi
call   1040 <fcntl@plt>
mov    %eax,%r14d
jmp    1310 <main+0x130>
mov    $0x2,%r14d
mov    0x2cc9(%rip),%rax
mov    (%r12),%esi
or     (%rax),%esi
lea    0xd0f(%rip),%rdi
call   10c0 <open@plt>
test   %eax,%eax
js     1370 <main+0x190>
mov    %eax,%ebp
xor    %edi,%edi
call   1030 <isatty@plt>
test   %eax,%eax
je     1343 <main+0x163>
mov    %ebp,%edi
xor    %esi,%esi
call   1060 <dup2@plt>
mov    $0x1,%edi
call   1030 <isatty@plt>
test   %eax,%eax
je     135d <main+0x17d>
mov    %ebp,%edi
mov    $0x1,%esi
call   1060 <dup2@plt>
test   %r15d,%r15d
je     13d1 <main+0x1f1>
mov    %ebp,%edi
mov    $0x2,%esi
call   1060 <dup2@plt>
jmp    13d1 <main+0x1f1>
mov    (%rbx),%rbp
mov    0x2c3e(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
lea    0xcb5(%rip),%rsi
mov    %r14d,%edi
mov    %rbp,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1090 <dprintf@plt>
xor    %edi,%edi
call   1030 <isatty@plt>
test   %eax,%eax
je     13aa <main+0x1ca>
xor    %edi,%edi
call   1080 <close@plt>
mov    $0x1,%edi
call   1030 <isatty@plt>
test   %eax,%eax
je     13c2 <main+0x1e2>
mov    $0x1,%edi
call   1080 <close@plt>
test   %r15d,%r15d
je     13d1 <main+0x1f1>
mov    $0x2,%edi
call   1080 <close@plt>
lea    0x8(%rbx),%rsi
mov    0x8(%rbx),%rdi
call   10d0 <execvp@plt>
mov    (%rbx),%rbp
mov    0x8(%rbx),%rbx
mov    0x2bcc(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
lea    0xc64(%rip),%rsi
mov    %r14d,%edi
mov    %rbp,%rdx
mov    %rbx,%rcx
mov    %rax,%r8
xor    %eax,%eax
call   1090 <dprintf@plt>
mov    0xc(%rsp),%edi
lea    0xc03(%rip),%rsi
mov    $0x1,%ebx
mov    $0x1,%edx
call   1050 <write@plt>
mov    0xc(%rsp),%edi
call   1080 <close@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [28 x i8] c"Usage: %s command [arg]...\0A\00"
@O_CLOEXEC = global i32 0
@.str.1 = [14 x i8] c"%s: fork: %s\0A\00"
@errno = global i32 0
@.str.2 = [9 x i8] c"/dev/tty\00"
@O_RDONLY = global i32 0
@TIOCNOTTY = global i32 0
@F_DUPFD_CLOEXEC = global i32 0
@.str.3 = [10 x i8] c"/dev/null\00"
@O_RDWR = global i32 0
@.str.4 = [33 x i8] c"%s: couldn't open /dev/null: %s\0A\00"
@.str.5 = [12 x i8] c"%s: %s: %s\0A\00"
@.str.6 = [1 x i8] zeroinitializer
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [2 x i32]
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %18)
store i32 2, i32* %3
br label %145
20: ; preds = %2
%21 = call i32 @isatty(i32 2)
store i32 %21, i32* %6
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%23 = load i32, i32* @O_CLOEXEC
%24 = call i32 @pipe2(i32* %22, i32 %23)
%25 = call i64 (...) @fork()
store i64 %25, i64* %8
%26 = load i64, i64* %8
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %36
28: ; preds = %20
%29 = load i32, i32* @stderr
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 0
%32 = load i8*, i8** %31
%33 = load i32, i32* @errno
%34 = call i8* @strerror(i32 %33)
%35 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %32, i8* %34)
store i32 1, i32* %3
br label %145
36: ; preds = %20
%37 = load i64, i64* %8
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %134
39: ; preds = %36
%40 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%41 = load i32, i32* %40
%42 = call i32 @close(i32 %41)
%43 = load i32, i32* @O_RDONLY
%44 = load i32, i32* @O_CLOEXEC
%45 = or i32 %43, %44
%46 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %45)
store i32 %46, i32* %9
%47 = load i32, i32* %9
%48 = icmp sge i32 %47, 0
br i1 %48, label %49, label %55
49: ; preds = %39
%50 = load i32, i32* %9
%51 = load i32, i32* @TIOCNOTTY
%52 = call i32 @ioctl(i32 %50, i32 %51)
%53 = load i32, i32* %9
%54 = call i32 @close(i32 %53)
br label %55
55: ; preds = %49, %39
%56 = load i32, i32* %6
%57 = icmp ne i32 %56, 0
br i1 %57, label %58, label %61
58: ; preds = %55
%59 = load i32, i32* @F_DUPFD_CLOEXEC
%60 = call i32 @fcntl(i32 2, i32 %59)
store i32 %60, i32* %10
br label %62
61: ; preds = %55
store i32 2, i32* %10
br label %62
62: ; preds = %61, %58
%63 = load i32, i32* @O_RDWR
%64 = load i32, i32* @O_CLOEXEC
%65 = or i32 %63, %64
%66 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %65)
store i32 %66, i32* %11
%67 = load i32, i32* %11
%68 = icmp slt i32 %67, 0
br i1 %68, label %69, label %92
69: ; preds = %62
%70 = load i32, i32* %10
%71 = load i8**, i8*** %5
%72 = getelementptr inbounds i8*, i8** %71, i64 0
%73 = load i8*, i8** %72
%74 = load i32, i32* @errno
%75 = call i8* @strerror(i32 %74)
%76 = call i32 (i32, i8*, i8*, i8*, ...) @dprintf(i32 %70, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* %73, i8* %75)
%77 = call i32 @isatty(i32 0)
%78 = icmp ne i32 %77, 0
br i1 %78, label %79, label %81
79: ; preds = %69
%80 = call i32 @close(i32 0)
br label %81
81: ; preds = %79, %69
%82 = call i32 @isatty(i32 1)
%83 = icmp ne i32 %82, 0
br i1 %83, label %84, label %86
84: ; preds = %81
%85 = call i32 @close(i32 1)
br label %86
86: ; preds = %84, %81
%87 = load i32, i32* %6
%88 = icmp ne i32 %87, 0
br i1 %88, label %89, label %91
89: ; preds = %86
%90 = call i32 @close(i32 2)
br label %91
91: ; preds = %89, %86
br label %111
92: ; preds = %62
%93 = call i32 @isatty(i32 0)
%94 = icmp ne i32 %93, 0
br i1 %94, label %95, label %98
95: ; preds = %92
%96 = load i32, i32* %11
%97 = call i32 @dup2(i32 %96, i32 0)
br label %98
98: ; preds = %95, %92
%99 = call i32 @isatty(i32 1)
%100 = icmp ne i32 %99, 0
br i1 %100, label %101, label %104
101: ; preds = %98
%102 = load i32, i32* %11
%103 = call i32 @dup2(i32 %102, i32 1)
br label %104
104: ; preds = %101, %98
%105 = load i32, i32* %6
%106 = icmp ne i32 %105, 0
br i1 %106, label %107, label %110
107: ; preds = %104
%108 = load i32, i32* %11
%109 = call i32 @dup2(i32 %108, i32 2)
br label %110
110: ; preds = %107, %104
br label %111
111: ; preds = %110, %91
%112 = load i8**, i8*** %5
%113 = getelementptr inbounds i8*, i8** %112, i64 1
%114 = load i8*, i8** %113
%115 = load i8**, i8*** %5
%116 = getelementptr inbounds i8*, i8** %115, i64 1
%117 = call i32 @execvp(i8* %114, i8** %116)
%118 = load i32, i32* %10
%119 = load i8**, i8*** %5
%120 = getelementptr inbounds i8*, i8** %119, i64 0
%121 = load i8*, i8** %120
%122 = load i8**, i8*** %5
%123 = getelementptr inbounds i8*, i8** %122, i64 1
%124 = load i8*, i8** %123
%125 = load i32, i32* @errno
%126 = call i8* @strerror(i32 %125)
%127 = call i32 (i32, i8*, i8*, i8*, ...) @dprintf(i32 %118, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* %121, i8* %124, i8* %126)
%128 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%129 = load i32, i32* %128
%130 = call i32 @write(i32 %129, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i64 0, i64 0), i32 1)
%131 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%132 = load i32, i32* %131
%133 = call i32 @close(i32 %132)
store i32 1, i32* %3
br label %145
134: ; preds = %36
%135 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%136 = load i32, i32* %135
%137 = call i32 @close(i32 %136)
%138 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%139 = load i32, i32* %138
%140 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%141 = call i64 @read(i32 %139, i32* %140, i32 1)
%142 = icmp sgt i64 %141, 0
br i1 %142, label %143, label %144
143: ; preds = %134
store i32 1, i32* %3
br label %145
144: ; preds = %134
store i32 0, i32* %3
br label %145
145: ; preds = %144, %143, %111, %28, %14
%146 = load i32, i32* %3
ret i32 %146
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [28 x i8] c"Usage: %s command [arg]...\0A\00"
@O_CLOEXEC = global i32 0
@.str.1 = [14 x i8] c"%s: fork: %s\0A\00"
@errno = global i32 0
@.str.2 = [9 x i8] c"/dev/tty\00"
@O_RDONLY = global i32 0
@TIOCNOTTY = global i32 0
@F_DUPFD_CLOEXEC = global i32 0
@.str.3 = [10 x i8] c"/dev/null\00"
@O_RDWR = global i32 0
@.str.4 = [33 x i8] c"%s: couldn't open /dev/null: %s\0A\00"
@.str.5 = [12 x i8] c"%s: %s: %s\0A\00"
@.str.6 = [1 x i8] zeroinitializer
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [2 x i32]
%4 = icmp slt i32 %0, 2
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i8*, i8** %1
%8 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %103
9: ; preds = %2
%10 = tail call i32 @isatty(i32 2)
%11 = bitcast [2 x i32]* %3 to i8*
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%13 = load i32, i32* @O_CLOEXEC
%14 = call i32 @pipe2(i32* %12, i32 %13)
%15 = call i64 (...) @fork()
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %9
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %1
%20 = load i32, i32* @errno
%21 = call i8* @strerror(i32 %20)
%22 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %19, i8* %21)
br label %101
23: ; preds = %9
%24 = icmp eq i64 %15, 0
br i1 %24, label %25, label %93
25: ; preds = %23
%26 = load i32, i32* %12
%27 = call i32 @close(i32 %26)
%28 = load i32, i32* @O_RDONLY
%29 = load i32, i32* @O_CLOEXEC
%30 = or i32 %29, %28
%31 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %30)
%32 = icmp sgt i32 %31, -1
br i1 %32, label %33, label %37
33: ; preds = %25
%34 = load i32, i32* @TIOCNOTTY
%35 = call i32 @ioctl(i32 %31, i32 %34)
%36 = call i32 @close(i32 %31)
br label %37
37: ; preds = %33, %25
%38 = icmp eq i32 %10, 0
br i1 %38, label %42, label %39
39: ; preds = %37
%40 = load i32, i32* @F_DUPFD_CLOEXEC
%41 = call i32 @fcntl(i32 2, i32 %40)
br label %42
42: ; preds = %37, %39
%43 = phi i32 [ %41, %39 ], [ 2, %37 ]
%44 = load i32, i32* @O_RDWR
%45 = load i32, i32* @O_CLOEXEC
%46 = or i32 %45, %44
%47 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %46)
%48 = icmp slt i32 %47, 0
br i1 %48, label %49, label %66
49: ; preds = %42
%50 = load i8*, i8** %1
%51 = load i32, i32* @errno
%52 = call i8* @strerror(i32 %51)
%53 = call i32 (i32, i8*, i8*, i8*, ...) @dprintf(i32 %43, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* %50, i8* %52)
%54 = call i32 @isatty(i32 0)
%55 = icmp eq i32 %54, 0
br i1 %55, label %58, label %56
56: ; preds = %49
%57 = call i32 @close(i32 0)
br label %58
58: ; preds = %56, %49
%59 = call i32 @isatty(i32 1)
%60 = icmp eq i32 %59, 0
br i1 %60, label %63, label %61
61: ; preds = %58
%62 = call i32 @close(i32 1)
br label %63
63: ; preds = %61, %58
br i1 %38, label %79, label %64
64: ; preds = %63
%65 = call i32 @close(i32 2)
br label %79
66: ; preds = %42
%67 = call i32 @isatty(i32 0)
%68 = icmp eq i32 %67, 0
br i1 %68, label %71, label %69
69: ; preds = %66
%70 = call i32 @dup2(i32 %47, i32 0)
br label %71
71: ; preds = %69, %66
%72 = call i32 @isatty(i32 1)
%73 = icmp eq i32 %72, 0
br i1 %73, label %76, label %74
74: ; preds = %71
%75 = call i32 @dup2(i32 %47, i32 1)
br label %76
76: ; preds = %74, %71
br i1 %38, label %79, label %77
77: ; preds = %76
%78 = call i32 @dup2(i32 %47, i32 2)
br label %79
79: ; preds = %76, %77, %63, %64
%80 = getelementptr inbounds i8*, i8** %1, i64 1
%81 = load i8*, i8** %80
%82 = call i32 @execvp(i8* %81, i8** %80)
%83 = load i8*, i8** %1
%84 = load i8*, i8** %80
%85 = load i32, i32* @errno
%86 = call i8* @strerror(i32 %85)
%87 = call i32 (i32, i8*, i8*, i8*, ...) @dprintf(i32 %43, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* %83, i8* %84, i8* %86)
%88 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%89 = load i32, i32* %88
%90 = call i32 @write(i32 %89, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i64 0, i64 0), i32 1)
%91 = load i32, i32* %88
%92 = call i32 @close(i32 %91)
br label %101
93: ; preds = %23
%94 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%95 = load i32, i32* %94
%96 = call i32 @close(i32 %95)
%97 = load i32, i32* %12
%98 = call i64 @read(i32 %97, i32* %94, i32 1)
%99 = icmp sgt i64 %98, 0
%100 = zext i1 %99 to i32
br label %101
101: ; preds = %93, %79, %17
%102 = phi i32 [ 1, %17 ], [ 1, %79 ], [ %100, %93 ]
br label %103
103: ; preds = %101, %5
%104 = phi i32 [ 2, %5 ], [ %102, %101 ]
ret i32 %104
}