// File: /workspace/github_cpp_makefile_star2_O1/Ciaxur[P]yagb-emu/include/imgui/imgui.cpp
// Function: ImGui::ScrollToBringRectIntoView(ImGuiWindow*, ImRect const&)
ImVec2 ImGui::ScrollToBringRectIntoView(ImGuiWindow* window, const ImRect& item_rect)
{
    ImGuiContext& g = *GImGui;
    ImRect window_rect(window->InnerRect.Min - ImVec2(1, 1), window->InnerRect.Max + ImVec2(1, 1));
    //GetForegroundDrawList(window)->AddRect(window_rect.Min, window_rect.Max, IM_COL32_WHITE); // [DEBUG]

    ImVec2 delta_scroll;
    if (!window_rect.Contains(item_rect))
    {
        if (window->ScrollbarX && item_rect.Min.x < window_rect.Min.x)
            SetScrollFromPosX(window, item_rect.Min.x - window->Pos.x - g.Style.ItemSpacing.x, 0.0f);
        else if (window->ScrollbarX && item_rect.Max.x >= window_rect.Max.x)
            SetScrollFromPosX(window, item_rect.Max.x - window->Pos.x + g.Style.ItemSpacing.x, 1.0f);
        if (item_rect.Min.y < window_rect.Min.y)
            SetScrollFromPosY(window, item_rect.Min.y - window->Pos.y - g.Style.ItemSpacing.y, 0.0f);
        else if (item_rect.Max.y >= window_rect.Max.y)
            SetScrollFromPosY(window, item_rect.Max.y - window->Pos.y + g.Style.ItemSpacing.y, 1.0f);

        ImVec2 next_scroll = CalcNextScrollFromScrollTargetAndClamp(window);
        delta_scroll = next_scroll - window->Scroll;
    }

    // Also scroll parent window to keep us into view if necessary
    if (window->Flags & ImGuiWindowFlags_ChildWindow)
        delta_scroll += ScrollToBringRectIntoView(window->ParentWindow, ImRect(item_rect.Min - delta_scroll, item_rect.Max - delta_scroll));

    return delta_scroll;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x20, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movq 0xa6593(%rip), %rax     # 0xfdcd0
movss 0x5f88b(%rip), %xmm1    # 0xb6fd0
movss 0x218(%rdi), %xmm5
addss %xmm1, %xmm5
addss 0x21c(%rdi), %xmm1
movss 0x5f883(%rip), %xmm0    # 0xb6fe4
movss 0x220(%rdi), %xmm4
addss %xmm0, %xmm4
movss 0x224(%rdi), %xmm2
addss %xmm0, %xmm2
movss (%rsi), %xmm3
ucomiss %xmm5, %xmm3
jb 0x5779f
movss 0x4(%rbx), %xmm6
ucomiss %xmm1, %xmm6
jb 0x5779f
ucomiss 0x8(%rbx), %xmm4
jb 0x5779f
xorps %xmm6, %xmm6
ucomiss 0xc(%rbx), %xmm2
jae 0x57864
movb 0x8c(%r14), %cl
movl %ecx, %edx
xorb $0x1, %dl
ucomiss %xmm3, %xmm5
setbe %sil
orb %dl, %sil
jne 0x577eb
subss 0x10(%r14), %xmm3
subss 0x15a8(%rax), %xmm3
xorps %xmm0, %xmm0
addss 0x5c(%r14), %xmm3
cvttps2dq %xmm3, %xmm3
cvtdq2ps %xmm3, %xmm3
movss %xmm3, 0x6c(%r14)
movss %xmm0, 0x74(%r14)
movl $0x0, 0x7c(%r14)
jmp 0x577fd
testb %cl, %cl
je 0x577fd
movss 0x8(%rbx), %xmm3
ucomiss %xmm4, %xmm3
jae 0x578c8
movss 0x4(%rbx), %xmm0
ucomiss %xmm0, %xmm1
jbe 0x5781a
subss 0x14(%r14), %xmm0
subss 0x15ac(%rax), %xmm0
xorps %xmm1, %xmm1
jmp 0x5783a
movss 0xc(%rbx), %xmm0
ucomiss %xmm2, %xmm0
jb 0x57842
subss 0x14(%r14), %xmm0
addss 0x15ac(%rax), %xmm0
movss 0x5f7aa(%rip), %xmm1    # 0xb6fe4
movq %r14, %rdi
callq 0x57931
movq %r14, %rdi
callq 0x545aa
movss 0x5c(%r14), %xmm1
movaps %xmm0, %xmm6
subss %xmm1, %xmm6
shufps $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
subss 0x60(%r14), %xmm0
unpcklps %xmm0, %xmm6            # xmm6 = xmm6[0],xmm0[0],xmm6[1],xmm0[1]
testb $0x1, 0xf(%r14)
je 0x578bc
movq 0x388(%r14), %rdi
movss (%rbx), %xmm0
movss 0x4(%rbx), %xmm1
subss %xmm6, %xmm0
movaps %xmm6, %xmm2
shufps $0x55, %xmm6, %xmm2     # xmm2 = xmm2[1,1],xmm6[1,1]
subss %xmm2, %xmm1
unpcklps %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movss 0x8(%rbx), %xmm1
subss %xmm6, %xmm1
movss 0xc(%rbx), %xmm3
subss %xmm2, %xmm3
unpcklps %xmm3, %xmm1            # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
movlhps %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0]
leaq -0x30(%rbp), %rsi
movups %xmm0, (%rsi)
movaps %xmm6, -0x20(%rbp)
callq 0x57725
movaps -0x20(%rbp), %xmm6
addps %xmm0, %xmm6
movaps %xmm6, %xmm0
addq $0x20, %rsp
popq %rbx
popq %r14
popq %rbp
retq
subss 0x10(%r14), %xmm3
addss 0x15a8(%rax), %xmm3
jmp 0x577c8