#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*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int chdir(char *);
int /*<<< orphan*/ chkbuiltin(char **);
int dup(int /*<<< orphan*/);
int /*<<< orphan*/ dup2(int, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char *getenv(char *);
int /*<<< orphan*/ launchjob(char **, char *, char **, int, int, int, int);
int /*<<< orphan*/ log_update(char *, char **, int *);
char **logalloc();
int /*<<< orphan*/ memoryalloc(char ***, char **, char ***);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ tokenize(char **, char **, char *, int *, int *, int *,
                            int *);
int main(int argc, char **argv) {
  int inred, outred, save_in, save_out, append, n = 0, i, pipe_flag;
  char **arguments;
  char *line, **fname, **log;
  if (argc != 1) {
    if (chdir(argv[1]) == -1) {
      printf(
          "There is no such directory as %s, you will be redirected to home!\n",
          argv[1]);
      chdir(getenv("HOME"));
    }
  } else if (chdir(getenv("HOME")) == -1) {
    printf("ERROR setting the default path\n");
    exit(103);
  }
  memoryalloc(&arguments, &line, &fname);
  log = logalloc();
  save_in = dup(STDIN_FILENO);
  save_out = dup(STDOUT_FILENO);
  fprintf(stdout, "[%s]", getenv("USER"));
  while (fgets(line, 81 - 1, stdin) != NULL) {
    log_update(line, log, &n);
    tokenize(arguments, fname, line, &inred, &outred, &append, &pipe_flag);
    if (!chkbuiltin(arguments)) {
      launchjob(arguments, line, fname, inred, outred, append, pipe_flag);
    }
    dup2(save_in, STDIN_FILENO);
    dup2(save_out, STDOUT_FILENO);
    fprintf(stdout, "[%s]", getenv("USER"));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x1,-0x8(%rbp)
je     124c <main+0x6c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <chdir@plt>
cmp    $0xffffffff,%eax
jne    1247 <main+0x67>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xdd4(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe09(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
call   1040 <chdir@plt>
jmp    1286 <main+0xa6>
lea    0xdf0(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
call   1040 <chdir@plt>
cmp    $0xffffffff,%eax
jne    1281 <main+0xa1>
lea    0xdd8(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x67,%edi
call   10e0 <exit@plt>
jmp    1286 <main+0xa6>
lea    -0x38(%rbp),%rdi
lea    -0x40(%rbp),%rsi
lea    -0x48(%rbp),%rdx
call   1080 <memoryalloc@plt>
mov    $0x0,%al
call   1100 <logalloc@plt>
mov    %rax,-0x50(%rbp)
mov    0x2d1f(%rip),%rax
mov    (%rax),%edi
call   1070 <dup@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2d36(%rip),%rax
mov    (%rax),%edi
call   1070 <dup@plt>
mov    %eax,-0x20(%rbp)
mov    0x2d05(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
lea    0xd96(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x54(%rbp),%edi
mov    %rax,%rdx
lea    0xd7f(%rip),%rsi
call   10a0 <fprintf@plt>
mov    -0x40(%rbp),%rdi
mov    0x2ce7(%rip),%rax
mov    (%rax),%edx
mov    $0x50,%esi
call   1090 <fgets@plt>
cmp    $0x0,%rax
je     13ca <main+0x1ea>
mov    -0x40(%rbp),%rdi
mov    -0x50(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   10d0 <log_update@plt>
mov    -0x38(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x40(%rbp),%rdx
lea    -0x14(%rbp),%rcx
lea    -0x18(%rbp),%r8
lea    -0x24(%rbp),%r9
lea    -0x30(%rbp),%rax
mov    %rax,(%rsp)
call   10c0 <tokenize@plt>
mov    -0x38(%rbp),%rdi
call   10f0 <chkbuiltin@plt>
cmp    $0x0,%eax
jne    1379 <main+0x199>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x48(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
mov    -0x24(%rbp),%r9d
mov    -0x30(%rbp),%eax
mov    %eax,(%rsp)
call   10b0 <launchjob@plt>
mov    -0x1c(%rbp),%edi
mov    0x2c45(%rip),%rax
mov    (%rax),%esi
call   1050 <dup2@plt>
mov    -0x20(%rbp),%edi
mov    0x2c5c(%rip),%rax
mov    (%rax),%esi
call   1050 <dup2@plt>
mov    0x2c2e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x58(%rbp)
lea    0xcbf(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x58(%rbp),%edi
mov    %rax,%rdx
lea    0xca8(%rip),%rsi
call   10a0 <fprintf@plt>
jmp    12ee <main+0x10e>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
movl   $0x0,0x20(%rsp)
cmp    $0x1,%edi
jne    123a <main+0x4a>
lea    0xe31(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
call   1050 <chdir@plt>
cmp    $0xffffffff,%eax
jne    1271 <main+0x81>
lea    0xe27(%rip),%rdi
call   1040 <puts@plt>
mov    $0x67,%edi
call   10f0 <exit@plt>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1050 <chdir@plt>
cmp    $0xffffffff,%eax
jne    1271 <main+0x81>
mov    0x8(%rbx),%rsi
lea    0xdaa(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xddf(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
call   1050 <chdir@plt>
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
lea    0x30(%rsp),%rdx
call   1090 <memoryalloc@plt>
xor    %eax,%eax
call   1110 <logalloc@plt>
mov    %rax,%r14
mov    0x2d32(%rip),%rax
mov    (%rax),%edi
call   1080 <dup@plt>
mov    %eax,%ebp
mov    0x2d4a(%rip),%rax
mov    (%rax),%edi
call   1080 <dup@plt>
mov    %eax,%ebx
mov    0x2d1a(%rip),%rax
mov    (%rax),%r15d
lea    0xd8d(%rip),%rdi
call   1030 <getenv@plt>
lea    0xd7c(%rip),%rsi
mov    %r15d,%edi
mov    %rax,%rdx
call   10b0 <fprintf@plt>
mov    0x8(%rsp),%rdi
mov    0x2cfd(%rip),%rax
mov    (%rax),%edx
mov    $0x50,%esi
call   10a0 <fgets@plt>
test   %rax,%rax
je     13eb <main+0x1fb>
lea    0xd4e(%rip),%r12
lea    0xd42(%rip),%r13
jmp    136d <main+0x17d>
nopl   0x0(%rax,%rax,1)
mov    0x2cb1(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   1060 <dup2@plt>
mov    0x2cc9(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1060 <dup2@plt>
mov    0x2c99(%rip),%rax
mov    (%rax),%r15d
mov    %r12,%rdi
call   1030 <getenv@plt>
mov    %r15d,%edi
mov    %r13,%rsi
mov    %rax,%rdx
call   10b0 <fprintf@plt>
mov    0x8(%rsp),%rdi
mov    0x2c84(%rip),%rax
mov    (%rax),%edx
mov    $0x50,%esi
call   10a0 <fgets@plt>
test   %rax,%rax
je     13eb <main+0x1fb>
mov    0x8(%rsp),%rdi
mov    %r14,%rsi
lea    0x20(%rsp),%rdx
call   10e0 <log_update@plt>
mov    0x10(%rsp),%rdi
mov    0x30(%rsp),%rsi
mov    0x8(%rsp),%rdx
lea    0x1c(%rsp),%rax
mov    %rax,(%rsp)
lea    0x2c(%rsp),%rcx
lea    0x28(%rsp),%r8
lea    0x24(%rsp),%r9
call   10d0 <tokenize@plt>
mov    0x10(%rsp),%rdi
call   1100 <chkbuiltin@plt>
test   %eax,%eax
jne    1310 <main+0x120>
mov    0x10(%rsp),%rdi
mov    0x8(%rsp),%rsi
mov    0x30(%rsp),%rdx
mov    0x2c(%rsp),%ecx
mov    0x28(%rsp),%r8d
mov    0x24(%rsp),%r9d
mov    0x1c(%rsp),%eax
mov    %eax,(%rsp)
call   10c0 <launchjob@plt>
jmp    1310 <main+0x120>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [67 x i8] c"There is no such directory as %s, you will be redirected to home!\0A\00"
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [32 x i8] c"ERROR setting the default path\0A\00"
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@stdout = global i32 0
@.str.3 = [5 x i8] c"[%s]\00"
@.str.4 = [5 x i8] c"USER\00"
@stdin = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8**
%15 = alloca i8*
%16 = alloca i8**
%17 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %11
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 1
br i1 %19, label %20, label %34
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32 @chdir(i8* %23)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %33
26: ; preds = %20
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str, i64 0, i64 0), i8* %29)
%31 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%32 = call i32 @chdir(i8* %31)
br label %33
33: ; preds = %26, %20
br label %42
34: ; preds = %2
%35 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%36 = call i32 @chdir(i8* %35)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %41
38: ; preds = %34
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%40 = call i32 @exit(i32 103)
unreachable
41: ; preds = %34
br label %42
42: ; preds = %41, %33
%43 = call i32 @memoryalloc(i8*** %14, i8** %15, i8*** %16)
%44 = call i8** (...) @logalloc()
store i8** %44, i8*** %17
%45 = load i32, i32* @STDIN_FILENO
%46 = call i32 @dup(i32 %45)
store i32 %46, i32* %8
%47 = load i32, i32* @STDOUT_FILENO
%48 = call i32 @dup(i32 %47)
store i32 %48, i32* %9
%49 = load i32, i32* @stdout
%50 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%51 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %50)
br label %52
52: ; preds = %77, %42
%53 = load i8*, i8** %15
%54 = load i32, i32* @stdin
%55 = call i32* @fgets(i8* %53, i32 80, i32 %54)
%56 = icmp ne i32* %55, null
br i1 %56, label %57, label %87
57: ; preds = %52
%58 = load i8*, i8** %15
%59 = load i8**, i8*** %17
%60 = call i32 @log_update(i8* %58, i8** %59, i32* %11)
%61 = load i8**, i8*** %14
%62 = load i8**, i8*** %16
%63 = load i8*, i8** %15
%64 = call i32 @tokenize(i8** %61, i8** %62, i8* %63, i32* %6, i32* %7, i32* %10, i32* %13)
%65 = load i8**, i8*** %14
%66 = call i32 @chkbuiltin(i8** %65)
%67 = icmp ne i32 %66, 0
br i1 %67, label %77, label %68
68: ; preds = %57
%69 = load i8**, i8*** %14
%70 = load i8*, i8** %15
%71 = load i8**, i8*** %16
%72 = load i32, i32* %6
%73 = load i32, i32* %7
%74 = load i32, i32* %10
%75 = load i32, i32* %13
%76 = call i32 @launchjob(i8** %69, i8* %70, i8** %71, i32 %72, i32 %73, i32 %74, i32 %75)
br label %77
77: ; preds = %68, %57
%78 = load i32, i32* %8
%79 = load i32, i32* @STDIN_FILENO
%80 = call i32 @dup2(i32 %78, i32 %79)
%81 = load i32, i32* %9
%82 = load i32, i32* @STDOUT_FILENO
%83 = call i32 @dup2(i32 %81, i32 %82)
%84 = load i32, i32* @stdout
%85 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%86 = call i32 @fprintf(i32 %84, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %85)
br label %52
87: ; preds = %52
ret i32 0
}

LLVM IR (-O2):
@.str = [67 x i8] c"There is no such directory as %s, you will be redirected to home!\0A\00"
@.str.1 = [5 x i8] c"HOME\00"
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@stdout = global i32 0
@.str.3 = [5 x i8] c"[%s]\00"
@.str.4 = [5 x i8] c"USER\00"
@stdin = global i32 0
@str = [31 x i8] c"ERROR setting the default path\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8**
%9 = alloca i8*
%10 = alloca i8**
%11 = bitcast i32* %3 to i8*
%12 = bitcast i32* %4 to i8*
%13 = bitcast i32* %5 to i8*
%14 = bitcast i32* %6 to i8*
store i32 0, i32* %6
%15 = bitcast i32* %7 to i8*
%16 = bitcast i8*** %8 to i8*
%17 = bitcast i8** %9 to i8*
%18 = bitcast i8*** %10 to i8*
%19 = icmp eq i32 %0, 1
br i1 %19, label %30, label %20
20: ; preds = %2
%21 = getelementptr inbounds i8*, i8** %1, i64 1
%22 = load i8*, i8** %21
%23 = tail call i32 @chdir(i8* %22)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %37
25: ; preds = %20
%26 = load i8*, i8** %21
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([67 x i8], [67 x i8]* @.str, i64 0, i64 0), i8* %26)
%28 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%29 = tail call i32 @chdir(i8* %28)
br label %37
30: ; preds = %2
%31 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%32 = tail call i32 @chdir(i8* %31)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %37
34: ; preds = %30
%35 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%36 = tail call i32 @exit(i32 103)
unreachable
37: ; preds = %30, %20, %25
%38 = call i32 @memoryalloc(i8*** %8, i8** %9, i8*** %10)
%39 = call i8** (...) @logalloc()
%40 = load i32, i32* @STDIN_FILENO
%41 = call i32 @dup(i32 %40)
%42 = load i32, i32* @STDOUT_FILENO
%43 = call i32 @dup(i32 %42)
%44 = load i32, i32* @stdout
%45 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%46 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %45)
%47 = load i8*, i8** %9
%48 = load i32, i32* @stdin
%49 = call i32* @fgets(i8* %47, i32 80, i32 %48)
%50 = icmp eq i32* %49, null
br i1 %50, label %82, label %51
51: ; preds = %37, %70
%52 = load i8*, i8** %9
%53 = call i32 @log_update(i8* %52, i8** %39, i32* %6)
%54 = load i8**, i8*** %8
%55 = load i8**, i8*** %10
%56 = load i8*, i8** %9
%57 = call i32 @tokenize(i8** %54, i8** %55, i8* %56, i32* %3, i32* %4, i32* %5, i32* %7)
%58 = load i8**, i8*** %8
%59 = call i32 @chkbuiltin(i8** %58)
%60 = icmp eq i32 %59, 0
br i1 %60, label %61, label %70
61: ; preds = %51
%62 = load i8**, i8*** %8
%63 = load i8*, i8** %9
%64 = load i8**, i8*** %10
%65 = load i32, i32* %3
%66 = load i32, i32* %4
%67 = load i32, i32* %5
%68 = load i32, i32* %7
%69 = call i32 @launchjob(i8** %62, i8* %63, i8** %64, i32 %65, i32 %66, i32 %67, i32 %68)
br label %70
70: ; preds = %61, %51
%71 = load i32, i32* @STDIN_FILENO
%72 = call i32 @dup2(i32 %41, i32 %71)
%73 = load i32, i32* @STDOUT_FILENO
%74 = call i32 @dup2(i32 %43, i32 %73)
%75 = load i32, i32* @stdout
%76 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%77 = call i32 @fprintf(i32 %75, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %76)
%78 = load i8*, i8** %9
%79 = load i32, i32* @stdin
%80 = call i32* @fgets(i8* %78, i32 80, i32 %79)
%81 = icmp eq i32* %80, null
br i1 %81, label %82, label %51
82: ; preds = %70, %37
ret i32 0
}