#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ parse_args(char *, char **, int, size_t *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strcmp(char *, char *);
int main(int argc, char *argv[], char *envp[]) {
  char buffer[1 << 16];
  char *args[1 << 16];
  int *ret_status;
  size_t nargs;
  pid_t pid;
  while (1) {
    printf("$ ");
    fgets(buffer, 1 << 16, stdin);
    parse_args(buffer, args, 1 << 16, &nargs);
    if (nargs == 0)
      continue;
    if (!strcmp(args[0], "exit"))
      exit(0);
    if (!strcmp(args[0], "ver")) {
      printf("losh - version 1.0\n");
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90040,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    0xe8c(%rip),%rdi
call   1030 <printf@plt>
lea    -0x10020(%rbp),%rdi
mov    0x2e61(%rip),%rax
mov    (%rax),%edx
mov    $0x10000,%esi
call   1050 <fgets@plt>
lea    -0x10020(%rbp),%rdi
lea    -0x90020(%rbp),%rsi
mov    $0x10000,%edx
lea    -0x90030(%rbp),%rcx
call   1040 <parse_args@plt>
cmpq   $0x0,-0x90030(%rbp)
jne    11c5 <main+0x75>
jmp    116d <main+0x1d>
mov    -0x90020(%rbp),%rdi
lea    0xe30(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    11e8 <main+0x98>
xor    %edi,%edi
call   1070 <exit@plt>
mov    -0x90020(%rbp),%rdi
lea    0xe12(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    1210 <main+0xc0>
lea    0xe01(%rip),%rdi
call   1030 <printf@plt>
jmp    116d <main+0x1d>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x90018,%rsp
lea    0xe88(%rip),%r14
mov    0x2e69(%rip),%rbp
lea    0x10(%rsp),%rbx
lea    0x10010(%rsp),%r15
lea    0x8(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1040 <printf@plt>
mov    0x0(%rbp),%edx
mov    %rbx,%rdi
mov    $0x10000,%esi
call   1060 <fgets@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x10000,%edx
mov    %r12,%rcx
call   1050 <parse_args@plt>
cmpq   $0x0,0x8(%rsp)
je     11a0 <main+0x40>
mov    0x10010(%rsp),%r13
mov    %r13,%rdi
lea    0xe1e(%rip),%rsi
call   1070 <strcmp@plt>
test   %eax,%eax
je     120f <main+0xaf>
mov    %r13,%rdi
lea    0xe10(%rip),%rsi
call   1070 <strcmp@plt>
test   %eax,%eax
jne    11a0 <main+0x40>
lea    0xe04(%rip),%rdi
call   1030 <puts@plt>
jmp    11a0 <main+0x40>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"$ \00"
@stdin = global i32 0
@.str.1 = [5 x i8] c"exit\00"
@.str.2 = [4 x i8] c"ver\00"
@.str.3 = [20 x i8] c"losh - version 1.0\0A\00"
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca [65536 x i8]
%9 = alloca [65536 x i8*]
%10 = alloca i32*
%11 = alloca i64
%12 = alloca i32
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
br label %13
13: ; preds = %3, %23, %38
%14 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%15 = getelementptr inbounds [65536 x i8], [65536 x i8]* %8, i64 0, i64 0
%16 = load i32, i32* @stdin
%17 = call i32 @fgets(i8* %15, i32 65536, i32 %16)
%18 = getelementptr inbounds [65536 x i8], [65536 x i8]* %8, i64 0, i64 0
%19 = getelementptr inbounds [65536 x i8*], [65536 x i8*]* %9, i64 0, i64 0
%20 = call i32 @parse_args(i8* %18, i8** %19, i32 65536, i64* %11)
%21 = load i64, i64* %11
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %13
br label %13
24: ; preds = %13
%25 = getelementptr inbounds [65536 x i8*], [65536 x i8*]* %9, i64 0, i64 0
%26 = load i8*, i8** %25
%27 = call i32 @strcmp(i8* %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp ne i32 %27, 0
br i1 %28, label %31, label %29
29: ; preds = %24
%30 = call i32 @exit(i32 0)
unreachable
31: ; preds = %24
%32 = getelementptr inbounds [65536 x i8*], [65536 x i8*]* %9, i64 0, i64 0
%33 = load i8*, i8** %32
%34 = call i32 @strcmp(i8* %33, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%35 = icmp ne i32 %34, 0
br i1 %35, label %38, label %36
36: ; preds = %31
%37 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %38
38: ; preds = %36, %31
br label %13
}

LLVM IR (-O2):
@.str = [3 x i8] c"$ \00"
@stdin = global i32 0
@.str.1 = [5 x i8] c"exit\00"
@.str.2 = [4 x i8] c"ver\00"
@str = [19 x i8] c"losh - version 1.0\00"
define i32 @main(i32 %0, i8** nocapture readnone %1, i8** nocapture readnone %2) {
%4 = alloca [65536 x i8]
%5 = alloca [65536 x i8*]
%6 = alloca i64
%7 = getelementptr inbounds [65536 x i8], [65536 x i8]* %4, i64 0, i64 0
%8 = bitcast [65536 x i8*]* %5 to i8*
%9 = bitcast i64* %6 to i8*
%10 = getelementptr inbounds [65536 x i8*], [65536 x i8*]* %5, i64 0, i64 0
br label %11
11: ; preds = %27, %3
%12 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @stdin
%14 = call i32 @fgets(i8* %7, i32 65536, i32 %13)
%15 = call i32 @parse_args(i8* %7, i8** %10, i32 65536, i64* %6)
%16 = load i64, i64* %6
%17 = icmp eq i64 %16, 0
br i1 %17, label %27, label %18
18: ; preds = %11
%19 = load i8*, i8** %10
%20 = call i32 @strcmp(i8* dereferenceable(1) %19, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = call i32 @exit(i32 0)
unreachable
24: ; preds = %18
%25 = call i32 @strcmp(i8* dereferenceable(1) %19, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%26 = icmp eq i32 %25, 0
br i1 %26, label %28, label %27
27: ; preds = %24, %28, %11
br label %11
28: ; preds = %24
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %27
}