#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 int /*<<< orphan*/ pid_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ PATH_MAX;
scalar_t__ WIFSIGNALED(int);
int WTERMSIG(int);
int close(int);
int dup2(int, int);
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ perror(char *);
int pipe(int *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ promptAndParse(char *, char **, char **);
int /*<<< orphan*/ waitpid(int /*<<< orphan*/, int *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int p[2];
  int status1, status2;
  pid_t child1, child2;
  char cmd[PATH_MAX + 1];
  char *upstream[PATH_MAX + 1];
  char *downstream[PATH_MAX + 1];
  while (promptAndParse(cmd, upstream, downstream)) {
    if (downstream[0] == NULL) {
      if ((child1 = fork()) == 0) {
        execvp(upstream[0], upstream);
        printf("Unknown command %s\n", upstream[0]);
        exit(EXIT_FAILURE);
      } else {
        waitpid(child1, &status1, 0);
        if (WIFSIGNALED(status1)) {
          printf("Child exited due to signal = %d\n", WTERMSIG(status1));
        }
      }
    } else {
      if (pipe(p) == -1) {
        do {
          perror("pipe creation");
          exit(EXIT_FAILURE);
        } while (0);
      }
      if ((child1 = fork()) == 0) {
        if (dup2(p[1], 1) == -1) {
          do {
            perror("dup2");
            exit(EXIT_FAILURE);
          } while (0);
        }
        if (close(p[0]) == -1) {
          do {
            perror("close");
            exit(EXIT_FAILURE);
          } while (0);
        }
        execvp(upstream[0], upstream);
        printf("Unknown command %s\n", upstream[0]);
        exit(EXIT_FAILURE);
      }
      if ((child2 = fork()) == 0) {
        if (dup2(p[0], 0) == -1) {
          do {
            perror("dup2");
            exit(EXIT_FAILURE);
          } while (0);
        }
        if (close(p[1]) == -1) {
          do {
            perror("close");
            exit(EXIT_FAILURE);
          } while (0);
        }
        execvp(downstream[0], downstream);
        printf("Unknown command %s\n", downstream[0]);
        exit(EXIT_FAILURE);
      } else {
        close(p[0]);
        close(p[1]);
        waitpid(child1, &status1, 0);
        waitpid(child2, &status2, 0);
        if (WIFSIGNALED(status1)) {
          printf("Child exited due to signal = %d\n", WTERMSIG(status1));
        }
        if (WIFSIGNALED(status2)) {
          printf("Child exited due to signal = %d\n", WTERMSIG(status2));
        }
      }
    }
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e13(%rip),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %rsp,%rdx
mov    %rdx,-0x30(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x60(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x38(%rbp)
mov    (%rax),%ecx
add    $0x1,%ecx
lea    0xf(,%rcx,8),%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x58(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x40(%rbp)
mov    (%rax),%eax
add    $0x1,%eax
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x48(%rbp)
mov    -0x50(%rbp),%rdx
mov    -0x58(%rbp),%rsi
mov    -0x60(%rbp),%rdi
call   10c0 <promptAndParse@plt>
cmp    $0x0,%rax
je     1501 <main+0x341>
mov    -0x50(%rbp),%rax
cmpq   $0x0,(%rax)
jne    12f6 <main+0x136>
mov    $0x0,%al
call   10e0 <fork@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jne    12b4 <main+0xf4>
mov    -0x58(%rbp),%rsi
mov    (%rsi),%rdi
call   10b0 <execvp@plt>
mov    -0x58(%rbp),%rax
mov    (%rax),%rsi
lea    0xd61(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d2b(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x24(%rbp),%edi
lea    -0x1c(%rbp),%rsi
xor    %edx,%edx
call   1090 <waitpid@plt>
mov    -0x1c(%rbp),%edi
call   1070 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     12ec <main+0x12c>
mov    -0x1c(%rbp),%edi
call   1080 <WTERMSIG@plt>
mov    %eax,%esi
lea    0xd2f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12f1 <main+0x131>
jmp    14fc <main+0x33c>
lea    -0x18(%rbp),%rdi
call   1060 <pipe@plt>
cmp    $0xffffffff,%eax
jne    1327 <main+0x167>
jmp    130d <main+0x14d>
lea    0xd21(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2cb8(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    $0x0,%al
call   10e0 <fork@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jne    13ce <main+0x20e>
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
cmp    $0xffffffff,%eax
jne    136f <main+0x1af>
jmp    1355 <main+0x195>
lea    0xce7(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2c70(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
jne    139f <main+0x1df>
jmp    1385 <main+0x1c5>
lea    0xcbc(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2c40(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x58(%rbp),%rsi
mov    (%rsi),%rdi
call   10b0 <execvp@plt>
mov    -0x58(%rbp),%rax
mov    (%rax),%rsi
lea    0xc47(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2c11(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    $0x0,%al
call   10e0 <fork@plt>
mov    %eax,-0x28(%rbp)
cmp    $0x0,%eax
jne    1472 <main+0x2b2>
mov    -0x18(%rbp),%edi
xor    %esi,%esi
call   1030 <dup2@plt>
cmp    $0xffffffff,%eax
jne    1413 <main+0x253>
jmp    13f9 <main+0x239>
lea    0xc43(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2bcc(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
jne    1443 <main+0x283>
jmp    1429 <main+0x269>
lea    0xc18(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2b9c(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x50(%rbp),%rsi
mov    (%rsi),%rdi
call   10b0 <execvp@plt>
mov    -0x50(%rbp),%rax
mov    (%rax),%rsi
lea    0xba3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2b6d(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x24(%rbp),%edi
lea    -0x1c(%rbp),%rsi
xor    %edx,%edx
call   1090 <waitpid@plt>
mov    -0x28(%rbp),%edi
lea    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1090 <waitpid@plt>
mov    -0x1c(%rbp),%edi
call   1070 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     14c8 <main+0x308>
mov    -0x1c(%rbp),%edi
call   1080 <WTERMSIG@plt>
mov    %eax,%esi
lea    0xb53(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%edi
call   1070 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     14f2 <main+0x332>
mov    -0x20(%rbp),%edi
call   1080 <WTERMSIG@plt>
mov    %eax,%esi
lea    0xb29(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    14f7 <main+0x337>
jmp    14fc <main+0x33c>
jmp    1249 <main+0x89>
mov    0x2ac8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsp,-0x40(%rbp)
mov    0x2e14(%rip),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %rsp,%rdi
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%rdi
mov    %rdi,%rsp
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rbx
lea    0xf(,%rax,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rsp,%r14
sub    %rax,%r14
mov    %r14,%rsp
mov    %rdi,-0x48(%rbp)
mov    %rbx,%rsi
mov    %r14,%rdx
call   10c0 <promptAndParse@plt>
test   %rax,%rax
je     135e <main+0x19e>
lea    -0x38(%rbp),%r15
jmp    126f <main+0xaf>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%rcx),%edi
call   1080 <WTERMSIG@plt>
lea    0xdc6(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0x48(%rbp),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   10c0 <promptAndParse@plt>
test   %rax,%rax
je     135e <main+0x19e>
cmpq   $0x0,(%r14)
je     1320 <main+0x160>
lea    -0x34(%rbp),%rdi
call   1060 <pipe@plt>
cmp    $0xffffffff,%eax
je     137a <main+0x1ba>
xor    %eax,%eax
call   10e0 <fork@plt>
test   %eax,%eax
je     1383 <main+0x1c3>
mov    %eax,%r13d
xor    %eax,%eax
call   10e0 <fork@plt>
mov    -0x34(%rbp),%edi
test   %eax,%eax
je     13b2 <main+0x1f2>
mov    %eax,%r12d
call   1050 <close@plt>
mov    -0x30(%rbp),%edi
call   1050 <close@plt>
mov    %r13d,%edi
lea    -0x2c(%rbp),%rsi
xor    %edx,%edx
call   1090 <waitpid@plt>
mov    %r12d,%edi
mov    %r15,%rsi
xor    %edx,%edx
call   1090 <waitpid@plt>
mov    -0x2c(%rbp),%edi
call   1070 <WIFSIGNALED@plt>
test   %rax,%rax
je     12ff <main+0x13f>
mov    -0x2c(%rbp),%edi
call   1080 <WTERMSIG@plt>
lea    0xd1e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0x38(%rbp),%edi
call   1070 <WIFSIGNALED@plt>
mov    %r15,%rcx
test   %rax,%rax
jne    1240 <main+0x80>
jmp    1257 <main+0x97>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%r12
xor    %eax,%eax
call   10e0 <fork@plt>
test   %eax,%eax
je     13c7 <main+0x207>
mov    %eax,%edi
lea    -0x2c(%rbp),%rbx
mov    %rbx,%rsi
xor    %edx,%edx
call   1090 <waitpid@plt>
mov    -0x2c(%rbp),%edi
call   1070 <WIFSIGNALED@plt>
mov    %rbx,%rcx
test   %rax,%rax
mov    %r12,%rbx
jne    1240 <main+0x80>
jmp    1257 <main+0x97>
mov    -0x40(%rbp),%rsp
mov    0x2c67(%rip),%rax
mov    (%rax),%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcb4(%rip),%rdi
jmp    13ed <main+0x22d>
mov    -0x30(%rbp),%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
cmp    $0xffffffff,%eax
je     13be <main+0x1fe>
mov    -0x34(%rbp),%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
je     13e6 <main+0x226>
mov    (%rbx),%rdi
mov    %rbx,%rsi
call   10b0 <execvp@plt>
mov    (%rbx),%rsi
jmp    1402 <main+0x242>
xor    %esi,%esi
call   1030 <dup2@plt>
cmp    $0xffffffff,%eax
jne    13d9 <main+0x219>
lea    0xc7e(%rip),%rdi
jmp    13ed <main+0x22d>
mov    (%r12),%rdi
mov    %r12,%rsi
call   10b0 <execvp@plt>
mov    (%r12),%rsi
jmp    1402 <main+0x242>
mov    -0x30(%rbp),%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
jne    13f4 <main+0x234>
lea    0xc5b(%rip),%rdi
call   10a0 <perror@plt>
jmp    1410 <main+0x250>
mov    (%r14),%rdi
mov    %r14,%rsi
call   10b0 <execvp@plt>
mov    (%r14),%rsi
lea    0xbf7(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2bc1(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>

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

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [20 x i8] c"Unknown command %s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [33 x i8] c"Child exited due to signal = %d\0A\00"
@.str.2 = [14 x i8] c"pipe creation\00"
@.str.3 = [5 x i8] c"dup2\00"
@.str.4 = [6 x i8] c"close\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [2 x i32]
%4 = alloca i32
%5 = alloca i32
%6 = bitcast [2 x i32]* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = load i32, i32* @PATH_MAX
%10 = add nsw i32 %9, 1
%11 = zext i32 %10 to i64
%12 = tail call i8* @llvm.stacksave()
%13 = alloca i8, i64 %11
%14 = load i32, i32* @PATH_MAX
%15 = add nsw i32 %14, 1
%16 = zext i32 %15 to i64
%17 = alloca i8*, i64 %16
%18 = alloca i8*, i64 %16
%19 = call i64 @promptAndParse(i8* %13, i8** %17, i8** %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %126, label %21
21: ; preds = %2
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%23 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
br label %24
24: ; preds = %21, %123
%25 = load i8*, i8** %18
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %42
27: ; preds = %24
%28 = call i32 (...) @fork()
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %37
30: ; preds = %27
%31 = load i8*, i8** %17
%32 = call i32 @execvp(i8* %31, i8** %17)
%33 = load i8*, i8** %17
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %33)
%35 = load i32, i32* @EXIT_FAILURE
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %27
%38 = call i32 @waitpid(i32 %28, i32* %4, i32 0)
%39 = load i32, i32* %4
%40 = call i64 @WIFSIGNALED(i32 %39)
%41 = icmp eq i64 %40, 0
br i1 %41, label %123, label %118
42: ; preds = %24
%43 = call i32 @pipe(i32* %22)
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %49
45: ; preds = %42
%46 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%47 = load i32, i32* @EXIT_FAILURE
%48 = call i32 @exit(i32 %47)
unreachable
49: ; preds = %42
%50 = call i32 (...) @fork()
%51 = icmp eq i32 %50, 0
br i1 %51, label %52, label %75
52: ; preds = %49
%53 = load i32, i32* %23
%54 = call i32 @dup2(i32 %53, i32 1)
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %60
56: ; preds = %52
%57 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%58 = load i32, i32* @EXIT_FAILURE
%59 = call i32 @exit(i32 %58)
unreachable
60: ; preds = %52
%61 = load i32, i32* %22
%62 = call i32 @close(i32 %61)
%63 = icmp eq i32 %62, -1
br i1 %63, label %64, label %68
64: ; preds = %60
%65 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%66 = load i32, i32* @EXIT_FAILURE
%67 = call i32 @exit(i32 %66)
unreachable
68: ; preds = %60
%69 = load i8*, i8** %17
%70 = call i32 @execvp(i8* %69, i8** %17)
%71 = load i8*, i8** %17
%72 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %71)
%73 = load i32, i32* @EXIT_FAILURE
%74 = call i32 @exit(i32 %73)
unreachable
75: ; preds = %49
%76 = call i32 (...) @fork()
%77 = icmp eq i32 %76, 0
%78 = load i32, i32* %22
br i1 %77, label %79, label %101
79: ; preds = %75
%80 = call i32 @dup2(i32 %78, i32 0)
%81 = icmp eq i32 %80, -1
br i1 %81, label %82, label %86
82: ; preds = %79
%83 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%84 = load i32, i32* @EXIT_FAILURE
%85 = call i32 @exit(i32 %84)
unreachable
86: ; preds = %79
%87 = load i32, i32* %23
%88 = call i32 @close(i32 %87)
%89 = icmp eq i32 %88, -1
br i1 %89, label %90, label %94
90: ; preds = %86
%91 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%92 = load i32, i32* @EXIT_FAILURE
%93 = call i32 @exit(i32 %92)
unreachable
94: ; preds = %86
%95 = load i8*, i8** %18
%96 = call i32 @execvp(i8* %95, i8** %18)
%97 = load i8*, i8** %18
%98 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %97)
%99 = load i32, i32* @EXIT_FAILURE
%100 = call i32 @exit(i32 %99)
unreachable
101: ; preds = %75
%102 = call i32 @close(i32 %78)
%103 = load i32, i32* %23
%104 = call i32 @close(i32 %103)
%105 = call i32 @waitpid(i32 %50, i32* %4, i32 0)
%106 = call i32 @waitpid(i32 %76, i32* %5, i32 0)
%107 = load i32, i32* %4
%108 = call i64 @WIFSIGNALED(i32 %107)
%109 = icmp eq i64 %108, 0
br i1 %109, label %114, label %110
110: ; preds = %101
%111 = load i32, i32* %4
%112 = call i32 @WTERMSIG(i32 %111)
%113 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %112)
br label %114
114: ; preds = %110, %101
%115 = load i32, i32* %5
%116 = call i64 @WIFSIGNALED(i32 %115)
%117 = icmp eq i64 %116, 0
br i1 %117, label %123, label %118
118: ; preds = %114, %37
%119 = phi i32* [ %4, %37 ], [ %5, %114 ]
%120 = load i32, i32* %119
%121 = call i32 @WTERMSIG(i32 %120)
%122 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %121)
br label %123
123: ; preds = %118, %114, %37
%124 = call i64 @promptAndParse(i8* %13, i8** %17, i8** %18)
%125 = icmp eq i64 %124, 0
br i1 %125, label %126, label %24
126: ; preds = %123, %2
%127 = load i32, i32* @EXIT_SUCCESS
ret i32 %127
}