#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 O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_TRUNC;
int O_WRONLY;
int cd_cmd(char **, char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ execv(char *, char **);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ exit_logout(char **);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
char *get_input_name(char **, int);
char *get_output_name(char **, int);
int /*<<< orphan*/ getcwd(char *, int);
int open(char *, int, ...);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ readline(char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strtok(char *, char *);
int /*<<< orphan*/ wait(int /*<<< orphan*/);
int main(void) {
  char argstr[16][32];
  char *argv[16];
  char *token;
  char buffer[32];
  char delimiter[] = " |\n\t";
  int idx;
  pid_t PID;
  int fdw;
  int fdr;
  int ret;
  char pwd_buffer[50];
  char *fname_in_ptr = NULL;
  char *fname_out_ptr = NULL;
  fprintf(stdout, "\E[0;0H");
  fprintf(stdout, "\E[2J");
  getcwd(pwd_buffer, 50);
  while (1) {
    printf("# ");
    readline(buffer, 32);
    idx = 0;
    token = strtok(buffer, delimiter);
    while (token != NULL) {
      strcpy(&(argstr[idx][0]), token);
      argv[idx] = argstr[idx];
      idx++;
      token = strtok(NULL, delimiter);
    }
    argv[idx] = NULL;
    fname_in_ptr = get_input_name(argv, idx);
    fname_out_ptr = get_output_name(argv, idx);
    exit_logout(argv);
    ret = cd_cmd(argv, pwd_buffer);
    if (ret) {
      if ((PID = fork()) == 0) {
        if (fname_out_ptr != NULL) {
          close(1);
          fdw = open(fname_out_ptr, O_CREAT | O_TRUNC | O_WRONLY, 0644);
          if (fdw < 0) {
            fprintf(stderr, "Could not write to file %s\n", fname_out_ptr);
            exit(-1);
          }
        }
        if (fname_in_ptr != NULL) {
          close(0);
          fdr = open(fname_in_ptr, O_RDONLY);
          if (fdr < 0) {
            fprintf(stderr, "Could not read file %s\n", fname_in_ptr);
            exit(-1);
          }
        }
        strcpy(buffer, "/bin/");
        strcat(buffer, argv[0]);
        execv(buffer, &argv[0]);
        strcpy(buffer, "/usr/bin/");
        strcat(buffer, argv[0]);
        execv(buffer, &argv[0]);
        printf("%s: command not found\n", argv[0]);
        exit(0);
      } else if (PID < 0) {
        printf("fork failed\n");
        exit(-1);
      } else
        wait(0);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x330,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xdd8(%rip),%eax
mov    %eax,-0x2c5(%rbp)
mov    0xdd0(%rip),%al
mov    %al,-0x2c1(%rbp)
movq   $0x0,-0x328(%rbp)
movq   $0x0,-0x330(%rbp)
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
lea    0xda5(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2d52(%rip),%rax
mov    (%rax),%edi
lea    0xd95(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
lea    -0x320(%rbp),%rdi
mov    $0x32,%esi
call   1060 <getcwd@plt>
lea    0xd7b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x2c0(%rbp),%rdi
mov    $0x20,%esi
call   1070 <readline@plt>
movl   $0x0,-0x2cc(%rbp)
lea    -0x2c0(%rbp),%rdi
lea    -0x2c5(%rbp),%rsi
call   10d0 <strtok@plt>
mov    %rax,-0x298(%rbp)
cmpq   $0x0,-0x298(%rbp)
je     1350 <main+0x140>
movslq -0x2cc(%rbp),%rax
lea    -0x210(%rbp),%rdi
shl    $0x5,%rax
add    %rax,%rdi
mov    -0x298(%rbp),%rsi
call   1030 <strcpy@plt>
movslq -0x2cc(%rbp),%rax
lea    -0x210(%rbp),%rcx
shl    $0x5,%rax
add    %rax,%rcx
movslq -0x2cc(%rbp),%rax
mov    %rcx,-0x290(%rbp,%rax,8)
ff
mov    -0x2cc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2cc(%rbp)
lea    -0x2c5(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   10d0 <strtok@plt>
mov    %rax,-0x298(%rbp)
jmp    12d2 <main+0xc2>
movslq -0x2cc(%rbp),%rax
movq   $0x0,-0x290(%rbp,%rax,8)
lea    -0x290(%rbp),%rdi
mov    -0x2cc(%rbp),%esi
call   1040 <get_input_name@plt>
mov    %rax,-0x328(%rbp)
lea    -0x290(%rbp),%rdi
mov    -0x2cc(%rbp),%esi
call   10f0 <get_output_name@plt>
mov    %rax,-0x330(%rbp)
lea    -0x290(%rbp),%rdi
call   10a0 <exit_logout@plt>
lea    -0x290(%rbp),%rdi
lea    -0x320(%rbp),%rsi
call   10b0 <cd_cmd@plt>
mov    %eax,-0x2e4(%rbp)
cmpl   $0x0,-0x2e4(%rbp)
je     1596 <main+0x386>
mov    $0x0,%al
call   1130 <fork@plt>
mov    %rax,-0x2d8(%rbp)
cmp    $0x0,%rax
jne    155f <main+0x34f>
cmpq   $0x0,-0x330(%rbp)
je     1465 <main+0x255>
mov    $0x1,%edi
call   1080 <close@plt>
mov    -0x330(%rbp),%rdi
mov    0x2bf3(%rip),%rax
mov    (%rax),%esi
mov    0x2be2(%rip),%rax
or     (%rax),%esi
mov    0x2b99(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
mov    $0x0,%al
call   10c0 <open@plt>
mov    %eax,-0x2dc(%rbp)
cmpl   $0x0,-0x2dc(%rbp)
jge    1460 <main+0x250>
mov    0x2b89(%rip),%rax
mov    (%rax),%edi
mov    -0x330(%rbp),%rdx
lea    0xbc5(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0xffffffff,%edi
call   1100 <exit@plt>
jmp    1465 <main+0x255>
cmpq   $0x0,-0x328(%rbp)
je     14d1 <main+0x2c1>
xor    %edi,%edi
call   1080 <close@plt>
mov    -0x328(%rbp),%rdi
mov    0x2b50(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   10c0 <open@plt>
mov    %eax,-0x2e0(%rbp)
cmpl   $0x0,-0x2e0(%rbp)
jge    14cc <main+0x2bc>
mov    0x2b1d(%rip),%rax
mov    (%rax),%edi
mov    -0x328(%rbp),%rdx
lea    0xb75(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0xffffffff,%edi
call   1100 <exit@plt>
jmp    14d1 <main+0x2c1>
lea    -0x2c0(%rbp),%rdi
lea    0xb6d(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x2c0(%rbp),%rdi
mov    -0x290(%rbp),%rsi
call   10e0 <strcat@plt>
lea    -0x2c0(%rbp),%rdi
lea    -0x290(%rbp),%rsi
call   1120 <execv@plt>
lea    -0x2c0(%rbp),%rdi
lea    0xb30(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x2c0(%rbp),%rdi
mov    -0x290(%rbp),%rsi
call   10e0 <strcat@plt>
lea    -0x2c0(%rbp),%rdi
lea    -0x290(%rbp),%rsi
call   1120 <execv@plt>
mov    -0x290(%rbp),%rsi
lea    0xb01(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   1100 <exit@plt>
cmpq   $0x0,-0x2d8(%rbp)
jge    1585 <main+0x375>
lea    0xaf5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   1100 <exit@plt>
xor    %edi,%edi
call   1110 <wait@plt>
jmp    1591 <main+0x381>
jmp    1596 <main+0x386>
jmp    128f <main+0x7f>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2f8,%rsp
movb   $0x0,0xc(%rsp)
movl   $0x90a7c20,0x8(%rsp)
09
mov    0x2d7b(%rip),%rbx
mov    (%rbx),%edi
lea    0xdb7(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    (%rbx),%edi
lea    0xdae(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
lea    0xb0(%rsp),%rdi
mov    $0x32,%esi
call   1070 <getcwd@plt>
lea    0x8(%rsp),%r12
lea    0x30(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0xd7a(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x20,%esi
call   1080 <readline@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   10e0 <strtok@plt>
mov    $0x0,%ebp
test   %rax,%rax
je     12f7 <main+0xd7>
lea    0xf0(%rsp),%rbx
xor    %ebp,%ebp
nop
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
mov    %rbx,0x30(%rsp,%rbp,8)
add    $0x1,%rbp
xor    %edi,%edi
mov    %r12,%rsi
call   10e0 <strtok@plt>
add    $0x20,%rbx
test   %rax,%rax
jne    12d0 <main+0xb0>
mov    %ebp,%eax
movq   $0x0,0x30(%rsp,%rax,8)
mov    %r13,%rdi
mov    %ebp,%esi
call   1050 <get_input_name@plt>
mov    %rax,%r15
mov    %r13,%rdi
mov    %ebp,%esi
call   1100 <get_output_name@plt>
mov    %rax,%r14
mov    %r13,%rdi
call   10b0 <exit_logout@plt>
mov    %r13,%rdi
lea    0xb0(%rsp),%rsi
call   10c0 <cd_cmd@plt>
test   %eax,%eax
je     1290 <main+0x70>
xor    %eax,%eax
call   1140 <fork@plt>
test   %rax,%rax
je     1356 <main+0x136>
js     13a8 <main+0x188>
xor    %edi,%edi
call   1120 <wait@plt>
jmp    1290 <main+0x70>
test   %r14,%r14
je     13be <main+0x19e>
mov    $0x1,%edi
call   1090 <close@plt>
mov    0x2c8c(%rip),%rax
mov    0x2c7d(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2c32(%rip),%rax
or     (%rax),%esi
mov    %r14,%rdi
mov    $0x1a4,%edx
xor    %eax,%eax
call   10d0 <open@plt>
test   %eax,%eax
jns    13be <main+0x19e>
mov    0x2c2e(%rip),%rax
mov    (%rax),%edi
lea    0xc71(%rip),%rsi
mov    %r14,%rdx
jmp    13f4 <main+0x1d4>
lea    0xcba(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%edi
call   1110 <exit@plt>
test   %r15,%r15
je     1405 <main+0x1e5>
xor    %edi,%edi
call   1090 <close@plt>
mov    0x2c07(%rip),%rax
mov    (%rax),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   10d0 <open@plt>
test   %eax,%eax
jns    1405 <main+0x1e5>
mov    0x2be0(%rip),%rax
mov    (%rax),%edi
lea    0xc3f(%rip),%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0xffffffff,%edi
call   1110 <exit@plt>
lea    0xc40(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    0x30(%rsp),%rsi
mov    %rbx,%rdi
call   10f0 <strcat@plt>
lea    0x30(%rsp),%rbp
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1130 <execv@plt>
lea    0xc0b(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    0x30(%rsp),%rsi
mov    %rbx,%rdi
call   10f0 <strcat@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1130 <execv@plt>
mov    0x30(%rsp),%rsi
lea    0xbe9(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
call   1110 <exit@plt>

LLVM IR (-O0):
@__const.main.delimiter = [5 x i8] c" |\0A\09\00"
@stdout = global i32 0
@.str = [7 x i8] c"\1B[0;0H\00"
@.str.1 = [5 x i8] c"\1B[2J\00"
@.str.2 = [3 x i8] c"# \00"
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@O_WRONLY = global i32 0
@stderr = global i32 0
@.str.3 = [28 x i8] c"Could not write to file %s\0A\00"
@O_RDONLY = global i32 0
@.str.4 = [24 x i8] c"Could not read file %s\0A\00"
@.str.5 = [6 x i8] c"/bin/\00"
@.str.6 = [10 x i8] c"/usr/bin/\00"
@.str.7 = [23 x i8] c"%s: command not found\0A\00"
@.str.8 = [13 x i8] c"fork failed\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [16 x [32 x i8]]
%3 = alloca [16 x i8*]
%4 = alloca i8*
%5 = alloca [32 x i8]
%6 = alloca [5 x i8]
%7 = alloca i32
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca [50 x i8]
%13 = alloca i8*
%14 = alloca i8*
store i32 0, i32* %1
%15 = bitcast [5 x i8]* %6 to i8*
store i8* null, i8** %13
store i8* null, i8** %14
%16 = load i32, i32* @stdout
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* @stdout
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%20 = getelementptr inbounds [50 x i8], [50 x i8]* %12, i64 0, i64 0
%21 = call i32 @getcwd(i8* %20, i32 50)
br label %22
22: ; preds = %0, %139
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%24 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%25 = call i32 @readline(i8* %24, i32 32)
store i32 0, i32* %7
%26 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%27 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 0
%28 = call i8* @strtok(i8* %26, i8* %27)
store i8* %28, i8** %4
br label %29
29: ; preds = %32, %22
%30 = load i8*, i8** %4
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %50
32: ; preds = %29
%33 = load i32, i32* %7
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [16 x [32 x i8]], [16 x [32 x i8]]* %2, i64 0, i64 %34
%36 = getelementptr inbounds [32 x i8], [32 x i8]* %35, i64 0, i64 0
%37 = load i8*, i8** %4
%38 = call i32 @strcpy(i8* %36, i8* %37)
%39 = load i32, i32* %7
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [16 x [32 x i8]], [16 x [32 x i8]]* %2, i64 0, i64 %40
%42 = getelementptr inbounds [32 x i8], [32 x i8]* %41, i64 0, i64 0
%43 = load i32, i32* %7
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [16 x i8*], [16 x i8*]* %3, i64 0, i64 %44
store i8* %42, i8** %45
%46 = load i32, i32* %7
%47 = add nsw i32 %46, 1
store i32 %47, i32* %7
%48 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 0
%49 = call i8* @strtok(i8* null, i8* %48)
store i8* %49, i8** %4
br label %29
50: ; preds = %29
%51 = load i32, i32* %7
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [16 x i8*], [16 x i8*]* %3, i64 0, i64 %52
store i8* null, i8** %53
%54 = getelementptr inbounds [16 x i8*], [16 x i8*]* %3, i64 0, i64 0
%55 = load i32, i32* %7
%56 = call i8* @get_input_name(i8** %54, i32 %55)
store i8* %56, i8** %13
%57 = getelementptr inbounds [16 x i8*], [16 x i8*]* %3, i64 0, i64 0
%58 = load i32, i32* %7
%59 = call i8* @get_output_name(i8** %57, i32 %58)
store i8* %59, i8** %14
%60 = getelementptr inbounds [16 x i8*], [16 x i8*]* %3, i64 0, i64 0
%61 = call i32 @exit_logout(i8** %60)
%62 = getelementptr inbounds [16 x i8*], [16 x i8*]* %3, i64 0, i64 0
%63 = getelementptr inbounds [50 x i8], [50 x i8]* %12, i64 0, i64 0
%64 = call i32 @cd_cmd(i8** %62, i8* %63)
store i32 %64, i32* %11
%65 = load i32, i32* %11
%66 = icmp ne i32 %65, 0
br i1 %66, label %67, label %139
67: ; preds = %50
%68 = call i64 (...) @fork()
store i64 %68, i64* %8
%69 = icmp eq i64 %68, 0
br i1 %69, label %70, label %129
70: ; preds = %67
%71 = load i8*, i8** %14
%72 = icmp ne i8* %71, null
br i1 %72, label %73, label %90
73: ; preds = %70
%74 = call i32 @close(i32 1)
%75 = load i8*, i8** %14
%76 = load i32, i32* @O_CREAT
%77 = load i32, i32* @O_TRUNC
%78 = or i32 %76, %77
%79 = load i32, i32* @O_WRONLY
%80 = or i32 %78, %79
%81 = call i32 (i8*, i32, ...) @open(i8* %75, i32 %80, i32 420)
store i32 %81, i32* %9
%82 = load i32, i32* %9
%83 = icmp slt i32 %82, 0
br i1 %83, label %84, label %89
84: ; preds = %73
%85 = load i32, i32* @stderr
%86 = load i8*, i8** %14
%87 = call i32 (i32, i8*, ...) @fprintf(i32 %85, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %86)
%88 = call i32 @exit(i32 -1)
unreachable
89: ; preds = %73
br label %90
90: ; preds = %89, %70
%91 = load i8*, i8** %13
%92 = icmp ne i8* %91, null
br i1 %92, label %93, label %106
93: ; preds = %90
%94 = call i32 @close(i32 0)
%95 = load i8*, i8** %13
%96 = load i32, i32* @O_RDONLY
%97 = call i32 (i8*, i32, ...) @open(i8* %95, i32 %96)
store i32 %97, i32* %10
%98 = load i32, i32* %10
%99 = icmp slt i32 %98, 0
br i1 %99, label %100, label %105
100: ; preds = %93
%101 = load i32, i32* @stderr
%102 = load i8*, i8** %13
%103 = call i32 (i32, i8*, ...) @fprintf(i32 %101, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %102)
%104 = call i32 @exit(i32 -1)
unreachable
105: ; preds = %93
br label %106
106: ; preds = %105, %90
%107 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%108 = call i32 @strcpy(i8* %107, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%109 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%110 = getelementptr inbounds [16 x i8*], [16 x i8*]* %3, i64 0, i64 0
%111 = load i8*, i8** %110
%112 = call i32 @strcat(i8* %109, i8* %111)
%113 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%114 = getelementptr inbounds [16 x i8*], [16 x i8*]* %3, i64 0, i64 0
%115 = call i32 @execv(i8* %113, i8** %114)
%116 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%117 = call i32 @strcpy(i8* %116, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
%118 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%119 = getelementptr inbounds [16 x i8*], [16 x i8*]* %3, i64 0, i64 0
%120 = load i8*, i8** %119
%121 = call i32 @strcat(i8* %118, i8* %120)
%122 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%123 = getelementptr inbounds [16 x i8*], [16 x i8*]* %3, i64 0, i64 0
%124 = call i32 @execv(i8* %122, i8** %123)
%125 = getelementptr inbounds [16 x i8*], [16 x i8*]* %3, i64 0, i64 0
%126 = load i8*, i8** %125
%127 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i8* %126)
%128 = call i32 @exit(i32 0)
unreachable
129: ; preds = %67
%130 = load i64, i64* %8
%131 = icmp slt i64 %130, 0
br i1 %131, label %132, label %135
132: ; preds = %129
%133 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0))
%134 = call i32 @exit(i32 -1)
unreachable
135: ; preds = %129
%136 = call i32 @wait(i32 0)
br label %137
137: ; preds = %135
br label %138
138: ; preds = %137
br label %139
139: ; preds = %138, %50
br label %22
}

LLVM IR (-O2):
@__const.main.delimiter = [5 x i8] c" |\0A\09\00"
@stdout = global i32 0
@.str = [7 x i8] c"\1B[0;0H\00"
@.str.1 = [5 x i8] c"\1B[2J\00"
@.str.2 = [3 x i8] c"# \00"
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@O_WRONLY = global i32 0
@stderr = global i32 0
@.str.3 = [28 x i8] c"Could not write to file %s\0A\00"
@O_RDONLY = global i32 0
@.str.4 = [24 x i8] c"Could not read file %s\0A\00"
@.str.5 = [6 x i8] c"/bin/\00"
@.str.6 = [10 x i8] c"/usr/bin/\00"
@.str.7 = [23 x i8] c"%s: command not found\0A\00"
@str = [12 x i8] c"fork failed\00"
define i32 @main() {
%1 = alloca [16 x [32 x i8]]
%2 = alloca [16 x i8*]
%3 = alloca [32 x i8]
%4 = alloca [5 x i8]
%5 = alloca [50 x i8]
%6 = getelementptr inbounds [16 x [32 x i8]], [16 x [32 x i8]]* %1, i64 0, i64 0, i64 0
%7 = bitcast [16 x i8*]* %2 to i8*
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%11 = load i32, i32* @stdout
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @stdout
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @getcwd(i8* %10, i32 50)
%16 = getelementptr inbounds [16 x i8*], [16 x i8*]* %2, i64 0, i64 0
br label %17
17: ; preds = %90, %0
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%19 = call i32 @readline(i8* %8, i32 32)
%20 = call i8* @strtok(i8* %8, i8* %9)
%21 = icmp eq i8* %20, null
br i1 %21, label %33, label %22
22: ; preds = %17, %22
%23 = phi i64 [ %28, %22 ], [ 0, %17 ]
%24 = phi i8* [ %29, %22 ], [ %20, %17 ]
%25 = getelementptr inbounds [16 x [32 x i8]], [16 x [32 x i8]]* %1, i64 0, i64 %23, i64 0
%26 = call i32 @strcpy(i8* %25, i8* %24)
%27 = getelementptr inbounds [16 x i8*], [16 x i8*]* %2, i64 0, i64 %23
store i8* %25, i8** %27
%28 = add nuw i64 %23, 1
%29 = call i8* @strtok(i8* null, i8* %9)
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %22
31: ; preds = %22
%32 = trunc i64 %28 to i32
br label %33
33: ; preds = %31, %17
%34 = phi i32 [ 0, %17 ], [ %32, %31 ]
%35 = zext i32 %34 to i64
%36 = getelementptr inbounds [16 x i8*], [16 x i8*]* %2, i64 0, i64 %35
store i8* null, i8** %36
%37 = call i8* @get_input_name(i8** %16, i32 %34)
%38 = call i8* @get_output_name(i8** %16, i32 %34)
%39 = call i32 @exit_logout(i8** %16)
%40 = call i32 @cd_cmd(i8** %16, i8* %10)
%41 = icmp eq i32 %40, 0
br i1 %41, label %90, label %42
42: ; preds = %33
%43 = call i64 (...) @fork()
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %83
45: ; preds = %42
%46 = icmp eq i8* %38, null
br i1 %46, label %60, label %47
47: ; preds = %45
%48 = call i32 @close(i32 1)
%49 = load i32, i32* @O_CREAT
%50 = load i32, i32* @O_TRUNC
%51 = or i32 %50, %49
%52 = load i32, i32* @O_WRONLY
%53 = or i32 %51, %52
%54 = call i32 (i8*, i32, ...) @open(i8* %38, i32 %53, i32 420)
%55 = icmp slt i32 %54, 0
br i1 %55, label %56, label %60
56: ; preds = %47
%57 = load i32, i32* @stderr
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %38)
%59 = call i32 @exit(i32 -1)
unreachable
60: ; preds = %47, %45
%61 = icmp eq i8* %37, null
br i1 %61, label %71, label %62
62: ; preds = %60
%63 = call i32 @close(i32 0)
%64 = load i32, i32* @O_RDONLY
%65 = call i32 (i8*, i32, ...) @open(i8* %37, i32 %64)
%66 = icmp slt i32 %65, 0
br i1 %66, label %67, label %71
67: ; preds = %62
%68 = load i32, i32* @stderr
%69 = call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %37)
%70 = call i32 @exit(i32 -1)
unreachable
71: ; preds = %62, %60
%72 = call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%73 = load i8*, i8** %16
%74 = call i32 @strcat(i8* %8, i8* %73)
%75 = call i32 @execv(i8* %8, i8** %16)
%76 = call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
%77 = load i8*, i8** %16
%78 = call i32 @strcat(i8* %8, i8* %77)
%79 = call i32 @execv(i8* %8, i8** %16)
%80 = load i8*, i8** %16
%81 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i8* %80)
%82 = call i32 @exit(i32 0)
unreachable
83: ; preds = %42
%84 = icmp slt i64 %43, 0
br i1 %84, label %85, label %88
85: ; preds = %83
%86 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%87 = call i32 @exit(i32 -1)
unreachable
88: ; preds = %83
%89 = call i32 @wait(i32 0)
br label %90
90: ; preds = %88, %33
br label %17
}