#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*/ EXIT_SUCCESS;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
char *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ find_hostname(char *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
char *getcwd(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ run_command(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
scalar_t__ strcmp(char *, char *);
char *strerror(int /*<<< orphan*/);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strtok(char *, char *);
int /*<<< orphan*/ trim(char *);
int main(int argc, char *argv[]) {
  char line[10000];
  char hostname[10];
  char name[100] = "user";
  char *cwd;
  char *l;
  int running = 1;
  find_hostname(hostname, 10);
  while (running) {
    cwd = getcwd(NULL, 0);
    if (cwd == NULL) {
      fprintf(stderr, "Can not get cwd: %s\n", strerror(errno));
      break;
    }
    printf("%s:%s$ ", hostname, cwd);
    l = fgets(line, 10000, stdin);
    if (l == NULL) {
      printf("EOF\n");
      break;
    }
    trim(l);
    l = strtok(l, ";");
    while (l != NULL) {
      if (strcmp(l, "exit") == 0) {
        running = 0;
        break;
      } else if (strncmp(l, "welcome ", 8) == 0) {
        l += 8;
        strncpy(name, l, 100 - 1);
        name[100 - 1] = '\0';
        printf("Welcome %s, please don't hurt me.\n", name);
      } else {
        run_command(l);
      }
      l = strtok(NULL, ";");
    }
    free(cwd);
  }
  printf("Goodbye %s, I hope I served you well.\n", name);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x27b0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x2790(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1080 <memset@plt>
movb   $0x75,-0x2790(%rbp)
movb   $0x73,-0x278f(%rbp)
movb   $0x65,-0x278e(%rbp)
movb   $0x72,-0x278d(%rbp)
movl   $0x1,-0x27a4(%rbp)
lea    -0x272a(%rbp),%rdi
mov    $0xa,%esi
call   10e0 <find_hostname@plt>
cmpl   $0x0,-0x27a4(%rbp)
je     1420 <main+0x230>
xor    %eax,%eax
mov    %eax,%edi
xor    %esi,%esi
call   1090 <getcwd@plt>
mov    %rax,-0x2798(%rbp)
cmpq   $0x0,-0x2798(%rbp)
jne    12b7 <main+0xc7>
mov    0x2d51(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x27a8(%rbp)
mov    0x2d3a(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0x27a8(%rbp),%edi
mov    %rax,%rdx
lea    0xd53(%rip),%rsi
call   10c0 <fprintf@plt>
jmp    1420 <main+0x230>
lea    -0x272a(%rbp),%rsi
mov    -0x2798(%rbp),%rdx
lea    0xd49(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x2720(%rbp),%rdi
mov    0x2d07(%rip),%rax
mov    (%rax),%edx
mov    $0x2710,%esi
call   10a0 <fgets@plt>
mov    %rax,-0x27a0(%rbp)
cmpq   $0x0,-0x27a0(%rbp)
jne    1315 <main+0x125>
lea    0xd14(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1420 <main+0x230>
mov    -0x27a0(%rbp),%rdi
call   1070 <trim@plt>
mov    -0x27a0(%rbp),%rdi
lea    0xcf3(%rip),%rsi
call   10f0 <strtok@plt>
mov    %rax,-0x27a0(%rbp)
cmpq   $0x0,-0x27a0(%rbp)
je     140f <main+0x21f>
mov    -0x27a0(%rbp),%rdi
lea    0xccd(%rip),%rsi
call   10b0 <strcmp@plt>
cmp    $0x0,%rax
jne    1375 <main+0x185>
movl   $0x0,-0x27a4(%rbp)
jmp    140f <main+0x21f>
mov    -0x27a0(%rbp),%rdi
lea    0xca6(%rip),%rsi
mov    $0x8,%edx
call   1050 <strncmp@plt>
cmp    $0x0,%rax
jne    13e2 <main+0x1f2>
mov    -0x27a0(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x27a0(%rbp)
lea    -0x2790(%rbp),%rdi
mov    -0x27a0(%rbp),%rsi
mov    $0x63,%edx
call   1040 <strncpy@plt>
movb   $0x0,-0x272d(%rbp)
lea    -0x2790(%rbp),%rsi
lea    0xc5c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    13ee <main+0x1fe>
mov    -0x27a0(%rbp),%rdi
call   10d0 <run_command@plt>
jmp    13f3 <main+0x203>
xor    %eax,%eax
mov    %eax,%edi
lea    0xc24(%rip),%rsi
call   10f0 <strtok@plt>
mov    %rax,-0x27a0(%rbp)
jmp    133b <main+0x14b>
mov    -0x2798(%rbp),%rdi
call   1030 <free@plt>
jmp    1253 <main+0x63>
lea    -0x2790(%rbp),%rsi
lea    0xc27(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2b8c(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x27a8,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movl   $0x0,0x80(%rsp)
movl   $0x72657375,0x20(%rsp)
72
lea    0x16(%rsp),%rdi
mov    $0xa,%esi
call   10e0 <find_hostname@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1090 <getcwd@plt>
test   %rax,%rax
jne    127f <main+0x8f>
mov    0x2d7f(%rip),%rax
mov    (%rax),%ebx
mov    0x2d6e(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
lea    0xd90(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   10c0 <fprintf@plt>
jmp    13a8 <main+0x1b8>
mov    %rax,%r12
lea    0xd94(%rip),%r15
lea    0xd8f(%rip),%rbx
lea    0xd8d(%rip),%r14
lea    0x20(%rsp),%rbp
jmp    12bb <main+0xcb>
xchg   %ax,%ax
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1090 <getcwd@plt>
mov    %rax,%r12
test   %rax,%rax
je     1252 <main+0x62>
mov    %rbp,%r13
lea    0xd50(%rip),%rdi
lea    0x16(%rsp),%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2d0d(%rip),%rax
mov    (%rax),%edx
lea    0x90(%rsp),%rdi
mov    $0x2710,%esi
call   10a0 <fgets@plt>
test   %rax,%rax
je     13c9 <main+0x1d9>
mov    %rax,%rbp
mov    %r12,0x8(%rsp)
mov    %rax,%rdi
call   1080 <trim@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
call   10f0 <strtok@plt>
test   %rax,%rax
mov    %r13,%rbp
lea    0xd0d(%rip),%r13
je     12a0 <main+0xb0>
mov    %rax,%r12
jmp    134e <main+0x15e>
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   10d0 <run_command@plt>
xor    %edi,%edi
mov    %r15,%rsi
call   10f0 <strtok@plt>
mov    %rax,%r12
test   %rax,%rax
je     12a0 <main+0xb0>
mov    %r12,%rdi
mov    %rbx,%rsi
call   10b0 <strcmp@plt>
test   %rax,%rax
je     139e <main+0x1ae>
mov    %r12,%rdi
mov    %r14,%rsi
mov    $0x8,%edx
call   1050 <strncmp@plt>
test   %rax,%rax
jne    1330 <main+0x140>
add    $0x8,%r12
mov    %rbp,%rdi
mov    %r12,%rsi
mov    $0x63,%edx
call   1040 <strncpy@plt>
movb   $0x0,0x83(%rsp)
mov    %r13,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1338 <main+0x148>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
lea    0xca1(%rip),%rdi
lea    0x20(%rsp),%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2c06(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
lea    0xca7(%rip),%rdi
call   1060 <puts@plt>
jmp    13a8 <main+0x1b8>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [21 x i8] c"Can not get cwd: %s\0A\00"
@errno = global i32 0
@.str.1 = [8 x i8] c"%s:%s$ \00"
@stdin = global i32 0
@.str.2 = [5 x i8] c"EOF\0A\00"
@.str.3 = [2 x i8] c";\00"
@.str.4 = [5 x i8] c"exit\00"
@.str.5 = [9 x i8] c"welcome \00"
@.str.6 = [35 x i8] c"Welcome %s, please don't hurt me.\0A\00"
@.str.7 = [39 x i8] c"Goodbye %s, I hope I served you well.\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [10000 x i8]
%7 = alloca [10 x i8]
%8 = alloca [100 x i8]
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = bitcast [100 x i8]* %8 to i8*
%13 = bitcast i8* %12 to [100 x i8]*
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %13, i32 0, i32 0
store i8 117, i8* %14
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %13, i32 0, i32 1
store i8 115, i8* %15
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %13, i32 0, i32 2
store i8 101, i8* %16
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %13, i32 0, i32 3
store i8 114, i8* %17
store i32 1, i32* %11
%18 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%19 = call i32 @find_hostname(i8* %18, i32 10)
br label %20
20: ; preds = %75, %2
%21 = load i32, i32* %11
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %78
23: ; preds = %20
%24 = call i8* @getcwd(i32* null, i32 0)
store i8* %24, i8** %9
%25 = load i8*, i8** %9
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %32
27: ; preds = %23
%28 = load i32, i32* @stderr
%29 = load i32, i32* @errno
%30 = call i8* @strerror(i32 %29)
%31 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %30)
br label %78
32: ; preds = %23
%33 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%34 = load i8*, i8** %9
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %33, i8* %34)
%36 = getelementptr inbounds [10000 x i8], [10000 x i8]* %6, i64 0, i64 0
%37 = load i32, i32* @stdin
%38 = call i8* @fgets(i8* %36, i32 10000, i32 %37)
store i8* %38, i8** %10
%39 = load i8*, i8** %10
%40 = icmp eq i8* %39, null
br i1 %40, label %41, label %43
41: ; preds = %32
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %78
43: ; preds = %32
%44 = load i8*, i8** %10
%45 = call i32 @trim(i8* %44)
%46 = load i8*, i8** %10
%47 = call i8* @strtok(i8* %46, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i8* %47, i8** %10
br label %48
48: ; preds = %73, %43
%49 = load i8*, i8** %10
%50 = icmp ne i8* %49, null
br i1 %50, label %51, label %75
51: ; preds = %48
%52 = load i8*, i8** %10
%53 = call i64 @strcmp(i8* %52, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%54 = icmp eq i64 %53, 0
br i1 %54, label %55, label %56
55: ; preds = %51
store i32 0, i32* %11
br label %75
56: ; preds = %51
%57 = load i8*, i8** %10
%58 = call i64 @strncmp(i8* %57, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 8)
%59 = icmp eq i64 %58, 0
br i1 %59, label %60, label %69
60: ; preds = %56
%61 = load i8*, i8** %10
%62 = getelementptr inbounds i8, i8* %61, i64 8
store i8* %62, i8** %10
%63 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%64 = load i8*, i8** %10
%65 = call i32 @strncpy(i8* %63, i8* %64, i32 99)
%66 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 99
store i8 0, i8* %66
%67 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0), i8* %67)
br label %72
69: ; preds = %56
%70 = load i8*, i8** %10
%71 = call i32 @run_command(i8* %70)
br label %72
72: ; preds = %69, %60
br label %73
73: ; preds = %72
%74 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i8* %74, i8** %10
br label %48
75: ; preds = %55, %48
%76 = load i8*, i8** %9
%77 = call i32 @free(i8* %76)
br label %20
78: ; preds = %41, %27, %20
%79 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.7, i64 0, i64 0), i8* %79)
%81 = load i32, i32* @EXIT_SUCCESS
%82 = call i32 @exit(i32 %81)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [21 x i8] c"Can not get cwd: %s\0A\00"
@errno = global i32 0
@.str.1 = [8 x i8] c"%s:%s$ \00"
@stdin = global i32 0
@.str.3 = [2 x i8] c";\00"
@.str.4 = [5 x i8] c"exit\00"
@.str.5 = [9 x i8] c"welcome \00"
@.str.6 = [35 x i8] c"Welcome %s, please don't hurt me.\0A\00"
@.str.7 = [39 x i8] c"Goodbye %s, I hope I served you well.\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [4 x i8] c"EOF\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [10000 x i8]
%4 = alloca [10 x i8]
%5 = alloca [100 x i8]
%6 = getelementptr inbounds [10000 x i8], [10000 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
store i8 117, i8* %8
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 1
store i8 115, i8* %9
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 2
store i8 101, i8* %10
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 3
store i8 114, i8* %11
%12 = call i32 @find_hostname(i8* %7, i32 10)
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 99
%14 = call i8* @getcwd(i32* null, i32 0)
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %21
16: ; preds = %49, %2
%17 = load i32, i32* @stderr
%18 = load i32, i32* @errno
%19 = call i8* @strerror(i32 %18)
%20 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %19)
br label %55
21: ; preds = %2, %49
%22 = phi i8* [ %51, %49 ], [ %14, %2 ]
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %7, i8* %22)
%24 = load i32, i32* @stdin
%25 = call i8* @fgets(i8* %6, i32 10000, i32 %24)
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %29
27: ; preds = %21
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str, i64 0, i64 0))
br label %55
29: ; preds = %21
%30 = call i32 @trim(i8* %25)
%31 = call i8* @strtok(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%32 = icmp eq i8* %31, null
br i1 %32, label %49, label %33
33: ; preds = %29, %46
%34 = phi i8* [ %47, %46 ], [ %31, %29 ]
%35 = call i64 @strcmp(i8* %34, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
br i1 %36, label %53, label %37
37: ; preds = %33
%38 = call i64 @strncmp(i8* %34, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 8)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %44
40: ; preds = %37
%41 = getelementptr inbounds i8, i8* %34, i64 8
%42 = call i32 @strncpy(i8* %8, i8* %41, i32 99)
store i8 0, i8* %13
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0), i8* %8)
br label %46
44: ; preds = %37
%45 = call i32 @run_command(i8* %34)
br label %46
46: ; preds = %40, %44
%47 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%48 = icmp eq i8* %47, null
br i1 %48, label %49, label %33
49: ; preds = %46, %29
%50 = call i32 @free(i8* %22)
%51 = call i8* @getcwd(i32* null, i32 0)
%52 = icmp eq i8* %51, null
br i1 %52, label %16, label %21
53: ; preds = %33
%54 = call i32 @free(i8* %22)
br label %55
55: ; preds = %53, %27, %16
%56 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.7, i64 0, i64 0), i8* %8)
%57 = load i32, i32* @EXIT_SUCCESS
%58 = call i32 @exit(i32 %57)
unreachable
}