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

/* Variables and functions */
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ execv(char *, char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ free(char **);
char **parse_input(char *, int /*<<< orphan*/, int *);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ say(char *);
int /*<<< orphan*/ strlen(char *);
scalar_t__ strncmp(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ wait(int *);
int main() {
  bool running = true;
  ssize_t sz;
  int pid, stat_loc, argc = 0;
  char buf[256];
  char **args;
  while (running) {
    say("$>");
    sz = read(1, buf, 256);
    if (*buf == '\n')
      continue;
    args = parse_input(buf, sz, &argc);
    if (strncmp(args[0], "exit", strlen("exit")) == 0 ||
        strncmp(args[0], "quit", strlen("quit")) == 0) {
      running = false;
    } else {
      pid = fork();
      if (pid == 0) {
        execv(args[0], args);
      } else {
        wait(&stat_loc);
      }
    }
  }
  free(args);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     12e4 <main+0x144>
lea    0xe2f(%rip),%rdi
call   10c0 <say@plt>
lea    -0x120(%rbp),%rsi
mov    $0x1,%edi
mov    $0x100,%edx
call   1060 <read@plt>
mov    %eax,-0xc(%rbp)
movsbl -0x120(%rbp),%eax
cmp    $0xa,%eax
jne    1204 <main+0x64>
jmp    11c0 <main+0x20>
lea    -0x120(%rbp),%rdi
mov    -0xc(%rbp),%esi
lea    -0x18(%rbp),%rdx
call   1070 <parse_input@plt>
mov    %rax,-0x128(%rbp)
mov    -0x128(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x130(%rbp)
lea    0xdcd(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x130(%rbp),%rdi
mov    %eax,%edx
lea    0xdb8(%rip),%rsi
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     1296 <main+0xf6>
mov    -0x128(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x138(%rbp)
lea    0xd96(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x138(%rbp),%rdi
mov    %eax,%edx
lea    0xd81(%rip),%rsi
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    12a2 <main+0x102>
movl   $0x0,-0x8(%rbp)
jmp    12df <main+0x13f>
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    12d1 <main+0x131>
mov    -0x128(%rbp),%rax
mov    (%rax),%rdi
mov    -0x128(%rbp),%rsi
call   10a0 <execv@plt>
jmp    12da <main+0x13a>
lea    -0x14(%rbp),%rdi
call   1090 <wait@plt>
jmp    12df <main+0x13f>
jmp    11c0 <main+0x20>
mov    -0x128(%rbp),%rdi
call   1030 <free@plt>
mov    0x2ce9(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
movl   $0x0,0x8(%rsp)
lea    0xe40(%rip),%r14
lea    0x10(%rsp),%rbx
lea    0xe37(%rip),%r12
lea    0xe35(%rip),%r13
jmp    11e0 <main+0x40>
lea    0xc(%rsp),%rdi
call   1090 <wait@plt>
nop
mov    %r14,%rdi
call   10c0 <say@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x100,%edx
call   1060 <read@plt>
cmpb   $0xa,0x10(%rsp)
je     11e0 <main+0x40>
mov    %rbx,%rdi
mov    %eax,%esi
lea    0x8(%rsp),%rdx
call   1070 <parse_input@plt>
mov    %rax,%rbp
mov    (%rax),%r15
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %eax,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     126e <main+0xce>
mov    0x0(%rbp),%r15
mov    %r13,%rdi
call   1050 <strlen@plt>
mov    %r15,%rdi
mov    %r13,%rsi
mov    %eax,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     126e <main+0xce>
xor    %eax,%eax
call   10b0 <fork@plt>
test   %eax,%eax
jne    11d5 <main+0x35>
mov    0x0(%rbp),%rdi
mov    %rbp,%rsi
call   10a0 <execv@plt>
jmp    11e0 <main+0x40>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    0x2d63(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"$>\00"
@.str.1 = [5 x i8] c"exit\00"
@.str.2 = [5 x i8] c"quit\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [256 x i8]
%8 = alloca i8**
store i32 0, i32* %1
store i32 1, i32* %2
store i32 0, i32* %6
br label %9
9: ; preds = %52, %20, %0
%10 = load i32, i32* %2
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %53
12: ; preds = %9
%13 = call i32 @say(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%15 = call i32 @read(i32 1, i8* %14, i32 256)
store i32 %15, i32* %3
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 10
br i1 %19, label %20, label %21
20: ; preds = %12
br label %9
21: ; preds = %12
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%23 = load i32, i32* %3
%24 = call i8** @parse_input(i8* %22, i32 %23, i32* %6)
store i8** %24, i8*** %8
%25 = load i8**, i8*** %8
%26 = getelementptr inbounds i8*, i8** %25, i64 0
%27 = load i8*, i8** %26
%28 = call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%29 = call i64 @strncmp(i8* %27, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %38, label %31
31: ; preds = %21
%32 = load i8**, i8*** %8
%33 = getelementptr inbounds i8*, i8** %32, i64 0
%34 = load i8*, i8** %33
%35 = call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%36 = call i64 @strncmp(i8* %34, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %35)
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %31, %21
store i32 0, i32* %2
br label %52
39: ; preds = %31
%40 = call i32 (...) @fork()
store i32 %40, i32* %4
%41 = load i32, i32* %4
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %49
43: ; preds = %39
%44 = load i8**, i8*** %8
%45 = getelementptr inbounds i8*, i8** %44, i64 0
%46 = load i8*, i8** %45
%47 = load i8**, i8*** %8
%48 = call i32 @execv(i8* %46, i8** %47)
br label %51
49: ; preds = %39
%50 = call i32 @wait(i32* %5)
br label %51
51: ; preds = %49, %43
br label %52
52: ; preds = %51, %38
br label %9
53: ; preds = %9
%54 = load i8**, i8*** %8
%55 = call i32 @free(i8** %54)
%56 = load i32, i32* @EXIT_SUCCESS
%57 = call i32 @exit(i32 %56)
unreachable
}

LLVM IR (-O2):
@.str = [3 x i8] c"$>\00"
@.str.1 = [5 x i8] c"exit\00"
@.str.2 = [5 x i8] c"quit\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [256 x i8]
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
br label %7
7: ; preds = %35, %0
%8 = call i32 @say(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @read(i32 1, i8* %6, i32 256)
%10 = load i8, i8* %6
%11 = icmp eq i8 %10, 10
br i1 %11, label %12, label %17
12: ; preds = %7, %12
%13 = call i32 @say(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @read(i32 1, i8* %6, i32 256)
%15 = load i8, i8* %6
%16 = icmp eq i8 %15, 10
br i1 %16, label %12, label %17
17: ; preds = %12, %7
%18 = phi i32 [ %9, %7 ], [ %14, %12 ]
%19 = call i8** @parse_input(i8* %6, i32 %18, i32* %2)
%20 = load i8*, i8** %19
%21 = call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%22 = call i64 @strncmp(i8* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %38, label %24
24: ; preds = %17
%25 = load i8*, i8** %19
%26 = call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%27 = call i64 @strncmp(i8* %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %38, label %29
29: ; preds = %24
%30 = call i32 (...) @fork()
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %29
%33 = load i8*, i8** %19
%34 = call i32 @execv(i8* %33, i8** %19)
br label %35
35: ; preds = %32, %36
br label %7
36: ; preds = %29
%37 = call i32 @wait(i32* %1)
br label %35
38: ; preds = %24, %17
%39 = call i32 @free(i8** %19)
%40 = load i32, i32* @EXIT_SUCCESS
%41 = call i32 @exit(i32 %40)
unreachable
}