// File: /workspace/github_cpp_makefile_star2_O3/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 0xa8ae4(%rip), %r14     # 0xfbcd0
movss 0x160c(%r14), %xmm0
movss 0x1610(%r14), %xmm1
movss 0x10(%r14), %xmm2
movss 0x14(%r14), %xmm3
movaps %xmm0, %xmm4
addss %xmm0, %xmm4
movaps 0x61da8(%rip), %xmm5    # 0xb4fc0
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, -0x48(%rbp)
movl 0xc(%rdi), %eax
btl $0x1c, %eax
jb 0x532da
btl $0x1a, %eax
jb 0x53332
btl $0x19, %eax
jae 0x5349b
movss 0x1614(%r14), %xmm0
movss %xmm0, -0x14(%rbp)
callq 0x56f29
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 0x533ec
cmpb $0x1, 0x1ce7(%r14)
jne 0x533ec
testb $0x4, 0x8(%r14)
jne 0x533ec
movss 0x625ef(%rip), %xmm2    # 0xb58b8
addss %xmm0, %xmm2
movss 0x62603(%rip), %xmm4    # 0xb58d8
jmp 0x53400
cmpq %rbx, 0x1ae0(%r14)
jne 0x5345d
movslq 0x1ab8(%r14), %rax
cmpq $0x1, %rax
jle 0x5347c
movq 0x1ac0(%r14), %rcx
movq -0x10(%rcx,%rax,8), %rax
cmpb $0x1, 0x15e(%rax)
jne 0x53380
movss 0x25c(%rax), %xmm3
movss 0x264(%rax), %xmm2
movss 0x6251b(%rip), %xmm0    # 0xb5840
movss 0x6257b(%rip), %xmm1    # 0xb58a8
jmp 0x533b6
leaq 0x10(%rbx), %rdi
movss 0x10(%rbx), %xmm0
movss 0x14(%rbx), %xmm1
movss 0x61c88(%rip), %xmm2    # 0xb4fd0
movaps %xmm0, %xmm3
addss %xmm2, %xmm3
addss %xmm1, %xmm2
movss 0x61c89(%rip), %xmm4    # 0xb4fe4
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 0x533d5
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 0x62492(%rip), %xmm2    # 0xb5840
movss 0x624f2(%rip), %xmm3    # 0xb58a8
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 0x5344f
movss -0x14(%rbp), %xmm4
mulss 0x624e3(%rip), %xmm4    # 0xb58dc
movaps %xmm4, %xmm2
addss %xmm0, %xmm2
addss %xmm1, %xmm4
addss 0x624d4(%rip), %xmm1    # 0xb58e0
movss 0x624d0(%rip), %xmm3    # 0xb58e4
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
movq %rbx, %rdx
movl $0x2, %r9d
callq 0x57828
addq $0x40, %rsp
popq %rbx
popq %r14
popq %rbp
retq
leaq 0x64e2d(%rip), %rdi     # 0xb8291
leaq 0x62cfa(%rip), %rsi     # 0xb6165
leaq 0x64e39(%rip), %rcx     # 0xb82ab
movl $0x207e, %edx           # imm = 0x207E
callq 0xc140
leaq 0x661f5(%rip), %rdi     # 0xb9678
leaq 0x66201(%rip), %rsi     # 0xb968b
leaq 0x675d6(%rip), %rcx     # 0xbaa67
movl $0x65c, %edx            # imm = 0x65C
callq 0xc140
leaq 0x64c4a(%rip), %rdi     # 0xb80ec
leaq 0x62cbc(%rip), %rsi     # 0xb6165
leaq 0x64dfb(%rip), %rcx     # 0xb82ab
movl $0x2099, %edx           # imm = 0x2099
callq 0xc140