#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*/ cmd;

/* Variables and functions */
int chdir(char *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ get(char *, char **);
char *getenv(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ run(char **);
int /*<<< orphan*/ stdin;
scalar_t__ strcmp(char *, char *);
int strlen(char *);
int main() {
  char *param[1 + 16];
  char cmd[1 + 128];
  while (1) {
    char *uname = getenv("USER");
    printf("%s@topgnushell -->", uname);
    if (fgets(cmd, sizeof(cmd), stdin) == NULL)
      break;
    cmd[strlen(cmd) - 1] =
        (cmd[strlen(cmd) - 1] == '\n') ? '\0' : cmd[strlen(cmd) - 1];
    get(cmd, param);
    if (strcmp(param[0], "exit") == 0)
      break;
    if (strcmp(param[0], "cd") == 0)
      if (chdir(param[1]) == -1)
        printf("Line 36");
    if (run(param) == 0)
      break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe67(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x128(%rbp)
mov    -0x128(%rbp),%rsi
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x120(%rbp),%rdi
mov    0x2e20(%rip),%rax
mov    (%rax),%edx
mov    $0x81,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
jne    11e3 <main+0x63>
jmp    12f5 <main+0x175>
lea    -0x120(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
cltq
movsbl -0x120(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    1212 <main+0x92>
xor    %eax,%eax
mov    %eax,-0x12c(%rbp)
jmp    1231 <main+0xb1>
lea    -0x120(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
cltq
movsbl -0x120(%rbp,%rax,1),%eax
ff
mov    %eax,-0x12c(%rbp)
mov    -0x12c(%rbp),%eax
mov    %al,-0x12d(%rbp)
lea    -0x120(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x12d(%rbp),%cl
sub    $0x1,%eax
cltq
mov    %cl,-0x120(%rbp,%rax,1)
lea    -0x120(%rbp),%rdi
lea    -0x90(%rbp),%rsi
call   10a0 <get@plt>
mov    -0x90(%rbp),%rdi
lea    0xd9c(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    1290 <main+0x110>
jmp    12f5 <main+0x175>
mov    -0x90(%rbp),%rdi
lea    0xd7f(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    12d5 <main+0x155>
mov    -0x88(%rbp),%rdi
call   1060 <chdir@plt>
cmp    $0xffffffff,%eax
jne    12d0 <main+0x150>
lea    0xd57(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    12d5 <main+0x155>
lea    -0x90(%rbp),%rdi
call   1040 <run@plt>
cmp    $0x0,%rax
jne    12f0 <main+0x170>
jmp    12f5 <main+0x175>
jmp    1192 <main+0x12>
xor    %eax,%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
lea    0xe6d(%rip),%r15
mov    0x2e49(%rip),%rbp
lea    0x90(%rsp),%rbx
mov    %rsp,%r12
lea    0xe67(%rip),%r13
jmp    11d1 <main+0x51>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r12,%rdi
call   1040 <run@plt>
test   %rax,%rax
je     129a <main+0x11a>
lea    0xe28(%rip),%rdi
call   1030 <getenv@plt>
mov    %r15,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x0(%rbp),%edx
mov    %rbx,%rdi
mov    $0x81,%esi
call   1080 <fgets@plt>
test   %rax,%rax
je     129a <main+0x11a>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%rbx,1)
jne    1220 <main+0xa0>
xor    %r14d,%r14d
jmp    1230 <main+0xb0>
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
movzbl -0x1(%rax,%rbx,1),%r14d
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
mov    %r14b,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
mov    %r12,%rsi
call   10a0 <get@plt>
mov    (%rsp),%rdi
mov    %r13,%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     129a <main+0x11a>
mov    (%rsp),%rdi
lea    0xdb7(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
jne    11c0 <main+0x40>
mov    0x8(%rsp),%rdi
call   1060 <chdir@plt>
cmp    $0xffffffff,%eax
jne    11c0 <main+0x40>
lea    0xd92(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    11c0 <main+0x40>
xor    %eax,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"USER\00"
@.str.1 = [19 x i8] c"%s@topgnushell -->\00"
@stdin = global i32 0
@.str.2 = [5 x i8] c"exit\00"
@.str.3 = [3 x i8] c"cd\00"
@.str.4 = [8 x i8] c"Line 36\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [17 x i8*]
%3 = alloca [129 x i8]
%4 = alloca i8*
store i32 0, i32* %1
br label %5
5: ; preds = %0, %66
%6 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%9 = getelementptr inbounds [129 x i8], [129 x i8]* %3, i64 0, i64 0
%10 = load i32, i32* @stdin
%11 = call i32* @fgets(i8* %9, i32 129, i32 %10)
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %14
13: ; preds = %5
br label %67
14: ; preds = %5
%15 = getelementptr inbounds [129 x i8], [129 x i8]* %3, i64 0, i64 0
%16 = call i32 @strlen(i8* %15)
%17 = sub nsw i32 %16, 1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [129 x i8], [129 x i8]* %3, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 10
br i1 %22, label %23, label %24
23: ; preds = %14
br label %32
24: ; preds = %14
%25 = getelementptr inbounds [129 x i8], [129 x i8]* %3, i64 0, i64 0
%26 = call i32 @strlen(i8* %25)
%27 = sub nsw i32 %26, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [129 x i8], [129 x i8]* %3, i64 0, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
br label %32
32: ; preds = %24, %23
%33 = phi i32 [ 0, %23 ], [ %31, %24 ]
%34 = trunc i32 %33 to i8
%35 = getelementptr inbounds [129 x i8], [129 x i8]* %3, i64 0, i64 0
%36 = call i32 @strlen(i8* %35)
%37 = sub nsw i32 %36, 1
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [129 x i8], [129 x i8]* %3, i64 0, i64 %38
store i8 %34, i8* %39
%40 = getelementptr inbounds [129 x i8], [129 x i8]* %3, i64 0, i64 0
%41 = getelementptr inbounds [17 x i8*], [17 x i8*]* %2, i64 0, i64 0
%42 = call i32 @get(i8* %40, i8** %41)
%43 = getelementptr inbounds [17 x i8*], [17 x i8*]* %2, i64 0, i64 0
%44 = load i8*, i8** %43
%45 = call i64 @strcmp(i8* %44, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %32
br label %67
48: ; preds = %32
%49 = getelementptr inbounds [17 x i8*], [17 x i8*]* %2, i64 0, i64 0
%50 = load i8*, i8** %49
%51 = call i64 @strcmp(i8* %50, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %61
53: ; preds = %48
%54 = getelementptr inbounds [17 x i8*], [17 x i8*]* %2, i64 0, i64 1
%55 = load i8*, i8** %54
%56 = call i32 @chdir(i8* %55)
%57 = icmp eq i32 %56, -1
br i1 %57, label %58, label %60
58: ; preds = %53
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %60
60: ; preds = %58, %53
br label %61
61: ; preds = %60, %48
%62 = getelementptr inbounds [17 x i8*], [17 x i8*]* %2, i64 0, i64 0
%63 = call i64 @run(i8** %62)
%64 = icmp eq i64 %63, 0
br i1 %64, label %65, label %66
65: ; preds = %61
br label %67
66: ; preds = %61
br label %5
67: ; preds = %65, %47, %13
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"USER\00"
@.str.1 = [19 x i8] c"%s@topgnushell -->\00"
@stdin = global i32 0
@.str.2 = [5 x i8] c"exit\00"
@.str.3 = [3 x i8] c"cd\00"
@.str.4 = [8 x i8] c"Line 36\00"
define i32 @main() {
%1 = alloca [17 x i8*]
%2 = alloca [129 x i8]
%3 = bitcast [17 x i8*]* %1 to i8*
%4 = getelementptr inbounds [129 x i8], [129 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [17 x i8*], [17 x i8*]* %1, i64 0, i64 0
%6 = getelementptr inbounds [17 x i8*], [17 x i8*]* %1, i64 0, i64 1
br label %7
7: ; preds = %46, %0
%8 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%10 = load i32, i32* @stdin
%11 = call i32* @fgets(i8* %4, i32 129, i32 %10)
%12 = icmp eq i32* %11, null
br i1 %12, label %49, label %13
13: ; preds = %7
%14 = call i32 @strlen(i8* %4)
%15 = add nsw i32 %14, -1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [129 x i8], [129 x i8]* %2, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 10
br i1 %19, label %26, label %20
20: ; preds = %13
%21 = call i32 @strlen(i8* %4)
%22 = add nsw i32 %21, -1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [129 x i8], [129 x i8]* %2, i64 0, i64 %23
%25 = load i8, i8* %24
br label %26
26: ; preds = %13, %20
%27 = phi i8 [ %25, %20 ], [ 0, %13 ]
%28 = call i32 @strlen(i8* %4)
%29 = add nsw i32 %28, -1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [129 x i8], [129 x i8]* %2, i64 0, i64 %30
store i8 %27, i8* %31
%32 = call i32 @get(i8* %4, i8** %5)
%33 = load i8*, i8** %5
%34 = call i64 @strcmp(i8* %33, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%35 = icmp eq i64 %34, 0
br i1 %35, label %49, label %36
36: ; preds = %26
%37 = load i8*, i8** %5
%38 = call i64 @strcmp(i8* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %46
40: ; preds = %36
%41 = load i8*, i8** %6
%42 = call i32 @chdir(i8* %41)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %46
44: ; preds = %40
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %46
46: ; preds = %40, %44, %36
%47 = call i64 @run(i8** %5)
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %7
49: ; preds = %46, %7, %26
ret i32 0
}