#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 */
scalar_t__ checkPath(char *, char *);
int /*<<< orphan*/ execv(char *, char **);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ free(char **);
int /*<<< orphan*/ getcwd(char *, int);
char *getenv(char *);
char **malloc(int);
char *mergePath(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
char **realloc(char **, int);
int /*<<< orphan*/ stdin;
scalar_t__ strcmp(char *, char *);
char *strtok(char *, char *);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  char buffer[500];
  char cwd[1024];
  char *path = getenv("PATH");
  char *execPath;
  char *token;
  int pid;
  char **arguments = malloc(sizeof(char *) * 5);
  int maxArgs = 5;
  int numArgs = 0;
  char **paths = malloc(sizeof(char *) * 5);
  int numPaths = 0;
  int maxPaths = 5;
  token = strtok(path, ":");
  do {
    if (numPaths >= maxPaths - 1) {
      maxPaths *= 2;
      paths = realloc(paths, sizeof(char *) * maxPaths);
    }
    paths[numPaths] = token;
    numPaths++;
  } while ((token = strtok(NULL, ":")));
  if (0) {
    for (int i = 0; i < numPaths; i++) {
      printf("Path %d: %s\n", i, paths[i]);
    }
  }
  while (1) {
    numArgs = 0;
    execPath = NULL;
    getcwd(cwd, 1024);
    for (int i = 0; i < maxArgs; i++) {
      arguments[i] = NULL;
    }
    printf("esh/:-> ");
    fgets(buffer, 500, stdin);
    token = strtok(buffer, " \n\r");
    do {
      if (token != NULL && numArgs >= maxArgs - 1) {
        maxArgs *= 2;
        arguments = realloc(arguments, (maxArgs * sizeof(char *)));
      }
      arguments[numArgs] = token;
      numArgs++;
    } while ((token = strtok(NULL, " \n\r")));
    if (!strcmp(arguments[0], "exit")) {
      free(arguments);
      break;
    }
    if (0) {
      printf("Command: %s \n", arguments[0]);
      for (int i = 1; i < numArgs; i++) {
        printf("Argument %d: %s \n", i, arguments[i]);
      }
    }
    for (int i = 0; i < numPaths; i++) {
      if (checkPath(paths[i], arguments[0])) {
        execPath = paths[i];
      }
    }
    if (!execPath && checkPath(cwd, arguments[0])) {
      execPath = cwd;
    }
    if (!execPath) {
      printf("Command `%s' not found.\n", arguments[0]);
      continue;
    }
    pid = fork();
    if (pid != 0) {
      wait(NULL);
    } else {
      if (strcmp("&", arguments[numArgs - 1]) == 0) {
        arguments[numArgs - 1] = NULL;
      }
      char *merged = mergePath(execPath, arguments[0]);
      execv(merged, arguments);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x660,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe00(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x618(%rbp)
mov    $0x28,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x638(%rbp)
movl   $0x5,-0x63c(%rbp)
movl   $0x0,-0x640(%rbp)
mov    $0x28,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x648(%rbp)
movl   $0x0,-0x64c(%rbp)
movl   $0x5,-0x650(%rbp)
mov    -0x618(%rbp),%rdi
lea    0xda1(%rip),%rsi
call   10d0 <strtok@plt>
mov    %rax,-0x628(%rbp)
mov    -0x64c(%rbp),%eax
mov    -0x650(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jl     12b6 <main+0xd6>
mov    -0x650(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x650(%rbp)
mov    -0x648(%rbp),%rdi
movslq -0x650(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%esi
call   10c0 <realloc@plt>
mov    %rax,-0x648(%rbp)
mov    -0x628(%rbp),%rdx
mov    -0x648(%rbp),%rax
movslq -0x64c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x64c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64c(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xd1c(%rip),%rsi
call   10d0 <strtok@plt>
mov    %rax,-0x628(%rbp)
cmp    $0x0,%rax
jne    1270 <main+0x90>
jmp    1304 <main+0x124>
movl   $0x0,-0x640(%rbp)
movq   $0x0,-0x620(%rbp)
lea    -0x610(%rbp),%rdi
mov    $0x400,%esi
call   1080 <getcwd@plt>
movl   $0x0,-0x654(%rbp)
mov    -0x654(%rbp),%eax
cmp    -0x63c(%rbp),%eax
jge    1370 <main+0x190>
mov    -0x638(%rbp),%rax
movslq -0x654(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x654(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x654(%rbp)
jmp    1334 <main+0x154>
lea    0xc90(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x210(%rbp),%rdi
mov    0x2c5c(%rip),%rax
mov    (%rax),%edx
mov    $0x1f4,%esi
call   1090 <fgets@plt>
lea    -0x210(%rbp),%rdi
lea    0xc6a(%rip),%rsi
call   10d0 <strtok@plt>
mov    %rax,-0x628(%rbp)
cmpq   $0x0,-0x628(%rbp)
je     1406 <main+0x226>
mov    -0x640(%rbp),%eax
mov    -0x63c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jl     1406 <main+0x226>
mov    -0x63c(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x63c(%rbp)
mov    -0x638(%rbp),%rdi
movslq -0x63c(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%esi
call   10c0 <realloc@plt>
mov    %rax,-0x638(%rbp)
mov    -0x628(%rbp),%rdx
mov    -0x638(%rbp),%rax
movslq -0x640(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x640(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x640(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xbd7(%rip),%rsi
call   10d0 <strtok@plt>
mov    %rax,-0x628(%rbp)
cmp    $0x0,%rax
jne    13b2 <main+0x1d2>
mov    -0x638(%rbp),%rax
mov    (%rax),%rdi
lea    0xbb4(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    1480 <main+0x2a0>
mov    -0x638(%rbp),%rdi
call   1040 <free@plt>
jmp    1605 <main+0x425>
movl   $0x0,-0x658(%rbp)
mov    -0x658(%rbp),%eax
cmp    -0x64c(%rbp),%eax
jge    14f9 <main+0x319>
mov    -0x648(%rbp),%rax
movslq -0x658(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x638(%rbp),%rax
mov    (%rax),%rsi
call   1070 <checkPath@plt>
cmp    $0x0,%rax
je     14e0 <main+0x300>
mov    -0x648(%rbp),%rax
movslq -0x658(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x620(%rbp)
jmp    14e5 <main+0x305>
mov    -0x658(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x658(%rbp)
jmp    148a <main+0x2aa>
cmpq   $0x0,-0x620(%rbp)
jne    1535 <main+0x355>
lea    -0x610(%rbp),%rdi
mov    -0x638(%rbp),%rax
mov    (%rax),%rsi
call   1070 <checkPath@plt>
cmp    $0x0,%rax
je     1535 <main+0x355>
lea    -0x610(%rbp),%rax
mov    %rax,-0x620(%rbp)
cmpq   $0x0,-0x620(%rbp)
jne    1560 <main+0x380>
mov    -0x638(%rbp),%rax
mov    (%rax),%rsi
lea    0xac5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1304 <main+0x124>
mov    $0x0,%al
call   1100 <fork@plt>
mov    %eax,-0x62c(%rbp)
cmpl   $0x0,-0x62c(%rbp)
je     1588 <main+0x3a8>
xor    %eax,%eax
mov    %eax,%edi
call   10e0 <wait@plt>
jmp    1600 <main+0x420>
mov    -0x638(%rbp),%rax
mov    -0x640(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xa8c(%rip),%rdi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    15d0 <main+0x3f0>
mov    -0x638(%rbp),%rax
mov    -0x640(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x620(%rbp),%rdi
mov    -0x638(%rbp),%rax
mov    (%rax),%rsi
call   1050 <mergePath@plt>
mov    %rax,-0x660(%rbp)
mov    -0x660(%rbp),%rdi
mov    -0x638(%rbp),%rsi
call   10f0 <execv@plt>
jmp    1304 <main+0x124>
xor    %eax,%eax
add    $0x660,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x618,%rsp
lea    0xdf8(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
mov    $0x28,%edi
call   10c0 <malloc@plt>
mov    %rax,%r13
mov    $0x28,%edi
call   10c0 <malloc@plt>
mov    %rax,(%rsp)
lea    0xdd3(%rip),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   10e0 <strtok@plt>
mov    %rax,%rbp
mov    $0x5,%r12d
xor    %ebx,%ebx
jmp    1285 <main+0x95>
nopw   0x0(%rax,%rax,1)
lea    (%r12,%r12,1),%r15d
shl    $0x4,%r12d
mov    (%rsp),%rdi
mov    %r12d,%esi
call   10d0 <realloc@plt>
mov    %r15d,%r12d
mov    %rax,(%rsp)
mov    %rbp,(%rax,%rbx,8)
add    $0x1,%rbx
xor    %edi,%edi
mov    %r14,%rsi
call   10e0 <strtok@plt>
mov    %rax,%rbp
test   %rax,%rax
je     1297 <main+0xa7>
lea    -0x1(%r12),%eax
cltq
cmp    %rax,%rbx
jge    1250 <main+0x60>
mov    (%rsp),%rax
jmp    1267 <main+0x77>
mov    %ebx,%eax
mov    %rax,0x8(%rsp)
mov    $0x5,%r14d
lea    0xd65(%rip),%r15
mov    (%rsp),%rbp
jmp    12ce <main+0xde>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %edi,%edi
call   10f0 <wait@plt>
lea    0xd42(%rip),%r15
lea    0x210(%rsp),%rdi
mov    $0x400,%esi
call   1090 <getcwd@plt>
test   %r14d,%r14d
jle    12f6 <main+0x106>
mov    %r14d,%edx
shl    $0x3,%rdx
mov    %r13,%rdi
xor    %esi,%esi
call   1080 <memset@plt>
lea    0xd0a(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2cdd(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1f4,%esi
call   10a0 <fgets@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   10e0 <strtok@plt>
mov    %rax,%rbx
xor    %r12d,%r12d
jmp    135b <main+0x16b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,0x0(%r13,%r12,8)
add    $0x1,%r12
xor    %edi,%edi
mov    %r15,%rsi
call   10e0 <strtok@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1390 <main+0x1a0>
test   %rbx,%rbx
je     1340 <main+0x150>
lea    -0x1(%r14),%eax
cltq
cmp    %rax,%r12
jl     1340 <main+0x150>
lea    (%r14,%r14,1),%ebp
shl    $0x4,%r14d
mov    %r13,%rdi
mov    %r14d,%esi
call   10d0 <realloc@plt>
mov    %rax,%r13
mov    %ebp,%r14d
mov    (%rsp),%rbp
jmp    1340 <main+0x150>
nopw   0x0(%rax,%rax,1)
mov    0x0(%r13),%rdi
lea    0xc79(%rip),%rsi
call   10b0 <strcmp@plt>
test   %rax,%rax
je     147d <main+0x28d>
add    $0xffffffff,%r12d
xor    %ebx,%ebx
xor    %r15d,%r15d
jmp    13cb <main+0x1db>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%rbx
cmp    %rbx,0x8(%rsp)
je     13f0 <main+0x200>
mov    0x0(%rbp,%rbx,8),%rdi
mov    0x0(%r13),%rsi
call   1070 <checkPath@plt>
test   %rax,%rax
je     13c0 <main+0x1d0>
mov    0x0(%rbp,%rbx,8),%r15
jmp    13c0 <main+0x1d0>
cs nopw 0x0(%rax,%rax,1)
nop
test   %r15,%r15
jne    140e <main+0x21e>
mov    0x0(%r13),%rsi
lea    0x210(%rsp),%r15
mov    %r15,%rdi
call   1070 <checkPath@plt>
test   %rax,%rax
je     145f <main+0x26f>
xor    %eax,%eax
call   1110 <fork@plt>
test   %eax,%eax
jne    12c0 <main+0xd0>
mov    0x0(%r13,%r12,8),%rsi
lea    0xc09(%rip),%rdi
call   10b0 <strcmp@plt>
test   %rax,%rax
jne    143c <main+0x24c>
movq   $0x0,0x0(%r13,%r12,8)
mov    0x0(%r13),%rsi
mov    %r15,%rdi
call   1050 <mergePath@plt>
mov    %rax,%rdi
mov    %r13,%rsi
call   1100 <execv@plt>
lea    0xbb6(%rip),%r15
jmp    12ce <main+0xde>
mov    0x0(%r13),%rsi
lea    0xbaf(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xb98(%rip),%r15
jmp    12ce <main+0xde>
mov    %r13,%rdi
call   1040 <free@plt>
xor    %eax,%eax
add    $0x618,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"PATH\00"
@.str.1 = [2 x i8] c":\00"
@.str.2 = [9 x i8] c"esh/:-> \00"
@stdin = global i32 0
@.str.3 = [4 x i8] c" \0A\0D\00"
@.str.4 = [5 x i8] c"exit\00"
@.str.5 = [25 x i8] c"Command `%s' not found.\0A\00"
@.str.6 = [2 x i8] c"&\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [500 x i8]
%7 = alloca [1024 x i8]
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i8**
%13 = alloca i32
%14 = alloca i32
%15 = alloca i8**
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%21 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %21, i8** %8
%22 = call i8** @malloc(i32 40)
store i8** %22, i8*** %12
store i32 5, i32* %13
store i32 0, i32* %14
%23 = call i8** @malloc(i32 40)
store i8** %23, i8*** %15
store i32 0, i32* %16
store i32 5, i32* %17
%24 = load i8*, i8** %8
%25 = call i8* @strtok(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %25, i8** %10
br label %26
26: ; preds = %48, %2
%27 = load i32, i32* %16
%28 = load i32, i32* %17
%29 = sub nsw i32 %28, 1
%30 = icmp sge i32 %27, %29
br i1 %30, label %31, label %40
31: ; preds = %26
%32 = load i32, i32* %17
%33 = mul nsw i32 %32, 2
store i32 %33, i32* %17
%34 = load i8**, i8*** %15
%35 = load i32, i32* %17
%36 = sext i32 %35 to i64
%37 = mul i64 8, %36
%38 = trunc i64 %37 to i32
%39 = call i8** @realloc(i8** %34, i32 %38)
store i8** %39, i8*** %15
br label %40
40: ; preds = %31, %26
%41 = load i8*, i8** %10
%42 = load i8**, i8*** %15
%43 = load i32, i32* %16
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8*, i8** %42, i64 %44
store i8* %41, i8** %45
%46 = load i32, i32* %16
%47 = add nsw i32 %46, 1
store i32 %47, i32* %16
br label %48
48: ; preds = %40
%49 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %49, i8** %10
%50 = icmp ne i8* %49, null
br i1 %50, label %26, label %51
51: ; preds = %48
br label %52
52: ; preds = %51, %152, %187
store i32 0, i32* %14
store i8* null, i8** %9
%53 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%54 = call i32 @getcwd(i8* %53, i32 1024)
store i32 0, i32* %18
br label %55
55: ; preds = %64, %52
%56 = load i32, i32* %18
%57 = load i32, i32* %13
%58 = icmp slt i32 %56, %57
br i1 %58, label %59, label %67
59: ; preds = %55
%60 = load i8**, i8*** %12
%61 = load i32, i32* %18
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8*, i8** %60, i64 %62
store i8* null, i8** %63
br label %64
64: ; preds = %59
%65 = load i32, i32* %18
%66 = add nsw i32 %65, 1
store i32 %66, i32* %18
br label %55
67: ; preds = %55
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%69 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 0
%70 = load i32, i32* @stdin
%71 = call i32 @fgets(i8* %69, i32 500, i32 %70)
%72 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 0
%73 = call i8* @strtok(i8* %72, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
store i8* %73, i8** %10
br label %74
74: ; preds = %99, %67
%75 = load i8*, i8** %10
%76 = icmp ne i8* %75, null
br i1 %76, label %77, label %91
77: ; preds = %74
%78 = load i32, i32* %14
%79 = load i32, i32* %13
%80 = sub nsw i32 %79, 1
%81 = icmp sge i32 %78, %80
br i1 %81, label %82, label %91
82: ; preds = %77
%83 = load i32, i32* %13
%84 = mul nsw i32 %83, 2
store i32 %84, i32* %13
%85 = load i8**, i8*** %12
%86 = load i32, i32* %13
%87 = sext i32 %86 to i64
%88 = mul i64 %87, 8
%89 = trunc i64 %88 to i32
%90 = call i8** @realloc(i8** %85, i32 %89)
store i8** %90, i8*** %12
br label %91
91: ; preds = %82, %77, %74
%92 = load i8*, i8** %10
%93 = load i8**, i8*** %12
%94 = load i32, i32* %14
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds i8*, i8** %93, i64 %95
store i8* %92, i8** %96
%97 = load i32, i32* %14
%98 = add nsw i32 %97, 1
store i32 %98, i32* %14
br label %99
99: ; preds = %91
%100 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
store i8* %100, i8** %10
%101 = icmp ne i8* %100, null
br i1 %101, label %74, label %102
102: ; preds = %99
%103 = load i8**, i8*** %12
%104 = getelementptr inbounds i8*, i8** %103, i64 0
%105 = load i8*, i8** %104
%106 = call i64 @strcmp(i8* %105, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%107 = icmp ne i64 %106, 0
br i1 %107, label %111, label %108
108: ; preds = %102
%109 = load i8**, i8*** %12
%110 = call i32 @free(i8** %109)
br label %188
111: ; preds = %102
store i32 0, i32* %19
br label %112
112: ; preds = %134, %111
%113 = load i32, i32* %19
%114 = load i32, i32* %16
%115 = icmp slt i32 %113, %114
br i1 %115, label %116, label %137
116: ; preds = %112
%117 = load i8**, i8*** %15
%118 = load i32, i32* %19
%119 = sext i32 %118 to i64
%120 = getelementptr inbounds i8*, i8** %117, i64 %119
%121 = load i8*, i8** %120
%122 = load i8**, i8*** %12
%123 = getelementptr inbounds i8*, i8** %122, i64 0
%124 = load i8*, i8** %123
%125 = call i64 @checkPath(i8* %121, i8* %124)
%126 = icmp ne i64 %125, 0
br i1 %126, label %127, label %133
127: ; preds = %116
%128 = load i8**, i8*** %15
%129 = load i32, i32* %19
%130 = sext i32 %129 to i64
%131 = getelementptr inbounds i8*, i8** %128, i64 %130
%132 = load i8*, i8** %131
store i8* %132, i8** %9
br label %133
133: ; preds = %127, %116
br label %134
134: ; preds = %133
%135 = load i32, i32* %19
%136 = add nsw i32 %135, 1
store i32 %136, i32* %19
br label %112
137: ; preds = %112
%138 = load i8*, i8** %9
%139 = icmp ne i8* %138, null
br i1 %139, label %149, label %140
140: ; preds = %137
%141 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%142 = load i8**, i8*** %12
%143 = getelementptr inbounds i8*, i8** %142, i64 0
%144 = load i8*, i8** %143
%145 = call i64 @checkPath(i8* %141, i8* %144)
%146 = icmp ne i64 %145, 0
br i1 %146, label %147, label %149
147: ; preds = %140
%148 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
store i8* %148, i8** %9
br label %149
149: ; preds = %147, %140, %137
%150 = load i8*, i8** %9
%151 = icmp ne i8* %150, null
br i1 %151, label %157, label %152
152: ; preds = %149
%153 = load i8**, i8*** %12
%154 = getelementptr inbounds i8*, i8** %153, i64 0
%155 = load i8*, i8** %154
%156 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i8* %155)
br label %52
157: ; preds = %149
%158 = call i32 (...) @fork()
store i32 %158, i32* %11
%159 = load i32, i32* %11
%160 = icmp ne i32 %159, 0
br i1 %160, label %161, label %163
161: ; preds = %157
%162 = call i32 @wait(i32* null)
br label %187
163: ; preds = %157
%164 = load i8**, i8*** %12
%165 = load i32, i32* %14
%166 = sub nsw i32 %165, 1
%167 = sext i32 %166 to i64
%168 = getelementptr inbounds i8*, i8** %164, i64 %167
%169 = load i8*, i8** %168
%170 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i8* %169)
%171 = icmp eq i64 %170, 0
br i1 %171, label %172, label %178
172: ; preds = %163
%173 = load i8**, i8*** %12
%174 = load i32, i32* %14
%175 = sub nsw i32 %174, 1
%176 = sext i32 %175 to i64
%177 = getelementptr inbounds i8*, i8** %173, i64 %176
store i8* null, i8** %177
br label %178
178: ; preds = %172, %163
%179 = load i8*, i8** %9
%180 = load i8**, i8*** %12
%181 = getelementptr inbounds i8*, i8** %180, i64 0
%182 = load i8*, i8** %181
%183 = call i8* @mergePath(i8* %179, i8* %182)
store i8* %183, i8** %20
%184 = load i8*, i8** %20
%185 = load i8**, i8*** %12
%186 = call i32 @execv(i8* %184, i8** %185)
br label %187
187: ; preds = %178, %161
br label %52
188: ; preds = %108
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"PATH\00"
@.str.1 = [2 x i8] c":\00"
@.str.2 = [9 x i8] c"esh/:-> \00"
@stdin = global i32 0
@.str.3 = [4 x i8] c" \0A\0D\00"
@.str.4 = [5 x i8] c"exit\00"
@.str.5 = [25 x i8] c"Command `%s' not found.\0A\00"
@.str.6 = [2 x i8] c"&\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [500 x i8]
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [500 x i8], [500 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = tail call i8** @malloc(i32 40)
%9 = tail call i8** @malloc(i32 40)
%10 = tail call i8* @strtok(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %23, %2
%12 = phi i64 [ %27, %23 ], [ 0, %2 ]
%13 = phi i8* [ %28, %23 ], [ %10, %2 ]
%14 = phi i8** [ %24, %23 ], [ %9, %2 ]
%15 = phi i32 [ %25, %23 ], [ 5, %2 ]
%16 = add nsw i32 %15, -1
%17 = sext i32 %16 to i64
%18 = icmp slt i64 %12, %17
br i1 %18, label %23, label %19
19: ; preds = %11
%20 = shl nsw i32 %15, 1
%21 = shl i32 %15, 4
%22 = tail call i8** @realloc(i8** %14, i32 %21)
br label %23
23: ; preds = %19, %11
%24 = phi i8** [ %22, %19 ], [ %14, %11 ]
%25 = phi i32 [ %20, %19 ], [ %15, %11 ]
%26 = getelementptr inbounds i8*, i8** %24, i64 %12
store i8* %13, i8** %26
%27 = add nuw i64 %12, 1
%28 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %11
30: ; preds = %23
%31 = add i64 %12, 1
%32 = and i64 %31, 4294967295
br label %33
33: ; preds = %105, %30
%34 = phi i8** [ %8, %30 ], [ %62, %105 ]
%35 = phi i32 [ 5, %30 ], [ %63, %105 ]
%36 = call i32 @getcwd(i8* %6, i32 1024)
%37 = icmp sgt i32 %35, 0
br i1 %37, label %38, label %42
38: ; preds = %33
%39 = bitcast i8** %34 to i8*
%40 = zext i32 %35 to i64
%41 = shl nuw nsw i64 %40, 3
br label %42
42: ; preds = %38, %33
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%44 = load i32, i32* @stdin
%45 = call i32 @fgets(i8* %5, i32 500, i32 %44)
%46 = call i8* @strtok(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %47
47: ; preds = %61, %42
%48 = phi i64 [ %65, %61 ], [ 0, %42 ]
%49 = phi i8* [ %66, %61 ], [ %46, %42 ]
%50 = phi i8** [ %62, %61 ], [ %34, %42 ]
%51 = phi i32 [ %63, %61 ], [ %35, %42 ]
%52 = icmp eq i8* %49, null
%53 = add nsw i32 %51, -1
%54 = sext i32 %53 to i64
%55 = icmp slt i64 %48, %54
%56 = select i1 %52, i1 true, i1 %55
br i1 %56, label %61, label %57
57: ; preds = %47
%58 = shl nsw i32 %51, 1
%59 = shl i32 %51, 4
%60 = call i8** @realloc(i8** %50, i32 %59)
br label %61
61: ; preds = %57, %47
%62 = phi i8** [ %60, %57 ], [ %50, %47 ]
%63 = phi i32 [ %58, %57 ], [ %51, %47 ]
%64 = getelementptr inbounds i8*, i8** %62, i64 %48
store i8* %49, i8** %64
%65 = add nuw i64 %48, 1
%66 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%67 = icmp eq i8* %66, null
br i1 %67, label %68, label %47
68: ; preds = %61
%69 = and i64 %48, 4294967295
%70 = getelementptr inbounds i8*, i8** %62, i64 %69
%71 = load i8*, i8** %62
%72 = call i64 @strcmp(i8* %71, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%73 = icmp eq i64 %72, 0
br i1 %73, label %74, label %78
74: ; preds = %68
%75 = call i32 @free(i8** %62)
ret i32 0
76: ; preds = %88
%77 = icmp eq i8* %89, null
br i1 %77, label %92, label %99
78: ; preds = %68, %88
%79 = phi i64 [ %90, %88 ], [ 0, %68 ]
%80 = phi i8* [ %89, %88 ], [ null, %68 ]
%81 = getelementptr inbounds i8*, i8** %24, i64 %79
%82 = load i8*, i8** %81
%83 = load i8*, i8** %62
%84 = call i64 @checkPath(i8* %82, i8* %83)
%85 = icmp eq i64 %84, 0
br i1 %85, label %88, label %86
86: ; preds = %78
%87 = load i8*, i8** %81
br label %88
88: ; preds = %78, %86
%89 = phi i8* [ %87, %86 ], [ %80, %78 ]
%90 = add nuw nsw i64 %79, 1
%91 = icmp eq i64 %90, %32
br i1 %91, label %76, label %78
92: ; preds = %76
%93 = load i8*, i8** %62
%94 = call i64 @checkPath(i8* %6, i8* %93)
%95 = icmp eq i64 %94, 0
br i1 %95, label %96, label %99
96: ; preds = %92
%97 = load i8*, i8** %62
%98 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i8* %97)
br label %105
99: ; preds = %76, %92
%100 = phi i8* [ %6, %92 ], [ %89, %76 ]
%101 = call i32 (...) @fork()
%102 = icmp eq i32 %101, 0
br i1 %102, label %106, label %103
103: ; preds = %99
%104 = call i32 @wait(i32* null)
br label %105
105: ; preds = %103, %111, %96
br label %33
106: ; preds = %99
%107 = load i8*, i8** %70
%108 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i8* %107)
%109 = icmp eq i64 %108, 0
br i1 %109, label %110, label %111
110: ; preds = %106
store i8* null, i8** %70
br label %111
111: ; preds = %110, %106
%112 = load i8*, i8** %62
%113 = call i8* @mergePath(i8* %100, i8* %112)
%114 = call i32 @execv(i8* %113, i8** %62)
br label %105
}