// File: /workspace/github_cpp_makefile_star2_O2/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, %rbx
movq %rdi, %r14
movq 0xa2883(%rip), %r15     # 0xe3ce0
callq 0x4b4aa
movss %xmm0, -0x1c(%rbp)
movq %r14, %rdi
callq 0x4b4de
addss -0x1c(%rbp), %xmm0
movss 0x40(%r14), %xmm4
movss 0x44(%r14), %xmm3
addss %xmm4, %xmm4
addss %xmm3, %xmm3
movss (%rbx), %xmm2
addss %xmm4, %xmm2
movss 0x4(%rbx), %xmm1
addss %xmm3, %xmm1
xorps %xmm5, %xmm5
addss %xmm2, %xmm5
addss %xmm0, %xmm1
unpcklps %xmm1, %xmm5            # xmm5 = xmm5[0],xmm1[0],xmm5[1],xmm1[1]
movlps %xmm5, -0x30(%rbp)
movl 0xc(%r14), %eax
btl $0x19, %eax
jb 0x4160a
movss %xmm0, -0x1c(%rbp)
movq 0x1574(%r15), %rcx
movq %rcx, %rdx
shrq $0x20, %rdx
movd %ecx, %xmm2
movd %edx, %xmm1
testl $0x14000000, %eax       # imm = 0x14000000
movss %xmm3, -0x24(%rbp)
movss %xmm4, -0x20(%rbp)
je 0x414fd
movss 0x5b3a3(%rip), %xmm0    # 0x9c890
minss %xmm0, %xmm2
minss %xmm0, %xmm1
movaps %xmm2, %xmm0
unpcklps %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
jmp 0x41502
movq %rcx, %xmm0
leaq -0x48(%rbp), %rsi
movlps %xmm0, (%rsi)
movss 0x160c(%r15), %xmm0
addss %xmm0, %xmm0
movss 0x1610(%r15), %xmm3
addss %xmm3, %xmm3
movss 0x10(%r15), %xmm4
movss 0x14(%r15), %xmm5
subss %xmm0, %xmm4
subss %xmm3, %xmm5
movaps %xmm4, %xmm0
cmpless %xmm2, %xmm0
movaps %xmm0, %xmm3
andnps %xmm4, %xmm3
andps %xmm2, %xmm0
orps %xmm3, %xmm0
movaps %xmm5, %xmm2
cmpless %xmm1, %xmm2
movaps %xmm2, %xmm3
andnps %xmm5, %xmm3
andps %xmm1, %xmm2
orps %xmm3, %xmm2
unpcklps %xmm2, %xmm0            # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
leaq -0x30(%rbp), %rdi
callq 0x45358
movq %r14, %rdi
movaps %xmm0, -0x40(%rbp)
callq 0x41618
movaps %xmm0, %xmm1
subss -0x20(%rbp), %xmm1
movss (%rbx), %xmm2
ucomiss %xmm1, %xmm2
seta %sil
movl 0xc(%r14), %ecx
movl %ecx, %eax
andl $0x808, %eax            # imm = 0x808
cmpl $0x800, %eax            # imm = 0x800
sete %dil
movb $0x1, %al
movb $0x1, %dl
testb %dil, %sil
jne 0x415ad
movzwl %cx, %edx
shrl $0xf, %edx
shufps $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
subss -0x24(%rbp), %xmm0
subss -0x1c(%rbp), %xmm0
movss 0x4(%rbx), %xmm1
ucomiss %xmm0, %xmm1
seta %sil
testb $0x8, %cl
sete %dil
testb %dil, %sil
jne 0x415db
shrl $0xe, %ecx
andl $0x1, %ecx
movl %ecx, %eax
testb %dl, %dl
movaps -0x40(%rbp), %xmm5
je 0x415fd
movaps %xmm5, %xmm0
shufps $0x55, %xmm5, %xmm0     # xmm0 = xmm0[1,1],xmm5[1,1]
addss 0x15d0(%r15), %xmm0
movlhps %xmm5, %xmm0            # xmm0 = xmm0[0],xmm5[0]
shufps $0xe2, %xmm5, %xmm0     # xmm0 = xmm0[2,0],xmm5[2,3]
movaps %xmm0, %xmm5
testb %al, %al
je 0x4160a
addss 0x15d0(%r15), %xmm5
movaps %xmm5, %xmm0
addq $0x38, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq