// File: /workspace/github_cpp_makefile_star2_O3/donfreiday[P]gb/main.cpp
// Function: imguiLCD()
void imguiLCD() {
  // Update texture
  // bind the texture again when you want to update it.
  glBindTexture(GL_TEXTURE_2D, g_lcdTexture);
  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, g_gpu.width, g_gpu.height, 0, GL_RGB,
               GL_UNSIGNED_BYTE, g_gpu.screenData);

  // Set up window flags
  ImGuiWindowFlags windowFlags = 0;
  windowFlags |= ImGuiWindowFlags_NoTitleBar;
  windowFlags |= ImGuiWindowFlags_NoScrollbar;
  windowFlags |= ImGuiWindowFlags_NoCollapse;
  windowFlags |= ImGuiWindowFlags_NoResize;
  windowFlags |= ImGuiWindowFlags_NoMove;

  // Get window dimensions
  float winWidth = ImGui::GetIO().DisplaySize.x;
  float winHeight = ImGui::GetIO().DisplaySize.y;

  // Fullscreen
  if (g_fullscreenLcd) {
    // Scale while maintaining approximate aspect ratio
    // Todo: calculate proper scale factor
    float width = g_gpu.width;
    float height = g_gpu.height;
    while (width * 1.1f < winWidth && height * 1.1f < winHeight) {
      width *= 1.1;
      height *= 1.1;
    }
    ImGui::SetNextWindowSize(ImVec2(width, height));

    // Position centered
    ImGui::SetNextWindowPosCenter();
  }

  // Windowed
  else {
    // Set the window size to Gameboy LCD dimensions
    ImGui::SetNextWindowSize(ImVec2(g_gpu.width * 2, g_gpu.height * 2));
    // Position top right
    ImGui::SetNextWindowPos(ImVec2(winWidth - g_gpu.width * 2, 0.0f));
  }

  // No padding
  ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));

  // Render window
  ImGui::Begin("lcd", nullptr, windowFlags);
  ImGui::Image((void*)g_lcdTexture, ImGui::GetWindowSize());

  // Done, clean up
  ImGui::End();
  ImGui::PopStyleVar();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x48, %rsp
movl 0x37c98(%rip), %esi     # 0x72f60
movl $0xde1, %edi            # imm = 0xDE1
callq 0x7890
movl 0x26ddc(%rip), %ecx     # 0x620b4
movl 0x26dd9(%rip), %r8d     # 0x620b8
subq $0x8, %rsp
leaq 0x26dd3(%rip), %rax     # 0x620bd
movl $0xde1, %edi            # imm = 0xDE1
xorl %esi, %esi
movl $0x1907, %edx           # imm = 0x1907
xorl %r9d, %r9d
pushq %rax
pushq $0x1401                 # imm = 0x1401
pushq $0x1907                 # imm = 0x1907
callq 0x77f0
addq $0x20, %rsp
callq 0xb0ca
movss (%rax), %xmm0
movss %xmm0, -0x1c(%rbp)
callq 0xb0ca
cmpb $0x1, 0x37c2b(%rip)     # 0x72f52
jne 0x3b3bf
xorps %xmm0, %xmm0
cvtsi2ssl 0x26d7c(%rip), %xmm0 # 0x620b4
cvtsi2ssl 0x26d78(%rip), %xmm1 # 0x620b8
movss 0xe870(%rip), %xmm2     # 0x49bb8
movaps %xmm0, %xmm3
mulss %xmm2, %xmm3
movss -0x1c(%rbp), %xmm6
ucomiss %xmm3, %xmm6
jbe 0x3b3a2
movss 0x4(%rax), %xmm3
movaps %xmm1, %xmm4
mulss %xmm2, %xmm4
ucomiss %xmm4, %xmm3
jbe 0x3b3a2
movsd 0xe84e(%rip), %xmm4     # 0x49bc0
cvtss2sd %xmm0, %xmm0
mulsd %xmm4, %xmm0
cvtsd2ss %xmm0, %xmm0
cvtss2sd %xmm1, %xmm1
mulsd %xmm4, %xmm1
cvtsd2ss %xmm1, %xmm1
movaps %xmm0, %xmm5
mulss %xmm2, %xmm5
ucomiss %xmm5, %xmm6
jbe 0x3b3a2
movaps %xmm1, %xmm5
mulss %xmm2, %xmm5
ucomiss %xmm5, %xmm3
ja 0x3b372
leaq -0x2c(%rbp), %rdi
movss %xmm0, (%rdi)
movss %xmm1, 0x4(%rdi)
xorl %esi, %esi
callq 0xc42a
xorl %edi, %edi
callq 0x153ca
jmp 0x3b41f
movl 0x26cef(%rip), %eax     # 0x620b4
addl %eax, %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
movl 0x26ce4(%rip), %eax     # 0x620b8
addl %eax, %eax
cvtsi2ss %eax, %xmm1
leaq -0x2c(%rbp), %rbx
movss %xmm0, (%rbx)
movss %xmm1, 0x4(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
callq 0xc42a
movl 0x26cbd(%rip), %eax     # 0x620b4
addl %eax, %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
movss -0x1c(%rbp), %xmm1
subss %xmm0, %xmm1
movss %xmm1, (%rbx)
movl $0x0, 0x4(%rbx)
leaq -0x2c(%rbp), %rdi
xorl %esi, %esi
callq 0x153a7
xorl %r15d, %r15d
leaq -0x2c(%rbp), %rbx
movq %r15, (%rbx)
movl $0x1, %edi
movq %rbx, %rsi
callq 0x14ee8
leaq 0xe813(%rip), %rdi      # 0x49c50
xorl %esi, %esi
movl $0x2f, %edx
callq 0xc44d
movl 0x37b10(%rip), %r14d    # 0x72f60
callq 0x1324c
leaq -0x38(%rbp), %rsi
movlps %xmm0, (%rsi)
leaq -0x48(%rbp), %rdx
movq %r15, (%rdx)
movabsq $0x3f8000003f800000, %rax # imm = 0x3F8000003F800000
leaq -0x40(%rbp), %rcx
movq %rax, (%rcx)
movaps 0x1df5(%rip), %xmm0     # 0x3d270
movups %xmm0, (%rbx)
xorps %xmm0, %xmm0
leaq -0x60(%rbp), %r9
movaps %xmm0, (%r9)
leaq -0x2c(%rbp), %r8
movq %r14, %rdi
callq 0x1657b
callq 0xcc43
movl $0x1, %edi
callq 0x12c6e
addq $0x48, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq