#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 */

/* Variables and functions */
int O_CREAT;
int O_RDWR;
int O_TRUNC;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int S_IRGRP;
int S_IRUSR;
int S_IWGRP;
int S_IWUSR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup2(int, int /*<<< orphan*/);
int /*<<< orphan*/ execvp(char *, char **);
int fork();
int getArguments(char *, char **);
int /*<<< orphan*/ getLine(char *, int);
scalar_t__ malloc(int);
int open(char *, int, int);
int /*<<< orphan*/ perror(char *);
int pipe(int *);
int /*<<< orphan*/ printf(char *);
char *splitCommand(char *, char);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ wait(int *);
int /*<<< orphan*/ waitpid(int, int *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  char commandLine[200 + 1];
  char *arguments[10];
  char *arguments1[10];
  char *arguments2[10];
  char *arguments3[10];
  printf("Welcome to Extremely Simple Shell\n");
  int exit = 0;
  do {
    int status;
    int i = 0;
    char *temp, *index1 = NULL, *index2 = NULL, *index3 = NULL;
    int fd[2];
    if (pipe(fd) == -1) {
      continue;
    }
    printf("\n$ ");
    getLine(commandLine, 200 + 1);
    if (!strcmp(commandLine, ""))
      continue;
    index1 = (char *)malloc(sizeof(char) * (strlen(commandLine) + 1));
    strcpy(index1, commandLine);
    index2 = splitCommand(index1, '|');
    if (index2 == NULL) {
      index3 = splitCommand(index1, '>');
    } else {
      index3 = splitCommand(index2, '>');
    }
    int numArgs = getArguments(commandLine, arguments);
    int numArgs1 = getArguments(index1, arguments1);
    int numArgs2, numArgs3;
    if (index2 != NULL) {
      numArgs2 = getArguments(index2, arguments2);
    }
    if (index3 != NULL) {
      numArgs3 = getArguments(index3, arguments3);
    }
    if (numArgs == 0) {
      continue;
    } else if (!strcmp(arguments[0], "quit") || !strcmp(arguments[0], "exit"))
      break;
    int pid = fork();
    if (pid == 0) {
      if (index2 == NULL) {
        int fd_new;
        if (index3 != NULL) {
          fd_new = open(arguments3[0], O_CREAT | O_TRUNC | O_RDWR,
                        S_IRUSR | S_IRGRP | S_IWGRP | S_IWUSR);
          if (fd_new < 0) {
            return 0;
          }
          dup2(fd_new, STDOUT_FILENO);
          close(fd_new);
        }
        execvp(arguments1[0], arguments1);
        perror("Exec Error");
      } else {
        int status2;
        int pid2 = fork();
        if (pid2 == 0) {
          int fd_new_2;
          int i = 0;
          char buffer[1024];
          close(fd[1]);
          dup2(fd[0], STDIN_FILENO);
          close(fd[0]);
          if (index3 != NULL) {
            fd_new_2 = open(arguments3[0], O_CREAT | O_TRUNC | O_RDWR,
                            S_IRUSR | S_IRGRP | S_IWGRP | S_IWUSR);
            if (fd_new_2 < 0) {
              return 0;
            }
            dup2(fd_new_2, STDOUT_FILENO);
            close(fd_new_2);
          }
          execvp(arguments2[0], arguments2);
          perror("Exec Error");
        } else if (pid2 > 0) {
          int pid3;
          int status3;
          close(fd[0]);
          dup2(fd[1], STDOUT_FILENO);
          close(fd[1]);
          pid3 = fork();
          if (pid3 == 0) {
            execvp(arguments1[0], arguments1);
            perror("Exec Error");
          } else if (pid3 > 0) {
            wait(&status3);
            return 1;
          } else {
            perror("Fork Error");
          }
          waitpid(pid2, &status2, 0);
          return 1;
        } else if (pid2 < 0) {
          perror("Fork error\n");
        }
      }
    } else if (pid > 0) {
      waitpid(pid, &status, 0);
    } else if (pid < 0) {
      perror("Fork error\n");
    }
  } while (1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x690,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xdd0(%rip),%rdi
call   1070 <printf@plt>
movl   $0x0,-0x224(%rbp)
movl   $0x0,-0x22c(%rbp)
movq   $0x0,-0x240(%rbp)
movq   $0x0,-0x248(%rbp)
movq   $0x0,-0x250(%rbp)
lea    -0x258(%rbp),%rdi
call   1090 <pipe@plt>
cmp    $0xffffffff,%eax
jne    1284 <main+0x74>
jmp    1759 <main+0x549>
lea    0xd98(%rip),%rdi
call   1070 <printf@plt>
lea    -0xe0(%rbp),%rdi
mov    $0xc9,%esi
call   10f0 <getLine@plt>
lea    -0xe0(%rbp),%rdi
lea    0xd73(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
jne    12c2 <main+0xb2>
jmp    1759 <main+0x549>
lea    -0xe0(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x240(%rbp)
mov    -0x240(%rbp),%rdi
lea    -0xe0(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x240(%rbp),%rdi
mov    $0x7c,%esi
call   10c0 <splitCommand@plt>
mov    %rax,-0x248(%rbp)
cmpq   $0x0,-0x248(%rbp)
jne    133b <main+0x12b>
mov    -0x240(%rbp),%rdi
mov    $0x3e,%esi
call   10c0 <splitCommand@plt>
mov    %rax,-0x250(%rbp)
jmp    1353 <main+0x143>
mov    -0x248(%rbp),%rdi
mov    $0x3e,%esi
call   10c0 <splitCommand@plt>
mov    %rax,-0x250(%rbp)
lea    -0xe0(%rbp),%rdi
lea    -0x130(%rbp),%rsi
call   1040 <getArguments@plt>
mov    %eax,-0x25c(%rbp)
mov    -0x240(%rbp),%rdi
lea    -0x180(%rbp),%rsi
call   1040 <getArguments@plt>
mov    %eax,-0x260(%rbp)
cmpq   $0x0,-0x248(%rbp)
je     13ac <main+0x19c>
mov    -0x248(%rbp),%rdi
lea    -0x1d0(%rbp),%rsi
call   1040 <getArguments@plt>
mov    %eax,-0x264(%rbp)
cmpq   $0x0,-0x250(%rbp)
je     13d3 <main+0x1c3>
mov    -0x250(%rbp),%rdi
lea    -0x220(%rbp),%rsi
call   1040 <getArguments@plt>
mov    %eax,-0x268(%rbp)
cmpl   $0x0,-0x25c(%rbp)
jne    13e5 <main+0x1d5>
jmp    1759 <main+0x549>
mov    -0x130(%rbp),%rdi
lea    0xc34(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
je     141d <main+0x20d>
mov    -0x130(%rbp),%rdi
lea    0xc1d(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
jne    1422 <main+0x212>
jmp    1768 <main+0x558>
jmp    1427 <main+0x217>
mov    $0x0,%al
call   1130 <fork@plt>
mov    %eax,-0x26c(%rbp)
cmpl   $0x0,-0x26c(%rbp)
jne    170b <main+0x4fb>
cmpq   $0x0,-0x248(%rbp)
jne    150a <main+0x2fa>
cmpq   $0x0,-0x250(%rbp)
je     14e6 <main+0x2d6>
mov    -0x220(%rbp),%rdi
mov    0x2b8d(%rip),%rax
mov    (%rax),%esi
mov    0x2b7c(%rip),%rax
or     (%rax),%esi
mov    0x2b53(%rip),%rax
or     (%rax),%esi
mov    0x2b22(%rip),%rax
mov    (%rax),%edx
mov    0x2b21(%rip),%rax
or     (%rax),%edx
mov    0x2b30(%rip),%rax
or     (%rax),%edx
mov    0x2b1f(%rip),%rax
or     (%rax),%edx
call   10e0 <open@plt>
mov    %eax,-0x270(%rbp)
cmpl   $0x0,-0x270(%rbp)
jge    14c7 <main+0x2b7>
movl   $0x0,-0x4(%rbp)
jmp    176f <main+0x55f>
mov    -0x270(%rbp),%edi
mov    0x2b0c(%rip),%rax
mov    (%rax),%esi
call   1060 <dup2@plt>
mov    -0x270(%rbp),%edi
call   1080 <close@plt>
mov    -0x180(%rbp),%rdi
lea    -0x180(%rbp),%rsi
call   1110 <execvp@plt>
lea    0xb31(%rip),%rdi
call   1100 <perror@plt>
jmp    1706 <main+0x4f6>
mov    $0x0,%al
call   1130 <fork@plt>
mov    %eax,-0x278(%rbp)
cmpl   $0x0,-0x278(%rbp)
jne    1613 <main+0x403>
movl   $0x0,-0x280(%rbp)
mov    -0x254(%rbp),%edi
call   1080 <close@plt>
mov    -0x258(%rbp),%edi
mov    0x2a5a(%rip),%rax
mov    (%rax),%esi
call   1060 <dup2@plt>
mov    -0x258(%rbp),%edi
call   1080 <close@plt>
cmpq   $0x0,-0x250(%rbp)
je     15ef <main+0x3df>
mov    -0x220(%rbp),%rdi
mov    0x2a84(%rip),%rax
mov    (%rax),%esi
mov    0x2a73(%rip),%rax
or     (%rax),%esi
mov    0x2a4a(%rip),%rax
or     (%rax),%esi
mov    0x2a19(%rip),%rax
mov    (%rax),%edx
mov    0x2a18(%rip),%rax
or     (%rax),%edx
mov    0x2a27(%rip),%rax
or     (%rax),%edx
mov    0x2a16(%rip),%rax
or     (%rax),%edx
call   10e0 <open@plt>
mov    %eax,-0x27c(%rbp)
cmpl   $0x0,-0x27c(%rbp)
jge    15d0 <main+0x3c0>
movl   $0x0,-0x4(%rbp)
jmp    176f <main+0x55f>
mov    -0x27c(%rbp),%edi
mov    0x2a03(%rip),%rax
mov    (%rax),%esi
call   1060 <dup2@plt>
mov    -0x27c(%rbp),%edi
call   1080 <close@plt>
mov    -0x1d0(%rbp),%rdi
lea    -0x1d0(%rbp),%rsi
call   1110 <execvp@plt>
lea    0xa28(%rip),%rdi
call   1100 <perror@plt>
jmp    1701 <main+0x4f1>
cmpl   $0x0,-0x278(%rbp)
jle    16de <main+0x4ce>
mov    -0x258(%rbp),%edi
call   1080 <close@plt>
mov    -0x254(%rbp),%edi
mov    0x29a8(%rip),%rax
mov    (%rax),%esi
call   1060 <dup2@plt>
mov    -0x254(%rbp),%edi
call   1080 <close@plt>
mov    $0x0,%al
call   1130 <fork@plt>
mov    %eax,-0x684(%rbp)
cmpl   $0x0,-0x684(%rbp)
jne    1688 <main+0x478>
mov    -0x180(%rbp),%rdi
lea    -0x180(%rbp),%rsi
call   1110 <execvp@plt>
lea    0x9b3(%rip),%rdi
call   1100 <perror@plt>
jmp    16be <main+0x4ae>
cmpl   $0x0,-0x684(%rbp)
jle    16ad <main+0x49d>
lea    -0x688(%rbp),%rdi
call   1120 <wait@plt>
movl   $0x1,-0x4(%rbp)
jmp    176f <main+0x55f>
lea    0x988(%rip),%rdi
call   1100 <perror@plt>
jmp    16be <main+0x4ae>
mov    -0x278(%rbp),%edi
lea    -0x274(%rbp),%rsi
xor    %edx,%edx
call   10d0 <waitpid@plt>
movl   $0x1,-0x4(%rbp)
jmp    176f <main+0x55f>
cmpl   $0x0,-0x278(%rbp)
jge    16f7 <main+0x4e7>
lea    0x955(%rip),%rdi
call   1100 <perror@plt>
jmp    16fc <main+0x4ec>
jmp    1701 <main+0x4f1>
jmp    1706 <main+0x4f6>
jmp    1754 <main+0x544>
cmpl   $0x0,-0x26c(%rbp)
jle    1731 <main+0x521>
mov    -0x26c(%rbp),%edi
lea    -0x228(%rbp),%rsi
xor    %edx,%edx
call   10d0 <waitpid@plt>
jmp    174f <main+0x53f>
cmpl   $0x0,-0x26c(%rbp)
jge    174a <main+0x53a>
lea    0x902(%rip),%rdi
call   1100 <perror@plt>
jmp    174f <main+0x53f>
jmp    1754 <main+0x544>
jmp    1759 <main+0x549>
mov    $0x1,%al
test   $0x1,%al
jne    123f <main+0x2f>
jmp    1768 <main+0x558>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x690,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x238,%rsp
lea    0xdf8(%rip),%rdi
call   1040 <puts@plt>
lea    0xc(%rsp),%rbx
lea    0x160(%rsp),%r15
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   10a0 <pipe@plt>
cmp    $0xffffffff,%eax
je     1250 <main+0x30>
lea    0xd9c(%rip),%rdi
call   1080 <printf@plt>
mov    %r15,%rdi
mov    $0xc9,%esi
call   1100 <getLine@plt>
cmpb   $0x0,0x160(%rsp)
je     1250 <main+0x30>
mov    %r15,%rdi
call   1060 <strlen@plt>
lea    0x1(%rax),%edi
call   10c0 <malloc@plt>
mov    %rax,%r13
mov    %rax,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %r13,%rdi
mov    $0x7c,%esi
call   10d0 <splitCommand@plt>
mov    %rax,%r12
test   %rax,%rax
je     12b8 <main+0x98>
mov    %r12,%rdi
jmp    12bb <main+0x9b>
mov    %r13,%rdi
mov    $0x3e,%esi
call   10d0 <splitCommand@plt>
mov    %rax,%rbp
mov    %r15,%rdi
lea    0x110(%rsp),%rsi
call   1050 <getArguments@plt>
mov    %eax,%r14d
mov    %r13,%rdi
lea    0x20(%rsp),%rsi
call   1050 <getArguments@plt>
test   %r12,%r12
je     12fd <main+0xdd>
mov    %r12,%rdi
lea    0xc0(%rsp),%rsi
call   1050 <getArguments@plt>
test   %rbp,%rbp
je     130f <main+0xef>
mov    %rbp,%rdi
lea    0x70(%rsp),%rsi
call   1050 <getArguments@plt>
test   %r14d,%r14d
je     1250 <main+0x30>
mov    %rbx,%r14
mov    0x110(%rsp),%rbx
mov    %rbx,%rdi
lea    0xcd7(%rip),%rsi
call   10b0 <strcmp@plt>
test   %eax,%eax
je     14dd <main+0x2bd>
mov    %rbx,%rdi
lea    0xcc5(%rip),%rsi
call   10b0 <strcmp@plt>
test   %eax,%eax
je     14dd <main+0x2bd>
xor    %eax,%eax
call   1140 <fork@plt>
test   %eax,%eax
je     1378 <main+0x158>
jle    14d4 <main+0x2b4>
mov    %eax,%edi
lea    0x1c(%rsp),%rsi
xor    %edx,%edx
call   10e0 <waitpid@plt>
mov    %r14,%rbx
jmp    1250 <main+0x30>
test   %r12,%r12
je     139e <main+0x17e>
xor    %eax,%eax
call   1140 <fork@plt>
test   %eax,%eax
je     141c <main+0x1fc>
lea    0xc91(%rip),%rdi
jle    14c7 <main+0x2a7>
jmp    14e1 <main+0x2c1>
test   %rbp,%rbp
je     140d <main+0x1ed>
mov    0x2c46(%rip),%rax
mov    (%rax),%esi
mov    0x2c45(%rip),%rax
or     (%rax),%esi
mov    0x2c14(%rip),%rax
or     (%rax),%esi
mov    0x70(%rsp),%rdi
mov    0x2be6(%rip),%rax
mov    (%rax),%edx
mov    0x2bd5(%rip),%rax
or     (%rax),%edx
mov    0x2bec(%rip),%rax
or     (%rax),%edx
mov    0x2bdb(%rip),%rax
or     (%rax),%edx
call   10f0 <open@plt>
test   %eax,%eax
js     14dd <main+0x2bd>
mov    %eax,%ebx
mov    0x2be3(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1070 <dup2@plt>
mov    %ebx,%edi
call   1090 <close@plt>
mov    0x20(%rsp),%rdi
lea    0x20(%rsp),%rsi
jmp    14bb <main+0x29b>
mov    0x10(%rsp),%edi
call   1090 <close@plt>
mov    0xc(%rsp),%edi
mov    0x2b70(%rip),%rax
mov    (%rax),%esi
call   1070 <dup2@plt>
mov    0xc(%rsp),%edi
call   1090 <close@plt>
test   %rbp,%rbp
je     14ab <main+0x28b>
mov    0x2ba4(%rip),%rax
mov    (%rax),%esi
mov    0x2ba3(%rip),%rax
or     (%rax),%esi
mov    0x2b72(%rip),%rax
or     (%rax),%esi
mov    0x70(%rsp),%rdi
mov    0x2b44(%rip),%rax
mov    (%rax),%edx
mov    0x2b33(%rip),%rax
or     (%rax),%edx
mov    0x2b4a(%rip),%rax
or     (%rax),%edx
mov    0x2b39(%rip),%rax
or     (%rax),%edx
call   10f0 <open@plt>
test   %eax,%eax
js     14dd <main+0x2bd>
mov    %eax,%ebx
mov    0x2b45(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1070 <dup2@plt>
mov    %ebx,%edi
call   1090 <close@plt>
mov    0xc0(%rsp),%rdi
lea    0xc0(%rsp),%rsi
call   1120 <execvp@plt>
lea    0xb47(%rip),%rdi
call   1110 <perror@plt>
mov    %r14,%rbx
jmp    1250 <main+0x30>
lea    0xb49(%rip),%rdi
jmp    14c7 <main+0x2a7>
xor    %eax,%eax
jmp    1524 <main+0x304>
mov    %eax,%r12d
mov    0xc(%rsp),%edi
call   1090 <close@plt>
mov    0x10(%rsp),%edi
mov    0x2ae8(%rip),%rax
mov    (%rax),%esi
call   1070 <dup2@plt>
mov    0x10(%rsp),%edi
call   1090 <close@plt>
xor    %eax,%eax
call   1140 <fork@plt>
test   %eax,%eax
je     1536 <main+0x316>
jle    154e <main+0x32e>
lea    0x14(%rsp),%rdi
call   1130 <wait@plt>
mov    $0x1,%eax
add    $0x238,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x20(%rsp),%rdi
lea    0x20(%rsp),%rsi
call   1120 <execvp@plt>
lea    0xac2(%rip),%rdi
jmp    1555 <main+0x335>
lea    0xac4(%rip),%rdi
call   1110 <perror@plt>
lea    0x18(%rsp),%rsi
mov    %r12d,%edi
xor    %edx,%edx
call   10e0 <waitpid@plt>
jmp    151f <main+0x2ff>

LLVM IR (-O0):
@.str = [35 x i8] c"Welcome to Extremely Simple Shell\0A\00"
@.str.1 = [4 x i8] c"\0A$ \00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [5 x i8] c"quit\00"
@.str.4 = [5 x i8] c"exit\00"
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@O_RDWR = global i32 0
@S_IRUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@S_IWUSR = global i32 0
@STDOUT_FILENO = global i32 0
@.str.5 = [11 x i8] c"Exec Error\00"
@STDIN_FILENO = global i32 0
@.str.6 = [11 x i8] c"Fork Error\00"
@.str.7 = [12 x i8] c"Fork error\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [201 x i8]
%7 = alloca [10 x i8*]
%8 = alloca [10 x i8*]
%9 = alloca [10 x i8*]
%10 = alloca [10 x i8*]
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca i8*
%18 = alloca [2 x i32]
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
%24 = alloca i32
%25 = alloca i32
%26 = alloca i32
%27 = alloca i32
%28 = alloca i32
%29 = alloca [1024 x i8]
%30 = alloca i32
%31 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%32 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %11
br label %33
33: ; preds = %250, %2
store i32 0, i32* %13
store i8* null, i8** %15
store i8* null, i8** %16
store i8* null, i8** %17
%34 = getelementptr inbounds [2 x i32], [2 x i32]* %18, i64 0, i64 0
%35 = call i32 @pipe(i32* %34)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %38
37: ; preds = %33
br label %250
38: ; preds = %33
%39 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%40 = getelementptr inbounds [201 x i8], [201 x i8]* %6, i64 0, i64 0
%41 = call i32 @getLine(i8* %40, i32 201)
%42 = getelementptr inbounds [201 x i8], [201 x i8]* %6, i64 0, i64 0
%43 = call i32 @strcmp(i8* %42, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
%44 = icmp ne i32 %43, 0
br i1 %44, label %46, label %45
45: ; preds = %38
br label %250
46: ; preds = %38
%47 = getelementptr inbounds [201 x i8], [201 x i8]* %6, i64 0, i64 0
%48 = call i32 @strlen(i8* %47)
%49 = add nsw i32 %48, 1
%50 = sext i32 %49 to i64
%51 = mul i64 1, %50
%52 = trunc i64 %51 to i32
%53 = call i64 @malloc(i32 %52)
%54 = inttoptr i64 %53 to i8*
store i8* %54, i8** %15
%55 = load i8*, i8** %15
%56 = getelementptr inbounds [201 x i8], [201 x i8]* %6, i64 0, i64 0
%57 = call i32 @strcpy(i8* %55, i8* %56)
%58 = load i8*, i8** %15
%59 = call i8* @splitCommand(i8* %58, i8 signext 124)
store i8* %59, i8** %16
%60 = load i8*, i8** %16
%61 = icmp eq i8* %60, null
br i1 %61, label %62, label %65
62: ; preds = %46
%63 = load i8*, i8** %15
%64 = call i8* @splitCommand(i8* %63, i8 signext 62)
store i8* %64, i8** %17
br label %68
65: ; preds = %46
%66 = load i8*, i8** %16
%67 = call i8* @splitCommand(i8* %66, i8 signext 62)
store i8* %67, i8** %17
br label %68
68: ; preds = %65, %62
%69 = getelementptr inbounds [201 x i8], [201 x i8]* %6, i64 0, i64 0
%70 = getelementptr inbounds [10 x i8*], [10 x i8*]* %7, i64 0, i64 0
%71 = call i32 @getArguments(i8* %69, i8** %70)
store i32 %71, i32* %19
%72 = load i8*, i8** %15
%73 = getelementptr inbounds [10 x i8*], [10 x i8*]* %8, i64 0, i64 0
%74 = call i32 @getArguments(i8* %72, i8** %73)
store i32 %74, i32* %20
%75 = load i8*, i8** %16
%76 = icmp ne i8* %75, null
br i1 %76, label %77, label %81
77: ; preds = %68
%78 = load i8*, i8** %16
%79 = getelementptr inbounds [10 x i8*], [10 x i8*]* %9, i64 0, i64 0
%80 = call i32 @getArguments(i8* %78, i8** %79)
store i32 %80, i32* %21
br label %81
81: ; preds = %77, %68
%82 = load i8*, i8** %17
%83 = icmp ne i8* %82, null
br i1 %83, label %84, label %88
84: ; preds = %81
%85 = load i8*, i8** %17
%86 = getelementptr inbounds [10 x i8*], [10 x i8*]* %10, i64 0, i64 0
%87 = call i32 @getArguments(i8* %85, i8** %86)
store i32 %87, i32* %22
br label %88
88: ; preds = %84, %81
%89 = load i32, i32* %19
%90 = icmp eq i32 %89, 0
br i1 %90, label %91, label %92
91: ; preds = %88
br label %250
92: ; preds = %88
%93 = getelementptr inbounds [10 x i8*], [10 x i8*]* %7, i64 0, i64 0
%94 = load i8*, i8** %93
%95 = call i32 @strcmp(i8* %94, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%96 = icmp ne i32 %95, 0
br i1 %96, label %97, label %102
97: ; preds = %92
%98 = getelementptr inbounds [10 x i8*], [10 x i8*]* %7, i64 0, i64 0
%99 = load i8*, i8** %98
%100 = call i32 @strcmp(i8* %99, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%101 = icmp ne i32 %100, 0
br i1 %101, label %103, label %102
102: ; preds = %97, %92
br label %251
103: ; preds = %97
br label %104
104: ; preds = %103
%105 = call i32 (...) @fork()
store i32 %105, i32* %23
%106 = load i32, i32* %23
%107 = icmp eq i32 %106, 0
br i1 %107, label %108, label %236
108: ; preds = %104
%109 = load i8*, i8** %16
%110 = icmp eq i8* %109, null
br i1 %110, label %111, label %145
111: ; preds = %108
%112 = load i8*, i8** %17
%113 = icmp ne i8* %112, null
br i1 %113, label %114, label %139
114: ; preds = %111
%115 = getelementptr inbounds [10 x i8*], [10 x i8*]* %10, i64 0, i64 0
%116 = load i8*, i8** %115
%117 = load i32, i32* @O_CREAT
%118 = load i32, i32* @O_TRUNC
%119 = or i32 %117, %118
%120 = load i32, i32* @O_RDWR
%121 = or i32 %119, %120
%122 = load i32, i32* @S_IRUSR
%123 = load i32, i32* @S_IRGRP
%124 = or i32 %122, %123
%125 = load i32, i32* @S_IWGRP
%126 = or i32 %124, %125
%127 = load i32, i32* @S_IWUSR
%128 = or i32 %126, %127
%129 = call i32 @open(i8* %116, i32 %121, i32 %128)
store i32 %129, i32* %24
%130 = load i32, i32* %24
%131 = icmp slt i32 %130, 0
br i1 %131, label %132, label %133
132: ; preds = %114
store i32 0, i32* %3
br label %252
133: ; preds = %114
%134 = load i32, i32* %24
%135 = load i32, i32* @STDOUT_FILENO
%136 = call i32 @dup2(i32 %134, i32 %135)
%137 = load i32, i32* %24
%138 = call i32 @close(i32 %137)
br label %139
139: ; preds = %133, %111
%140 = getelementptr inbounds [10 x i8*], [10 x i8*]* %8, i64 0, i64 0
%141 = load i8*, i8** %140
%142 = getelementptr inbounds [10 x i8*], [10 x i8*]* %8, i64 0, i64 0
%143 = call i32 @execvp(i8* %141, i8** %142)
%144 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
br label %235
145: ; preds = %108
%146 = call i32 (...) @fork()
store i32 %146, i32* %26
%147 = load i32, i32* %26
%148 = icmp eq i32 %147, 0
br i1 %148, label %149, label %193
149: ; preds = %145
store i32 0, i32* %28
%150 = getelementptr inbounds [2 x i32], [2 x i32]* %18, i64 0, i64 1
%151 = load i32, i32* %150
%152 = call i32 @close(i32 %151)
%153 = getelementptr inbounds [2 x i32], [2 x i32]* %18, i64 0, i64 0
%154 = load i32, i32* %153
%155 = load i32, i32* @STDIN_FILENO
%156 = call i32 @dup2(i32 %154, i32 %155)
%157 = getelementptr inbounds [2 x i32], [2 x i32]* %18, i64 0, i64 0
%158 = load i32, i32* %157
%159 = call i32 @close(i32 %158)
%160 = load i8*, i8** %17
%161 = icmp ne i8* %160, null
br i1 %161, label %162, label %187
162: ; preds = %149
%163 = getelementptr inbounds [10 x i8*], [10 x i8*]* %10, i64 0, i64 0
%164 = load i8*, i8** %163
%165 = load i32, i32* @O_CREAT
%166 = load i32, i32* @O_TRUNC
%167 = or i32 %165, %166
%168 = load i32, i32* @O_RDWR
%169 = or i32 %167, %168
%170 = load i32, i32* @S_IRUSR
%171 = load i32, i32* @S_IRGRP
%172 = or i32 %170, %171
%173 = load i32, i32* @S_IWGRP
%174 = or i32 %172, %173
%175 = load i32, i32* @S_IWUSR
%176 = or i32 %174, %175
%177 = call i32 @open(i8* %164, i32 %169, i32 %176)
store i32 %177, i32* %27
%178 = load i32, i32* %27
%179 = icmp slt i32 %178, 0
br i1 %179, label %180, label %181
180: ; preds = %162
store i32 0, i32* %3
br label %252
181: ; preds = %162
%182 = load i32, i32* %27
%183 = load i32, i32* @STDOUT_FILENO
%184 = call i32 @dup2(i32 %182, i32 %183)
%185 = load i32, i32* %27
%186 = call i32 @close(i32 %185)
br label %187
187: ; preds = %181, %149
%188 = getelementptr inbounds [10 x i8*], [10 x i8*]* %9, i64 0, i64 0
%189 = load i8*, i8** %188
%190 = getelementptr inbounds [10 x i8*], [10 x i8*]* %9, i64 0, i64 0
%191 = call i32 @execvp(i8* %189, i8** %190)
%192 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
br label %234
193: ; preds = %145
%194 = load i32, i32* %26
%195 = icmp sgt i32 %194, 0
br i1 %195, label %196, label %227
196: ; preds = %193
%197 = getelementptr inbounds [2 x i32], [2 x i32]* %18, i64 0, i64 0
%198 = load i32, i32* %197
%199 = call i32 @close(i32 %198)
%200 = getelementptr inbounds [2 x i32], [2 x i32]* %18, i64 0, i64 1
%201 = load i32, i32* %200
%202 = load i32, i32* @STDOUT_FILENO
%203 = call i32 @dup2(i32 %201, i32 %202)
%204 = getelementptr inbounds [2 x i32], [2 x i32]* %18, i64 0, i64 1
%205 = load i32, i32* %204
%206 = call i32 @close(i32 %205)
%207 = call i32 (...) @fork()
store i32 %207, i32* %30
%208 = load i32, i32* %30
%209 = icmp eq i32 %208, 0
br i1 %209, label %210, label %216
210: ; preds = %196
%211 = getelementptr inbounds [10 x i8*], [10 x i8*]* %8, i64 0, i64 0
%212 = load i8*, i8** %211
%213 = getelementptr inbounds [10 x i8*], [10 x i8*]* %8, i64 0, i64 0
%214 = call i32 @execvp(i8* %212, i8** %213)
%215 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
br label %224
216: ; preds = %196
%217 = load i32, i32* %30
%218 = icmp sgt i32 %217, 0
br i1 %218, label %219, label %221
219: ; preds = %216
%220 = call i32 @wait(i32* %31)
store i32 1, i32* %3
br label %252
221: ; preds = %216
%222 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
br label %223
223: ; preds = %221
br label %224
224: ; preds = %223, %210
%225 = load i32, i32* %26
%226 = call i32 @waitpid(i32 %225, i32* %25, i32 0)
store i32 1, i32* %3
br label %252
227: ; preds = %193
%228 = load i32, i32* %26
%229 = icmp slt i32 %228, 0
br i1 %229, label %230, label %232
230: ; preds = %227
%231 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
br label %232
232: ; preds = %230, %227
br label %233
233: ; preds = %232
br label %234
234: ; preds = %233, %187
br label %235
235: ; preds = %234, %139
br label %249
236: ; preds = %104
%237 = load i32, i32* %23
%238 = icmp sgt i32 %237, 0
br i1 %238, label %239, label %242
239: ; preds = %236
%240 = load i32, i32* %23
%241 = call i32 @waitpid(i32 %240, i32* %12, i32 0)
br label %248
242: ; preds = %236
%243 = load i32, i32* %23
%244 = icmp slt i32 %243, 0
br i1 %244, label %245, label %247
245: ; preds = %242
%246 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
br label %247
247: ; preds = %245, %242
br label %248
248: ; preds = %247, %239
br label %249
249: ; preds = %248, %235
br label %250
250: ; preds = %249, %91, %45, %37
br i1 true, label %33, label %251
251: ; preds = %250, %102
store i32 0, i32* %3
br label %252
252: ; preds = %251, %224, %219, %180, %132
%253 = load i32, i32* %3
ret i32 %253
}

LLVM IR (-O2):
@.str.1 = [4 x i8] c"\0A$ \00"
@.str.3 = [5 x i8] c"quit\00"
@.str.4 = [5 x i8] c"exit\00"
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@O_RDWR = global i32 0
@S_IRUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@S_IWUSR = global i32 0
@STDOUT_FILENO = global i32 0
@.str.5 = [11 x i8] c"Exec Error\00"
@STDIN_FILENO = global i32 0
@.str.6 = [11 x i8] c"Fork Error\00"
@.str.7 = [12 x i8] c"Fork error\0A\00"
@str = [34 x i8] c"Welcome to Extremely Simple Shell\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [201 x i8]
%4 = alloca [10 x i8*]
%5 = alloca [10 x i8*]
%6 = alloca [10 x i8*]
%7 = alloca [10 x i8*]
%8 = alloca i32
%9 = alloca [2 x i32]
%10 = alloca i32
%11 = alloca i32
%12 = getelementptr inbounds [201 x i8], [201 x i8]* %3, i64 0, i64 0
%13 = bitcast [10 x i8*]* %4 to i8*
%14 = bitcast [10 x i8*]* %5 to i8*
%15 = bitcast [10 x i8*]* %6 to i8*
%16 = bitcast [10 x i8*]* %7 to i8*
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
%18 = bitcast i32* %8 to i8*
%19 = bitcast [2 x i32]* %9 to i8*
%20 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%21 = getelementptr inbounds [10 x i8*], [10 x i8*]* %4, i64 0, i64 0
%22 = getelementptr inbounds [10 x i8*], [10 x i8*]* %5, i64 0, i64 0
%23 = getelementptr inbounds [10 x i8*], [10 x i8*]* %6, i64 0, i64 0
%24 = getelementptr inbounds [10 x i8*], [10 x i8*]* %7, i64 0, i64 0
%25 = bitcast i32* %10 to i8*
%26 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 1
br label %27
27: ; preds = %167, %2
%28 = call i32 @pipe(i32* %20)
%29 = icmp eq i32 %28, -1
br i1 %29, label %167, label %30
30: ; preds = %27
%31 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%32 = call i32 @getLine(i8* %12, i32 201)
%33 = load i8, i8* %12
%34 = icmp eq i8 %33, 0
br i1 %34, label %167, label %35
35: ; preds = %30
%36 = call i32 @strlen(i8* %12)
%37 = add nsw i32 %36, 1
%38 = call i64 @malloc(i32 %37)
%39 = inttoptr i64 %38 to i8*
%40 = call i32 @strcpy(i8* %39, i8* %12)
%41 = call i8* @splitCommand(i8* %39, i8 signext 124)
%42 = icmp eq i8* %41, null
br i1 %42, label %43, label %45
43: ; preds = %35
%44 = call i8* @splitCommand(i8* %39, i8 signext 62)
br label %47
45: ; preds = %35
%46 = call i8* @splitCommand(i8* %41, i8 signext 62)
br label %47
47: ; preds = %45, %43
%48 = phi i8* [ %44, %43 ], [ %46, %45 ]
%49 = call i32 @getArguments(i8* %12, i8** %21)
%50 = call i32 @getArguments(i8* %39, i8** %22)
br i1 %42, label %53, label %51
51: ; preds = %47
%52 = call i32 @getArguments(i8* %41, i8** %23)
br label %53
53: ; preds = %51, %47
%54 = icmp eq i8* %48, null
br i1 %54, label %57, label %55
55: ; preds = %53
%56 = call i32 @getArguments(i8* %48, i8** %24)
br label %57
57: ; preds = %55, %53
%58 = icmp eq i32 %49, 0
br i1 %58, label %167, label %59
59: ; preds = %57
%60 = load i8*, i8** %21
%61 = call i32 @strcmp(i8* dereferenceable(1) %60, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%62 = icmp eq i32 %61, 0
br i1 %62, label %168, label %63
63: ; preds = %59
%64 = call i32 @strcmp(i8* dereferenceable(1) %60, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%65 = icmp eq i32 %64, 0
br i1 %65, label %168, label %66
66: ; preds = %63
%67 = call i32 (...) @fork()
%68 = icmp eq i32 %67, 0
br i1 %68, label %69, label %159
69: ; preds = %66
br i1 %42, label %70, label %95
70: ; preds = %69
br i1 %54, label %91, label %71
71: ; preds = %70
%72 = load i8*, i8** %24
%73 = load i32, i32* @O_CREAT
%74 = load i32, i32* @O_TRUNC
%75 = or i32 %74, %73
%76 = load i32, i32* @O_RDWR
%77 = or i32 %75, %76
%78 = load i32, i32* @S_IRUSR
%79 = load i32, i32* @S_IRGRP
%80 = or i32 %79, %78
%81 = load i32, i32* @S_IWGRP
%82 = or i32 %80, %81
%83 = load i32, i32* @S_IWUSR
%84 = or i32 %82, %83
%85 = call i32 @open(i8* %72, i32 %77, i32 %84)
%86 = icmp slt i32 %85, 0
br i1 %86, label %165, label %87
87: ; preds = %71
%88 = load i32, i32* @STDOUT_FILENO
%89 = call i32 @dup2(i32 %85, i32 %88)
%90 = call i32 @close(i32 %85)
br label %91
91: ; preds = %70, %87
%92 = load i8*, i8** %22
%93 = call i32 @execvp(i8* %92, i8** %22)
%94 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
br label %167
95: ; preds = %69
%96 = call i32 (...) @fork()
%97 = icmp eq i32 %96, 0
br i1 %97, label %98, label %129
98: ; preds = %95
%99 = load i32, i32* %26
%100 = call i32 @close(i32 %99)
%101 = load i32, i32* %20
%102 = load i32, i32* @STDIN_FILENO
%103 = call i32 @dup2(i32 %101, i32 %102)
%104 = load i32, i32* %20
%105 = call i32 @close(i32 %104)
br i1 %54, label %126, label %106
106: ; preds = %98
%107 = load i8*, i8** %24
%108 = load i32, i32* @O_CREAT
%109 = load i32, i32* @O_TRUNC
%110 = or i32 %109, %108
%111 = load i32, i32* @O_RDWR
%112 = or i32 %110, %111
%113 = load i32, i32* @S_IRUSR
%114 = load i32, i32* @S_IRGRP
%115 = or i32 %114, %113
%116 = load i32, i32* @S_IWGRP
%117 = or i32 %115, %116
%118 = load i32, i32* @S_IWUSR
%119 = or i32 %117, %118
%120 = call i32 @open(i8* %107, i32 %112, i32 %119)
%121 = icmp slt i32 %120, 0
br i1 %121, label %157, label %122
122: ; preds = %106
%123 = load i32, i32* @STDOUT_FILENO
%124 = call i32 @dup2(i32 %120, i32 %123)
%125 = call i32 @close(i32 %120)
br label %126
126: ; preds = %98, %122
%127 = load i8*, i8** %23
%128 = call i32 @execvp(i8* %127, i8** %23)
br label %154
129: ; preds = %95
%130 = icmp sgt i32 %96, 0
br i1 %130, label %131, label %154
131: ; preds = %129
%132 = bitcast i32* %11 to i8*
%133 = load i32, i32* %20
%134 = call i32 @close(i32 %133)
%135 = load i32, i32* %26
%136 = load i32, i32* @STDOUT_FILENO
%137 = call i32 @dup2(i32 %135, i32 %136)
%138 = load i32, i32* %26
%139 = call i32 @close(i32 %138)
%140 = call i32 (...) @fork()
%141 = icmp eq i32 %140, 0
br i1 %141, label %142, label %145
142: ; preds = %131
%143 = load i8*, i8** %22
%144 = call i32 @execvp(i8* %143, i8** %22)
br label %149
145: ; preds = %131
%146 = icmp sgt i32 %140, 0
br i1 %146, label %147, label %149
147: ; preds = %145
%148 = call i32 @wait(i32* %11)
br label %153
149: ; preds = %145, %142
%150 = phi i8* [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), %142 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), %145 ]
%151 = call i32 @perror(i8* %150)
%152 = call i32 @waitpid(i32 %96, i32* %10, i32 0)
br label %153
153: ; preds = %149, %147
br label %157
154: ; preds = %129, %126
%155 = phi i8* [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), %126 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), %129 ]
%156 = call i32 @perror(i8* %155)
br label %167
157: ; preds = %106, %153
%158 = phi i32 [ 1, %153 ], [ 0, %106 ]
br label %165
159: ; preds = %66
%160 = icmp sgt i32 %67, 0
br i1 %160, label %161, label %163
161: ; preds = %159
%162 = call i32 @waitpid(i32 %67, i32* %8, i32 0)
br label %167
163: ; preds = %159
%164 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
br label %167
165: ; preds = %71, %157
%166 = phi i32 [ %158, %157 ], [ 0, %71 ]
br label %169
167: ; preds = %27, %30, %57, %154, %91, %161, %163
br label %27
168: ; preds = %59, %63
br label %169
169: ; preds = %165, %168
%170 = phi i32 [ 0, %168 ], [ %166, %165 ]
ret i32 %170
}