#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 STDIN_FILENO;
int STDOUT_FILENO;
scalar_t__ chdir(char *);
int /*<<< orphan*/ clear_input(char *);
int /*<<< orphan*/ create_process(char ***, int);
int /*<<< orphan*/ dup2(int, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char *getenv(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ signal_handler();
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *strtok(char *, char *);
int /*<<< orphan*/ test_stdin(char *);
int /*<<< orphan*/ typePrompt();
int /*<<< orphan*/ wait(int /*<<< orphan*/);
int main() {
  char fullCommand[255];
  int firstArgCount;
  signal_handler();
  while (1) {
    do {
      typePrompt();
      clear_input(fullCommand);
      fgets(fullCommand, sizeof(char) * 255, stdin);
      if (fullCommand[strlen(fullCommand) - 1] == '\n')
        fullCommand[strlen(fullCommand) - 1] = '\0';
    } while (!(test_stdin(fullCommand)));
    if (strcmp(fullCommand, "exit") == 0)
      exit(0);
    char *token_p;
    char tokenFullCommand[255];
    strcpy(tokenFullCommand, fullCommand);
    int pipeCount = -1;
    for (token_p = strtok(tokenFullCommand, "|"); token_p != NULL;
         token_p = strtok(NULL, "|"))
      pipeCount++;
    char ***arg_list = (char ***)malloc((pipeCount + 1) * sizeof(char **));
    char **command = (char **)malloc((pipeCount + 1) * sizeof(char *));
    int i_command = 0;
    strcpy(tokenFullCommand, fullCommand);
    for (token_p = strtok(tokenFullCommand, "|"); token_p != NULL;
         token_p = strtok(NULL, "|")) {
      command[i_command] = (char *)malloc(255 * sizeof(char));
      strcpy(command[i_command], token_p);
      i_command++;
    }
    i_command = 0;
    strcpy(tokenFullCommand, fullCommand);
    while (i_command <= pipeCount) {
      char *token;
      char tokenCommand[255];
      strcpy(tokenCommand, command[i_command]);
      int argCount = 0;
      for (token = strtok(tokenCommand, " "); token != NULL;
           token = strtok(NULL, " "))
        argCount++;
      if (i_command == 0)
        firstArgCount = argCount;
      arg_list[i_command] = (char **)malloc((argCount + 1) * sizeof(char *));
      int j_command = 0;
      strcpy(tokenCommand, command[i_command]);
      for (token = strtok(tokenCommand, " "); token != NULL;
           token = strtok(NULL, " ")) {
        arg_list[i_command][j_command] = (char *)malloc(255 * sizeof(char));
        strcpy(arg_list[i_command][j_command], token);
        j_command++;
      }
      arg_list[i_command][j_command] = NULL;
      i_command++;
    }
    if (strcmp(arg_list[0][0], "cd") == 0) {
      if (arg_list[0][1] == NULL) {
        char homeDir[50] = "";
        strcpy(homeDir, getenv("HOME"));
        arg_list[0][1] = (char *)malloc(255 * sizeof(char));
        strcpy(arg_list[0][1], homeDir);
      }
      if (chdir(arg_list[0][1]) != 0)
        fprintf(stderr, "cd: '%s' file or directory not found\n",
                arg_list[0][1]);
      continue;
    }
    int stdin_cp = STDIN_FILENO;
    int stdout_cp = STDOUT_FILENO;
    create_process(arg_list, pipeCount + 1);
    wait(0);
    dup2(stdin_cp, STDIN_FILENO);
    dup2(stdout_cp, STDOUT_FILENO);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x3a0,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   10b0 <signal_handler@plt>
jmp    123e <main+0x1e>
mov    $0x0,%al
call   1040 <typePrompt@plt>
lea    -0x110(%rbp),%rdi
call   1120 <clear_input@plt>
lea    -0x110(%rbp),%rdi
mov    0x2d81(%rip),%rax
mov    (%rax),%edx
mov    $0xff,%esi
call   10c0 <fgets@plt>
lea    -0x110(%rbp),%rdi
call   1070 <strlen@plt>
sub    $0x1,%eax
cltq
movsbl -0x110(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    12a6 <main+0x86>
lea    -0x110(%rbp),%rdi
call   1070 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x110(%rbp,%rax,1)
jmp    12ab <main+0x8b>
lea    -0x110(%rbp),%rdi
call   1060 <test_stdin@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    123e <main+0x1e>
lea    -0x110(%rbp),%rdi
lea    0xd2b(%rip),%rsi
call   10d0 <strcmp@plt>
cmp    $0x0,%rax
jne    12eb <main+0xcb>
xor    %edi,%edi
call   1130 <exit@plt>
lea    -0x220(%rbp),%rdi
lea    -0x110(%rbp),%rsi
call   1050 <strcpy@plt>
movl   $0xffffffff,-0x224(%rbp)
ff ff ff
lea    -0x220(%rbp),%rdi
lea    0xcef(%rip),%rsi
call   1110 <strtok@plt>
mov    %rax,-0x120(%rbp)
cmpq   $0x0,-0x120(%rbp)
je     135b <main+0x13b>
mov    -0x224(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x224(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xcbb(%rip),%rsi
call   1110 <strtok@plt>
mov    %rax,-0x120(%rbp)
jmp    1322 <main+0x102>
mov    -0x224(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   10f0 <malloc@plt>
mov    %rax,-0x230(%rbp)
mov    -0x224(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   10f0 <malloc@plt>
mov    %rax,-0x238(%rbp)
movl   $0x0,-0x23c(%rbp)
lea    -0x220(%rbp),%rdi
lea    -0x110(%rbp),%rsi
call   1050 <strcpy@plt>
lea    -0x220(%rbp),%rdi
lea    0xc45(%rip),%rsi
call   1110 <strtok@plt>
mov    %rax,-0x120(%rbp)
cmpq   $0x0,-0x120(%rbp)
je     1442 <main+0x222>
mov    $0xff,%edi
call   10f0 <malloc@plt>
mov    %rax,%rdx
mov    -0x238(%rbp),%rax
movslq -0x23c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x238(%rbp),%rax
movslq -0x23c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x120(%rbp),%rsi
call   1050 <strcpy@plt>
mov    -0x23c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x23c(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xbd4(%rip),%rsi
call   1110 <strtok@plt>
mov    %rax,-0x120(%rbp)
jmp    13cc <main+0x1ac>
movl   $0x0,-0x23c(%rbp)
lea    -0x220(%rbp),%rdi
lea    -0x110(%rbp),%rsi
call   1050 <strcpy@plt>
mov    -0x23c(%rbp),%eax
cmp    -0x224(%rbp),%eax
jg     1633 <main+0x413>
lea    -0x350(%rbp),%rdi
mov    -0x238(%rbp),%rax
movslq -0x23c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1050 <strcpy@plt>
movl   $0x0,-0x354(%rbp)
lea    -0x350(%rbp),%rdi
lea    0xb60(%rip),%rsi
call   1110 <strtok@plt>
mov    %rax,-0x248(%rbp)
cmpq   $0x0,-0x248(%rbp)
je     14ec <main+0x2cc>
mov    -0x354(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x354(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xb2c(%rip),%rsi
call   1110 <strtok@plt>
mov    %rax,-0x248(%rbp)
jmp    14b3 <main+0x293>
cmpl   $0x0,-0x23c(%rbp)
jne    1505 <main+0x2e5>
mov    -0x354(%rbp),%eax
mov    %eax,-0x114(%rbp)
mov    -0x354(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   10f0 <malloc@plt>
mov    %rax,%rdx
mov    -0x230(%rbp),%rax
movslq -0x23c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
movl   $0x0,-0x358(%rbp)
lea    -0x350(%rbp),%rdi
mov    -0x238(%rbp),%rax
movslq -0x23c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1050 <strcpy@plt>
lea    -0x350(%rbp),%rdi
lea    0xaa1(%rip),%rsi
call   1110 <strtok@plt>
mov    %rax,-0x248(%rbp)
cmpq   $0x0,-0x248(%rbp)
je     15fe <main+0x3de>
mov    $0xff,%edi
call   10f0 <malloc@plt>
mov    %rax,%rdx
mov    -0x230(%rbp),%rax
movslq -0x23c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x358(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x230(%rbp),%rax
movslq -0x23c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x358(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x248(%rbp),%rsi
call   1050 <strcpy@plt>
mov    -0x358(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x358(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xa1a(%rip),%rsi
call   1110 <strtok@plt>
mov    %rax,-0x248(%rbp)
jmp    1572 <main+0x352>
mov    -0x230(%rbp),%rax
movslq -0x23c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x358(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x23c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x23c(%rbp)
jmp    145f <main+0x23f>
mov    -0x230(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rdi
lea    0x9c2(%rip),%rsi
call   10d0 <strcmp@plt>
cmp    $0x0,%rax
jne    1721 <main+0x501>
mov    -0x230(%rbp),%rax
mov    (%rax),%rax
cmpq   $0x0,0x8(%rax)
jne    16dc <main+0x4bc>
lea    -0x390(%rbp),%rdi
xor    %esi,%esi
mov    $0x32,%edx
call   10a0 <memset@plt>
lea    -0x390(%rbp),%rax
mov    %rax,-0x3a0(%rbp)
lea    0x979(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x3a0(%rbp),%rdi
mov    %rax,%rsi
call   1050 <strcpy@plt>
mov    $0xff,%edi
call   10f0 <malloc@plt>
mov    %rax,%rcx
mov    -0x230(%rbp),%rax
mov    (%rax),%rax
mov    %rcx,0x8(%rax)
mov    -0x230(%rbp),%rax
mov    (%rax),%rax
mov    0x8(%rax),%rdi
lea    -0x390(%rbp),%rsi
call   1050 <strcpy@plt>
mov    -0x230(%rbp),%rax
mov    (%rax),%rax
mov    0x8(%rax),%rdi
call   1080 <chdir@plt>
cmp    $0x0,%rax
je     171c <main+0x4fc>
mov    0x28d0(%rip),%rax
mov    (%rax),%edi
mov    -0x230(%rbp),%rax
mov    (%rax),%rax
mov    0x8(%rax),%rdx
lea    0x8fa(%rip),%rsi
call   10e0 <fprintf@plt>
jmp    1239 <main+0x19>
mov    0x28a0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x394(%rbp)
mov    0x28b9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x398(%rbp)
mov    -0x230(%rbp),%rdi
mov    -0x224(%rbp),%esi
add    $0x1,%esi
call   1100 <create_process@plt>
xor    %edi,%edi
call   1140 <wait@plt>
mov    -0x394(%rbp),%edi
mov    0x2860(%rip),%rax
mov    (%rax),%esi
call   1090 <dup2@plt>
mov    -0x398(%rbp),%edi
mov    0x2874(%rip),%rax
mov    (%rax),%esi
call   1090 <dup2@plt>
jmp    1239 <main+0x19>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x328,%rsp
xor    %eax,%eax
call   10a0 <signal_handler@plt>
lea    0x120(%rsp),%r15
lea    0xdce(%rip),%rbp
lea    0xdc9(%rip),%r14
jmp    12a9 <main+0x99>
mov    0x0(%r13),%rax
mov    (%rax),%rdi
lea    0xdbb(%rip),%rsi
call   10c0 <strcmp@plt>
test   %rax,%rax
je     1500 <main+0x2f0>
mov    0x2d65(%rip),%rbp
mov    0x0(%rbp),%ebx
mov    0x2d83(%rip),%r12
mov    (%r12),%r15d
mov    %r13,%rdi
mov    0xc(%rsp),%esi
call   10f0 <create_process@plt>
xor    %edi,%edi
call   1130 <wait@plt>
mov    0x0(%rbp),%esi
mov    %ebx,%edi
call   1090 <dup2@plt>
mov    (%r12),%esi
mov    %r15d,%edi
call   1090 <dup2@plt>
lea    0x120(%rsp),%r15
lea    0xd5c(%rip),%rbp
xor    %eax,%eax
call   1040 <typePrompt@plt>
mov    %r15,%rdi
call   1110 <clear_input@plt>
mov    0x2d21(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
mov    $0xff,%esi
call   10b0 <fgets@plt>
mov    %r15,%rdi
call   1070 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%r15,1)
jne    12f0 <main+0xe0>
mov    %r15,%rdi
call   1070 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r15,1)
mov    %r15,%rdi
call   1060 <test_stdin@plt>
test   %eax,%eax
je     12a9 <main+0x99>
mov    %r15,%rdi
lea    0xcfa(%rip),%rsi
call   10c0 <strcmp@plt>
test   %rax,%rax
je     15a6 <main+0x396>
lea    0x220(%rsp),%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <strcpy@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1100 <strtok@plt>
mov    $0xffffffff,%r12d
test   %rax,%rax
je     1353 <main+0x143>
nopl   (%rax)
add    $0x1,%r12d
xor    %edi,%edi
mov    %rbp,%rsi
call   1100 <strtok@plt>
test   %rax,%rax
jne    1340 <main+0x130>
lea    0x8(,%r12,8),%ebx
mov    %ebx,%edi
call   10e0 <malloc@plt>
mov    %rax,%r13
mov    %ebx,%edi
call   10e0 <malloc@plt>
mov    %rbp,%r15
mov    %rax,0x10(%rsp)
lea    0x220(%rsp),%rbx
mov    %rbx,%rdi
lea    0x120(%rsp),%rsi
call   1050 <strcpy@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1100 <strtok@plt>
test   %rax,%rax
je     13df <main+0x1cf>
mov    %rax,%rbx
mov    0x10(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0xff,%edi
call   10e0 <malloc@plt>
mov    %rax,0x0(%rbp)
mov    %rax,%rdi
mov    %rbx,%rsi
call   1050 <strcpy@plt>
xor    %edi,%edi
mov    %r15,%rsi
call   1100 <strtok@plt>
mov    %rax,%rbx
add    $0x8,%rbp
test   %rax,%rax
jne    13b0 <main+0x1a0>
lea    0x1(%r12),%eax
mov    %eax,0xc(%rsp)
lea    0x220(%rsp),%rdi
lea    0x120(%rsp),%rsi
call   1050 <strcpy@plt>
test   %r12d,%r12d
lea    0x20(%rsp),%r15
js     1240 <main+0x30>
mov    0xc(%rsp),%eax
mov    %rax,0x18(%rsp)
xor    %ebp,%ebp
jmp    1440 <main+0x230>
nopl   0x0(%rax,%rax,1)
xor    %ebx,%ebx
mov    0x0(%r13,%rbp,8),%rax
mov    %ebx,%ecx
movq   $0x0,(%rax,%rcx,8)
add    $0x1,%rbp
cmp    0x18(%rsp),%rbp
je     1240 <main+0x30>
mov    0x10(%rsp),%rax
mov    (%rax,%rbp,8),%rsi
mov    %r15,%rdi
call   1050 <strcpy@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1100 <strtok@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     1482 <main+0x272>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%ebx
xor    %edi,%edi
mov    %r14,%rsi
call   1100 <strtok@plt>
test   %rax,%rax
jne    1470 <main+0x260>
lea    0x8(,%rbx,8),%edi
call   10e0 <malloc@plt>
mov    %rax,0x0(%r13,%rbp,8)
mov    0x10(%rsp),%rax
mov    (%rax,%rbp,8),%rsi
mov    %r15,%rdi
call   1050 <strcpy@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1100 <strtok@plt>
test   %rax,%rax
je     1420 <main+0x210>
mov    %rax,%r12
xor    %ebx,%ebx
nopl   (%rax)
mov    $0xff,%edi
call   10e0 <malloc@plt>
mov    0x0(%r13,%rbp,8),%rcx
mov    %rax,(%rcx,%rbx,8)
mov    0x0(%r13,%rbp,8),%rax
mov    (%rax,%rbx,8),%rdi
mov    %r12,%rsi
call   1050 <strcpy@plt>
add    $0x1,%rbx
xor    %edi,%edi
mov    %r14,%rsi
call   1100 <strtok@plt>
mov    %rax,%r12
test   %rax,%rax
jne    14c0 <main+0x2b0>
jmp    1422 <main+0x212>
nop
mov    0x0(%r13),%rax
mov    0x8(%rax),%rdi
test   %rdi,%rdi
jne    1567 <main+0x357>
xorps  %xmm0,%xmm0
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movw   $0x0,0x50(%rsp)
lea    0xadf(%rip),%rdi
call   1030 <getenv@plt>
mov    %r15,%rdi
mov    %rax,%rsi
call   1050 <strcpy@plt>
mov    $0xff,%edi
call   10e0 <malloc@plt>
mov    0x0(%r13),%rcx
mov    %rax,0x8(%rcx)
mov    0x0(%r13),%rax
mov    0x8(%rax),%rdi
mov    %r15,%rsi
call   1050 <strcpy@plt>
mov    0x0(%r13),%rax
mov    0x8(%rax),%rdi
call   1080 <chdir@plt>
test   %rax,%rax
lea    0x120(%rsp),%r15
lea    0xa87(%rip),%rbp
je     12a9 <main+0x99>
mov    0x2a45(%rip),%rax
mov    (%rax),%edi
mov    0x0(%r13),%rax
mov    0x8(%rax),%rdx
lea    0xa75(%rip),%rsi
call   10d0 <fprintf@plt>
jmp    12a9 <main+0x99>
xor    %edi,%edi
call   1120 <exit@plt>

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

LLVM IR (-O2):
@stdin = global i32 0
@.str = [5 x i8] c"exit\00"
@.str.1 = [2 x i8] c"|\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [3 x i8] c"cd\00"
@.str.4 = [5 x i8] c"HOME\00"
@stderr = global i32 0
@.str.5 = [38 x i8] c"cd: '%s' file or directory not found\0A\00"
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
define i32 @main() {
%1 = alloca [255 x i8]
%2 = alloca [255 x i8]
%3 = alloca [255 x i8]
%4 = alloca [50 x i8]
%5 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 0
%6 = tail call i32 (...) @signal_handler()
%7 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%8 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
br label %10
10: ; preds = %29, %0
%11 = call i32 (...) @typePrompt()
%12 = call i32 @clear_input(i8* %5)
%13 = load i32, i32* @stdin
%14 = call i32 @fgets(i8* %5, i32 255, i32 %13)
%15 = call i32 @strlen(i8* %5)
%16 = add nsw i32 %15, -1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 10
br i1 %20, label %21, label %26
21: ; preds = %10
%22 = call i32 @strlen(i8* %5)
%23 = add nsw i32 %22, -1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 %24
store i8 0, i8* %25
br label %26
26: ; preds = %10, %21
%27 = call i32 @test_stdin(i8* %5)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %26, %157
br label %10
30: ; preds = %26
%31 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = call i32 @exit(i32 0)
unreachable
35: ; preds = %30
%36 = call i32 @strcpy(i8* %7, i8* %5)
%37 = call i8* @strtok(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%38 = icmp eq i8* %37, null
br i1 %38, label %44, label %39
39: ; preds = %35, %39
%40 = phi i32 [ %41, %39 ], [ -1, %35 ]
%41 = add nsw i32 %40, 1
%42 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%43 = icmp eq i8* %42, null
br i1 %43, label %44, label %39
44: ; preds = %39, %35
%45 = phi i32 [ -1, %35 ], [ %41, %39 ]
%46 = add i32 %45, 1
%47 = shl i32 %46, 3
%48 = call i64 @malloc(i32 %47)
%49 = inttoptr i64 %48 to i8***
%50 = call i64 @malloc(i32 %47)
%51 = inttoptr i64 %50 to i8**
%52 = call i32 @strcpy(i8* %7, i8* %5)
%53 = call i8* @strtok(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%54 = icmp eq i8* %53, null
br i1 %54, label %65, label %55
55: ; preds = %44, %55
%56 = phi i64 [ %62, %55 ], [ 0, %44 ]
%57 = phi i8* [ %63, %55 ], [ %53, %44 ]
%58 = call i64 @malloc(i32 255)
%59 = inttoptr i64 %58 to i8*
%60 = getelementptr inbounds i8*, i8** %51, i64 %56
store i8* %59, i8** %60
%61 = call i32 @strcpy(i8* %59, i8* %57)
%62 = add nuw i64 %56, 1
%63 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%64 = icmp eq i8* %63, null
br i1 %64, label %65, label %55
65: ; preds = %55, %44
%66 = call i32 @strcpy(i8* %7, i8* %5)
%67 = icmp slt i32 %45, 0
br i1 %67, label %114, label %68
68: ; preds = %65
%69 = zext i32 %46 to i64
br label %70
70: ; preds = %68, %107
%71 = phi i64 [ 0, %68 ], [ %112, %107 ]
%72 = getelementptr inbounds i8*, i8** %51, i64 %71
%73 = load i8*, i8** %72
%74 = call i32 @strcpy(i8* %8, i8* %73)
%75 = call i8* @strtok(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%76 = icmp eq i8* %75, null
br i1 %76, label %82, label %77
77: ; preds = %70, %77
%78 = phi i32 [ %79, %77 ], [ 0, %70 ]
%79 = add nuw nsw i32 %78, 1
%80 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%81 = icmp eq i8* %80, null
br i1 %81, label %82, label %77
82: ; preds = %77, %70
%83 = phi i32 [ 0, %70 ], [ %79, %77 ]
%84 = shl i32 %83, 3
%85 = add i32 %84, 8
%86 = call i64 @malloc(i32 %85)
%87 = inttoptr i64 %86 to i8**
%88 = getelementptr inbounds i8**, i8*** %49, i64 %71
store i8** %87, i8*** %88
%89 = load i8*, i8** %72
%90 = call i32 @strcpy(i8* %8, i8* %89)
%91 = call i8* @strtok(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%92 = icmp eq i8* %91, null
br i1 %92, label %107, label %93
93: ; preds = %82, %93
%94 = phi i64 [ %104, %93 ], [ 0, %82 ]
%95 = phi i8* [ %105, %93 ], [ %91, %82 ]
%96 = call i64 @malloc(i32 255)
%97 = inttoptr i64 %96 to i8*
%98 = load i8**, i8*** %88
%99 = getelementptr inbounds i8*, i8** %98, i64 %94
store i8* %97, i8** %99
%100 = load i8**, i8*** %88
%101 = getelementptr inbounds i8*, i8** %100, i64 %94
%102 = load i8*, i8** %101
%103 = call i32 @strcpy(i8* %102, i8* %95)
%104 = add nuw i64 %94, 1
%105 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%106 = icmp eq i8* %105, null
br i1 %106, label %107, label %93
107: ; preds = %93, %82
%108 = phi i64 [ 0, %82 ], [ %104, %93 ]
%109 = load i8**, i8*** %88
%110 = and i64 %108, 4294967295
%111 = getelementptr inbounds i8*, i8** %109, i64 %110
store i8* null, i8** %111
%112 = add nuw nsw i64 %71, 1
%113 = icmp eq i64 %112, %69
br i1 %113, label %114, label %70
114: ; preds = %107, %65
%115 = load i8**, i8*** %49
%116 = load i8*, i8** %115
%117 = call i64 @strcmp(i8* %116, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%118 = icmp eq i64 %117, 0
br i1 %118, label %119, label %148
119: ; preds = %114
%120 = load i8**, i8*** %49
%121 = getelementptr inbounds i8*, i8** %120, i64 1
%122 = load i8*, i8** %121
%123 = icmp eq i8* %122, null
br i1 %123, label %124, label %138
124: ; preds = %119
%125 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%126 = call i32 @strcpy(i8* %9, i8* %125)
%127 = call i64 @malloc(i32 255)
%128 = inttoptr i64 %127 to i8*
%129 = load i8**, i8*** %49
%130 = getelementptr inbounds i8*, i8** %129, i64 1
store i8* %128, i8** %130
%131 = load i8**, i8*** %49
%132 = getelementptr inbounds i8*, i8** %131, i64 1
%133 = load i8*, i8** %132
%134 = call i32 @strcpy(i8* %133, i8* %9)
%135 = load i8**, i8*** %49
%136 = getelementptr inbounds i8*, i8** %135, i64 1
%137 = load i8*, i8** %136
br label %138
138: ; preds = %124, %119
%139 = phi i8* [ %137, %124 ], [ %122, %119 ]
%140 = call i64 @chdir(i8* %139)
%141 = icmp eq i64 %140, 0
br i1 %141, label %157, label %142
142: ; preds = %138
%143 = load i32, i32* @stderr
%144 = load i8**, i8*** %49
%145 = getelementptr inbounds i8*, i8** %144, i64 1
%146 = load i8*, i8** %145
%147 = call i32 @fprintf(i32 %143, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i8* %146)
br label %157
148: ; preds = %114
%149 = load i32, i32* @STDIN_FILENO
%150 = load i32, i32* @STDOUT_FILENO
%151 = call i32 @create_process(i8*** %49, i32 %46)
%152 = call i32 @wait(i32 0)
%153 = load i32, i32* @STDIN_FILENO
%154 = call i32 @dup2(i32 %149, i32 %153)
%155 = load i32, i32* @STDOUT_FILENO
%156 = call i32 @dup2(i32 %150, i32 %155)
br label %157
157: ; preds = %138, %142, %148
br label %29
}