#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[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     1278 <main+0xe8>
movsbl 0x2ebf(%rip),%eax
cmp    $0x63,%eax
jne    1246 <main+0xb6>
movsbl 0x2eb0(%rip),%eax
cmp    $0x64,%eax
jne    1246 <main+0xb6>
movsbl 0x2ea1(%rip),%eax
cmp    $0x20,%eax
jne    1246 <main+0xb6>
lea    0x2e8f(%rip),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
movslq %eax,%rcx
lea    0x2e7d(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2e72(%rip),%rdi
add    $0x3,%rdi
call   1060 <chdir@plt>
cmp    $0x0,%rax
jge    1241 <main+0xb1>
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
lea    0xdcf(%rip),%rsi
lea    0x2e48(%rip),%rdx
add    $0x3,%rdx
call   1070 <fprintf@plt>
jmp    119f <main+0xf>
mov    $0x0,%al
call   1080 <fork1@plt>
cmp    $0x0,%rax
jne    126a <main+0xda>
lea    0x2e22(%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     125f <main+0xcf>
lea    0x2ec2(%rip),%r14
mov    0x2e18(%rip),%r13
lea    0xe31(%rip),%r15
lea    0xc(%rsp),%r12
jmp    1206 <main+0x76>
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1080 <fork1@plt>
test   %rax,%rax
je     124e <main+0xbe>
mov    %r12,%rdi
call   10b0 <wait@plt>
mov    %rbx,%rdi
mov    $0x64,%esi
call   1030 <getcmd@plt>
test   %rax,%rax
js     125f <main+0xcf>
cmpb   $0x63,0x2e73(%rip)
jne    11e0 <main+0x50>
cmpb   $0x64,0x2e6b(%rip)
jne    11e0 <main+0x50>
cmpb   $0x20,0x2e63(%rip)
jne    11e0 <main+0x50>
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    11f4 <main+0x64>
mov    0x0(%r13),%edi
mov    %r15,%rsi
mov    %r14,%rdx
call   1070 <fprintf@plt>
jmp    11f4 <main+0x64>
mov    %rbx,%rdi
call   1090 <parsecmd@plt>
mov    %eax,%edi
call   1050 <runcmd@plt>
jmp    11ec <main+0x5c>
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 = %36, %29, %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 %38
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, 99
br i1 %10, label %11, label %30
11: ; preds = %7
%12 = load i8, i8* getelementptr inbounds ([100 x i8], [100 x i8]* @main.buf, i64 0, i64 1)
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 100
br i1 %14, label %15, label %30
15: ; preds = %11
%16 = load i8, i8* getelementptr inbounds ([100 x i8], [100 x i8]* @main.buf, i64 0, i64 2)
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 32
br i1 %18, label %19, label %30
19: ; preds = %15
%20 = call i32 @strlen(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @main.buf, i64 0, i64 0))
%21 = sub nsw i32 %20, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [100 x i8], [100 x i8]* @main.buf, i64 0, i64 %22
store i8 0, i8* %23
%24 = call i64 @chdir(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @main.buf, i64 0, i64 3))
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %19
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, 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 %29
29: ; preds = %26, %19
br label %4
30: ; preds = %15, %11, %7
%31 = call i64 (...) @fork1()
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = call i32 @parsecmd(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @main.buf, i64 0, i64 0))
%35 = call i32 @runcmd(i32 %34)
br label %36
36: ; preds = %33, %30
%37 = call i32 @wait(i32* %3)
br label %4
38: ; preds = %4
%39 = 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 sgt i64 %3, -1
br i1 %4, label %5, label %35
5: ; preds = %0, %24
%6 = load i8, i8* getelementptr inbounds ([100 x i8], [100 x i8]* @main.buf, i64 0, i64 0)
%7 = icmp eq i8 %6, 99
%8 = load i8, i8* getelementptr inbounds ([100 x i8], [100 x i8]* @main.buf, i64 0, i64 1)
%9 = icmp eq i8 %8, 100
%10 = select i1 %7, i1 %9, i1 false
%11 = load i8, i8* getelementptr inbounds ([100 x i8], [100 x i8]* @main.buf, i64 0, i64 2)
%12 = icmp eq i8 %11, 32
%13 = select i1 %10, i1 %12, i1 false
br i1 %13, label %14, label %27
14: ; preds = %5
%15 = call i32 @strlen(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @main.buf, i64 0, i64 0))
%16 = add nsw i32 %15, -1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [100 x i8], [100 x i8]* @main.buf, i64 0, i64 %17
store i8 0, i8* %18
%19 = call i64 @chdir(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @main.buf, i64 0, i64 3))
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %14
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, 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 %24
24: ; preds = %14, %21, %33
%25 = call i64 @getcmd(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @main.buf, i64 0, i64 0), i32 100)
%26 = icmp sgt i64 %25, -1
br i1 %26, label %5, label %35
27: ; preds = %5
%28 = call i64 (...) @fork1()
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %27
%31 = call i32 @parsecmd(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @main.buf, i64 0, i64 0))
%32 = call i32 @runcmd(i32 %31)
br label %33
33: ; preds = %30, %27
%34 = call i32 @wait(i32* %1)
br label %24
35: ; preds = %24, %0
%36 = call i32 @exit(i32 0)
unreachable
}