// File: Ciaxur[P]yagb-emu/include/imgui/imgui.cpp
// Function: CalcNextScrollFromScrollTargetAndClamp(ImGuiWindow*)
static ImVec2 CalcNextScrollFromScrollTargetAndClamp(ImGuiWindow* window)
{
    ImVec2 scroll = window->Scroll;
    if (window->ScrollTarget.x < FLT_MAX)
    {
        float center_x_ratio = window->ScrollTargetCenterRatio.x;
        float scroll_target_x = window->ScrollTarget.x;
        float snap_x_min = 0.0f;
        float snap_x_max = window->ScrollMax.x + window->Size.x;
        if (window->ScrollTargetEdgeSnapDist.x > 0.0f)
            scroll_target_x = CalcScrollEdgeSnap(scroll_target_x, snap_x_min, snap_x_max, window->ScrollTargetEdgeSnapDist.x, center_x_ratio);
        scroll.x = scroll_target_x - center_x_ratio * (window->SizeFull.x - window->ScrollbarSizes.x);
    }
    if (window->ScrollTarget.y < FLT_MAX)
    {
        float decoration_up_height = window->TitleBarHeight() + window->MenuBarHeight();
        float center_y_ratio = window->ScrollTargetCenterRatio.y;
        float scroll_target_y = window->ScrollTarget.y;
        float snap_y_min = 0.0f;
        float snap_y_max = window->ScrollMax.y + window->Size.y - decoration_up_height;
        if (window->ScrollTargetEdgeSnapDist.y > 0.0f)
            scroll_target_y = CalcScrollEdgeSnap(scroll_target_y, snap_y_min, snap_y_max, window->ScrollTargetEdgeSnapDist.y, center_y_ratio);
        scroll.y = scroll_target_y - center_y_ratio * (window->SizeFull.y - window->ScrollbarSizes.y - decoration_up_height);
    }
    scroll.x = IM_FLOOR(ImMax(scroll.x, 0.0f));
    scroll.y = IM_FLOOR(ImMax(scroll.y, 0.0f));
    if (!window->Collapsed && !window->SkipItems)
    {
        scroll.x = ImMin(scroll.x, window->ScrollMax.x);
        scroll.y = ImMin(scroll.y, window->ScrollMax.y);
    }
    return scroll;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x5c(%rax), %rax
movq %rax, -0x8(%rbp)
movq -0x10(%rbp), %rax
movss 0x997d0(%rip), %xmm0    # 0x171fb4
ucomiss 0x6c(%rax), %xmm0
jbe 0xd889a
movq -0x10(%rbp), %rax
movss 0x74(%rax), %xmm0
movss %xmm0, -0x14(%rbp)
movq -0x10(%rbp), %rax
movss 0x6c(%rax), %xmm0
movss %xmm0, -0x18(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movss 0x64(%rax), %xmm0
movq -0x10(%rbp), %rax
addss 0x18(%rax), %xmm0
movss %xmm0, -0x20(%rbp)
movq -0x10(%rbp), %rax
movss 0x7c(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0xd8861
movss -0x18(%rbp), %xmm0
movss -0x1c(%rbp), %xmm1
movss -0x20(%rbp), %xmm2
movq -0x10(%rbp), %rax
movss 0x7c(%rax), %xmm3
movss -0x14(%rbp), %xmm4
callq 0xe5e10
movss %xmm0, -0x18(%rbp)
movss -0x18(%rbp), %xmm1
movss -0x14(%rbp), %xmm0
movq -0x10(%rbp), %rax
movss 0x20(%rax), %xmm2
movq -0x10(%rbp), %rax
subss 0x84(%rax), %xmm2
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x8(%rbp)
movq -0x10(%rbp), %rax
movss 0x9970e(%rip), %xmm0    # 0x171fb4
ucomiss 0x70(%rax), %xmm0
jbe 0xd8994
movq -0x10(%rbp), %rdi
callq 0xeb6f0
movss %xmm0, -0x38(%rbp)
movq -0x10(%rbp), %rdi
callq 0xeb760
movaps %xmm0, %xmm1
movss -0x38(%rbp), %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x24(%rbp)
movq -0x10(%rbp), %rax
movss 0x78(%rax), %xmm0
movss %xmm0, -0x28(%rbp)
movq -0x10(%rbp), %rax
movss 0x70(%rax), %xmm0
movss %xmm0, -0x2c(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x30(%rbp)
movq -0x10(%rbp), %rax
movss 0x68(%rax), %xmm0
movq -0x10(%rbp), %rax
addss 0x1c(%rax), %xmm0
subss -0x24(%rbp), %xmm0
movss %xmm0, -0x34(%rbp)
movq -0x10(%rbp), %rax
movss 0x80(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0xd8956
movss -0x2c(%rbp), %xmm0
movss -0x30(%rbp), %xmm1
movss -0x34(%rbp), %xmm2
movq -0x10(%rbp), %rax
movss 0x80(%rax), %xmm3
movss -0x28(%rbp), %xmm4
callq 0xe5e10
movss %xmm0, -0x2c(%rbp)
movss -0x2c(%rbp), %xmm1
movss -0x28(%rbp), %xmm0
movq -0x10(%rbp), %rax
movss 0x24(%rax), %xmm2
movq -0x10(%rbp), %rax
subss 0x88(%rax), %xmm2
subss -0x24(%rbp), %xmm2
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x4(%rbp)
movss -0x8(%rbp), %xmm0
xorps %xmm1, %xmm1
callq 0xc88c0
cvttss2si %xmm0, %eax
cvtsi2ss %eax, %xmm0
movss %xmm0, -0x8(%rbp)
movss -0x4(%rbp), %xmm0
xorps %xmm1, %xmm1
callq 0xc88c0
cvttss2si %xmm0, %eax
cvtsi2ss %eax, %xmm0
movss %xmm0, -0x4(%rbp)
movq -0x10(%rbp), %rax
testb $0x1, 0x91(%rax)
jne 0xd8a12
movq -0x10(%rbp), %rax
testb $0x1, 0x93(%rax)
jne 0xd8a12
movss -0x8(%rbp), %xmm0
movq -0x10(%rbp), %rax
movss 0x64(%rax), %xmm1
callq 0xc4620
movss %xmm0, -0x8(%rbp)
movss -0x4(%rbp), %xmm0
movq -0x10(%rbp), %rax
movss 0x68(%rax), %xmm1
callq 0xc4620
movss %xmm0, -0x4(%rbp)
movsd -0x8(%rbp), %xmm0
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)