#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*/ initializeMemory();
int /*<<< orphan*/ loadCartridgeWithFilename(char *);
int /*<<< orphan*/ printf(char *, ...);
int stringMatches(char *, char *);
int /*<<< orphan*/ updateEmulator();
int main(int argc, char *argv[]) {
  if (argc < 2) {
    printf("Nope! Usage is: %s -rom romname.gb\n", argv[0]);
  } else {
    int isRom = stringMatches("-rom", argv[1]);
    int isHelp = stringMatches("-help", argv[1]);
    int isTest = stringMatches("-test", argv[1]);
    int isDis = stringMatches("-dis", argv[1]);
    if (isRom == 1) {
      loadCartridgeWithFilename(argv[2]);
      initializeMemory();
      updateEmulator();
    } else if (isHelp == 1) {
      printf("TODO: make help page lol\n");
    } else if (isTest == 1) {
      printf("This mode will prove all opcodes are implimented.\n");
    } else if (isDis == 1) {
      printf("This mode just spits out disassembly");
    } else {
      printf("Unknown Argument\n");
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    118a <main+0x3a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1289 <main+0x139>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe8b(%rip),%rdi
call   1060 <stringMatches@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe79(%rip),%rdi
call   1060 <stringMatches@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe68(%rip),%rdi
call   1060 <stringMatches@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe57(%rip),%rdi
call   1060 <stringMatches@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x1,-0x14(%rbp)
jne    1210 <main+0xc0>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1050 <loadCartridgeWithFilename@plt>
mov    $0x0,%al
call   1040 <initializeMemory@plt>
mov    $0x0,%al
call   1070 <updateEmulator@plt>
jmp    1284 <main+0x134>
cmpl   $0x1,-0x18(%rbp)
jne    122d <main+0xdd>
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    127f <main+0x12f>
cmpl   $0x1,-0x1c(%rbp)
jne    124a <main+0xfa>
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    127a <main+0x12a>
cmpl   $0x1,-0x20(%rbp)
jne    1267 <main+0x117>
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1275 <main+0x125>
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    127a <main+0x12a>
jmp    127f <main+0x12f>
jmp    1284 <main+0x134>
jmp    1289 <main+0x139>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x1,%edi
jg     1185 <main+0x25>
mov    (%rbx),%rsi
lea    0xe87(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    122a <main+0xca>
mov    0x8(%rbx),%rsi
lea    0xe94(%rip),%rdi
call   1070 <stringMatches@plt>
mov    %eax,%ebp
mov    0x8(%rbx),%rsi
lea    0xe87(%rip),%rdi
call   1070 <stringMatches@plt>
mov    %eax,%r15d
mov    0x8(%rbx),%rsi
lea    0xe7a(%rip),%rdi
call   1070 <stringMatches@plt>
mov    %eax,%r14d
mov    0x8(%rbx),%rsi
lea    0xe6d(%rip),%rdi
call   1070 <stringMatches@plt>
cmp    $0x1,%ebp
jne    11eb <main+0x8b>
mov    0x10(%rbx),%rdi
call   1060 <loadCartridgeWithFilename@plt>
xor    %eax,%eax
call   1050 <initializeMemory@plt>
xor    %eax,%eax
call   1080 <updateEmulator@plt>
jmp    122a <main+0xca>
cmp    $0x1,%r15d
jne    11fa <main+0x9a>
lea    0xeaa(%rip),%rdi
jmp    1225 <main+0xc5>
cmp    $0x1,%r14d
jne    1209 <main+0xa9>
lea    0xe69(%rip),%rdi
jmp    1225 <main+0xc5>
cmp    $0x1,%eax
jne    121e <main+0xbe>
lea    0xe25(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    122a <main+0xca>
lea    0xe3a(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [36 x i8] c"Nope! Usage is: %s -rom romname.gb\0A\00"
@.str.1 = [5 x i8] c"-rom\00"
@.str.2 = [6 x i8] c"-help\00"
@.str.3 = [6 x i8] c"-test\00"
@.str.4 = [5 x i8] c"-dis\00"
@.str.5 = [26 x i8] c"TODO: make help page lol\0A\00"
@.str.6 = [51 x i8] c"This mode will prove all opcodes are implimented.\0A\00"
@.str.7 = [37 x i8] c"This mode just spits out disassembly\00"
@.str.8 = [18 x i8] c"Unknown Argument\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %15)
br label %64
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @stringMatches(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %20)
store i32 %21, i32* %6
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @stringMatches(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %24)
store i32 %25, i32* %7
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @stringMatches(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %28)
store i32 %29, i32* %8
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32 @stringMatches(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %32)
store i32 %33, i32* %9
%34 = load i32, i32* %6
%35 = icmp eq i32 %34, 1
br i1 %35, label %36, label %43
36: ; preds = %17
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 2
%39 = load i8*, i8** %38
%40 = call i32 @loadCartridgeWithFilename(i8* %39)
%41 = call i32 (...) @initializeMemory()
%42 = call i32 (...) @updateEmulator()
br label %63
43: ; preds = %17
%44 = load i32, i32* %7
%45 = icmp eq i32 %44, 1
br i1 %45, label %46, label %48
46: ; preds = %43
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
br label %62
48: ; preds = %43
%49 = load i32, i32* %8
%50 = icmp eq i32 %49, 1
br i1 %50, label %51, label %53
51: ; preds = %48
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.6, i64 0, i64 0))
br label %61
53: ; preds = %48
%54 = load i32, i32* %9
%55 = icmp eq i32 %54, 1
br i1 %55, label %56, label %58
56: ; preds = %53
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0))
br label %60
58: ; preds = %53
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i64 0, i64 0))
br label %60
60: ; preds = %58, %56
br label %61
61: ; preds = %60, %51
br label %62
62: ; preds = %61, %46
br label %63
63: ; preds = %62, %36
br label %64
64: ; preds = %63, %12
ret i32 0
}

