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

/* Variables and functions */
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ printf(char *);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ wait(int *);
int main() {
  pid_t pid;
  int option, stat;
  char cmdbuf[80];
  char *cmdargs[4];
  while (1) {
    printf("myshell> ");
    gets(cmdbuf);
    cmdargs[0] = cmdbuf;
    cmdargs[1] = 0;
    if (strncmp(cmdbuf, "ver", 3) == 0) {
      printf("Simple shell version 1.00, Sep 25, 2008\n");
      continue;
    }
    if (strncmp(cmdbuf, "quit", 4) == 0)
      exit(0);
    if (fork() == 0) {
      execvp(cmdbuf, cmdargs);
      exit(0);
    }
    pid = wait(&stat);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe77(%rip),%rdi
call   1040 <printf@plt>
lea    -0x60(%rbp),%rdi
call   1050 <gets@plt>
lea    -0x60(%rbp),%rax
mov    %rax,-0x80(%rbp)
movq   $0x0,-0x78(%rbp)
lea    -0x60(%rbp),%rdi
lea    0xe58(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11d7 <main+0x67>
lea    0xe41(%rip),%rdi
call   1040 <printf@plt>
jmp    1182 <main+0x12>
lea    -0x60(%rbp),%rdi
lea    0xe55(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11fd <main+0x8d>
xor    %edi,%edi
call   1070 <exit@plt>
mov    $0x0,%al
call   1090 <fork@plt>
cmp    $0x0,%rax
jne    1222 <main+0xb2>
lea    -0x60(%rbp),%rdi
lea    -0x80(%rbp),%rsi
call   1060 <execvp@plt>
xor    %edi,%edi
call   1070 <exit@plt>
lea    -0x10(%rbp),%rdi
call   1080 <wait@plt>
mov    %eax,-0x8(%rbp)
jmp    1182 <main+0x12>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
lea    0xe68(%rip),%r14
lea    0x30(%rsp),%rbx
lea    0xe66(%rip),%r15
lea    0xe68(%rip),%r12
lea    0xe5c(%rip),%r13
lea    0xc(%rsp),%rbp
jmp    11c8 <main+0x48>
nopl   0x0(%rax)
mov    %r12,%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1060 <gets@plt>
mov    %rbx,0x10(%rsp)
movq   $0x0,0x18(%rsp)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11c0 <main+0x40>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1226 <main+0xa6>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %rax,%rax
je     122d <main+0xad>
mov    %rbp,%rdi
call   1090 <wait@plt>
jmp    11c8 <main+0x48>
xor    %edi,%edi
call   1080 <exit@plt>
lea    0x30(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1070 <execvp@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"myshell> \00"
@.str.1 = [4 x i8] c"ver\00"
@.str.2 = [41 x i8] c"Simple shell version 1.00, Sep 25, 2008\0A\00"
@.str.3 = [5 x i8] c"quit\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [80 x i8]
%6 = alloca [4 x i8*]
store i32 0, i32* %1
br label %7
7: ; preds = %0, %17, %33
%8 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%10 = call i32 @gets(i8* %9)
%11 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%12 = getelementptr inbounds [4 x i8*], [4 x i8*]* %6, i64 0, i64 0
store i8* %11, i8** %12
%13 = getelementptr inbounds [4 x i8*], [4 x i8*]* %6, i64 0, i64 1
store i8* null, i8** %13
%14 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%15 = call i64 @strncmp(i8* %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %7
%18 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0))
br label %7
19: ; preds = %7
%20 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%21 = call i64 @strncmp(i8* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = call i32 @exit(i32 0)
unreachable
25: ; preds = %19
%26 = call i64 (...) @fork()
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %25
%29 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%30 = getelementptr inbounds [4 x i8*], [4 x i8*]* %6, i64 0, i64 0
%31 = call i32 @execvp(i8* %29, i8** %30)
%32 = call i32 @exit(i32 0)
unreachable
33: ; preds = %25
%34 = call i32 @wait(i32* %4)
store i32 %34, i32* %2
br label %7
}

LLVM IR (-O2):
@.str = [10 x i8] c"myshell> \00"
@.str.1 = [4 x i8] c"ver\00"
@.str.3 = [5 x i8] c"quit\00"
@str = [40 x i8] c"Simple shell version 1.00, Sep 25, 2008\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [80 x i8]
%3 = alloca [4 x i8*]
%4 = bitcast i32* %1 to i8*
%5 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%6 = bitcast [4 x i8*]* %3 to i8*
%7 = getelementptr inbounds [4 x i8*], [4 x i8*]* %3, i64 0, i64 0
%8 = getelementptr inbounds [4 x i8*], [4 x i8*]* %3, i64 0, i64 1
br label %9
9: ; preds = %16, %0
%10 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @gets(i8* %5)
store i8* %5, i8** %7
store i8* null, i8** %8
%12 = call i64 @strncmp(i8* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
br label %16
16: ; preds = %14, %28
br label %9
17: ; preds = %9
%18 = call i64 @strncmp(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 @exit(i32 0)
unreachable
22: ; preds = %17
%23 = call i64 (...) @fork()
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = call i32 @execvp(i8* %5, i8** %7)
%27 = call i32 @exit(i32 0)
unreachable
28: ; preds = %22
%29 = call i32 @wait(i32* %1)
br label %16
}