// File: /workspace/github_cpp_makefile_star2_O1/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 0x3759a(%rip), %esi     # 0x72f70
movl $0xde1, %edi            # imm = 0xDE1
callq 0x78b0
movl 0x266de(%rip), %ecx     # 0x620c4
movl 0x266db(%rip), %r8d     # 0x620c8
subq $0x8, %rsp
leaq 0x266d5(%rip), %rax     # 0x620cd
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 0x7810
addq $0x20, %rsp
callq 0xb1e1
movss (%rax), %xmm0
movss %xmm0, -0x1c(%rbp)
callq 0xb1e1
cmpb $0x1, 0x3752d(%rip)     # 0x72f62
jne 0x3bacd
xorps %xmm0, %xmm0
cvtsi2ssl 0x2667e(%rip), %xmm0 # 0x620c4
cvtsi2ssl 0x2667a(%rip), %xmm1 # 0x620c8
movss 0xe1ba(%rip), %xmm2     # 0x49c10
movaps %xmm0, %xmm3
mulss %xmm2, %xmm3
movss -0x1c(%rbp), %xmm6
ucomiss %xmm3, %xmm6
jbe 0x3bab0
movss 0x4(%rax), %xmm3
movaps %xmm1, %xmm4
mulss %xmm2, %xmm4
ucomiss %xmm4, %xmm3
jbe 0x3bab0
movsd 0xe198(%rip), %xmm4     # 0x49c18
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 0x3bab0
movaps %xmm1, %xmm5
mulss %xmm2, %xmm5
ucomiss %xmm5, %xmm3
ja 0x3ba80
leaq -0x2c(%rbp), %rdi
movss %xmm0, (%rdi)
movss %xmm1, 0x4(%rdi)
xorl %esi, %esi
callq 0xc578
xorl %edi, %edi
callq 0x15826
jmp 0x3bb2d
movl 0x265f1(%rip), %eax     # 0x620c4
addl %eax, %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
movl 0x265e6(%rip), %eax     # 0x620c8
addl %eax, %eax
cvtsi2ss %eax, %xmm1
leaq -0x2c(%rbp), %rbx
movss %xmm0, (%rbx)
movss %xmm1, 0x4(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
callq 0xc578
movl 0x265bf(%rip), %eax     # 0x620c4
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 0x15803
xorl %r15d, %r15d
leaq -0x2c(%rbp), %rbx
movq %r15, (%rbx)
movl $0x1, %edi
movq %rbx, %rsi
callq 0x15319
leaq 0xe15d(%rip), %rdi      # 0x49ca8
xorl %esi, %esi
movl $0x2f, %edx
callq 0xc59b
movl 0x37412(%rip), %r14d    # 0x72f70
callq 0x135e9
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 0x16d7(%rip), %xmm0     # 0x3d260
movups %xmm0, (%rbx)
xorps %xmm0, %xmm0
leaq -0x60(%rbp), %r9
movaps %xmm0, (%r9)
leaq -0x2c(%rbp), %r8
movq %r14, %rdi
callq 0x16a22
callq 0xcdc7
movl $0x1, %edi
callq 0x12ffd
addq $0x48, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq