#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*/ executeProcess(char **);
int /*<<< orphan*/ executeProcessPipe(int, char **);
int /*<<< orphan*/ executeScript(char *, char **);
int parseCommand(char *);
int /*<<< orphan*/ printPrompt();
int readInput(char *);
int strlen(char *);
int /*<<< orphan*/ welcome();
int main(int argc, char *argv[], char *envp[]) {
  int script = 1;
  if (argc == 2) {
    executeScript(argv[1], envp);
    script = 0;
  }
  if (script)
    welcome();
  while (1) {
    int num_args;
    char input_line[1024];
    printPrompt();
    if (readInput(input_line) == 1) {
      int len = strlen(input_line);
      if (len < 1)
        continue;
      num_args = parseCommand(input_line);
      switch (num_args) {
      case 1:
        executeProcess(envp);
        break;
      default:
        executeProcessPipe(num_args, envp);
        break;
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    11c6 <main+0x46>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <executeScript@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11d7 <main+0x57>
mov    $0x0,%al
call   1070 <welcome@plt>
jmp    11dc <main+0x5c>
mov    $0x0,%al
call   1050 <printPrompt@plt>
lea    -0x420(%rbp),%rdi
call   1090 <readInput@plt>
cmp    $0x1,%eax
jne    125b <main+0xdb>
lea    -0x420(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x424(%rbp)
cmpl   $0x1,-0x424(%rbp)
jge    121c <main+0x9c>
jmp    11dc <main+0x5c>
lea    -0x420(%rbp),%rdi
call   10a0 <parseCommand@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
sub    $0x1,%eax
jne    124a <main+0xca>
jmp    123c <main+0xbc>
mov    -0x18(%rbp),%rdi
call   1060 <executeProcess@plt>
jmp    1256 <main+0xd6>
mov    -0x20(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1080 <executeProcessPipe@plt>
jmp    125b <main+0xdb>
jmp    11dc <main+0x5c>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rdx,%r14
cmp    $0x2,%edi
jne    11a0 <main+0x20>
mov    0x8(%rsi),%rdi
mov    %r14,%rsi
call   1030 <executeScript@plt>
jmp    11a7 <main+0x27>
xor    %eax,%eax
call   1070 <welcome@plt>
mov    %rsp,%rbx
jmp    11c0 <main+0x40>
mov    %eax,%edi
mov    %r14,%rsi
call   1080 <executeProcessPipe@plt>
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <printPrompt@plt>
mov    %rbx,%rdi
call   1090 <readInput@plt>
cmp    $0x1,%eax
jne    11c0 <main+0x40>
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    11c0 <main+0x40>
mov    %rbx,%rdi
call   10a0 <parseCommand@plt>
cmp    $0x1,%eax
jne    11ac <main+0x2c>
mov    %r14,%rdi
call   1060 <executeProcess@plt>
jmp    11c0 <main+0x40>

LLVM IR (-O0):
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i32
%10 = alloca [1024 x i8]
%11 = alloca i32
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
store i32 1, i32* %8
%12 = load i32, i32* %5
%13 = icmp eq i32 %12, 2
br i1 %13, label %14, label %20
14: ; preds = %3
%15 = load i8**, i8*** %6
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = load i8**, i8*** %7
%19 = call i32 @executeScript(i8* %17, i8** %18)
store i32 0, i32* %8
br label %20
20: ; preds = %14, %3
%21 = load i32, i32* %8
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = call i32 (...) @welcome()
br label %25
25: ; preds = %23, %20
br label %26
26: ; preds = %25, %36, %49
%27 = call i32 (...) @printPrompt()
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%29 = call i32 @readInput(i8* %28)
%30 = icmp eq i32 %29, 1
br i1 %30, label %31, label %49
31: ; preds = %26
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%33 = call i32 @strlen(i8* %32)
store i32 %33, i32* %11
%34 = load i32, i32* %11
%35 = icmp slt i32 %34, 1
br i1 %35, label %36, label %37
36: ; preds = %31
br label %26
37: ; preds = %31
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%39 = call i32 @parseCommand(i8* %38)
store i32 %39, i32* %9
%40 = load i32, i32* %9
switch i32 %40, label %44 [
i32 1, label %41
]
41: ; preds = %37
%42 = load i8**, i8*** %7
%43 = call i32 @executeProcess(i8** %42)
br label %48
44: ; preds = %37
%45 = load i32, i32* %9
%46 = load i8**, i8*** %7
%47 = call i32 @executeProcessPipe(i32 %45, i8** %46)
br label %48
48: ; preds = %44, %41
br label %49
49: ; preds = %48, %26
br label %26
}

LLVM IR (-O2):
define i32 @main(i32 %0, i8** nocapture %1, i8** %2) {
%4 = alloca [1024 x i8]
%5 = icmp eq i32 %0, 2
br i1 %5, label %6, label %10
6: ; preds = %3
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @executeScript(i8* %8, i8** %2)
br label %12
10: ; preds = %3
%11 = tail call i32 (...) @welcome()
br label %12
12: ; preds = %6, %10
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
br label %14
14: ; preds = %28, %12
%15 = call i32 (...) @printPrompt()
%16 = call i32 @readInput(i8* %13)
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %28
18: ; preds = %14
%19 = call i32 @strlen(i8* %13)
%20 = icmp slt i32 %19, 1
br i1 %20, label %28, label %21
21: ; preds = %18
%22 = call i32 @parseCommand(i8* %13)
%23 = icmp eq i32 %22, 1
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = call i32 @executeProcess(i8** %2)
br label %28
26: ; preds = %21
%27 = call i32 @executeProcessPipe(i32 %22, i8** %2)
br label %28
28: ; preds = %26, %24, %18, %14
br label %14
}