// File: 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
subq $0xc0, %rsp
movq %rdi, -0x10(%rbp)
movq 0x13b9ca(%rip), %rax    # 0x212f40
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rdi
callq 0xdf210
movlpd %xmm0, -0x28(%rbp)
movlpd %xmm1, -0x20(%rbp)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
andl $0x10000000, %eax       # imm = 0x10000000
cmpl $0x0, %eax
je 0xd76ef
movq -0x18(%rbp), %rax
movq 0x1ae0(%rax), %rax
cmpq -0x10(%rbp), %rax
jne 0xd75b5
jmp 0xd75d4
leaq 0x9dcf3(%rip), %rdi     # 0x1752af
leaq 0x9b946(%rip), %rsi     # 0x172f09
movl $0x207e, %edx           # imm = 0x207E
leaq 0x9dcfa(%rip), %rcx     # 0x1752c9
callq 0xd180
movq -0x18(%rbp), %rdi
addq $0x1ab8, %rdi           # imm = 0x1AB8
movq -0x18(%rbp), %rax
movl 0x1ab8(%rax), %esi
subl $0x2, %esi
callq 0xea8d0
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movss 0x15b0(%rax), %xmm0
movss %xmm0, -0x34(%rbp)
leaq -0x44(%rbp), %rdi
callq 0xe8c60
movq -0x30(%rbp), %rax
testb $0x1, 0x15e(%rax)
je 0xd7662
movq -0x30(%rbp), %rax
movss 0x25c(%rax), %xmm1
movq -0x30(%rbp), %rax
movss 0x264(%rax), %xmm3
leaq -0x54(%rbp), %rdi
movss 0x9b115(%rip), %xmm0    # 0x172758
movss 0x9a969(%rip), %xmm2    # 0x171fb4
callq 0xec090
movq -0x54(%rbp), %rax
movq %rax, -0x44(%rbp)
movq -0x4c(%rbp), %rax
movq %rax, -0x3c(%rbp)
jmp 0xd76bc
movq -0x30(%rbp), %rax
movss 0x10(%rax), %xmm0
addss -0x34(%rbp), %xmm0
movq -0x30(%rbp), %rax
movss 0x10(%rax), %xmm2
movq -0x30(%rbp), %rax
addss 0x18(%rax), %xmm2
subss -0x34(%rbp), %xmm2
movq -0x30(%rbp), %rax
subss 0x84(%rax), %xmm2
leaq -0x64(%rbp), %rdi
movss 0x9b0b9(%rip), %xmm1    # 0x172758
movss 0x9a90d(%rip), %xmm3    # 0x171fb4
callq 0xec090
movq -0x64(%rbp), %rax
movq %rax, -0x44(%rbp)
movq -0x5c(%rbp), %rax
movq %rax, -0x3c(%rbp)
movq -0x10(%rbp), %rdx
movq %rdx, %rdi
addq $0x10, %rdi
movq %rdx, %rsi
addq $0x18, %rsi
addq $0xa8, %rdx
leaq -0x28(%rbp), %rcx
leaq -0x44(%rbp), %r8
xorl %r9d, %r9d
callq 0xdead0
movlpd %xmm0, -0x8(%rbp)
jmp 0xd7911
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
andl $0x4000000, %eax        # imm = 0x4000000
cmpl $0x0, %eax
je 0xd7772
movq -0x10(%rbp), %rax
movss 0x10(%rax), %xmm2
movss 0x14(%rax), %xmm3
movss 0x99526(%rip), %xmm4    # 0x170c3c
movaps %xmm2, %xmm0
subss %xmm4, %xmm0
movaps %xmm3, %xmm1
subss %xmm4, %xmm1
addss %xmm4, %xmm2
addss %xmm4, %xmm3
leaq -0x74(%rbp), %rdi
movq %rdi, -0xb8(%rbp)
callq 0xec090
movq -0xb8(%rbp), %r8
movq -0x10(%rbp), %rdx
movq %rdx, %rdi
addq $0x10, %rdi
movq %rdx, %rsi
addq $0x18, %rsi
addq $0xa8, %rdx
leaq -0x28(%rbp), %rcx
xorl %r9d, %r9d
callq 0xdead0
movlpd %xmm0, -0x8(%rbp)
jmp 0xd7911
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
andl $0x2000000, %eax        # imm = 0x2000000
cmpl $0x0, %eax
je 0xd78f2
movq -0x18(%rbp), %rax
movss 0x1614(%rax), %xmm0
movss %xmm0, -0x78(%rbp)
callq 0xde000
movlpd %xmm0, -0x80(%rbp)
leaq -0x90(%rbp), %rdi
callq 0xe8c60
movq -0x18(%rbp), %rax
testb $0x1, 0x1ce6(%rax)
jne 0xd7841
movq -0x18(%rbp), %rax
testb $0x1, 0x1ce7(%rax)
je 0xd7841
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
jne 0xd7841
movss -0x80(%rbp), %xmm0
movss 0x9afa8(%rip), %xmm1    # 0x172790
subss %xmm1, %xmm0
movss -0x7c(%rbp), %xmm1
movss 0x9af4b(%rip), %xmm2    # 0x172744
subss %xmm2, %xmm1
movss 0x9af8b(%rip), %xmm2    # 0x172790
addss -0x80(%rbp), %xmm2
movss 0x9af32(%rip), %xmm3    # 0x172744
addss -0x7c(%rbp), %xmm3
leaq -0xa0(%rbp), %rdi
callq 0xec090
movq -0xa0(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0x88(%rbp)
jmp 0xd78bf
movss -0x80(%rbp), %xmm0
movss 0x9af42(%rip), %xmm1    # 0x172790
subss %xmm1, %xmm0
movss -0x7c(%rbp), %xmm1
movss 0x9aee5(%rip), %xmm2    # 0x172744
subss %xmm2, %xmm1
movss -0x80(%rbp), %xmm3
movss -0x78(%rbp), %xmm2
movss 0x9af33(%rip), %xmm4    # 0x1727a8
mulss %xmm4, %xmm2
addss %xmm3, %xmm2
movss -0x7c(%rbp), %xmm4
movss -0x78(%rbp), %xmm3
movss 0x9af19(%rip), %xmm5    # 0x1727a8
mulss %xmm5, %xmm3
addss %xmm4, %xmm3
leaq -0xb0(%rbp), %rdi
callq 0xec090
movq -0xb0(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0xa8(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x10(%rbp), %rdx
movq %rdx, %rsi
addq $0x18, %rsi
addq $0xa8, %rdx
leaq -0x80(%rbp), %rdi
leaq -0x28(%rbp), %rcx
leaq -0x90(%rbp), %r8
movl $0x2, %r9d
callq 0xdead0
movlpd %xmm0, -0x8(%rbp)
jmp 0xd7911
leaq 0x9d811(%rip), %rdi     # 0x17510a
leaq 0x9b609(%rip), %rsi     # 0x172f09
movl $0x2099, %edx           # imm = 0x2099
leaq 0x9d9bd(%rip), %rcx     # 0x1752c9
callq 0xd180
movsd -0x8(%rbp), %xmm0
addq $0xc0, %rsp
popq %rbp
retq
nop