// File: /workspace/github_cpp_makefile_star2_O2/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 0x39809(%rip), %rdi     # 0x6df58
callq 0x3117d
callq 0x34960
leaq 0x266a0(%rip), %r14     # 0x5ae00
leaq 0x26691(%rip), %r15     # 0x5adf8
leaq 0x397b2(%rip), %r13     # 0x6df20
leaq 0x397b3(%rip), %rbx     # 0x6df28
xorl %r12d, %r12d
cmpb $0x0, 0x21e9b(%rip)     # 0x5661a
je 0x3478f
cmpb $0x0, 0x28934(%rip)     # 0x5d0bc
je 0x347a5
jmp 0x3481c
cmpb $0x1, 0x397bb(%rip)     # 0x6df51
jne 0x3481c
testb $0x1, 0x28919(%rip)     # 0x5d0bc
jne 0x3481c
leaq 0x39744(%rip), %rdi     # 0x6def0
movq %r14, %rsi
callq 0x356da
cmpb $0x1, 0x39796(%rip)     # 0x6df51
jne 0x347cb
movb $0x0, 0x3978d(%rip)     # 0x6df51
movb $0x1, 0x21e50(%rip)     # 0x5661b
movq %r15, %rdi
callq 0x3411e
movq %r15, %rdi
callq 0x323d4
movzbl 0x26622(%rip), %esi     # 0x5ae04
leaq 0x288b7(%rip), %rdi     # 0x5d0a0
callq 0x31d58
movq %r13, %rdi
movq %r14, %rsi
callq 0x35870
cmpq %rbx, %rax
je 0x34778
movb %r12b, 0x21e11(%rip)    # 0x5661a
movb $0x1, 0x21e0b(%rip)     # 0x5661b
movb %r12b, 0x3973b(%rip)    # 0x6df52
jmp 0x34778
movb $0x0, 0x28899(%rip)     # 0x5d0bc
callq 0x349f4
cmpb $0x0, 0x39723(%rip)     # 0x6df52
jne 0x34845
callq 0x34bc3
callq 0x34c53
callq 0x34d3f
callq 0x35125
leaq -0x1d8(%rbp), %rdi
callq 0x7200
leaq -0x1c8(%rbp), %rdi
leaq 0xe5f9(%rip), %rsi      # 0x42e58
callq 0x7450
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rcx
movl $0xfffffefb, %edx       # imm = 0xFFFFFEFB
andl 0x18(%rbx,%rcx), %edx
orl $0x4, %edx
movl %edx, 0x18(%rbx,%rcx)
movq -0x18(%rax), %rax
andq $0x0, 0x8(%rbx,%rax)
callq 0xa0f5
movss 0x328(%rax), %xmm0
movq %rbx, %rdi
callq 0x77a0
callq 0xa0f5
movss (%rax), %xmm0
movss %xmm0, -0x2c(%rbp)
callq 0xa0f5
cvttss2si -0x2c(%rbp), %edx
cvttss2si 0x4(%rax), %ecx
xorl %edi, %edi
xorl %esi, %esi
callq 0x7320
xorps %xmm0, %xmm0
xorps %xmm1, %xmm1
xorps %xmm2, %xmm2
xorps %xmm3, %xmm3
callq 0x7110
movl $0x4000, %edi           # imm = 0x4000
callq 0x7440
callq 0xb71d
movq 0x3966e(%rip), %rbx     # 0x6df58
leaq -0x1c0(%rbp), %rsi
leaq -0x50(%rbp), %rdi
callq 0x72f0
movq -0x50(%rbp), %rsi
movq %rbx, %rdi
callq 0x7170
leaq -0x50(%rbp), %rdi
callq 0x74c0
movq 0x39642(%rip), %rdi     # 0x6df58
callq 0x7270
leaq -0x1d8(%rbp), %rdi
callq 0x72e0
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x74c0
jmp 0x3494c
jmp 0x34949
movq %rax, %rbx
leaq -0x1d8(%rbp), %rdi
callq 0x72e0
movq %rbx, %rdi
callq 0x74b0