// File: /workspace/github_cpp_makefile_star2_O1/Ciaxur[P]yagb-emu/include/imgui/imgui.cpp
// Function: CalcWindowAutoFitSize(ImGuiWindow*, ImVec2 const&)
static ImVec2 CalcWindowAutoFitSize(ImGuiWindow* window, const ImVec2& size_contents)
{
    ImGuiContext& g = *GImGui;
    ImGuiStyle& style = g.Style;
    ImVec2 size_decorations = ImVec2(0.0f, window->TitleBarHeight() + window->MenuBarHeight());
    ImVec2 size_pad = window->WindowPadding * 2.0f;
    ImVec2 size_desired = size_contents + size_pad + size_decorations;
    if (window->Flags & ImGuiWindowFlags_Tooltip)
    {
        // Tooltip always resize
        return size_desired;
    }
    else
    {
        // Maximum window size is determined by the viewport size or monitor size
        const bool is_popup = (window->Flags & ImGuiWindowFlags_Popup) != 0;
        const bool is_menu = (window->Flags & ImGuiWindowFlags_ChildMenu) != 0;
        ImVec2 size_min = style.WindowMinSize;
        if (is_popup || is_menu) // Popups and menus bypass style.WindowMinSize by default, but we give then a non-zero minimum size to facilitate understanding problematic cases (e.g. empty popups)
            size_min = ImMin(size_min, ImVec2(4.0f, 4.0f));
        ImVec2 size_auto_fit = ImClamp(size_desired, size_min, ImMax(size_min, g.IO.DisplaySize - style.DisplaySafeAreaPadding * 2.0f));

        // When the window cannot fit all contents (either because of constraints, either because screen is too small),
        // we are growing the size on the other axis to compensate for expected scrollbar. FIXME: Might turn bigger than ViewportSize-WindowPadding.
        ImVec2 size_auto_fit_after_constraint = CalcWindowSizeAfterConstraint(window, size_auto_fit);
        bool will_have_scrollbar_x = (size_auto_fit_after_constraint.x - size_pad.x - size_decorations.x < size_contents.x && !(window->Flags & ImGuiWindowFlags_NoScrollbar) && (window->Flags & ImGuiWindowFlags_HorizontalScrollbar)) || (window->Flags & ImGuiWindowFlags_AlwaysHorizontalScrollbar);
        bool will_have_scrollbar_y = (size_auto_fit_after_constraint.y - size_pad.y - size_decorations.y < size_contents.y && !(window->Flags & ImGuiWindowFlags_NoScrollbar)) || (window->Flags & ImGuiWindowFlags_AlwaysVerticalScrollbar);
        if (will_have_scrollbar_x)
            size_auto_fit.y += style.ScrollbarSize;
        if (will_have_scrollbar_y)
            size_auto_fit.x += style.ScrollbarSize;
        return size_auto_fit;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x38, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movq 0xaa21f(%rip), %r15     # 0xfdcd0
testb $0x1, 0xc(%rdi)
xorps %xmm1, %xmm1
jne 0x53af0
movss 0x1984(%r15), %xmm0
mulss 0x2b0(%rbx), %xmm0
movq 0x388(%rbx), %rax
testq %rax, %rax
je 0x53adf
mulss 0x2b0(%rax), %xmm0
movss 0x159c(%r15), %xmm1
addss %xmm1, %xmm1
addss %xmm0, %xmm1
movaps %xmm1, -0x40(%rbp)
movq %rbx, %rdi
callq 0x5f48e
movaps %xmm0, %xmm1
addss -0x40(%rbp), %xmm1
movss 0x40(%rbx), %xmm3
addss %xmm3, %xmm3
movss 0x44(%rbx), %xmm2
addss %xmm2, %xmm2
movss (%r14), %xmm0
addss %xmm3, %xmm0
movss 0x4(%r14), %xmm7
addss %xmm2, %xmm7
xorps %xmm8, %xmm8
addss %xmm0, %xmm8
addss %xmm1, %xmm7
movl 0xc(%rbx), %eax
btl $0x19, %eax
jb 0x53cac
movss %xmm2, -0x20(%rbp)
movss %xmm1, -0x24(%rbp)
movsd 0x1574(%r15), %xmm6
testl $0x14000000, %eax       # imm = 0x14000000
movss %xmm3, -0x1c(%rbp)
je 0x53b7f
movss 0x63cfa(%rip), %xmm1    # 0xb7864
movaps %xmm6, %xmm2
minss %xmm1, %xmm2
shufps $0x55, %xmm6, %xmm6     # xmm6 = xmm6[1,1,1,1]
minss %xmm1, %xmm6
unpcklps %xmm6, %xmm2            # xmm2 = xmm2[0],xmm6[0],xmm2[1],xmm6[1]
movaps %xmm2, %xmm6
movss 0x160c(%r15), %xmm1
addss %xmm1, %xmm1
movss 0x1610(%r15), %xmm2
addss %xmm2, %xmm2
movss 0x10(%r15), %xmm3
movss 0x14(%r15), %xmm4
subss %xmm1, %xmm3
subss %xmm2, %xmm4
movaps %xmm3, %xmm1
cmpless %xmm6, %xmm1
movaps %xmm1, %xmm2
andnps %xmm3, %xmm2
andps %xmm6, %xmm1
orps %xmm2, %xmm1
movaps %xmm6, %xmm2
shufps $0x55, %xmm6, %xmm2     # xmm2 = xmm2[1,1],xmm6[1,1]
movaps %xmm4, %xmm3
cmpless %xmm2, %xmm3
movaps %xmm3, %xmm5
andnps %xmm4, %xmm5
andps %xmm2, %xmm3
orps %xmm5, %xmm3
minss %xmm7, %xmm3
cmpltss %xmm2, %xmm7
movaps %xmm7, %xmm4
andnps %xmm3, %xmm4
andps %xmm2, %xmm7
orps %xmm4, %xmm7
movaps %xmm1, %xmm2
cmpltss %xmm0, %xmm2
movaps %xmm2, %xmm3
andps %xmm1, %xmm3
andnps %xmm8, %xmm2
orps %xmm3, %xmm2
cmpltss %xmm6, %xmm0
movaps %xmm0, %xmm1
andnps %xmm2, %xmm1
andps %xmm6, %xmm0
orps %xmm1, %xmm0
movaps %xmm7, -0x50(%rbp)
unpcklps %xmm7, %xmm0            # xmm0 = xmm0[0],xmm7[0],xmm0[1],xmm7[1]
movq %rbx, %rdi
movaps %xmm0, -0x40(%rbp)
callq 0x53cbf
movaps %xmm0, %xmm1
subss -0x1c(%rbp), %xmm1
movss (%r14), %xmm2
ucomiss %xmm1, %xmm2
jbe 0x53c4e
movl $0x808, %ecx            # imm = 0x808
andl 0xc(%rbx), %ecx
movb $0x1, %al
cmpl $0x800, %ecx            # imm = 0x800
je 0x53c54
movb 0xd(%rbx), %al
shrb $0x7, %al
shufps $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
subss -0x20(%rbp), %xmm0
subss -0x24(%rbp), %xmm0
movss 0x4(%r14), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x53c75
movb $0x1, %cl
testb $0x8, 0xc(%rbx)
je 0x53c7e
movb 0xd(%rbx), %cl
andb $0x40, %cl
shrb $0x6, %cl
testb %al, %al
movaps -0x40(%rbp), %xmm0
movaps -0x50(%rbp), %xmm1
je 0x53c9d
addss 0x15d0(%r15), %xmm1
movlhps %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0]
shufps $0xe2, %xmm0, %xmm1     # xmm1 = xmm1[2,0],xmm0[2,3]
movaps %xmm1, %xmm0
testb %cl, %cl
je 0x53cb4
addss 0x15d0(%r15), %xmm0
jmp 0x53cb4
unpcklps %xmm7, %xmm8            # xmm8 = xmm8[0],xmm7[0],xmm8[1],xmm7[1]
movaps %xmm8, %xmm0
addq $0x38, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq