#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*/ add_history(char *);
scalar_t__ chdir(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
char *readline(char *);
scalar_t__ strncmp(char *, char *, int);
scalar_t__ system(char *);
int main(int ac, char *av[]) {
  char *p;
  int doit;
  doit = ac == 1;
  while ((p = readline("testit> ")) != NULL) {
    printf("\t\t\t|%s|\n", p);
    if (doit) {
      if (strncmp(p, "cd ", 3) == 0) {
        if (chdir(&p[3]) < 0) {
          perror(&p[3]);
        }
      } else if (system(p) != 0) {
        perror(p);
      }
    }
    add_history(p);
    free(p);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x1c(%rbp)
lea    0xe44(%rip),%rdi
call   1090 <readline@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     126e <main+0xde>
mov    -0x18(%rbp),%rsi
lea    0xe2f(%rip),%rdi
call   1080 <printf@plt>
cmpl   $0x0,-0x1c(%rbp)
je     1257 <main+0xc7>
mov    -0x18(%rbp),%rdi
lea    0xe1e(%rip),%rsi
mov    $0x3,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    1231 <main+0xa1>
mov    -0x18(%rbp),%rdi
add    $0x3,%rdi
call   1060 <chdir@plt>
cmp    $0x0,%rax
jge    122c <main+0x9c>
mov    -0x18(%rbp),%rdi
add    $0x3,%rdi
call   10a0 <perror@plt>
jmp    1252 <main+0xc2>
mov    -0x18(%rbp),%rdi
call   1070 <system@plt>
cmp    $0x0,%rax
je     124d <main+0xbd>
mov    -0x18(%rbp),%rdi
call   10a0 <perror@plt>
jmp    1252 <main+0xc2>
jmp    1257 <main+0xc7>
mov    -0x18(%rbp),%rdi
call   1050 <add_history@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
jmp    11b5 <main+0x25>
xor    %edi,%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r13d
lea    0xe5b(%rip),%rdi
call   1090 <readline@plt>
test   %rax,%rax
jne    11b6 <main+0x26>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    %rax,%rbx
lea    0xe49(%rip),%r14
lea    0xe4b(%rip),%r15
lea    0xe32(%rip),%r12
jmp    1210 <main+0x80>
lea    0x3(%rbx),%rbp
mov    %rbp,%rdi
call   1060 <chdir@plt>
test   %rax,%rax
js     1246 <main+0xb6>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <add_history@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1090 <readline@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11af <main+0x1f>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1080 <printf@plt>
cmp    $0x1,%r13d
jne    11f0 <main+0x60>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x3,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     11d0 <main+0x40>
mov    %rbx,%rdi
call   1070 <system@plt>
mov    %rbx,%rbp
test   %rax,%rax
je     11f0 <main+0x60>
mov    %rbp,%rdi
call   10a0 <perror@plt>
jmp    11f0 <main+0x60>

LLVM IR (-O0):
@.str = [9 x i8] c"testit> \00"
@.str.1 = [9 x i8] c"\09\09\09|%s|\0A\00"
@.str.2 = [4 x i8] c"cd \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 1
%10 = zext i1 %9 to i32
store i32 %10, i32* %7
br label %11
11: ; preds = %42, %2
%12 = call i8* @readline(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i8* %12, i8** %6
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %47
14: ; preds = %11
%15 = load i8*, i8** %6
%16 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = load i32, i32* %7
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %42
19: ; preds = %14
%20 = load i8*, i8** %6
%21 = call i64 @strncmp(i8* %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 3)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %33
23: ; preds = %19
%24 = load i8*, i8** %6
%25 = getelementptr inbounds i8, i8* %24, i64 3
%26 = call i64 @chdir(i8* %25)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %23
%29 = load i8*, i8** %6
%30 = getelementptr inbounds i8, i8* %29, i64 3
%31 = call i32 @perror(i8* %30)
br label %32
32: ; preds = %28, %23
br label %41
33: ; preds = %19
%34 = load i8*, i8** %6
%35 = call i64 @system(i8* %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %33
%38 = load i8*, i8** %6
%39 = call i32 @perror(i8* %38)
br label %40
40: ; preds = %37, %33
br label %41
41: ; preds = %40, %32
br label %42
42: ; preds = %41, %14
%43 = load i8*, i8** %6
%44 = call i32 @add_history(i8* %43)
%45 = load i8*, i8** %6
%46 = call i32 @free(i8* %45)
br label %11
47: ; preds = %11
%48 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [9 x i8] c"testit> \00"
@.str.1 = [9 x i8] c"\09\09\09|%s|\0A\00"
@.str.2 = [4 x i8] c"cd \00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = icmp eq i32 %0, 1
%4 = tail call i8* @readline(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %27, label %6
6: ; preds = %2, %22
%7 = phi i8* [ %25, %22 ], [ %4, %2 ]
%8 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %7)
br i1 %3, label %9, label %22
9: ; preds = %6
%10 = tail call i64 @strncmp(i8* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 3)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = getelementptr inbounds i8, i8* %7, i64 3
%14 = tail call i64 @chdir(i8* %13)
%15 = icmp slt i64 %14, 0
br i1 %15, label %19, label %22
16: ; preds = %9
%17 = tail call i64 @system(i8* %7)
%18 = icmp eq i64 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %16, %12
%20 = phi i8* [ %13, %12 ], [ %7, %16 ]
%21 = tail call i32 @perror(i8* %20)
br label %22
22: ; preds = %19, %12, %16, %6
%23 = tail call i32 @add_history(i8* %7)
%24 = tail call i32 @free(i8* %7)
%25 = tail call i8* @readline(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %6
27: ; preds = %22, %2
%28 = tail call i32 @exit(i32 0)
unreachable
}