#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*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ system(char *);
int main(int argc, char **argv) {
  printf("Welcome to Moses Shell, the most limited experience of your life!\n");
  printf("Version: 0.1.updatesain'tgonnahappen\n");
  printf("Type 'help' for help.\n");
  for (int i = 1; i <= argc; i++) {
    printf("executing command: %s \n", argv[i]);
    system(argv[i]);
  }
  while (1) {
    char cmd[120];
    printf("$: ");
    fgets(cmd, 120, stdin);
    if (strncmp(cmd, "close", 5) == 0) {
      return 0;
    } else if (strncmp(cmd, "help", 4) == 0) {
      printf("simply type 'mshell' and then begin using your favorite command "
             "line things!\n");
      return 0;
    } else if (strncmp(cmd, "close", 5) != 0) {
      system(cmd);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xed5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xeed(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11cf <main+0x8f>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xed7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <system@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    118a <main+0x4a>
jmp    11d4 <main+0x94>
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x90(%rbp),%rdi
mov    0x2df8(%rip),%rax
mov    (%rax),%edx
mov    $0x78,%esi
call   1060 <fgets@plt>
lea    -0x90(%rbp),%rdi
lea    0xe92(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    122a <main+0xea>
movl   $0x0,-0x4(%rbp)
jmp    12a3 <main+0x163>
lea    -0x90(%rbp),%rdi
lea    0xe6a(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1266 <main+0x126>
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12a3 <main+0x163>
lea    -0x90(%rbp),%rdi
lea    0xe28(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     1294 <main+0x154>
lea    -0x90(%rbp),%rdi
call   1040 <system@plt>
jmp    1299 <main+0x159>
jmp    129e <main+0x15e>
jmp    11d4 <main+0x94>
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x80,%rsp
mov    %rsi,%r12
mov    %edi,%r14d
lea    0xeba(%rip),%rdi
call   1040 <puts@plt>
lea    0xef0(%rip),%rdi
call   1040 <puts@plt>
lea    0xf09(%rip),%rdi
call   1040 <puts@plt>
test   %r14d,%r14d
jle    11c0 <main+0x70>
add    $0x1,%r14d
mov    $0x1,%ebx
lea    0xe61(%rip),%r15
nop
mov    (%r12,%rbx,8),%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    (%r12,%rbx,8),%rdi
call   1050 <system@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    11a0 <main+0x50>
lea    0xe51(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2e13(%rip),%r13
mov    0x0(%r13),%edx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x78,%esi
call   1070 <fgets@plt>
lea    0xe2c(%rip),%rsi
mov    %rbx,%rdi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1290 <main+0x140>
lea    0xe15(%rip),%r14
mov    %rsp,%rbx
lea    0xe05(%rip),%r15
lea    0xdfa(%rip),%r12
jmp    1250 <main+0x100>
mov    %r12,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x0(%r13),%edx
mov    %rbx,%rdi
mov    $0x78,%esi
call   1070 <fgets@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1290 <main+0x140>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1284 <main+0x134>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1220 <main+0xd0>
mov    %rbx,%rdi
call   1050 <system@plt>
jmp    1220 <main+0xd0>
lea    0xe19(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [67 x i8] c"Welcome to Moses Shell, the most limited experience of your life!\0A\00"
@.str.1 = [38 x i8] c"Version: 0.1.updatesain'tgonnahappen\0A\00"
@.str.2 = [23 x i8] c"Type 'help' for help.\0A\00"
@.str.3 = [24 x i8] c"executing command: %s \0A\00"
@.str.4 = [4 x i8] c"$: \00"
@stdin = global i32 0
@.str.5 = [6 x i8] c"close\00"
@.str.6 = [5 x i8] c"help\00"
@.str.7 = [78 x i8] c"simply type 'mshell' and then begin using your favorite command line things!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [120 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %6
br label %11
11: ; preds = %28, %2
%12 = load i32, i32* %6
%13 = load i32, i32* %4
%14 = icmp sle i32 %12, %13
br i1 %14, label %15, label %31
15: ; preds = %11
%16 = load i8**, i8*** %5
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8*, i8** %16, i64 %18
%20 = load i8*, i8** %19
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %20)
%22 = load i8**, i8*** %5
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %22, i64 %24
%26 = load i8*, i8** %25
%27 = call i32 @system(i8* %26)
br label %28
28: ; preds = %15
%29 = load i32, i32* %6
%30 = add nsw i32 %29, 1
store i32 %30, i32* %6
br label %11
31: ; preds = %11
br label %32
32: ; preds = %31, %56
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%34 = getelementptr inbounds [120 x i8], [120 x i8]* %7, i64 0, i64 0
%35 = load i32, i32* @stdin
%36 = call i32 @fgets(i8* %34, i32 120, i32 %35)
%37 = getelementptr inbounds [120 x i8], [120 x i8]* %7, i64 0, i64 0
%38 = call i64 @strncmp(i8* %37, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 5)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %32
store i32 0, i32* %3
br label %57
41: ; preds = %32
%42 = getelementptr inbounds [120 x i8], [120 x i8]* %7, i64 0, i64 0
%43 = call i64 @strncmp(i8* %42, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 4)
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %41
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.7, i64 0, i64 0))
store i32 0, i32* %3
br label %57
47: ; preds = %41
%48 = getelementptr inbounds [120 x i8], [120 x i8]* %7, i64 0, i64 0
%49 = call i64 @strncmp(i8* %48, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 5)
%50 = icmp ne i64 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %47
%52 = getelementptr inbounds [120 x i8], [120 x i8]* %7, i64 0, i64 0
%53 = call i32 @system(i8* %52)
br label %54
54: ; preds = %51, %47
br label %55
55: ; preds = %54
br label %56
56: ; preds = %55
br label %32
57: ; preds = %45, %40
%58 = load i32, i32* %3
ret i32 %58
}

LLVM IR (-O2):
@.str.3 = [24 x i8] c"executing command: %s \0A\00"
@.str.4 = [4 x i8] c"$: \00"
@stdin = global i32 0
@.str.5 = [6 x i8] c"close\00"
@.str.6 = [5 x i8] c"help\00"
@str = [66 x i8] c"Welcome to Moses Shell, the most limited experience of your life!\00"
@str.8 = [37 x i8] c"Version: 0.1.updatesain'tgonnahappen\00"
@str.9 = [22 x i8] c"Type 'help' for help.\00"
@str.10 = [77 x i8] c"simply type 'mshell' and then begin using your favorite command line things!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [120 x i8]
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([66 x i8], [66 x i8]* @str, i64 0, i64 0))
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.8, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.9, i64 0, i64 0))
%7 = icmp slt i32 %0, 1
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = add nuw i32 %0, 1
%10 = zext i32 %9 to i64
br label %18
11: ; preds = %18, %2
%12 = getelementptr inbounds [120 x i8], [120 x i8]* %3, i64 0, i64 0
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%14 = load i32, i32* @stdin
%15 = call i32 @fgets(i8* %12, i32 120, i32 %14)
%16 = call i64 @strncmp(i8* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 5)
%17 = icmp eq i64 %16, 0
br i1 %17, label %43, label %27
18: ; preds = %8, %18
%19 = phi i64 [ 1, %8 ], [ %25, %18 ]
%20 = getelementptr inbounds i8*, i8** %1, i64 %19
%21 = load i8*, i8** %20
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %21)
%23 = load i8*, i8** %20
%24 = tail call i32 @system(i8* %23)
%25 = add nuw nsw i64 %19, 1
%26 = icmp eq i64 %25, %10
br i1 %26, label %11, label %18
27: ; preds = %11, %37
%28 = call i64 @strncmp(i8* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 4)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([77 x i8], [77 x i8]* @str.10, i64 0, i64 0))
br label %43
32: ; preds = %27
%33 = call i64 @strncmp(i8* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 5)
%34 = icmp eq i64 %33, 0
br i1 %34, label %37, label %35
35: ; preds = %32
%36 = call i32 @system(i8* %12)
br label %37
37: ; preds = %32, %35
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%39 = load i32, i32* @stdin
%40 = call i32 @fgets(i8* %12, i32 120, i32 %39)
%41 = call i64 @strncmp(i8* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 5)
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %27
43: ; preds = %37, %11, %30
ret i32 0
}