#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 int /*<<< orphan*/ buf;

/* Variables and functions */
scalar_t__ chdir(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork1();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ getcmd(char *, int);
int /*<<< orphan*/ parsecmd(char *);
int /*<<< orphan*/ runcmd(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int strlen(char *);
int /*<<< orphan*/ wait(int *);
int main(void) {
  static char buf[100];
  int fd, r;
  while (getcmd(buf, sizeof(buf)) >= 0) {
    if (*buf == '#')
      break;
    if (buf[0] == 'c' && buf[1] == 'd' && buf[2] == ' ') {
      buf[strlen(buf) - 1] = 0;
      if (chdir(buf + 3) < 0)
        fprintf(stderr, "cannot cd %s\n", buf + 3);
      continue;
    }
    if (fork1() == 0)
      runcmd(parsecmd(buf));
    wait(&r);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0x2eda(%rip),%rdi
mov    $0x64,%esi
call   1030 <getcmd@plt>
cmp    $0x0,%rax
jl     128d <main+0xfd>
movsbl 0x2ebf(%rip),%eax
cmp    $0x23,%eax
jne    11cf <main+0x3f>
jmp    128d <main+0xfd>
movsbl 0x2eaa(%rip),%eax
cmp    $0x63,%eax
jne    125b <main+0xcb>
movsbl 0x2e9b(%rip),%eax
cmp    $0x64,%eax
jne    125b <main+0xcb>
movsbl 0x2e8c(%rip),%eax
cmp    $0x20,%eax
jne    125b <main+0xcb>
lea    0x2e7a(%rip),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
movslq %eax,%rcx
lea    0x2e68(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2e5d(%rip),%rdi
add    $0x3,%rdi
call   1060 <chdir@plt>
cmp    $0x0,%rax
jge    1256 <main+0xc6>
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
lea    0xdba(%rip),%rsi
lea    0x2e33(%rip),%rdx
add    $0x3,%rdx
call   1070 <fprintf@plt>
jmp    119f <main+0xf>
mov    $0x0,%al
call   1080 <fork1@plt>
cmp    $0x0,%rax
jne    127f <main+0xef>
lea    0x2e0d(%rip),%rdi
call   1090 <parsecmd@plt>
mov    %eax,%edi
call   1050 <runcmd@plt>
lea    -0xc(%rbp),%rdi
call   10b0 <wait@plt>
jmp    119f <main+0xf>
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0x2edc(%rip),%rbx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1030 <getcmd@plt>
test   %rax,%rax
js     1284 <main+0xf4>
mov    0x2ec0(%rip),%al
cmp    $0x23,%al
je     1284 <main+0xf4>
lea    0x2eb4(%rip),%r14
mov    0x2e0a(%rip),%r13
lea    0xe23(%rip),%r15
lea    0xc(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    $0x63,%al
jne    1240 <main+0xb0>
cmpb   $0x64,0x2e86(%rip)
jne    1240 <main+0xb0>
cmpb   $0x20,0x2e7e(%rip)
jne    1240 <main+0xb0>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %r14,%rdi
call   1060 <chdir@plt>
test   %rax,%rax
jns    1263 <main+0xd3>
mov    0x0(%r13),%edi
mov    %r15,%rsi
mov    %r14,%rdx
call   1070 <fprintf@plt>
jmp    1263 <main+0xd3>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1080 <fork1@plt>
test   %rax,%rax
jne    125b <main+0xcb>
mov    %rbx,%rdi
call   1090 <parsecmd@plt>
mov    %eax,%edi
call   1050 <runcmd@plt>
mov    %r12,%rdi
call   10b0 <wait@plt>
mov    %rbx,%rdi
mov    $0x64,%esi
call   1030 <getcmd@plt>
test   %rax,%rax
js     1284 <main+0xf4>
movzbl 0x2e04(%rip),%eax
cmp    $0x23,%al
jne    11f0 <main+0x60>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@main.buf = internal global [100 x i8] zeroinitializer
@stderr = global i32 0
@.str = [14 x i8] c"cannot cd %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
br label %4
4: ; preds = %41, %34, %0
%5 = call i64 @getcmd(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @main.buf, i64 0, i64 0), i32 100)
%6 = icmp sge i64 %5, 0
br i1 %6, label %7, label %43
7: ; preds = %4
%8 = load i8, i8* getelementptr inbounds ([100 x i8], [100 x i8]* @main.buf, i64 0, i64 0)
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 35
br i1 %10, label %11, label %12
11: ; preds = %7
br label %43
12: ; preds = %7
%13 = load i8, i8* getelementptr inbounds ([100 x i8], [100 x i8]* @main.buf, i64 0, i64 0)
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 99
br i1 %15, label %16, label %35
16: ; preds = %12
%17 = load i8, i8* getelementptr inbounds ([100 x i8], [100 x i8]* @main.buf, i64 0, i64 1)
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 100
br i1 %19, label %20, label %35
20: ; preds = %16
%21 = load i8, i8* getelementptr inbounds ([100 x i8], [100 x i8]* @main.buf, i64 0, i64 2)
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 32
br i1 %23, label %24, label %35
24: ; preds = %20
%25 = call i32 @strlen(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @main.buf, i64 0, i64 0))
%26 = sub nsw i32 %25, 1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [100 x i8], [100 x i8]* @main.buf, i64 0, i64 %27
store i8 0, i8* %28
%29 = call i64 @chdir(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @main.buf, i64 0, i64 3))
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %24
%32 = load i32, i32* @stderr
%33 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([100 x i8], [100 x i8]* @main.buf, i64 0, i64 3))
br label %34
34: ; preds = %31, %24
br label %4
35: ; preds = %20, %16, %12
%36 = call i64 (...) @fork1()
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %35
%39 = call i32 @parsecmd(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @main.buf, i64 0, i64 0))
%40 = call i32 @runcmd(i32 %39)
br label %41
41: ; preds = %38, %35
%42 = call i32 @wait(i32* %3)
br label %4
43: ; preds = %11, %4
%44 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@main.buf = internal global [100 x i8] zeroinitializer
@stderr = global i32 0
@.str = [14 x i8] c"cannot cd %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i64 @getcmd(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @main.buf, i64 0, i64 0), i32 100)
%4 = icmp slt i64 %3, 0
%5 = load i8, i8* getelementptr inbounds ([100 x i8], [100 x i8]* @main.buf, i64 0, i64 0)
%6 = icmp eq i8 %5, 35
%7 = select i1 %4, i1 true, i1 %6
br i1 %7, label %41, label %8
8: ; preds = %0, %27
%9 = phi i8 [ %30, %27 ], [ %5, %0 ]
%10 = icmp eq i8 %9, 99
%11 = load i8, i8* getelementptr inbounds ([100 x i8], [100 x i8]* @main.buf, i64 0, i64 1)
%12 = icmp eq i8 %11, 100
%13 = select i1 %10, i1 %12, i1 false
%14 = load i8, i8* getelementptr inbounds ([100 x i8], [100 x i8]* @main.buf, i64 0, i64 2)
%15 = icmp eq i8 %14, 32
%16 = select i1 %13, i1 %15, i1 false
br i1 %16, label %17, label %33
17: ; preds = %8
%18 = call i32 @strlen(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @main.buf, i64 0, i64 0))
%19 = add nsw i32 %18, -1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [100 x i8], [100 x i8]* @main.buf, i64 0, i64 %20
store i8 0, i8* %21
%22 = call i64 @chdir(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @main.buf, i64 0, i64 3))
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %17
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([100 x i8], [100 x i8]* @main.buf, i64 0, i64 3))
br label %27
27: ; preds = %17, %24, %39
%28 = call i64 @getcmd(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @main.buf, i64 0, i64 0), i32 100)
%29 = icmp slt i64 %28, 0
%30 = load i8, i8* getelementptr inbounds ([100 x i8], [100 x i8]* @main.buf, i64 0, i64 0)
%31 = icmp eq i8 %30, 35
%32 = select i1 %29, i1 true, i1 %31
br i1 %32, label %41, label %8
33: ; preds = %8
%34 = call i64 (...) @fork1()
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %33
%37 = call i32 @parsecmd(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @main.buf, i64 0, i64 0))
%38 = call i32 @runcmd(i32 %37)
br label %39
39: ; preds = %36, %33
%40 = call i32 @wait(i32* %1)
br label %27
41: ; preds = %27, %0
%42 = call i32 @exit(i32 0)
unreachable
}