// File: 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
subq $0xd0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq 0x13c756(%rip), %rax    # 0x212f40
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
addq $0x1560, %rax           # imm = 0x1560
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
callq 0xeb6f0
movss %xmm0, -0xa4(%rbp)
movq -0x10(%rbp), %rdi
callq 0xeb760
movss -0xa4(%rbp), %xmm1
addss %xmm0, %xmm1
leaq -0x30(%rbp), %rdi
movq %rdi, -0xa0(%rbp)
xorps %xmm0, %xmm0
callq 0xbf4c0
movq -0x10(%rbp), %rdi
addq $0x40, %rdi
movss 0x9b787(%rip), %xmm0    # 0x171fcc
callq 0xc2f50
movlpd %xmm0, -0x38(%rbp)
movq -0x18(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0xc41b0
movq -0xa0(%rbp), %rsi
movlpd %xmm0, -0x48(%rbp)
leaq -0x48(%rbp), %rdi
callq 0xc41b0
movlpd %xmm0, -0x40(%rbp)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
andl $0x2000000, %eax        # imm = 0x2000000
cmpl $0x0, %eax
je 0xd6894
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xd6aac
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
andl $0x4000000, %eax        # imm = 0x4000000
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, -0x49(%rbp)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
andl $0x10000000, %eax       # imm = 0x10000000
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, -0x4a(%rbp)
movq -0x28(%rbp), %rax
movq 0x14(%rax), %rax
movq %rax, -0x54(%rbp)
testb $0x1, -0x49(%rbp)
jne 0xd68da
testb $0x1, -0x4a(%rbp)
je 0xd6912
leaq -0x64(%rbp), %rdi
movq %rdi, -0xb0(%rbp)
movss 0x9be47(%rip), %xmm1    # 0x172734
movaps %xmm1, %xmm0
callq 0xbf4c0
movq -0xb0(%rbp), %rsi
leaq -0x54(%rbp), %rdi
callq 0xe5240
movlpd %xmm0, -0x5c(%rbp)
movq -0x5c(%rbp), %rax
movq %rax, -0x54(%rbp)
movq -0x20(%rbp), %rax
addq $0x10, %rax
movq %rax, -0xc0(%rbp)
movq -0x28(%rbp), %rdi
addq $0xac, %rdi
movss 0x9b698(%rip), %xmm0    # 0x171fcc
callq 0xc2f50
movq -0xc0(%rbp), %rdi
movlpd %xmm0, -0x7c(%rbp)
leaq -0x7c(%rbp), %rsi
callq 0xc3c00
movlpd %xmm0, -0x74(%rbp)
leaq -0x54(%rbp), %rdi
movq %rdi, -0xb8(%rbp)
leaq -0x74(%rbp), %rsi
callq 0xd7960
movq -0xb8(%rbp), %rsi
movlpd %xmm0, -0x6c(%rbp)
movsd -0x6c(%rbp), %xmm0
leaq -0x40(%rbp), %rdi
callq 0xdf120
movlpd %xmm0, -0x8(%rbp)
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rax
movq %rax, -0x90(%rbp)
movsd -0x90(%rbp), %xmm0
callq 0xd6ac0
movlpd %xmm0, -0x84(%rbp)
movss -0x84(%rbp), %xmm1
subss -0x38(%rbp), %xmm1
subss -0x30(%rbp), %xmm1
movq -0x18(%rbp), %rax
movss (%rax), %xmm0
ucomiss %xmm1, %xmm0
jbe 0xd69f2
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
jne 0xd69f2
movq -0x10(%rbp), %rax
movl 0xc(%rax), %ecx
andl $0x800, %ecx            # imm = 0x800
movb $0x1, %al
cmpl $0x0, %ecx
movb %al, -0xc1(%rbp)
jne 0xd6a0a
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
andl $0x8000, %eax           # imm = 0x8000
cmpl $0x0, %eax
setne %al
movb %al, -0xc1(%rbp)
movb -0xc1(%rbp), %al
andb $0x1, %al
movb %al, -0x91(%rbp)
movss -0x80(%rbp), %xmm1
subss -0x34(%rbp), %xmm1
subss -0x2c(%rbp), %xmm1
movq -0x18(%rbp), %rax
movss 0x4(%rax), %xmm0
ucomiss %xmm1, %xmm0
jbe 0xd6a4c
movq -0x10(%rbp), %rax
movl 0xc(%rax), %ecx
andl $0x8, %ecx
movb $0x1, %al
cmpl $0x0, %ecx
movb %al, -0xc2(%rbp)
je 0xd6a64
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
andl $0x4000, %eax           # imm = 0x4000
cmpl $0x0, %eax
setne %al
movb %al, -0xc2(%rbp)
movb -0xc2(%rbp), %al
andb $0x1, %al
movb %al, -0x92(%rbp)
testb $0x1, -0x91(%rbp)
je 0xd6a8e
movq -0x28(%rbp), %rax
movss 0x70(%rax), %xmm0
addss -0x4(%rbp), %xmm0
movss %xmm0, -0x4(%rbp)
testb $0x1, -0x92(%rbp)
je 0xd6aaa
movq -0x28(%rbp), %rax
movss 0x70(%rax), %xmm0
addss -0x8(%rbp), %xmm0
movss %xmm0, -0x8(%rbp)
jmp 0xd6aac
movsd -0x8(%rbp), %xmm0
addq $0xd0, %rsp
popq %rbp
retq
nopw (%rax,%rax)