#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 scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ errno;
int execvp(char *, char **);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ setup(char *, char **, int *);
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ waitpid(scalar_t__, int *, int /*<<< orphan*/);
int main(void) {
  char inBuffer[80];
  char *args[80 / 2 + 1];
  int bkgrnd;
  pid_t pid;
  int status;
  while (1) {
    bkgrnd = 0;
    printf("SysIIShell--> ");
    fflush(0);
    setup(inBuffer, args, &bkgrnd);
    pid = fork();
    if (pid == 0) {
      status = execvp(inBuffer, args);
      if (status == -1) {
        printf("%s\n", strerror(errno));
      }
      break;
    } else {
      if (!bkgrnd) {
        waitpid(pid, &status, 0);
      }
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1d0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x1b4(%rbp)
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1040 <fflush@plt>
lea    -0x60(%rbp),%rdi
lea    -0x1b0(%rbp),%rsi
lea    -0x1b4(%rbp),%rdx
call   1090 <setup@plt>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x1c0(%rbp)
cmpq   $0x0,-0x1c0(%rbp)
jne    121b <main+0xab>
lea    -0x60(%rbp),%rdi
lea    -0x1b0(%rbp),%rsi
call   1060 <execvp@plt>
mov    %eax,-0x1c4(%rbp)
cmpl   $0xffffffff,-0x1c4(%rbp)
jne    1216 <main+0xa6>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %rax,%rsi
lea    0xe00(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1247 <main+0xd7>
cmpl   $0x0,-0x1b4(%rbp)
jne    123d <main+0xcd>
mov    -0x1c0(%rbp),%rdi
lea    -0x1c4(%rbp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
jmp    1242 <main+0xd2>
jmp    1182 <main+0x12>
mov    -0x4(%rbp),%eax
add    $0x1d0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1b0,%rsp
movl   $0x0,0x8(%rsp)
lea    0xe61(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
call   1050 <fflush@plt>
lea    0x10(%rsp),%rdi
lea    0x60(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   10a0 <setup@plt>
xor    %eax,%eax
call   1090 <fork@plt>
test   %rax,%rax
je     1239 <main+0xb9>
lea    0xc(%rsp),%r14
lea    0xe27(%rip),%r15
lea    0x10(%rsp),%r12
lea    0x60(%rsp),%r13
lea    0x8(%rsp),%rbx
jmp    1223 <main+0xa3>
nopw   0x0(%rax,%rax,1)
movl   $0x0,0x8(%rsp)
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
call   1050 <fflush@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   10a0 <setup@plt>
xor    %eax,%eax
call   1090 <fork@plt>
test   %rax,%rax
je     1239 <main+0xb9>
cmpl   $0x0,0x8(%rsp)
jne    11f0 <main+0x70>
mov    %rax,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1060 <waitpid@plt>
jmp    11f0 <main+0x70>
lea    0x10(%rsp),%rdi
lea    0x60(%rsp),%rsi
call   1070 <execvp@plt>
mov    %eax,0xc(%rsp)
cmp    $0xffffffff,%eax
jne    1267 <main+0xe7>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %rax,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x1b0,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [15 x i8] c"SysIIShell--> \00"
@.str.1 = [4 x i8] c"%s\0A\00"
@errno = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [80 x i8]
%3 = alloca [41 x i8*]
%4 = alloca i32
%5 = alloca i64
%6 = alloca i32
store i32 0, i32* %1
br label %7
7: ; preds = %0, %34
store i32 0, i32* %4
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @fflush(i32 0)
%10 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%11 = getelementptr inbounds [41 x i8*], [41 x i8*]* %3, i64 0, i64 0
%12 = call i32 @setup(i8* %10, i8** %11, i32* %4)
%13 = call i64 (...) @fork()
store i64 %13, i64* %5
%14 = load i64, i64* %5
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %27
16: ; preds = %7
%17 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%18 = getelementptr inbounds [41 x i8*], [41 x i8*]* %3, i64 0, i64 0
%19 = call i32 @execvp(i8* %17, i8** %18)
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %26
22: ; preds = %16
%23 = load i32, i32* @errno
%24 = call i8* @strerror(i32 %23)
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %24)
br label %26
26: ; preds = %22, %16
br label %35
27: ; preds = %7
%28 = load i32, i32* %4
%29 = icmp ne i32 %28, 0
br i1 %29, label %33, label %30
30: ; preds = %27
%31 = load i64, i64* %5
%32 = call i32 @waitpid(i64 %31, i32* %6, i32 0)
br label %33
33: ; preds = %30, %27
br label %34
34: ; preds = %33
br label %7
35: ; preds = %26
%36 = load i32, i32* %1
ret i32 %36
}

LLVM IR (-O2):
@.str = [15 x i8] c"SysIIShell--> \00"
@errno = global i32 0
define i32 @main() {
%1 = alloca [80 x i8]
%2 = alloca [41 x i8*]
%3 = alloca i32
%4 = alloca i32
%5 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%6 = bitcast [41 x i8*]* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
store i32 0, i32* %3
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @fflush(i32 0)
%11 = getelementptr inbounds [41 x i8*], [41 x i8*]* %2, i64 0, i64 0
%12 = call i32 @setup(i8* %5, i8** %11, i32* %3)
%13 = call i64 (...) @fork()
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %22
15: ; preds = %28, %0
%16 = call i32 @execvp(i8* %5, i8** %11)
store i32 %16, i32* %4
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %34
18: ; preds = %15
%19 = load i32, i32* @errno
%20 = call i8* @strerror(i32 %19)
%21 = call i32 @puts(i8* dereferenceable(1) %20)
br label %34
22: ; preds = %0, %28
%23 = phi i64 [ %32, %28 ], [ %13, %0 ]
%24 = load i32, i32* %3
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = call i32 @waitpid(i64 %23, i32* %4, i32 0)
br label %28
28: ; preds = %22, %26
store i32 0, i32* %3
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%30 = call i32 @fflush(i32 0)
%31 = call i32 @setup(i8* %5, i8** %11, i32* %3)
%32 = call i64 (...) @fork()
%33 = icmp eq i64 %32, 0
br i1 %33, label %15, label %22
34: ; preds = %15, %18
ret i32 0
}