// File: /workspace/github_cpp_makefile_star2_O2/Ciaxur[P]yagb-emu/include/imgui/imgui.cpp
// Function: ImGui::FindBestWindowPosForPopup(ImGuiWindow*)
ImVec2 ImGui::FindBestWindowPosForPopup(ImGuiWindow* window)
{
    ImGuiContext& g = *GImGui;

    ImRect r_outer = GetWindowAllowedExtentRect(window);
    if (window->Flags & ImGuiWindowFlags_ChildMenu)
    {
        // Child menus typically request _any_ position within the parent menu item, and then we move the new menu outside the parent bounds.
        // This is how we end up with child menus appearing (most-commonly) on the right of the parent menu.
        IM_ASSERT(g.CurrentWindow == window);
        ImGuiWindow* parent_window = g.CurrentWindowStack[g.CurrentWindowStack.Size - 2];
        float horizontal_overlap = g.Style.ItemInnerSpacing.x; // We want some overlap to convey the relative depth of each menu (currently the amount of overlap is hard-coded to style.ItemSpacing.x).
        ImRect r_avoid;
        if (parent_window->DC.MenuBarAppending)
            r_avoid = ImRect(-FLT_MAX, parent_window->ClipRect.Min.y, FLT_MAX, parent_window->ClipRect.Max.y); // Avoid parent menu-bar. If we wanted multi-line menu-bar, we may instead want to have the calling window setup e.g. a NextWindowData.PosConstraintAvoidRect field
        else
            r_avoid = ImRect(parent_window->Pos.x + horizontal_overlap, -FLT_MAX, parent_window->Pos.x + parent_window->Size.x - horizontal_overlap - parent_window->ScrollbarSizes.x, FLT_MAX);
        return FindBestWindowPosForPopupEx(window->Pos, window->Size, &window->AutoPosLastDirection, r_outer, r_avoid, ImGuiPopupPositionPolicy_Default);
    }
    if (window->Flags & ImGuiWindowFlags_Popup)
    {
        ImRect r_avoid = ImRect(window->Pos.x - 1, window->Pos.y - 1, window->Pos.x + 1, window->Pos.y + 1);
        return FindBestWindowPosForPopupEx(window->Pos, window->Size, &window->AutoPosLastDirection, r_outer, r_avoid, ImGuiPopupPositionPolicy_Default);
    }
    if (window->Flags & ImGuiWindowFlags_Tooltip)
    {
        // Position tooltip (always follows mouse)
        float sc = g.Style.MouseCursorScale;
        ImVec2 ref_pos = NavCalcPreferredRefPos();
        ImRect r_avoid;
        if (!g.NavDisableHighlight && g.NavDisableMouseHover && !(g.IO.ConfigFlags & ImGuiConfigFlags_NavEnableSetMousePos))
            r_avoid = ImRect(ref_pos.x - 16, ref_pos.y - 8, ref_pos.x + 16, ref_pos.y + 8);
        else
            r_avoid = ImRect(ref_pos.x - 16, ref_pos.y - 8, ref_pos.x + 24 * sc, ref_pos.y + 24 * sc); // FIXME: Hard-coded based on mouse cursor shape expectation. Exact dimension not very important.
        return FindBestWindowPosForPopupEx(ref_pos, window->Size, &window->AutoPosLastDirection, r_outer, r_avoid, ImGuiPopupPositionPolicy_Tooltip);
    }
    IM_ASSERT(0);
    return window->Pos;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x40, %rsp
movq %rdi, %rbx
movq 0xa21f6(%rip), %r14     # 0xe3ce0
callq 0x4539b
movlhps %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0]
movups %xmm0, -0x48(%rbp)
movl 0xc(%rbx), %eax
btl $0x1c, %eax
jb 0x41b78
btl $0x1a, %eax
jb 0x41bcc
btl $0x19, %eax
jae 0x41d14
movss 0x1614(%r14), %xmm0
movss %xmm0, -0x14(%rbp)
callq 0x44854
movlps %xmm0, -0x38(%rbp)
xorps %xmm1, %xmm1
movaps %xmm1, -0x30(%rbp)
movaps %xmm0, %xmm1
shufps $0x55, %xmm0, %xmm1     # xmm1 = xmm1[1,1],xmm0[1,1]
cmpb $0x0, 0x1ce6(%r14)
jne 0x41c86
cmpb $0x1, 0x1ce7(%r14)
jne 0x41c86
testb $0x4, 0x8(%r14)
jne 0x41c86
movss 0x5ad81(%rip), %xmm2    # 0x9c8e8
addss %xmm0, %xmm2
movss 0x5ad95(%rip), %xmm4    # 0x9c908
jmp 0x41c9a
cmpq %rbx, 0x1ae0(%r14)
jne 0x41cf5
leaq 0x1ab8(%r14), %rdi
movl 0x1ab8(%r14), %esi
addl $-0x2, %esi
callq 0x4ad62
movq (%rax), %rax
cmpb $0x1, 0x15e(%rax)
jne 0x41c1a
movss 0x25c(%rax), %xmm3
movss 0x264(%rax), %xmm2
movss 0x5acb1(%rip), %xmm0    # 0x9c870
movss 0x5ad11(%rip), %xmm1    # 0x9c8d8
jmp 0x41c50
leaq 0x10(%rbx), %rdi
movss 0x10(%rbx), %xmm0
movss 0x14(%rbx), %xmm1
movss 0x5a40e(%rip), %xmm2    # 0x9bff0
movaps %xmm0, %xmm3
addss %xmm2, %xmm3
addss %xmm1, %xmm2
movss 0x5a403(%rip), %xmm4    # 0x9bff8
addss %xmm4, %xmm0
addss %xmm4, %xmm1
leaq -0x30(%rbp), %r8
movss %xmm3, (%r8)
movss %xmm2, 0x4(%r8)
movss %xmm0, 0x8(%r8)
movss %xmm1, 0xc(%r8)
jmp 0x41c6f
movss 0x15b0(%r14), %xmm2
movss 0x10(%rax), %xmm0
movaps %xmm2, %xmm1
addss %xmm0, %xmm1
addss 0x18(%rax), %xmm0
subss %xmm2, %xmm0
subss 0x84(%rax), %xmm0
movss 0x5ac28(%rip), %xmm2    # 0x9c870
movss 0x5ac88(%rip), %xmm3    # 0x9c8d8
leaq -0x30(%rbp), %r8
movss %xmm1, (%r8)
movss %xmm3, 0x4(%r8)
movss %xmm0, 0x8(%r8)
movss %xmm2, 0xc(%r8)
leaq 0x10(%rbx), %rdi
leaq 0x18(%rbx), %rsi
addq $0xa8, %rbx
leaq -0x48(%rbp), %rcx
movq %rbx, %rdx
xorl %r9d, %r9d
jmp 0x41ce7
movss -0x14(%rbp), %xmm4
mulss 0x5ac79(%rip), %xmm4    # 0x9c90c
movaps %xmm4, %xmm2
addss %xmm0, %xmm2
addss %xmm1, %xmm4
addss 0x5ac6a(%rip), %xmm1    # 0x9c910
movss 0x5ac66(%rip), %xmm3    # 0x9c914
addss %xmm0, %xmm3
leaq -0x30(%rbp), %r8
movss %xmm3, (%r8)
movss %xmm1, 0x4(%r8)
movss %xmm2, 0x8(%r8)
movss %xmm4, 0xc(%r8)
leaq 0x18(%rbx), %rsi
addq $0xa8, %rbx
leaq -0x38(%rbp), %rdi
leaq -0x48(%rbp), %rcx
pushq $0x2
popq %r9
movq %rbx, %rdx
callq 0x44ffe
addq $0x40, %rsp
popq %rbx
popq %r14
popq %rbp
retq
leaq 0x5d5c5(%rip), %rdi     # 0x9f2c1
leaq 0x5b492(%rip), %rsi     # 0x9d195
leaq 0x5d5d1(%rip), %rcx     # 0x9f2db
movl $0x207e, %edx           # imm = 0x207E
callq 0xc140
leaq 0x5d401(%rip), %rdi     # 0x9f11c
leaq 0x5b473(%rip), %rsi     # 0x9d195
leaq 0x5d5b2(%rip), %rcx     # 0x9f2db
movl $0x2099, %edx           # imm = 0x2099
callq 0xc140