// File: 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
subq $0xd0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq 0x135b66(%rip), %rax    # 0x212f40
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
addq $0x218, %rax            # imm = 0x218
movq %rax, -0xb0(%rbp)
leaq -0x40(%rbp), %rdi
movq %rdi, -0xa8(%rbp)
movss 0x9383a(%rip), %xmm1    # 0x170c3c
movss %xmm1, -0x9c(%rbp)
movaps %xmm1, %xmm0
callq 0xbf4c0
movq -0xb0(%rbp), %rdi
movq -0xa8(%rbp), %rsi
callq 0xc3c00
movss -0x9c(%rbp), %xmm1
movlpd %xmm0, -0x38(%rbp)
movq -0x10(%rbp), %rax
addq $0x220, %rax            # imm = 0x220
movq %rax, -0x98(%rbp)
leaq -0x50(%rbp), %rdi
movq %rdi, -0x90(%rbp)
movaps %xmm1, %xmm0
callq 0xbf4c0
movq -0x98(%rbp), %rdi
movq -0x90(%rbp), %rsi
callq 0xc41b0
movlpd %xmm0, -0x48(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0x38(%rbp), %rsi
leaq -0x48(%rbp), %rdx
callq 0xe8660
leaq -0x8(%rbp), %rdi
callq 0xe7de0
movq -0x18(%rbp), %rsi
leaq -0x30(%rbp), %rdi
callq 0xe8a40
testb $0x1, %al
jne 0xdd5df
movq -0x10(%rbp), %rax
testb $0x1, 0x8c(%rax)
je 0xdd4e7
movq -0x18(%rbp), %rax
movss (%rax), %xmm1
movss -0x30(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0xdd4e7
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movss (%rax), %xmm0
movq -0x10(%rbp), %rax
subss 0x10(%rax), %xmm0
movq -0x20(%rbp), %rax
subss 0x15a8(%rax), %xmm0
xorps %xmm1, %xmm1
callq 0xdd690
jmp 0xdd534
movq -0x10(%rbp), %rax
testb $0x1, 0x8c(%rax)
je 0xdd532
movq -0x18(%rbp), %rax
movss 0x8(%rax), %xmm0
ucomiss -0x28(%rbp), %xmm0
jb 0xdd532
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movss 0x8(%rax), %xmm0
movq -0x10(%rbp), %rax
subss 0x10(%rax), %xmm0
movq -0x20(%rbp), %rax
addss 0x15a8(%rax), %xmm0
movss 0x9370f(%rip), %xmm1    # 0x170c3c
callq 0xdd690
jmp 0xdd534
movq -0x18(%rbp), %rax
movss 0x4(%rax), %xmm1
movss -0x2c(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0xdd573
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movss 0x4(%rax), %xmm0
movq -0x10(%rbp), %rax
subss 0x14(%rax), %xmm0
movq -0x20(%rbp), %rax
subss 0x15ac(%rax), %xmm0
xorps %xmm1, %xmm1
callq 0xdd740
jmp 0xdd5b3
movq -0x18(%rbp), %rax
movss 0xc(%rax), %xmm0
ucomiss -0x24(%rbp), %xmm0
jb 0xdd5b1
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movss 0xc(%rax), %xmm0
movq -0x10(%rbp), %rax
subss 0x14(%rax), %xmm0
movq -0x20(%rbp), %rax
addss 0x15ac(%rax), %xmm0
movss 0x93690(%rip), %xmm1    # 0x170c3c
callq 0xdd740
jmp 0xdd5b3
movq -0x10(%rbp), %rdi
callq 0xd87c0
movlpd %xmm0, -0x58(%rbp)
movq -0x10(%rbp), %rsi
addq $0x5c, %rsi
leaq -0x58(%rbp), %rdi
callq 0xc3c00
movlpd %xmm0, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
andl $0x1000000, %eax        # imm = 0x1000000
cmpl $0x0, %eax
je 0xdd67b
movq -0x10(%rbp), %rax
movq 0x388(%rax), %rax
movq %rax, -0xc0(%rbp)
movq -0x18(%rbp), %rdi
leaq -0x8(%rbp), %rsi
movq %rsi, -0xc8(%rbp)
callq 0xc3c00
movq -0xc8(%rbp), %rsi
movlpd %xmm0, -0x80(%rbp)
movq -0x18(%rbp), %rdi
addq $0x8, %rdi
callq 0xc3c00
movlpd %xmm0, -0x88(%rbp)
leaq -0x78(%rbp), %rdi
movq %rdi, -0xb8(%rbp)
leaq -0x80(%rbp), %rsi
leaq -0x88(%rbp), %rdx
callq 0xe8660
movq -0xc0(%rbp), %rdi
movq -0xb8(%rbp), %rsi
callq 0xdd3c0
movlpd %xmm0, -0x68(%rbp)
leaq -0x8(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0xda7f0
movsd -0x8(%rbp), %xmm0
addq $0xd0, %rsp
popq %rbp
retq
nopl (%rax)