// File: /workspace/github_cpp_makefile_star2_O3/rfotino[P]consolite-emulator/src/emu.cpp
// Function: main
int main(int argc, char **argv) {
  if (2 != argc && 3 != argc) {
    usage(argv[0]);
    return 1;
  }

  std::string keymap;
  if (3 == argc) {
    keymap = argv[2];
  } else {
    keymap = DEFAULT_KEYMAP_FILENAME;
  }
  
  EmuVideoMemory vidMem;
  EmuWindow window(&vidMem, keymap);
  EmuProcessor processor(&window, argv[1]);
  if (window.hasError() || processor.hasError()) {
    return 1;
  }

  // Start up separate threads for the UI and processor
  std::thread winThread(win_thread_start, &window);
  std::thread procThread(proc_thread_start, &processor);

  // Join the threads
  winThread.join();
  processor.setRunning(false);
  procThread.join();
  
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x10158, %rsp          # imm = 0x10158
movq %rsi, %rbx
leal -0x4(%rdi), %eax
cmpl $-0x3, %eax
ja 0x3718
movq (%rbx), %rsi
leaq 0x60(%rsp), %rdi
leaq 0x120(%rsp), %rdx
callq 0x3936
leaq 0x60(%rsp), %rdi
callq 0x363c
leaq 0x70(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x370e
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x3260
movl $0x1, %ebp
jmp 0x3888
leaq 0x50(%rsp), %r15
movq %r15, -0x10(%r15)
movq $0x0, -0x8(%r15)
movb $0x0, (%r15)
cmpl $0x3, %edi
jne 0x3754
movq 0x10(%rbx), %r14
movq %r14, %rdi
callq 0x30e0
leaq 0x40(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
movq %r14, %rcx
movq %rax, %r8
callq 0x3390
jmp 0x376f
leaq 0x28c2(%rip), %rcx      # 0x601d
leaq 0x40(%rsp), %rdi
movl $0x8, %r8d
xorl %esi, %esi
xorl %edx, %edx
callq 0x3390
leaq 0x30(%rsp), %rdi
callq 0x3b50
leaq 0x88(%rsp), %rdi
leaq 0x30(%rsp), %rsi
leaq 0x40(%rsp), %rdx
callq 0x3c2c
movq 0x8(%rbx), %rsi
leaq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x3936
leaq 0x120(%rsp), %rbx
leaq 0x88(%rsp), %r14
leaq 0x10(%rsp), %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4a6c
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x37de
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3260
movl $0x1, %ebp
cmpb $0x0, 0xb0(%rsp)
jne 0x385a
cmpb $0x0, 0x1014f(%rsp)
jne 0x385a
leaq 0x8(%rsp), %rdx
movq %r14, (%rdx)
leaq -0x154(%rip), %rsi      # 0x36b2
leaq 0x10(%rsp), %rdi
callq 0x3974
leaq 0x80(%rsp), %rdx
movq %rbx, (%rdx)
leaq -0x16b(%rip), %rsi      # 0x36b7
leaq 0x8(%rsp), %rdi
callq 0x39f4
leaq 0x10(%rsp), %rdi
callq 0x33e0
movb $0x0, 0x10150(%rsp)
leaq 0x8(%rsp), %rdi
callq 0x33e0
cmpq $0x0, 0x8(%rsp)
jne 0x38af
cmpq $0x0, 0x10(%rsp)
jne 0x38af
xorl %ebp, %ebp
leaq 0x88(%rsp), %rdi
callq 0x418a
leaq 0x30(%rsp), %rdi
callq 0x3b7a
movq 0x40(%rsp), %rdi
cmpq %r15, %rdi
je 0x3888
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x3260
movl %ebp, %eax
addq $0x10158, %rsp          # imm = 0x10158
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
jmp 0x38a4
jmp 0x38d4
cmpq $0x0, 0x8(%rsp)
jne 0x38af
movq %rax, %rbx
cmpq $0x0, 0x10(%rsp)
je 0x38d7
callq 0x3080
movq %rax, %rbx
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x38d7
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3260
jmp 0x38d7
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x418a
jmp 0x38e9
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x3b7a
jmp 0x3912
jmp 0x390f
movq %rax, %rbx
leaq 0x70(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x392e
movq 0x70(%rsp), %rsi
jmp 0x3921
movq %rax, %rbx
movq 0x40(%rsp), %rdi
cmpq %r15, %rdi
je 0x392e
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x3260
jmp 0x392e
movq %rax, %rbx
movq %rbx, %rdi
callq 0x3430