#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 /*<<< orphan*/ chdir(char *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ strtok(char *, char *);
int /*<<< orphan*/ substr(char *, char *, int, int);
int /*<<< orphan*/ system(char *);
int main() {
  char cmdtmp[100];
  char cmd[100], path[100];
  printf("$ ");
  fgets(cmd, 100, stdin);
  while (strncmp(cmd, "quit", 4) != 0) {
    substr(cmdtmp, cmd, 0, 3);
    if (strncmp(cmdtmp, "cd", 2) == 0) {
      substr(path, cmd, 3, 0);
      strtok(path, "\n");
      chdir(path);
    } else if (strncmp(cmdtmp, "dir", 3) == 0) {
      substr(path, cmd, 3, 0);
      strcpy(cmdtmp, "ls");
      strcat(cmdtmp, path);
      system(cmdtmp);
    } else if (strncmp(cmdtmp, "md", 2) == 0) {
      substr(path, cmd, 3, 0);
      strcpy(cmdtmp, "mkdir ");
      strcat(cmdtmp, path);
      system(cmdtmp);
    } else if (strncmp(cmdtmp, "rd", 2) == 0) {
      substr(path, cmd, 3, 0);
      strcpy(cmdtmp, "rmdir ");
      strcat(cmdtmp, path);
      system(cmdtmp);
    } else {
      system(cmd);
    }
    printf("$ ");
    fgets(cmd, 100, stdin);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe57(%rip),%rdi
call   1080 <printf@plt>
lea    -0xe0(%rbp),%rdi
mov    0x2e2c(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1090 <fgets@plt>
lea    -0xe0(%rbp),%rdi
lea    0xe2d(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     13d9 <main+0x249>
lea    -0x70(%rbp),%rdi
lea    -0xe0(%rbp),%rsi
xor    %edx,%edx
mov    $0x3,%ecx
call   1070 <substr@plt>
lea    -0x70(%rbp),%rdi
lea    0xdfc(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    125e <main+0xce>
lea    -0x150(%rbp),%rdi
lea    -0xe0(%rbp),%rsi
mov    $0x3,%edx
xor    %ecx,%ecx
call   1070 <substr@plt>
lea    -0x150(%rbp),%rdi
lea    0xdc3(%rip),%rsi
call   10a0 <strtok@plt>
lea    -0x150(%rbp),%rdi
call   1050 <chdir@plt>
jmp    13ae <main+0x21e>
lea    -0x70(%rbp),%rdi
lea    0xda4(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    12c5 <main+0x135>
lea    -0x150(%rbp),%rdi
lea    -0xe0(%rbp),%rsi
mov    $0x3,%edx
xor    %ecx,%ecx
call   1070 <substr@plt>
lea    -0x70(%rbp),%rdi
lea    0xd6f(%rip),%rsi
call   1040 <strcpy@plt>
lea    -0x70(%rbp),%rdi
lea    -0x150(%rbp),%rsi
call   10b0 <strcat@plt>
lea    -0x70(%rbp),%rdi
call   1060 <system@plt>
jmp    13a9 <main+0x219>
lea    -0x70(%rbp),%rdi
lea    0xd44(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    132c <main+0x19c>
lea    -0x150(%rbp),%rdi
lea    -0xe0(%rbp),%rsi
mov    $0x3,%edx
xor    %ecx,%ecx
call   1070 <substr@plt>
lea    -0x70(%rbp),%rdi
lea    0xd0e(%rip),%rsi
call   1040 <strcpy@plt>
lea    -0x70(%rbp),%rdi
lea    -0x150(%rbp),%rsi
call   10b0 <strcat@plt>
lea    -0x70(%rbp),%rdi
call   1060 <system@plt>
jmp    13a4 <main+0x214>
lea    -0x70(%rbp),%rdi
lea    0xce7(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1393 <main+0x203>
lea    -0x150(%rbp),%rdi
lea    -0xe0(%rbp),%rsi
mov    $0x3,%edx
xor    %ecx,%ecx
call   1070 <substr@plt>
lea    -0x70(%rbp),%rdi
lea    0xcb1(%rip),%rsi
call   1040 <strcpy@plt>
lea    -0x70(%rbp),%rdi
lea    -0x150(%rbp),%rsi
call   10b0 <strcat@plt>
lea    -0x70(%rbp),%rdi
call   1060 <system@plt>
jmp    139f <main+0x20f>
lea    -0xe0(%rbp),%rdi
call   1060 <system@plt>
jmp    13a4 <main+0x214>
jmp    13a9 <main+0x219>
jmp    13ae <main+0x21e>
lea    0xc4b(%rip),%rdi
call   1080 <printf@plt>
lea    -0xe0(%rbp),%rdi
mov    0x2c20(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1090 <fgets@plt>
jmp    11c8 <main+0x38>
xor    %eax,%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x148,%rsp
lea    0xe58(%rip),%rdi
call   1080 <printf@plt>
mov    0x2e34(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1090 <fgets@plt>
lea    0xe36(%rip),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     136d <main+0x1dd>
lea    0xe0(%rsp),%rbx
mov    %rsp,%r14
lea    0xe13(%rip),%r15
lea    0x70(%rsp),%r12
lea    0xdff(%rip),%rbp
lea    0xdfb(%rip),%r13
jmp    1270 <main+0xe0>
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r14,%rsi
mov    $0x3,%edx
xor    %ecx,%ecx
call   1070 <substr@plt>
mov    %r12,%rdi
lea    0xddf(%rip),%rsi
call   10a0 <strtok@plt>
mov    %r12,%rdi
call   1050 <chdir@plt>
mov    %rbp,%rdi
call   1080 <printf@plt>
mov    0x2da0(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
mov    $0x64,%esi
call   1090 <fgets@plt>
mov    %r14,%rdi
mov    %r13,%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     136d <main+0x1dd>
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
mov    $0x3,%ecx
call   1070 <substr@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1210 <main+0x80>
mov    %rbx,%rdi
lea    0xd68(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     12f0 <main+0x160>
mov    %rbx,%rdi
lea    0xd56(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     130e <main+0x17e>
mov    %rbx,%rdi
lea    0xd47(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     132c <main+0x19c>
mov    %r14,%rdi
jmp    1363 <main+0x1d3>
xchg   %ax,%ax
mov    %r12,%rdi
mov    %r14,%rsi
mov    $0x3,%edx
xor    %ecx,%ecx
call   1070 <substr@plt>
mov    %rbx,%rdi
lea    0xd05(%rip),%rsi
jmp    1350 <main+0x1c0>
mov    %r12,%rdi
mov    %r14,%rsi
mov    $0x3,%edx
xor    %ecx,%ecx
call   1070 <substr@plt>
mov    %rbx,%rdi
lea    0xced(%rip),%rsi
jmp    1350 <main+0x1c0>
mov    %r12,%rdi
mov    %r14,%rsi
mov    $0x3,%edx
xor    %ecx,%ecx
call   1070 <substr@plt>
mov    %rbx,%rdi
lea    0xcd9(%rip),%rsi
nopl   0x0(%rax,%rax,1)
call   1040 <strcpy@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   10b0 <strcat@plt>
mov    %rbx,%rdi
call   1060 <system@plt>
jmp    1239 <main+0xa9>
xor    %eax,%eax
add    $0x148,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"$ \00"
@stdin = global i32 0
@.str.1 = [5 x i8] c"quit\00"
@.str.2 = [3 x i8] c"cd\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [4 x i8] c"dir\00"
@.str.5 = [3 x i8] c"ls\00"
@.str.6 = [3 x i8] c"md\00"
@.str.7 = [7 x i8] c"mkdir \00"
@.str.8 = [3 x i8] c"rd\00"
@.str.9 = [7 x i8] c"rmdir \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = alloca [100 x i8]
%4 = alloca [100 x i8]
store i32 0, i32* %1
%5 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%7 = load i32, i32* @stdin
%8 = call i32 @fgets(i8* %6, i32 100, i32 %7)
br label %9
9: ; preds = %79, %0
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%11 = call i64 @strncmp(i8* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %84
13: ; preds = %9
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%16 = call i32 @substr(i8* %14, i8* %15, i32 0, i32 3)
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%18 = call i64 @strncmp(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %28
20: ; preds = %13
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%23 = call i32 @substr(i8* %21, i8* %22, i32 3, i32 0)
%24 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%25 = call i32 @strtok(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%26 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%27 = call i32 @chdir(i8* %26)
br label %79
28: ; preds = %13
%29 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%30 = call i64 @strncmp(i8* %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 3)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %43
32: ; preds = %28
%33 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%34 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%35 = call i32 @substr(i8* %33, i8* %34, i32 3, i32 0)
%36 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%37 = call i32 @strcpy(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%38 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%39 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%40 = call i32 @strcat(i8* %38, i8* %39)
%41 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%42 = call i32 @system(i8* %41)
br label %78
43: ; preds = %28
%44 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%45 = call i64 @strncmp(i8* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 2)
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %58
47: ; preds = %43
%48 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%49 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%50 = call i32 @substr(i8* %48, i8* %49, i32 3, i32 0)
%51 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%52 = call i32 @strcpy(i8* %51, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%53 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%54 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%55 = call i32 @strcat(i8* %53, i8* %54)
%56 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%57 = call i32 @system(i8* %56)
br label %77
58: ; preds = %43
%59 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%60 = call i64 @strncmp(i8* %59, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32 2)
%61 = icmp eq i64 %60, 0
br i1 %61, label %62, label %73
62: ; preds = %58
%63 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%64 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%65 = call i32 @substr(i8* %63, i8* %64, i32 3, i32 0)
%66 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%67 = call i32 @strcpy(i8* %66, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0))
%68 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%69 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%70 = call i32 @strcat(i8* %68, i8* %69)
%71 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%72 = call i32 @system(i8* %71)
br label %76
73: ; preds = %58
%74 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%75 = call i32 @system(i8* %74)
br label %76
76: ; preds = %73, %62
br label %77
77: ; preds = %76, %47
br label %78
78: ; preds = %77, %32
br label %79
79: ; preds = %78, %20
%80 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%81 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%82 = load i32, i32* @stdin
%83 = call i32 @fgets(i8* %81, i32 100, i32 %82)
br label %9
84: ; preds = %9
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"$ \00"
@stdin = global i32 0
@.str.1 = [5 x i8] c"quit\00"
@.str.2 = [3 x i8] c"cd\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [4 x i8] c"dir\00"
@.str.5 = [3 x i8] c"ls\00"
@.str.6 = [3 x i8] c"md\00"
@.str.7 = [7 x i8] c"mkdir \00"
@.str.8 = [3 x i8] c"rd\00"
@.str.9 = [7 x i8] c"rmdir \00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = alloca [100 x i8]
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%7 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @stdin
%9 = call i32 @fgets(i8* %5, i32 100, i32 %8)
%10 = call i64 @strncmp(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%11 = icmp eq i64 %10, 0
br i1 %11, label %52, label %12
12: ; preds = %0, %46
%13 = call i32 @substr(i8* %4, i8* %5, i32 0, i32 3)
%14 = call i64 @strncmp(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %12
%17 = call i32 @substr(i8* %6, i8* %5, i32 3, i32 0)
%18 = call i32 @strtok(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%19 = call i32 @chdir(i8* %6)
br label %46
20: ; preds = %12
%21 = call i64 @strncmp(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 3)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %20
%24 = call i32 @substr(i8* %6, i8* %5, i32 3, i32 0)
%25 = call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%26 = call i32 @strcat(i8* %4, i8* %6)
%27 = call i32 @system(i8* %4)
br label %46
28: ; preds = %20
%29 = call i64 @strncmp(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 2)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %28
%32 = call i32 @substr(i8* %6, i8* %5, i32 3, i32 0)
%33 = call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%34 = call i32 @strcat(i8* %4, i8* %6)
%35 = call i32 @system(i8* %4)
br label %46
36: ; preds = %28
%37 = call i64 @strncmp(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32 2)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %44
39: ; preds = %36
%40 = call i32 @substr(i8* %6, i8* %5, i32 3, i32 0)
%41 = call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0))
%42 = call i32 @strcat(i8* %4, i8* %6)
%43 = call i32 @system(i8* %4)
br label %46
44: ; preds = %36
%45 = call i32 @system(i8* %5)
br label %46
46: ; preds = %23, %39, %44, %31, %16
%47 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%48 = load i32, i32* @stdin
%49 = call i32 @fgets(i8* %5, i32 100, i32 %48)
%50 = call i64 @strncmp(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %12
52: ; preds = %46, %0
ret i32 0
}