#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 */
struct timeval {
  int dummy;
};
struct rusage {
  int dummy;
};
typedef int /*<<< orphan*/ pid_t;

/* Variables and functions */
scalar_t__ chdir(char *);
scalar_t__ errno;
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
scalar_t__ strcmp(char *, char *);
char *strtok(char *, char *);
int main(int argc, char *argv[]) {
  char *cmd;
  char line[128];
  char *line2[32];
  pid_t pid;
  struct rusage usage;
  struct rusage parallelusage;
  struct timeval starttime;
  struct timeval endtime;
  long double systime = 0;
  long double usrtime = 0;
  int nivcsw = 0;
  int nvcsw = 0;
  int minflts = 0;
  int majflts = 0;
  int i;
  int nextflag = 0;
  int nextproc = 1;
  int wait3returnstatus;
  while (1) {
    printf("==>");
    fgets(line, 128, stdin);
    cmd = strtok(line, " \t\r\n");
    line2[0] = cmd;
    if (cmd == NULL) {
      continue;
    }
    for (i = 1; i < 32; i++) {
      char *arg2 = strtok(NULL, " \t\r\n");
      if (arg2 == NULL) {
        line2[i] = NULL;
        if (strcmp(line2[i - 1], "&") == 0) {
          nextflag = 1;
        }
        break;
      } else {
        line2[i] = arg2;
      }
    }
    errno = 0;
    if (strcmp(line2[0], "cd") == 0) {
      if (chdir(line2[1]) != 0)
        fprintf(stderr, "directory does not exist.\n");
      else
        chdir(line2[1]);
    } else if (strcmp(cmd, "exit") == 0) {
      break;
    } else if (nextflag == 0) {
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x210,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
fldz
fld    %st(0)
fstpt  -0x1d0(%rbp)
fstpt  -0x1e0(%rbp)
movl   $0x0,-0x1e4(%rbp)
movl   $0x0,-0x1e8(%rbp)
movl   $0x0,-0x1ec(%rbp)
movl   $0x0,-0x1f0(%rbp)
movl   $0x0,-0x1f8(%rbp)
movl   $0x1,-0x1fc(%rbp)
lea    0xe34(%rip),%rdi
call   1040 <printf@plt>
lea    -0xa0(%rbp),%rdi
mov    0x2e09(%rip),%rax
mov    (%rax),%edx
mov    $0x80,%esi
call   1050 <fgets@plt>
lea    -0xa0(%rbp),%rdi
lea    0xe0b(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x1a0(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    121d <main+0xbd>
jmp    11c5 <main+0x65>
movl   $0x1,-0x1f4(%rbp)
cmpl   $0x20,-0x1f4(%rbp)
jge    12d3 <main+0x173>
xor    %eax,%eax
mov    %eax,%edi
lea    0xdc5(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x208(%rbp)
cmpq   $0x0,-0x208(%rbp)
jne    12a4 <main+0x144>
movslq -0x1f4(%rbp),%rax
movq   $0x0,-0x1a0(%rbp,%rax,8)
mov    -0x1f4(%rbp),%eax
sub    $0x1,%eax
cltq
mov    -0x1a0(%rbp,%rax,8),%rdi
ff
lea    0xd83(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    129f <main+0x13f>
movl   $0x1,-0x1f8(%rbp)
jmp    12d3 <main+0x173>
mov    -0x208(%rbp),%rcx
movslq -0x1f4(%rbp),%rax
mov    %rcx,-0x1a0(%rbp,%rax,8)
ff
jmp    12bf <main+0x15f>
mov    -0x1f4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1f4(%rbp)
jmp    1227 <main+0xc7>
mov    0x2cf6(%rip),%rax
movq   $0x0,(%rax)
mov    -0x1a0(%rbp),%rdi
lea    0xd1c(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    133f <main+0x1df>
mov    -0x198(%rbp),%rdi
call   1030 <chdir@plt>
cmp    $0x0,%rax
je     132e <main+0x1ce>
mov    0x2cbd(%rip),%rax
mov    (%rax),%edi
lea    0xcea(%rip),%rsi
call   1070 <fprintf@plt>
jmp    133a <main+0x1da>
mov    -0x198(%rbp),%rdi
call   1030 <chdir@plt>
jmp    137a <main+0x21a>
mov    -0x18(%rbp),%rdi
lea    0xcdf(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    135e <main+0x1fe>
jmp    137f <main+0x21f>
cmpl   $0x0,-0x1f8(%rbp)
jne    1370 <main+0x210>
jmp    1370 <main+0x210>
jmp    1375 <main+0x215>
jmp    137a <main+0x21a>
jmp    11c5 <main+0x65>
xor    %eax,%eax
add    $0x210,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x188,%rsp
lea    0x100(%rsp),%r15
lea    0xe84(%rip),%rbx
movabs $0x100000000,%r13
jmp    11a8 <main+0x48>
nopl   0x0(%rax)
mov    %r12,%rdi
lea    0xe8f(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     129b <main+0x13b>
lea    0xe51(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
mov    $0x80,%esi
call   1050 <fgets@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1080 <strtok@plt>
test   %rax,%rax
je     11a8 <main+0x48>
mov    %rax,%r12
mov    %rax,(%rsp)
mov    $0x1,%r14d
xor    %ebp,%ebp
nopl   0x0(%rax)
xor    %edi,%edi
mov    %rbx,%rsi
call   1080 <strtok@plt>
test   %rax,%rax
je     1220 <main+0xc0>
mov    %rax,(%rsp,%r14,8)
add    $0x1,%r14
add    %r13,%rbp
cmp    $0x20,%r14
jne    11f0 <main+0x90>
jmp    123c <main+0xdc>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movq   $0x0,(%rsp,%r14,8)
sar    $0x1d,%rbp
mov    (%rsp,%rbp,1),%rdi
lea    0xdd2(%rip),%rsi
call   1060 <strcmp@plt>
mov    0x2d8d(%rip),%rax
movq   $0x0,(%rax)
mov    %r12,%rdi
lea    0xdb7(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    1190 <main+0x30>
mov    0x8(%rsp),%rbp
mov    %rbp,%rdi
call   1030 <chdir@plt>
test   %rax,%rax
je     128e <main+0x12e>
mov    0x2d5d(%rip),%rax
mov    (%rax),%edi
lea    0xd8a(%rip),%rsi
call   1070 <fprintf@plt>
jmp    11a8 <main+0x48>
mov    %rbp,%rdi
call   1030 <chdir@plt>
jmp    11a8 <main+0x48>
xor    %eax,%eax
add    $0x188,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.rusage = type { i32 }
%struct.timeval = type { i32 }
@.str = [4 x i8] c"==>\00"
@stdin = global i32 0
@.str.1 = [5 x i8] c" \09\0D\0A\00"
@.str.2 = [2 x i8] c"&\00"
@errno = global i64 0
@.str.3 = [3 x i8] c"cd\00"
@stderr = global i32 0
@.str.4 = [27 x i8] c"directory does not exist.\0A\00"
@.str.5 = [5 x i8] c"exit\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca [128 x i8]
%8 = alloca [32 x i8*]
%9 = alloca i32
%10 = alloca %struct.rusage
%11 = alloca %struct.rusage
%12 = alloca %struct.timeval
%13 = alloca %struct.timeval
%14 = alloca x86_fp80
%15 = alloca x86_fp80
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
%24 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store x86_fp80 0xK00000000000000000000, x86_fp80* %14
store x86_fp80 0xK00000000000000000000, x86_fp80* %15
store i32 0, i32* %16
store i32 0, i32* %17
store i32 0, i32* %18
store i32 0, i32* %19
store i32 0, i32* %21
store i32 1, i32* %22
br label %25
25: ; preds = %2, %36, %96
%26 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%27 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%28 = load i32, i32* @stdin
%29 = call i32 @fgets(i8* %27, i32 128, i32 %28)
%30 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%31 = call i8* @strtok(i8* %30, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i8* %31, i8** %6
%32 = load i8*, i8** %6
%33 = getelementptr inbounds [32 x i8*], [32 x i8*]* %8, i64 0, i64 0
store i8* %32, i8** %33
%34 = load i8*, i8** %6
%35 = icmp eq i8* %34, null
br i1 %35, label %36, label %37
36: ; preds = %25
br label %25
37: ; preds = %25
store i32 1, i32* %20
br label %38
38: ; preds = %64, %37
%39 = load i32, i32* %20
%40 = icmp slt i32 %39, 32
br i1 %40, label %41, label %67
41: ; preds = %38
%42 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i8* %42, i8** %24
%43 = load i8*, i8** %24
%44 = icmp eq i8* %43, null
br i1 %44, label %45, label %58
45: ; preds = %41
%46 = load i32, i32* %20
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [32 x i8*], [32 x i8*]* %8, i64 0, i64 %47
store i8* null, i8** %48
%49 = load i32, i32* %20
%50 = sub nsw i32 %49, 1
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [32 x i8*], [32 x i8*]* %8, i64 0, i64 %51
%53 = load i8*, i8** %52
%54 = call i64 @strcmp(i8* %53, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%55 = icmp eq i64 %54, 0
br i1 %55, label %56, label %57
56: ; preds = %45
store i32 1, i32* %21
br label %57
57: ; preds = %56, %45
br label %67
58: ; preds = %41
%59 = load i8*, i8** %24
%60 = load i32, i32* %20
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [32 x i8*], [32 x i8*]* %8, i64 0, i64 %61
store i8* %59, i8** %62
br label %63
63: ; preds = %58
br label %64
64: ; preds = %63
%65 = load i32, i32* %20
%66 = add nsw i32 %65, 1
store i32 %66, i32* %20
br label %38
67: ; preds = %57, %38
store i64 0, i64* @errno
%68 = getelementptr inbounds [32 x i8*], [32 x i8*]* %8, i64 0, i64 0
%69 = load i8*, i8** %68
%70 = call i64 @strcmp(i8* %69, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%71 = icmp eq i64 %70, 0
br i1 %71, label %72, label %85
72: ; preds = %67
%73 = getelementptr inbounds [32 x i8*], [32 x i8*]* %8, i64 0, i64 1
%74 = load i8*, i8** %73
%75 = call i64 @chdir(i8* %74)
%76 = icmp ne i64 %75, 0
br i1 %76, label %77, label %80
77: ; preds = %72
%78 = load i32, i32* @stderr
%79 = call i32 @fprintf(i32 %78, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
br label %84
80: ; preds = %72
%81 = getelementptr inbounds [32 x i8*], [32 x i8*]* %8, i64 0, i64 1
%82 = load i8*, i8** %81
%83 = call i64 @chdir(i8* %82)
br label %84
84: ; preds = %80, %77
br label %96
85: ; preds = %67
%86 = load i8*, i8** %6
%87 = call i64 @strcmp(i8* %86, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%88 = icmp eq i64 %87, 0
br i1 %88, label %89, label %90
89: ; preds = %85
br label %97
90: ; preds = %85
%91 = load i32, i32* %21
%92 = icmp eq i32 %91, 0
br i1 %92, label %93, label %94
93: ; preds = %90
br label %94
94: ; preds = %93, %90
br label %95
95: ; preds = %94
br label %96
96: ; preds = %95, %84
br label %25
97: ; preds = %89
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"==>\00"
@stdin = global i32 0
@.str.1 = [5 x i8] c" \09\0D\0A\00"
@.str.2 = [2 x i8] c"&\00"
@errno = global i64 0
@.str.3 = [3 x i8] c"cd\00"
@stderr = global i32 0
@.str.4 = [27 x i8] c"directory does not exist.\0A\00"
@.str.5 = [5 x i8] c"exit\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [128 x i8]
%4 = alloca [32 x i8*]
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%6 = bitcast [32 x i8*]* %4 to i8*
%7 = getelementptr inbounds [32 x i8*], [32 x i8*]* %4, i64 0, i64 0
%8 = getelementptr inbounds [32 x i8*], [32 x i8*]* %4, i64 0, i64 1
br label %9
9: ; preds = %15, %2
%10 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @stdin
%12 = call i32 @fgets(i8* %5, i32 128, i32 %11)
%13 = call i8* @strtok(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %16
15: ; preds = %9, %46, %41, %44
br label %9
16: ; preds = %9
store i8* %13, i8** %7
br label %17
17: ; preds = %16, %30
%18 = phi i64 [ 1, %16 ], [ %32, %30 ]
%19 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %30
21: ; preds = %17
%22 = and i64 %18, 4294967295
%23 = getelementptr inbounds [32 x i8*], [32 x i8*]* %4, i64 0, i64 %22
store i8* null, i8** %23
%24 = shl i64 %18, 32
%25 = add i64 %24, -4294967296
%26 = ashr exact i64 %25, 32
%27 = getelementptr inbounds [32 x i8*], [32 x i8*]* %4, i64 0, i64 %26
%28 = load i8*, i8** %27
%29 = call i64 @strcmp(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %34
30: ; preds = %17
%31 = getelementptr inbounds [32 x i8*], [32 x i8*]* %4, i64 0, i64 %18
store i8* %19, i8** %31
%32 = add nuw nsw i64 %18, 1
%33 = icmp eq i64 %32, 32
br i1 %33, label %34, label %17
34: ; preds = %30, %21
store i64 0, i64* @errno
%35 = call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %46
37: ; preds = %34
%38 = load i8*, i8** %8
%39 = call i64 @chdir(i8* %38)
%40 = icmp eq i64 %39, 0
br i1 %40, label %44, label %41
41: ; preds = %37
%42 = load i32, i32* @stderr
%43 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
br label %15
44: ; preds = %37
%45 = call i64 @chdir(i8* %38)
br label %15
46: ; preds = %34
%47 = call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %15
49: ; preds = %46
ret i32 0
}