// File: /workspace/github_cpp_makefile_star2_O2/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 0x39559(%rip), %esi     # 0x6df60
movl $0xde1, %edi            # imm = 0xDE1
callq 0x7870
movl 0x2869d(%rip), %ecx     # 0x5d0b4
movl 0x2869a(%rip), %r8d     # 0x5d0b8
subq $0x8, %rsp
leaq 0x28694(%rip), %rax     # 0x5d0bd
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 0x77d0
addq $0x20, %rsp
callq 0xa0f5
movss (%rax), %xmm0
movss %xmm0, -0x1c(%rbp)
callq 0xa0f5
cmpb $0x1, 0x394ec(%rip)     # 0x6df52
jne 0x34ae1
cvtsi2ssl 0x28644(%rip), %xmm0 # 0x5d0b4
cvtsi2ssl 0x28640(%rip), %xmm1 # 0x5d0b8
movss 0x4(%rax), %xmm2
movss 0xe3c3(%rip), %xmm3     # 0x42e48
movsd 0xe3c3(%rip), %xmm4     # 0x42e50
movss -0x1c(%rbp), %xmm6
movaps %xmm0, %xmm5
mulss %xmm3, %xmm5
ucomiss %xmm5, %xmm6
jbe 0x34ac4
movaps %xmm1, %xmm5
mulss %xmm3, %xmm5
ucomiss %xmm5, %xmm2
jbe 0x34ac4
cvtss2sd %xmm0, %xmm0
mulsd %xmm4, %xmm0
cvtsd2ss %xmm0, %xmm0
cvtss2sd %xmm1, %xmm1
mulsd %xmm4, %xmm1
cvtsd2ss %xmm1, %xmm1
jmp 0x34a92
leaq -0x2c(%rbp), %rdi
movss %xmm0, (%rdi)
movss %xmm1, 0x4(%rdi)
xorl %esi, %esi
callq 0xb0b1
xorl %edi, %edi
callq 0x11ac8
jmp 0x34b38
movl 0x285cd(%rip), %eax     # 0x5d0b4
addl %eax, %eax
cvtsi2ss %eax, %xmm0
movl 0x285c5(%rip), %eax     # 0x5d0b8
addl %eax, %eax
cvtsi2ss %eax, %xmm1
leaq -0x2c(%rbp), %rbx
movss %xmm0, (%rbx)
movss %xmm1, 0x4(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
callq 0xb0b1
movl 0x2859e(%rip), %eax     # 0x5d0b4
addl %eax, %eax
cvtsi2ss %eax, %xmm0
movss -0x1c(%rbp), %xmm1
subss %xmm0, %xmm1
movss %xmm1, (%rbx)
andl $0x0, 0x4(%rbx)
leaq -0x2c(%rbp), %rdi
xorl %esi, %esi
callq 0x11aa5
leaq -0x2c(%rbp), %r14
andq $0x0, (%r14)
pushq $0x1
popq %rbx
movl %ebx, %edi
movq %r14, %rsi
callq 0x116b2
leaq 0xe38c(%rip), %rdi      # 0x42ee0
pushq $0x2f
popq %rdx
xorl %esi, %esi
callq 0xb0d4
movl 0x393fb(%rip), %r15d    # 0x6df60
callq 0xff92
leaq -0x38(%rbp), %rsi
movlps %xmm0, (%rsi)
leaq -0x48(%rbp), %rdx
andq $0x0, (%rdx)
movabsq $0x3f8000003f800000, %rax # imm = 0x3F8000003F800000
leaq -0x40(%rbp), %rcx
movq %rax, (%rcx)
movaps 0x16df(%rip), %xmm0     # 0x36270
movups %xmm0, (%r14)
xorps %xmm0, %xmm0
leaq -0x60(%rbp), %r9
movaps %xmm0, (%r9)
leaq -0x2c(%rbp), %r8
movq %r15, %rdi
callq 0x12ad6
callq 0xb516
movl %ebx, %edi
callq 0xfb23
addq $0x48, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq