// File: /workspace/github_cpp_makefile_star2_O3/donfreiday[P]gb/main.cpp
// Function: main_loop()
void main_loop() {
  // Setup SDL and start new ImGui frame
  ImGui_ImplSdl_NewFrame(g_window);

  handleSdlEvents();

  // Run the emulator until vsync or breakpoint
  while ((g_running || g_stepping) && !g_gpu.vsync) {
    g_disasm.knownEntryPoints.insert(g_cpu.reg.pc);

    if (g_stepping) {
      g_stepping = false;
      g_scrollDisasmToPC = true;
    }

    g_cpu.checkInterrupts();
    g_cpu.execute();
    g_gpu.step(g_cpu.cpu_clock_t);

    // Check for breakpoint
    if (g_breakpoints.find(g_cpu.reg.pc) != g_breakpoints.end()) {
      g_running = false;
      g_scrollDisasmToPC = true;
      g_fullscreenLcd = false;
    }
  }
  g_gpu.vsync = false;

  // Render GUI windows
  imguiLCD();
  if (!g_fullscreenLcd) {
    imguiRegisters();
    imguiLcdStatus();
    imguiDisassembly();
    imguiHelp();
  }

  // ImGui::ShowTestWindow();

  // Append FPS to window title
  std::stringstream windowTitle;
  windowTitle << "gb: A Gameboy Emulator    FPS: " << std::fixed
              << std::setprecision(0) << ImGui::GetIO().Framerate;

  // Rendering
  glViewport(0, 0, (int)ImGui::GetIO().DisplaySize.x,
             (int)ImGui::GetIO().DisplaySize.y);
  glClearColor(0, 0, 0, 0);
  glClear(GL_COLOR_BUFFER_BIT);
  ImGui::Render();
  SDL_SetWindowTitle(g_window, windowTitle.str().c_str());
  SDL_GL_SwapWindow(g_window);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1b8, %rsp            # imm = 0x1B8
movq 0x37fe9(%rip), %rdi     # 0x72f58
callq 0x374ab
callq 0x3b208
leaq 0x37f70(%rip), %rbx     # 0x72ef0
leaq 0x24e79(%rip), %r14     # 0x5fe00
leaq 0x24e6a(%rip), %r15     # 0x5fdf8
leaq 0x2710b(%rip), %r12     # 0x620a0
leaq 0x37f8c(%rip), %r13     # 0x72f28
cmpb $0x0, 0x20677(%rip)     # 0x5b61a
je 0x3afb3
cmpb $0x0, 0x27110(%rip)     # 0x620bc
je 0x3afcd
jmp 0x3b069
cmpb $0x1, 0x37f97(%rip)     # 0x72f51
jne 0x3b069
testb $0x1, 0x270f5(%rip)     # 0x620bc
jne 0x3b069
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3c07c
cmpb $0x1, 0x37f72(%rip)     # 0x72f51
jne 0x3afef
movb $0x0, 0x37f69(%rip)     # 0x72f51
movb $0x1, 0x2062c(%rip)     # 0x5b61b
movq %r15, %rdi
callq 0x3aa7e
movq %r15, %rdi
callq 0x3876e
movzbl 0x24dfe(%rip), %esi     # 0x5fe04
movq %r12, %rdi
callq 0x3803e
movq 0x37f1b(%rip), %rcx     # 0x72f30
testq %rcx, %rcx
je 0x3af9c
movzwl 0x24ddf(%rip), %eax     # 0x5fe00
movq %r13, %rdx
xorl %esi, %esi
cmpw %ax, 0x20(%rcx)
setb %sil
cmovaeq %rcx, %rdx
movq 0x10(%rcx,%rsi,8), %rcx
testq %rcx, %rcx
jne 0x3b024
cmpq %r13, %rdx
je 0x3af9c
cmpw 0x20(%rdx), %ax
jb 0x3af9c
xorl %eax, %eax
movb %al, 0x205c3(%rip)      # 0x5b61a
movb $0x1, 0x205bd(%rip)     # 0x5b61b
movb %al, 0x37eee(%rip)      # 0x72f52
jmp 0x3af9c
movb $0x0, 0x2704c(%rip)     # 0x620bc
callq 0x3b2b5
cmpb $0x0, 0x37ed6(%rip)     # 0x72f52
jne 0x3b092
callq 0x3b4af
callq 0x3b541
callq 0x3b62f
callq 0x3ba79
leaq -0x1d8(%rbp), %rdi
callq 0x7200
leaq -0x1c8(%rbp), %rbx
leaq 0xeb1c(%rip), %rsi      # 0x49bc8
movl $0x1f, %edx
movq %rbx, %rdi
callq 0x7710
movq -0x1c8(%rbp), %rax
movq -0x18(%rax), %rcx
movl $0xfffffefb, %edx       # imm = 0xFFFFFEFB
andl -0x1b0(%rbp,%rcx), %edx
orl $0x4, %edx
movl %edx, -0x1b0(%rbp,%rcx)
movq -0x18(%rax), %rax
movq $0x0, -0x1c0(%rbp,%rax)
callq 0xb0ca
cvtss2sd 0x328(%rax), %xmm0
movq %rbx, %rdi
callq 0x7590
callq 0xb0ca
movss (%rax), %xmm0
movss %xmm0, -0x2c(%rbp)
callq 0xb0ca
cvttss2si -0x2c(%rbp), %edx
cvttss2si 0x4(%rax), %ecx
xorl %edi, %edi
xorl %esi, %esi
callq 0x7300
xorps %xmm0, %xmm0
xorps %xmm1, %xmm1
xorps %xmm2, %xmm2
xorps %xmm3, %xmm3
callq 0x7110
movl $0x4000, %edi           # imm = 0x4000
callq 0x7450
callq 0xd147
movq 0x37e0c(%rip), %rbx     # 0x72f58
leaq -0x1c0(%rbp), %rsi
leaq -0x50(%rbp), %rdi
callq 0x72d0
movq -0x50(%rbp), %rsi
movq %rbx, %rdi
callq 0x7170
leaq -0x40(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3b181
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x70d0
movq 0x37dd0(%rip), %rdi     # 0x72f58
callq 0x7260
movq 0x19e54(%rip), %rsi     # 0x54fe8
leaq -0x1d8(%rbp), %rdi
callq 0x7570
leaq -0x158(%rbp), %rdi
callq 0x7510
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x40(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3b1e1
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x70d0
jmp 0x3b1e1
jmp 0x3b1de
movq %rax, %rbx
movq 0x19e00(%rip), %rsi     # 0x54fe8
leaq -0x1d8(%rbp), %rdi
callq 0x7570
leaq -0x158(%rbp), %rdi
callq 0x7510
movq %rbx, %rdi
callq 0x74c0