// File: /workspace/github_cpp_makefile_star2_O1/mindbeast[P]rnes/main.cpp
// Function: main
int main(int argc, char *argv[]) {
  using namespace std;
  namespace fs = boost::filesystem;
  string romFile;
  bool romFileSpecified = false;

  // Verify that the version of the library that we linked against is
  // compatible with the version of the headers we compiled against.
  GOOGLE_PROTOBUF_VERIFY_VERSION;

  // TODO: convert argument parsing to boost program options
  for (int i = 0; i < argc; i++) {
    if (argv[i] == string("--rom") || argv[i] == string("-r")) {
      romFile = argv[i + 1];
      romFileSpecified = true;
      i += 2;
    }
  }

  if (!romFileSpecified) {
    displayHelpAndQuit();
  }

  try {
    // verify the rom file exists.
    verifyRomExists(romFile);

    auto nes = unique_ptr<Nes>{new Nes{}};
    int res = nes->loadRom(romFile);
    if (res) {
      cerr << "Failed to load rom: " << romFile << endl;
      exit(1);
    }

    // Setup the rnes directories.
    setupDirectories(md5OfFile(romFile));

    // Start the emulator loop.
    nes->run();
  } catch (const fs::filesystem_error &exception) {
    cerr << "Exception: " << exception.what() << endl;
    return -1;
  } catch (const std::exception &exception) {
    cerr << "Exception: " << exception.what() << endl;
    return -1;
  } catch (...) {
    cerr << "Unknown Exception!" << endl;
    return -1;
  }

  google::protobuf::ShutdownProtobufLibrary();
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %rsi, -0x38(%rbp)
movl %edi, %r15d
leaq -0x48(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x1e30f(%rip), %rdx     # 0x34093
movl $0x2df5a4, %edi         # imm = 0x2DF5A4
movl $0x2df5a0, %esi         # imm = 0x2DF5A0
callq 0xb100
testl %r15d, %r15d
jle 0x16000
movq $0x0, -0x80(%rbp)
leaq -0x78(%rbp), %rbx
xorl %r14d, %r14d
movl %r15d, -0x2c(%rbp)
movslq %r14d, %r13
movq -0x38(%rbp), %rax
movq (%rax,%r13,8), %r12
leaq -0x68(%rbp), %rax
movq %rax, -0x78(%rbp)
movq %rbx, %rdi
leaq 0x1e2d0(%rip), %rsi     # 0x3409c
leaq 0x1e2ce(%rip), %rdx     # 0x340a1
callq 0x181ba
movq %rbx, %rdi
movq %r12, %rsi
callq 0xb6f0
movl %eax, %r12d
testl %eax, %eax
je 0x15e30
movq -0x38(%rbp), %rax
movq (%rax,%r13,8), %r15
leaq -0xf0(%rbp), %rax
movq %rax, -0x100(%rbp)
leaq -0x100(%rbp), %rbx
movq %rbx, %rdi
leaq 0x1e291(%rip), %rsi     # 0x340a2
leaq 0x1e28c(%rip), %rdx     # 0x340a4
callq 0x181ba
movq %rbx, %rdi
movq %r15, %rsi
callq 0xb6f0
testl %eax, %eax
sete %r15b
jmp 0x15e33
movb $0x1, %r15b
testl %r12d, %r12d
je 0x15e5a
movq -0x100(%rbp), %rdi
leaq -0xf0(%rbp), %rax
cmpq %rax, %rdi
je 0x15e5a
movq -0xf0(%rbp), %rsi
incq %rsi
callq 0xb0e0
movq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rax
cmpq %rax, %rdi
je 0x15e73
movq -0x68(%rbp), %rsi
incq %rsi
callq 0xb0e0
testb %r15b, %r15b
je 0x15eab
movq -0x38(%rbp), %rax
movq 0x8(%rax,%r13,8), %r15
movq -0x50(%rbp), %r12
movq %r15, %rdi
callq 0xb330
leaq -0x58(%rbp), %rdi
xorl %esi, %esi
movq %r12, %rdx
movq %r15, %rcx
movq %rax, %r8
callq 0xb3d0
addl $0x2, %r14d
movb $0x1, %al
movq %rax, -0x80(%rbp)
movl -0x2c(%rbp), %r15d
leaq -0x78(%rbp), %rbx
incl %r14d
cmpl %r15d, %r14d
jl 0x15daf
testb $0x1, -0x80(%rbp)
je 0x16000
leaq -0xb0(%rbp), %r15
movq %r15, -0x10(%r15)
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
addq %rsi, %rdx
leaq -0xc0(%rbp), %rdi
callq 0x18120
leaq -0xc0(%rbp), %rdi
callq 0x1586d
movq -0xc0(%rbp), %rdi
cmpq %r15, %rdi
je 0x15f12
movq -0xb0(%rbp), %rsi
incq %rsi
callq 0xb0e0
movl $0x88, %edi
callq 0xb130
movq %rax, %r15
movq %rax, %rdi
callq 0x2238c
movq %r15, -0x78(%rbp)
leaq -0x58(%rbp), %rsi
movq %r15, %rdi
callq 0x21d86
testl %eax, %eax
jne 0x1601d
leaq -0x90(%rbp), %r15
movq %r15, -0x10(%r15)
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
addq %rsi, %rdx
leaq -0xa0(%rbp), %rdi
callq 0x18120
leaq -0xe0(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x151ad
leaq -0xe0(%rbp), %rdi
callq 0x15652
leaq -0xd0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x15f9f
movq -0xd0(%rbp), %rsi
incq %rsi
callq 0xb0e0
movq -0xa0(%rbp), %rdi
cmpq %r15, %rdi
je 0x15fba
movq -0x90(%rbp), %rsi
incq %rsi
callq 0xb0e0
movq -0x78(%rbp), %rdi
callq 0x218d4
leaq -0x78(%rbp), %rdi
callq 0x1655a
xorl %ebx, %ebx
callq 0xb860
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x15fec
movq -0x48(%rbp), %rsi
incq %rsi
callq 0xb0e0
movl %ebx, %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x31fe9(%rip), %rdi     # 0x47ff0
leaq 0x32782(%rip), %rsi     # 0x48790
callq 0xb250
movl $0x1, %edi
callq 0xb4f0
movq 0x31fcc(%rip), %rdi     # 0x47ff0
leaq 0x1e07a(%rip), %rsi     # 0x340a5
movl $0x14, %edx
callq 0xb7a0
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq 0x31fac(%rip), %rdi     # 0x47ff0
callq 0xb7a0
movq %rax, %rdi
callq 0xb800
jmp 0x16013
movq %rdx, %rbx
movq %rax, %r14
leaq -0xd0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x16080
movq -0xd0(%rbp), %rsi
incq %rsi
callq 0xb0e0
jmp 0x16080
movq %rdx, %rbx
movq %rax, %r14
movq -0xa0(%rbp), %rdi
cmpq %r15, %rdi
je 0x160e0
movq -0x90(%rbp), %rsi
incq %rsi
callq 0xb0e0
jmp 0x160e0
movq %rdx, %rbx
movq %rax, %r14
movl $0x88, %esi
movq %r15, %rdi
jmp 0x160cb
jmp 0x160d2
movq %rdx, %rbx
movq %rax, %r14
movq -0xc0(%rbp), %rdi
cmpq %r15, %rdi
je 0x160e9
movq -0xb0(%rbp), %rsi
incq %rsi
callq 0xb0e0
jmp 0x160e9
movq %rdx, %rbx
movq %rax, %r14
jmp 0x160e9
movq %rdx, %rbx
movq %rax, %r14
leaq -0x78(%rbp), %rdi
callq 0x1655a
movq %r14, %rdi
cmpl $0x3, %ebx
jne 0x16140
callq 0xb060
movq %rax, %rbx
movq 0x31ef0(%rip), %rdi     # 0x47ff0
leaq 0x1df73(%rip), %rsi     # 0x3407a
movl $0xb, %edx
callq 0xb7a0
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movq 0x31ecf(%rip), %rdi     # 0x47ff0
movq %rax, %rsi
callq 0xb430
movq %rax, %rdi
callq 0xb800
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
callq 0xb5e0
jmp 0x15fd3
callq 0xb060
cmpl $0x2, %ebx
jne 0x16194
movq %rax, %r14
movq 0x31e9c(%rip), %rdi     # 0x47ff0
leaq 0x1df1f(%rip), %rsi     # 0x3407a
movl $0xb, %edx
callq 0xb7a0
movq (%r14), %rax
movq %r14, %rdi
callq *0x10(%rax)
movq 0x31e7b(%rip), %rdi     # 0x47ff0
movq %rax, %rsi
callq 0xb430
movq %rax, %rdi
callq 0xb800
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
callq 0xb5e0
jmp 0x15fd3
movq 0x31e55(%rip), %rdi     # 0x47ff0
leaq 0x1df18(%rip), %rsi     # 0x340ba
movl $0x12, %edx
callq 0xb7a0
movq 0x31e3d(%rip), %rdi     # 0x47ff0
callq 0xb800
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
callq 0xb5e0
jmp 0x15fd3
jmp 0x16213
movq %rax, %rbx
callq 0xb5e0
jmp 0x16216
jmp 0x16213
movq %rax, %rbx
callq 0xb5e0
jmp 0x16216
movq %rax, %rbx
callq 0xb5e0
jmp 0x16216
movq %rax, %rdi
callq 0x16237
jmp 0x16213
jmp 0x16213
movq %rax, %rbx
movq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rax
cmpq %rax, %rdi
je 0x16216
movq -0x68(%rbp), %rsi
incq %rsi
callq 0xb0e0
jmp 0x16216
movq %rax, %rbx
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x1622f
movq -0x48(%rbp), %rsi
incq %rsi
callq 0xb0e0
movq %rbx, %rdi
callq 0xb4d0