// File: /workspace/github_cpp_makefile_star2_O1/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 $0x30, %rsp
movq %rdi, %rbx
movq 0xa9aa4(%rip), %r14     # 0xfdcd0
movss 0x160c(%r14), %xmm0
movss 0x1610(%r14), %xmm1
movss 0x10(%r14), %xmm2
movss 0x14(%r14), %xmm3
movaps %xmm0, %xmm4
addss %xmm0, %xmm4
movaps 0x62d68(%rip), %xmm5    # 0xb6fc0
xorps %xmm5, %xmm0
cmpltss %xmm2, %xmm4
andps %xmm0, %xmm4
movaps %xmm1, %xmm0
addss %xmm1, %xmm0
xorps %xmm5, %xmm1
cmpltss %xmm3, %xmm0
andps %xmm1, %xmm0
xorps %xmm1, %xmm1
xorps %xmm5, %xmm5
subss %xmm4, %xmm5
subss %xmm0, %xmm1
unpcklps %xmm1, %xmm5            # xmm5 = xmm5[0],xmm1[0],xmm5[1],xmm1[1]
addss %xmm2, %xmm4
addss %xmm3, %xmm0
unpcklps %xmm0, %xmm4            # xmm4 = xmm4[0],xmm0[0],xmm4[1],xmm0[1]
movlhps %xmm4, %xmm5            # xmm5 = xmm5[0],xmm4[0]
movups %xmm5, -0x40(%rbp)
movl 0xc(%rdi), %eax
btl $0x1c, %eax
jb 0x5431d
btl $0x1a, %eax
jb 0x54382
btl $0x19, %eax
jae 0x544e8
movss 0x1614(%r14), %xmm0
movss %xmm0, -0x1c(%rbp)
callq 0x5803f
movlps %xmm0, -0x18(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x30(%rbp)
cmpb $0x0, 0x1ce6(%r14)
jne 0x54433
cmpb $0x1, 0x1ce7(%r14)
jne 0x54433
testb $0x4, 0x8(%r14)
jne 0x54433
movss -0x18(%rbp), %xmm0
movss -0x14(%rbp), %xmm1
movss 0x635ac(%rip), %xmm2    # 0xb78b8
addss %xmm0, %xmm2
movss 0x635c0(%rip), %xmm3    # 0xb78d8
jmp 0x54451
cmpq %rbx, 0x1ae0(%r14)
jne 0x544aa
movslq 0x1ab8(%r14), %rax
cmpq $0x1, %rax
jle 0x544c9
movq 0x1ac0(%r14), %rcx
movq -0x10(%rcx,%rax,8), %rax
movss 0x15b0(%r14), %xmm2
xorps %xmm0, %xmm0
movaps %xmm0, -0x30(%rbp)
cmpb $0x1, 0x15e(%rax)
jne 0x543d0
movss 0x25c(%rax), %xmm3
movss 0x264(%rax), %xmm2
movss 0x634c8(%rip), %xmm0    # 0xb7840
movss 0x63528(%rip), %xmm1    # 0xb78a8
jmp 0x543fd
leaq 0x10(%rbx), %rdi
movss 0x10(%rbx), %xmm0
movss 0x14(%rbx), %xmm1
movss 0x62c38(%rip), %xmm2    # 0xb6fd0
movaps %xmm0, %xmm3
addss %xmm2, %xmm3
addss %xmm1, %xmm2
movss 0x62c39(%rip), %xmm4    # 0xb6fe4
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 0x5441c
movss 0x10(%rax), %xmm0
movaps %xmm2, %xmm1
addss %xmm0, %xmm1
addss 0x18(%rax), %xmm0
subss %xmm2, %xmm0
subss 0x84(%rax), %xmm0
movss 0x6344b(%rip), %xmm2    # 0xb7840
movss 0x634ab(%rip), %xmm3    # 0xb78a8
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 -0x40(%rbp), %rcx
movq %rbx, %rdx
xorl %r9d, %r9d
jmp 0x5449c
movss -0x18(%rbp), %xmm0
movss -0x1c(%rbp), %xmm3
mulss 0x63497(%rip), %xmm3    # 0xb78dc
movss -0x14(%rbp), %xmm1
movaps %xmm3, %xmm2
addss %xmm0, %xmm2
addss %xmm1, %xmm3
addss 0x63483(%rip), %xmm1    # 0xb78e0
addss 0x6347f(%rip), %xmm0    # 0xb78e4
leaq -0x30(%rbp), %r8
movss %xmm0, (%r8)
movss %xmm1, 0x4(%r8)
movss %xmm2, 0x8(%r8)
movss %xmm3, 0xc(%r8)
leaq 0x18(%rbx), %rsi
addq $0xa8, %rbx
leaq -0x18(%rbp), %rdi
leaq -0x40(%rbp), %rcx
movq %rbx, %rdx
movl $0x2, %r9d
callq 0x5897c
addq $0x30, %rsp
popq %rbx
popq %r14
popq %rbp
retq
leaq 0x65de0(%rip), %rdi     # 0xba291
leaq 0x63cad(%rip), %rsi     # 0xb8165
leaq 0x65dec(%rip), %rcx     # 0xba2ab
movl $0x207e, %edx           # imm = 0x207E
callq 0xc140
leaq 0x671a8(%rip), %rdi     # 0xbb678
leaq 0x671b4(%rip), %rsi     # 0xbb68b
leaq 0x68589(%rip), %rcx     # 0xbca67
movl $0x65c, %edx            # imm = 0x65C
callq 0xc140
leaq 0x65bfd(%rip), %rdi     # 0xba0ec
leaq 0x63c6f(%rip), %rsi     # 0xb8165
leaq 0x65dae(%rip), %rcx     # 0xba2ab
movl $0x2099, %edx           # imm = 0x2099
callq 0xc140