#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ cmpstr(char *, char *);
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ free_array(char **);
char *prompt();
char **split(char *, char);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main() {
  char *cmd;
  char **cmd_array;
  while (1) {
    cmd = prompt();
    if (!cmpstr(cmd, "exit"))
      return EXIT_SUCCESS;
    cmd_array = split(cmd, ' ');
    if (!fork()) {
      execvp(cmd_array[0], cmd_array);
      fprintf(stderr, "error: %s: command not found\n", cmd_array[0]);
      return EXIT_FAILURE;
    }
    wait(NULL);
    free(cmd);
    free_array(cmd_array);
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <prompt@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe4b(%rip),%rsi
call   1080 <cmpstr@plt>
cmp    $0x0,%eax
jne    11d4 <main+0x44>
mov    0x2e06(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1253 <main+0xc3>
mov    -0x10(%rbp),%rdi
mov    $0x20,%esi
call   1060 <split@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   10b0 <fork@plt>
cmp    $0x0,%eax
jne    1233 <main+0xa3>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
call   1090 <execvp@plt>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%rdx
lea    0xde8(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2daf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1253 <main+0xc3>
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <wait@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1050 <free_array@plt>
jmp    119f <main+0xf>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1040 <prompt@plt>
mov    %rax,%rbx
lea    0xe57(%rip),%rsi
mov    %rax,%rdi
call   1080 <cmpstr@plt>
mov    0x2e18(%rip),%r12
test   %eax,%eax
je     1247 <main+0xb7>
lea    0xe39(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x20,%esi
call   1060 <split@plt>
mov    %rax,%r15
xor    %eax,%eax
call   10b0 <fork@plt>
test   %eax,%eax
je     121d <main+0x8d>
xor    %edi,%edi
call   10a0 <wait@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1050 <free_array@plt>
xor    %eax,%eax
call   1040 <prompt@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1080 <cmpstr@plt>
test   %eax,%eax
jne    11d0 <main+0x40>
jmp    1247 <main+0xb7>
mov    (%r15),%rdi
mov    %r15,%rsi
call   1090 <execvp@plt>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rdx
lea    0xdca(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d91(%rip),%r12
mov    (%r12),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"exit\00"
@EXIT_SUCCESS = global i32 0
@stderr = global i32 0
@.str.1 = [30 x i8] c"error: %s: command not found\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8**
store i32 0, i32* %1
br label %4
4: ; preds = %0, %28
%5 = call i8* (...) @prompt()
store i8* %5, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @cmpstr(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = icmp ne i32 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %4
%10 = load i32, i32* @EXIT_SUCCESS
store i32 %10, i32* %1
br label %34
11: ; preds = %4
%12 = load i8*, i8** %2
%13 = call i8** @split(i8* %12, i8 signext 32)
store i8** %13, i8*** %3
%14 = call i32 (...) @fork()
%15 = icmp ne i32 %14, 0
br i1 %15, label %28, label %16
16: ; preds = %11
%17 = load i8**, i8*** %3
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = load i8**, i8*** %3
%21 = call i32 @execvp(i8* %19, i8** %20)
%22 = load i32, i32* @stderr
%23 = load i8**, i8*** %3
%24 = getelementptr inbounds i8*, i8** %23, i64 0
%25 = load i8*, i8** %24
%26 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %25)
%27 = load i32, i32* @EXIT_FAILURE
store i32 %27, i32* %1
br label %34
28: ; preds = %11
%29 = call i32 @wait(i32* null)
%30 = load i8*, i8** %2
%31 = call i32 @free(i8* %30)
%32 = load i8**, i8*** %3
%33 = call i32 @free_array(i8** %32)
br label %4
34: ; preds = %16, %9
%35 = load i32, i32* %1
ret i32 %35
}

LLVM IR (-O2):
@.str = [5 x i8] c"exit\00"
@EXIT_SUCCESS = global i32 0
@stderr = global i32 0
@.str.1 = [30 x i8] c"error: %s: command not found\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @main() {
%1 = tail call i8* (...) @prompt()
%2 = tail call i32 @cmpstr(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32 %2, 0
br i1 %3, label %22, label %4
4: ; preds = %0, %15
%5 = phi i8* [ %19, %15 ], [ %1, %0 ]
%6 = tail call i8** @split(i8* %5, i8 signext 32)
%7 = tail call i32 (...) @fork()
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %4
%10 = load i8*, i8** %6
%11 = tail call i32 @execvp(i8* %10, i8** %6)
%12 = load i32, i32* @stderr
%13 = load i8*, i8** %6
%14 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %13)
br label %22
15: ; preds = %4
%16 = tail call i32 @wait(i32* null)
%17 = tail call i32 @free(i8* %5)
%18 = tail call i32 @free_array(i8** %6)
%19 = tail call i8* (...) @prompt()
%20 = tail call i32 @cmpstr(i8* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %4
22: ; preds = %15, %0, %9
%23 = phi i32* [ @EXIT_FAILURE, %9 ], [ @EXIT_SUCCESS, %0 ], [ @EXIT_SUCCESS, %15 ]
%24 = load i32, i32* %23
ret i32 %24
}