// File: /workspace/github_cpp_makefile_star2_O1/donfreiday[P]gb/./imgui/imgui.cpp
// Function: FindBestPopupWindowPos(ImVec2 const&, ImVec2 const&, int, int*, ImRect const&)
static ImVec2 FindBestPopupWindowPos(const ImVec2& base_pos, const ImVec2& size, ImGuiWindowFlags flags, int* last_dir, const ImRect& r_inner)
{
    const ImGuiStyle& style = GImGui->Style;

    // Clamp into visible area while not overlapping the cursor
    ImRect r_outer(GetVisibleRect());
    r_outer.Reduce(style.DisplaySafeAreaPadding);
    ImVec2 base_pos_clamped = ImClamp(base_pos, r_outer.Min, r_outer.Max - size);

    for (int n = (*last_dir != -1) ? -1 : 0; n < 4; n++)   // Right, down, up, left. Favor last used direction.
    {
        const int dir = (n == -1) ? *last_dir : n;
        ImRect rect(dir == 0 ? r_inner.Max.x : r_outer.Min.x, dir == 1 ? r_inner.Max.y : r_outer.Min.y, dir == 3 ? r_inner.Min.x : r_outer.Max.x, dir == 2 ? r_inner.Min.y : r_outer.Max.y);
        if (rect.GetWidth() < size.x || rect.GetHeight() < size.y)
            continue;
        *last_dir = dir;
        return ImVec2(dir == 0 ? r_inner.Max.x : dir == 3 ? r_inner.Min.x - size.x : base_pos_clamped.x, dir == 1 ? r_inner.Max.y : dir == 2 ? r_inner.Min.y - size.y : base_pos_clamped.y);
    }

    // Fallback
    *last_dir = -1;
    if (flags & ImGuiWindowFlags_Tooltip) // For tooltip we prefer avoiding the cursor at all cost even if it means that part of the tooltip won't be visible.
        return base_pos + ImVec2(2,2);

    // Otherwise try to keep within display
    ImVec2 pos = base_pos;
    pos.x = ImMax(ImMin(pos.x + size.x, r_outer.Max.x) - size.x, r_outer.Min.x);
    pos.y = ImMax(ImMin(pos.y + size.y, r_outer.Max.y) - size.y, r_outer.Min.y);
    return pos;
}

// Assembly:
movq 0x41907(%rip), %rax     # 0x55490
movss 0xa8(%rax), %xmm0
ucomiss 0xb0(%rax), %xmm0
jne 0x13b9c
jnp 0x13bc1
movss 0xac(%rax), %xmm0
ucomiss 0xb4(%rax), %xmm0
jne 0x13baf
jnp 0x13bc1
movsd 0xa8(%rax), %xmm2
movsd 0xb0(%rax), %xmm3
jmp 0x13bc9
movsd 0x8(%rax), %xmm3
xorps %xmm2, %xmm2
pushq %rbp
movq %rsp, %rbp
movss 0x1450(%rax), %xmm4
movss 0x1454(%rax), %xmm0
movaps %xmm3, %xmm6
subss %xmm4, %xmm6
addss %xmm2, %xmm4
shufps $0x55, %xmm2, %xmm2     # xmm2 = xmm2[1,1,1,1]
addss %xmm0, %xmm2
shufps $0x55, %xmm3, %xmm3     # xmm3 = xmm3[1,1,1,1]
subss %xmm0, %xmm3
movss (%rsi), %xmm5
movss 0x4(%rsi), %xmm1
movaps %xmm6, %xmm0
subss %xmm5, %xmm0
movaps %xmm3, %xmm9
subss %xmm1, %xmm9
movss (%rdi), %xmm7
movss 0x4(%rdi), %xmm10
minss %xmm7, %xmm0
movaps %xmm7, -0x20(%rbp)
cmpltss %xmm4, %xmm7
movaps %xmm7, %xmm8
andps %xmm4, %xmm8
andnps %xmm0, %xmm7
orps %xmm8, %xmm7
minss %xmm10, %xmm9
movaps %xmm10, -0x10(%rbp)
movaps %xmm10, %xmm8
cmpltss %xmm2, %xmm8
movaps %xmm8, %xmm0
andps %xmm2, %xmm0
andnps %xmm9, %xmm8
orps %xmm0, %xmm8
movl (%rcx), %esi
xorl %r9d, %r9d
cmpl $-0x1, %esi
setne %r9b
negl %r9d
movss 0x8(%r8), %xmm13
movss 0xc(%r8), %xmm9
movss (%r8), %xmm0
movss 0x4(%r8), %xmm10
cmpl $-0x1, %r9d
movl %r9d, %eax
cmovel %esi, %eax
movaps %xmm13, %xmm14
testl %eax, %eax
je 0x13c96
movaps %xmm4, %xmm14
movaps %xmm9, %xmm15
cmpl $0x1, %eax
je 0x13ca3
movaps %xmm2, %xmm15
movaps %xmm0, %xmm12
cmpl $0x3, %eax
je 0x13cb0
movaps %xmm6, %xmm12
movaps %xmm10, %xmm11
cmpl $0x2, %eax
je 0x13cbd
movaps %xmm3, %xmm11
subss %xmm14, %xmm12
ucomiss %xmm12, %xmm5
ja 0x13cd3
subss %xmm15, %xmm11
ucomiss %xmm11, %xmm1
jbe 0x13d36
incl %r9d
cmpl $0x4, %r9d
jne 0x13c80
movl $0xffffffff, (%rcx)     # imm = 0xFFFFFFFF
btl $0x18, %edx
jb 0x13d4a
movsd (%rdi), %xmm0
movaps %xmm5, %xmm8
addss %xmm0, %xmm8
minss %xmm6, %xmm8
subss %xmm5, %xmm8
movaps %xmm4, %xmm7
cmpless %xmm8, %xmm7
andps %xmm7, %xmm8
andnps %xmm4, %xmm7
orps %xmm8, %xmm7
shufps $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
addss %xmm1, %xmm0
minss %xmm3, %xmm0
subss %xmm1, %xmm0
movaps %xmm2, %xmm1
cmpless %xmm0, %xmm1
andps %xmm1, %xmm0
andnps %xmm2, %xmm1
orps %xmm0, %xmm1
jmp 0x13d62
movl %eax, (%rcx)
testl %eax, %eax
je 0x13d67
cmpl $0x3, %eax
jne 0x13d6d
subss %xmm5, %xmm0
movaps %xmm0, %xmm7
jmp 0x13d6d
movss 0x29672(%rip), %xmm0    # 0x3d3c4
movaps -0x20(%rbp), %xmm7
addss %xmm0, %xmm7
movaps -0x10(%rbp), %xmm1
addss %xmm0, %xmm1
unpcklps %xmm1, %xmm7            # xmm7 = xmm7[0],xmm1[0],xmm7[1],xmm1[1]
jmp 0x13d88
movss 0x8(%r8), %xmm7
cmpl $0x1, %eax
je 0x13d76
movaps %xmm8, %xmm9
cmpl $0x2, %eax
jne 0x13d84
subss %xmm1, %xmm10
movaps %xmm10, %xmm9
unpcklps %xmm9, %xmm7            # xmm7 = xmm7[0],xmm9[0],xmm7[1],xmm9[1]
movaps %xmm7, %xmm0
popq %rbp
retq