LLVM IR (-O2):
@.str = [36 x i8] c"Nope! Usage is: %s -rom romname.gb\0A\00"
@.str.1 = [5 x i8] c"-rom\00"
@.str.2 = [6 x i8] c"-help\00"
@.str.3 = [6 x i8] c"-test\00"
@.str.4 = [5 x i8] c"-dis\00"
@.str.7 = [37 x i8] c"This mode just spits out disassembly\00"
@str = [17 x i8] c"Unknown Argument\00"
@str.9 = [50 x i8] c"This mode will prove all opcodes are implimented.\00"
@str.10 = [25 x i8] c"TODO: make help page lol\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %38
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @stringMatches(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%11 = load i8*, i8** %8
%12 = tail call i32 @stringMatches(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %11)
%13 = load i8*, i8** %8
%14 = tail call i32 @stringMatches(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %13)
%15 = load i8*, i8** %8
%16 = tail call i32 @stringMatches(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %15)
%17 = icmp eq i32 %10, 1
br i1 %17, label %18, label %24
18: ; preds = %7
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
%21 = tail call i32 @loadCartridgeWithFilename(i8* %20)
%22 = tail call i32 (...) @initializeMemory()
%23 = tail call i32 (...) @updateEmulator()
br label %38
24: ; preds = %7
%25 = icmp eq i32 %12, 1
br i1 %25, label %26, label %28
26: ; preds = %24
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.10, i64 0, i64 0))
br label %38
28: ; preds = %24
%29 = icmp eq i32 %14, 1
br i1 %29, label %30, label %32
30: ; preds = %28
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str.9, i64 0, i64 0))
br label %38
32: ; preds = %28
%33 = icmp eq i32 %16, 1
br i1 %33, label %34, label %36
34: ; preds = %32
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0))
br label %38
36: ; preds = %32
%37 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
br label %38
38: ; preds = %18, %30, %36, %34, %26, %4
ret i32 0
}