// File: /workspace/github_cpp_makefile_star2_O1/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 0x378f5(%rip), %rdi     # 0x72f68
callq 0x37e13
callq 0x3b916
leaq 0x3787c(%rip), %rbx     # 0x72f00
leaq 0x24785(%rip), %r14     # 0x5fe10
leaq 0x24776(%rip), %r15     # 0x5fe08
leaq 0x26a17(%rip), %r12     # 0x620b0
leaq 0x37898(%rip), %r13     # 0x72f38
cmpb $0x0, 0x1ff83(%rip)     # 0x5b62a
je 0x3b6b7
cmpb $0x0, 0x26a1c(%rip)     # 0x620cc
je 0x3b6d1
jmp 0x3b777
cmpb $0x1, 0x378a3(%rip)     # 0x72f61
jne 0x3b777
testb $0x1, 0x26a01(%rip)     # 0x620cc
jne 0x3b777
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3c794
cmpb $0x1, 0x3787e(%rip)     # 0x72f61
jne 0x3b6f3
movb $0x0, 0x37875(%rip)     # 0x72f61
movb $0x1, 0x1ff38(%rip)     # 0x5b62b
movq %r15, %rdi
callq 0x3b13e
movq %r15, %rdi
callq 0x3909a
movzbl 0x2470a(%rip), %esi     # 0x5fe14
movq %r12, %rdi
callq 0x3896e
movq 0x37827(%rip), %rcx     # 0x72f40
movq %r13, %rax
testq %rcx, %rcx
je 0x3b743
movzwl 0x246e8(%rip), %edx     # 0x5fe10
movq %r13, %rax
xorl %esi, %esi
cmpw %dx, 0x20(%rcx)
setb %sil
cmovaeq %rcx, %rax
movq 0x10(%rcx,%rsi,8), %rcx
testq %rcx, %rcx
jne 0x3b72b
cmpq %r13, %rax
je 0x3b6a0
movzwl 0x246bd(%rip), %ecx     # 0x5fe10
cmpw 0x20(%rax), %cx
jb 0x3b6a0
xorl %eax, %eax
movb %al, 0x1fec5(%rip)      # 0x5b62a
movb $0x1, 0x1febf(%rip)     # 0x5b62b
movb %al, 0x377f0(%rip)      # 0x72f62
jmp 0x3b6a0
movb $0x0, 0x2694e(%rip)     # 0x620cc
callq 0x3b9c3
cmpb $0x0, 0x377d8(%rip)     # 0x72f62
jne 0x3b7a0
callq 0x3bbbd
callq 0x3bc4f
callq 0x3bd3d
callq 0x3c199
leaq -0x1d8(%rbp), %rdi
callq 0x7210
leaq -0x1c8(%rbp), %rbx
leaq 0xe466(%rip), %rsi      # 0x49c20
movl $0x1f, %edx
movq %rbx, %rdi
callq 0x7720
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 0xb1e1
cvtss2sd 0x328(%rax), %xmm0
movq %rbx, %rdi
callq 0x75a0
callq 0xb1e1
movss (%rax), %xmm0
movss %xmm0, -0x2c(%rbp)
callq 0xb1e1
cvttss2si -0x2c(%rbp), %edx
cvttss2si 0x4(%rax), %ecx
xorl %edi, %edi
xorl %esi, %esi
callq 0x7310
xorps %xmm0, %xmm0
xorps %xmm1, %xmm1
xorps %xmm2, %xmm2
xorps %xmm3, %xmm3
callq 0x7110
movl $0x4000, %edi           # imm = 0x4000
callq 0x7460
callq 0xd32b
movq 0x3770e(%rip), %rbx     # 0x72f68
leaq -0x1c0(%rbp), %rsi
leaq -0x50(%rbp), %rdi
callq 0x72e0
movq -0x50(%rbp), %rsi
movq %rbx, %rdi
callq 0x7170
leaq -0x40(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3b88f
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x70d0
movq 0x376d2(%rip), %rdi     # 0x72f68
callq 0x7270
movq 0x19746(%rip), %rsi     # 0x54fe8
leaq -0x1d8(%rbp), %rdi
callq 0x7580
leaq -0x158(%rbp), %rdi
callq 0x7520
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 0x3b8ef
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x70d0
jmp 0x3b8ef
jmp 0x3b8ec
movq %rax, %rbx
movq 0x196f2(%rip), %rsi     # 0x54fe8
leaq -0x1d8(%rbp), %rdi
callq 0x7580
leaq -0x158(%rbp), %rdi
callq 0x7520
movq %rbx, %rdi
callq 0x74d0