#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 *);
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 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, "diretorio não existe\n");
      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     126d <main+0xdd>
movsbl 0x2ebf(%rip),%eax
cmp    $0x63,%eax
jne    123b <main+0xab>
movsbl 0x2eb0(%rip),%eax
cmp    $0x64,%eax
jne    123b <main+0xab>
movsbl 0x2ea1(%rip),%eax
cmp    $0x20,%eax
jne    123b <main+0xab>
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    1236 <main+0xa6>
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
lea    0xdcf(%rip),%rsi
call   1070 <fprintf@plt>
jmp    119f <main+0xf>
mov    $0x0,%al
call   1080 <fork1@plt>
cmp    $0x0,%rax
jne    125f <main+0xcf>
lea    0x2e2d(%rip),%rdi
call   1090 <parsecmd@plt>
mov    %eax,%edi
call   1050 <runcmd@plt>
lea    -0x8(%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     125c <main+0xcc>
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     124b <main+0xbb>
mov    %r12,%rdi
call   10b0 <wait@plt>
mov    %rbx,%rdi
mov    $0x64,%esi
call   1030 <getcmd@plt>
test   %rax,%rax
js     125c <main+0xcc>
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
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 = [23 x i8] c"diretorio n\C3\A3o existe\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
br label %3
3: ; preds = %35, %28, %0
%4 = call i64 @getcmd(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @main.buf, i64 0, i64 0), i32 100)
%5 = icmp sge i64 %4, 0
br i1 %5, label %6, label %37
6: ; preds = %3
%7 = load i8, i8* getelementptr inbounds ([100 x i8], [100 x i8]* @main.buf, i64 0, i64 0)
%8 = sext i8 %7 to i32
%9 = icmp eq i32 %8, 99
br i1 %9, label %10, label %29
10: ; preds = %6
%11 = load i8, i8* getelementptr inbounds ([100 x i8], [100 x i8]* @main.buf, i64 0, i64 1)
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 100
br i1 %13, label %14, label %29
14: ; preds = %10
%15 = load i8, i8* getelementptr inbounds ([100 x i8], [100 x i8]* @main.buf, i64 0, i64 2)
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 32
br i1 %17, label %18, label %29
18: ; preds = %14
%19 = call i32 @strlen(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @main.buf, i64 0, i64 0))
%20 = sub nsw i32 %19, 1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [100 x i8], [100 x i8]* @main.buf, i64 0, i64 %21
store i8 0, i8* %22
%23 = call i64 @chdir(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @main.buf, i64 0, i64 3))
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %18
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %28
28: ; preds = %25, %18
br label %3
29: ; preds = %14, %10, %6
%30 = call i64 (...) @fork1()
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = call i32 @parsecmd(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @main.buf, i64 0, i64 0))
%34 = call i32 @runcmd(i32 %33)
br label %35
35: ; preds = %32, %29
%36 = call i32 @wait(i32* %2)
br label %3
37: ; preds = %3
%38 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@main.buf = internal global [100 x i8] zeroinitializer
@stderr = global i32 0
@.str = [23 x i8] c"diretorio n\C3\A3o existe\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 ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
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
}