// File: donfreiday[P]gb/./imgui/imgui.cpp
// Function: Scrollbar(ImGuiWindow*, bool)
static void Scrollbar(ImGuiWindow* window, bool horizontal)
{
    ImGuiState& g = *GImGui;
    const ImGuiStyle& style = g.Style;
    const ImGuiID id = window->GetID(horizontal ? "#SCROLLX" : "#SCROLLY");

    // Render background
    bool other_scrollbar = (horizontal ? window->ScrollbarY : window->ScrollbarX);
    float other_scrollbar_size_w = other_scrollbar ? style.ScrollbarSize : 0.0f;
    const ImRect window_rect = window->Rect();
    ImRect bb = horizontal
        ? ImRect(window->Pos.x + 1, window_rect.Max.y - style.ScrollbarSize, window_rect.Max.x - 1 - other_scrollbar_size_w, window_rect.Max.y)
        : ImRect(window_rect.Max.x - style.ScrollbarSize, window->Pos.y + window->TitleBarHeight()+1, window_rect.Max.x, window_rect.Max.y - 1 - other_scrollbar_size_w);
    window->DrawList->AddRectFilled(bb.Min, bb.Max, window->Color(ImGuiCol_ScrollbarBg));
    bb.Expand(-3.0f);

    // V denote the main axis of the scrollbar
    float scrollbar_size_v = horizontal ? bb.GetWidth() : bb.GetHeight();
    float scroll_v = horizontal ? window->Scroll.x : window->Scroll.y;
    float win_size_avail_v = (horizontal ? window->Size.x : window->Size.y) - other_scrollbar_size_w;
    float win_size_contents_v = horizontal ? window->SizeContents.x : window->SizeContents.y;

    // The grabable box size generally represent the amount visible (vs the total scrollable amount)
    // But we maintain a minimum size in pixel to allow for the user to still aim inside.
    const float grab_h_pixels = ImMin(ImMax(scrollbar_size_v * ImSaturate(win_size_avail_v / ImMax(win_size_contents_v, win_size_avail_v)), style.GrabMinSize), scrollbar_size_v);
    const float grab_h_norm = grab_h_pixels / scrollbar_size_v;

    // Handle input right away. None of the code of Begin() is relying on scrolling position before calling Scrollbar().
    bool held = false;
    bool hovered = false;
    const bool previously_held = (g.ActiveId == id);
    ImGui::ButtonBehavior(bb, id, &hovered, &held, true);

    float scroll_max = ImMax(1.0f, win_size_contents_v - win_size_avail_v);
    float scroll_ratio = ImSaturate(scroll_v / scroll_max);
    float grab_v_norm = scroll_ratio * (scrollbar_size_v - grab_h_pixels) / scrollbar_size_v;
    if (held && grab_h_norm < 1.0f)
    {
        float scrollbar_pos_v = horizontal ? bb.Min.x : bb.Min.y;
        float mouse_pos_v = horizontal ? g.IO.MousePos.x : g.IO.MousePos.y;
        float* click_delta_to_grab_center_v = horizontal ? &g.ScrollbarClickDeltaToGrabCenter.x : &g.ScrollbarClickDeltaToGrabCenter.y;

        // Click position in scrollbar normalized space (0.0f->1.0f)
        const float clicked_v_norm = ImSaturate((mouse_pos_v - scrollbar_pos_v) / scrollbar_size_v);
        g.HoveredId = id;

        bool seek_absolute = false;
        if (!previously_held)
        {
            // On initial click calculate the distance between mouse and the center of the grab
            if (clicked_v_norm >= grab_v_norm && clicked_v_norm <= grab_v_norm + grab_h_norm)
            {
                *click_delta_to_grab_center_v = clicked_v_norm - grab_v_norm - grab_h_norm*0.5f;
            }
            else
            {
                seek_absolute = true;
                *click_delta_to_grab_center_v = 0.0f;
            }
        }

        // Apply scroll
        // It is ok to modify Scroll here because we are being called in Begin() after the calculation of SizeContents and before setting up our starting position
        const float scroll_v_norm = ImSaturate((clicked_v_norm - *click_delta_to_grab_center_v - grab_h_norm*0.5f) / (1.0f - grab_h_norm));
        scroll_v = (float)(int)(0.5f + scroll_v_norm * scroll_max);//(win_size_contents_v - win_size_v));
        if (horizontal)
            window->Scroll.x = scroll_v;
        else
            window->Scroll.y = scroll_v;

        // Update values for rendering
        scroll_ratio = ImSaturate(scroll_v / scroll_max);
        grab_v_norm = scroll_ratio * (scrollbar_size_v - grab_h_pixels) / scrollbar_size_v;

        // Update distance to grab now that we have seeked and saturated
        if (seek_absolute)
            *click_delta_to_grab_center_v = clicked_v_norm - grab_v_norm - grab_h_norm*0.5f;
    }

    // Render
    const ImU32 grab_col = window->Color(held ? ImGuiCol_ScrollbarGrabActive : hovered ? ImGuiCol_ScrollbarGrabHovered : ImGuiCol_ScrollbarGrab);
    if (horizontal)
        window->DrawList->AddRectFilled(ImVec2(ImLerp(bb.Min.x, bb.Max.x, grab_v_norm), bb.Min.y), ImVec2(ImLerp(bb.Min.x, bb.Max.x, grab_v_norm) + grab_h_pixels, bb.Max.y), grab_col, style.ScrollbarRounding);
    else
        window->DrawList->AddRectFilled(ImVec2(bb.Min.x, ImLerp(bb.Min.y, bb.Max.y, grab_v_norm)), ImVec2(bb.Max.x, ImLerp(bb.Min.y, bb.Max.y, grab_v_norm) + grab_h_pixels), grab_col, style.ScrollbarRounding);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x140, %rsp            # imm = 0x140
movb %sil, %al
movq %rdi, -0x8(%rbp)
andb $0x1, %al
movb %al, -0x9(%rbp)
movq 0x62282(%rip), %rax     # 0x794c0
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
addq $0x13e8, %rax           # imm = 0x13E8
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xc0(%rbp)
testb $0x1, -0x9(%rbp)
je 0x17271
leaq 0x457d9(%rip), %rax     # 0x5ca41
movq %rax, -0xc8(%rbp)
jmp 0x17281
leaq 0x44ed1(%rip), %rax     # 0x5c149
movq %rax, -0xc8(%rbp)
jmp 0x17281
movq -0xc0(%rbp), %rdi
movq -0xc8(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0xbc60
movl %eax, -0x24(%rbp)
testb $0x1, -0x9(%rbp)
je 0x172b0
movq -0x8(%rbp), %rax
movb 0x65(%rax), %al
movb %al, -0xc9(%rbp)
jmp 0x172bd
movq -0x8(%rbp), %rax
movb 0x64(%rax), %al
movb %al, -0xc9(%rbp)
movb -0xc9(%rbp), %al
andb $0x1, %al
movb %al, -0x25(%rbp)
testb $0x1, -0x25(%rbp)
je 0x172e1
movq -0x20(%rbp), %rax
movss 0x50(%rax), %xmm0
movss %xmm0, -0xd0(%rbp)
jmp 0x172ee
xorps %xmm0, %xmm0
movss %xmm0, -0xd0(%rbp)
jmp 0x172ee
movss -0xd0(%rbp), %xmm0
movss %xmm0, -0x2c(%rbp)
movq -0x8(%rbp), %rdi
callq 0x2f2d0
movlpd %xmm0, -0x3c(%rbp)
movlpd %xmm1, -0x34(%rbp)
testb $0x1, -0x9(%rbp)
je 0x17359
movq -0x8(%rbp), %rax
movss 0x43cf8(%rip), %xmm0    # 0x5b018
addss 0x18(%rax), %xmm0
movss -0x30(%rbp), %xmm1
movq -0x20(%rbp), %rax
subss 0x50(%rax), %xmm1
movss -0x34(%rbp), %xmm2
movss 0x43cd8(%rip), %xmm3    # 0x5b018
subss %xmm3, %xmm2
subss -0x2c(%rbp), %xmm2
movss -0x30(%rbp), %xmm3
leaq -0x4c(%rbp), %rdi
callq 0x2f230
jmp 0x173d0
movss -0x34(%rbp), %xmm0
movq -0x20(%rbp), %rax
subss 0x50(%rax), %xmm0
movss %xmm0, -0xd4(%rbp)
movq -0x8(%rbp), %rax
movss 0x1c(%rax), %xmm0
movss %xmm0, -0xd8(%rbp)
movq -0x8(%rbp), %rdi
callq 0x2f170
movss -0xd8(%rbp), %xmm1
movaps %xmm0, %xmm2
movss -0xd4(%rbp), %xmm0
addss %xmm2, %xmm1
movss 0x43c70(%rip), %xmm2    # 0x5b018
addss %xmm2, %xmm1
movss -0x34(%rbp), %xmm2
movss -0x30(%rbp), %xmm3
movss 0x43c5a(%rip), %xmm4    # 0x5b018
subss %xmm4, %xmm3
subss -0x2c(%rbp), %xmm3
leaq -0x4c(%rbp), %rdi
callq 0x2f230
movq -0x8(%rbp), %rax
movq 0x270(%rax), %rax
movq %rax, -0xf0(%rbp)
leaq -0x4c(%rbp), %rax
movq %rax, -0xe8(%rbp)
leaq -0x4c(%rbp), %rax
addq $0x8, %rax
movq %rax, -0xe0(%rbp)
movq -0x8(%rbp), %rdi
movl $0xd, %esi
movss 0x43c0b(%rip), %xmm0    # 0x5b018
callq 0x2ea40
movq -0xf0(%rbp), %rdi
movq -0xe8(%rbp), %rsi
movq -0xe0(%rbp), %rdx
movl %eax, %ecx
xorps %xmm0, %xmm0
movl $0xf, %r8d
callq 0x40670
leaq -0x4c(%rbp), %rdi
movss 0x43cad(%rip), %xmm0    # 0x5b0f0
callq 0x2ed00
testb $0x1, -0x9(%rbp)
je 0x17461
leaq -0x4c(%rbp), %rdi
callq 0x2fe50
movss %xmm0, -0xf4(%rbp)
jmp 0x17472
leaq -0x4c(%rbp), %rdi
callq 0x2f520
movss %xmm0, -0xf4(%rbp)
movss -0xf4(%rbp), %xmm0
movss %xmm0, -0x50(%rbp)
testb $0x1, -0x9(%rbp)
je 0x17498
movq -0x8(%rbp), %rax
movss 0x4c(%rax), %xmm0
movss %xmm0, -0xf8(%rbp)
jmp 0x174a9
movq -0x8(%rbp), %rax
movss 0x50(%rax), %xmm0
movss %xmm0, -0xf8(%rbp)
movss -0xf8(%rbp), %xmm0
movss %xmm0, -0x54(%rbp)
testb $0x1, -0x9(%rbp)
je 0x174cf
movq -0x8(%rbp), %rax
movss 0x20(%rax), %xmm0
movss %xmm0, -0xfc(%rbp)
jmp 0x174e0
movq -0x8(%rbp), %rax
movss 0x24(%rax), %xmm0
movss %xmm0, -0xfc(%rbp)
movss -0xfc(%rbp), %xmm0
subss -0x2c(%rbp), %xmm0
movss %xmm0, -0x58(%rbp)
testb $0x1, -0x9(%rbp)
je 0x1750b
movq -0x8(%rbp), %rax
movss 0x30(%rax), %xmm0
movss %xmm0, -0x100(%rbp)
jmp 0x1751c
movq -0x8(%rbp), %rax
movss 0x34(%rax), %xmm0
movss %xmm0, -0x100(%rbp)
movss -0x100(%rbp), %xmm0
movss %xmm0, -0x5c(%rbp)
movss -0x50(%rbp), %xmm0
movss %xmm0, -0x104(%rbp)
movss -0x58(%rbp), %xmm0
movss %xmm0, -0x108(%rbp)
movss -0x5c(%rbp), %xmm0
movss -0x58(%rbp), %xmm1
callq 0xb7c0
movaps %xmm0, %xmm1
movss -0x108(%rbp), %xmm0
divss %xmm1, %xmm0
callq 0xa1d0
movaps %xmm0, %xmm1
movss -0x104(%rbp), %xmm0
mulss %xmm1, %xmm0
movq -0x20(%rbp), %rax
movss 0x58(%rax), %xmm1
callq 0xb7c0
movss -0x50(%rbp), %xmm1
callq 0xe370
movss %xmm0, -0x60(%rbp)
movss -0x60(%rbp), %xmm0
divss -0x50(%rbp), %xmm0
movss %xmm0, -0x64(%rbp)
movb $0x0, -0x65(%rbp)
movb $0x0, -0x66(%rbp)
movq -0x18(%rbp), %rax
movl 0x1790(%rax), %eax
cmpl -0x24(%rbp), %eax
sete %al
andb $0x1, %al
movb %al, -0x67(%rbp)
movl -0x24(%rbp), %esi
leaq -0x4c(%rbp), %rdi
leaq -0x66(%rbp), %rdx
leaq -0x65(%rbp), %rcx
movl $0x1, %r8d
xorl %r9d, %r9d
callq 0x17010
movss -0x5c(%rbp), %xmm1
subss -0x58(%rbp), %xmm1
movss 0x43a2b(%rip), %xmm0    # 0x5b018
callq 0xb7c0
movss %xmm0, -0x6c(%rbp)
movss -0x54(%rbp), %xmm0
divss -0x6c(%rbp), %xmm0
callq 0xa1d0
movss %xmm0, -0x70(%rbp)
movss -0x70(%rbp), %xmm0
movss -0x50(%rbp), %xmm1
subss -0x60(%rbp), %xmm1
mulss %xmm1, %xmm0
divss -0x50(%rbp), %xmm0
movss %xmm0, -0x74(%rbp)
testb $0x1, -0x65(%rbp)
je 0x178b1
movss 0x439de(%rip), %xmm0    # 0x5b018
ucomiss -0x64(%rbp), %xmm0
jbe 0x178b1
testb $0x1, -0x9(%rbp)
je 0x17659
movss -0x4c(%rbp), %xmm0
movss %xmm0, -0x10c(%rbp)
jmp 0x17666
movss -0x48(%rbp), %xmm0
movss %xmm0, -0x10c(%rbp)
movss -0x10c(%rbp), %xmm0
movss %xmm0, -0x78(%rbp)
testb $0x1, -0x9(%rbp)
je 0x1768f
movq -0x18(%rbp), %rax
movss 0xf0(%rax), %xmm0
movss %xmm0, -0x110(%rbp)
jmp 0x176a3
movq -0x18(%rbp), %rax
movss 0xf4(%rax), %xmm0
movss %xmm0, -0x110(%rbp)
movss -0x110(%rbp), %xmm0
movss %xmm0, -0x7c(%rbp)
testb $0x1, -0x9(%rbp)
je 0x176c9
movq -0x18(%rbp), %rax
addq $0x27d8, %rax           # imm = 0x27D8
movq %rax, -0x118(%rbp)
jmp 0x176de
movq -0x18(%rbp), %rax
addq $0x27d8, %rax           # imm = 0x27D8
addq $0x4, %rax
movq %rax, -0x118(%rbp)
movq -0x118(%rbp), %rax
movq %rax, -0x88(%rbp)
movss -0x7c(%rbp), %xmm0
subss -0x78(%rbp), %xmm0
divss -0x50(%rbp), %xmm0
callq 0xa1d0
movss %xmm0, -0x8c(%rbp)
movl -0x24(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x1788(%rax)
movb $0x0, -0x8d(%rbp)
testb $0x1, -0x67(%rbp)
jne 0x1779a
movss -0x8c(%rbp), %xmm0
ucomiss -0x74(%rbp), %xmm0
jb 0x17783
movss -0x8c(%rbp), %xmm1
movss -0x74(%rbp), %xmm0
addss -0x64(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jb 0x17783
movss -0x8c(%rbp), %xmm1
subss -0x74(%rbp), %xmm1
movss -0x64(%rbp), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
movss 0x438b6(%rip), %xmm2    # 0x5b024
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movq -0x88(%rbp), %rax
movss %xmm0, (%rax)
jmp 0x17798
movb $0x1, -0x8d(%rbp)
movq -0x88(%rbp), %rax
xorps %xmm0, %xmm0
movss %xmm0, (%rax)
jmp 0x1779a
movss -0x8c(%rbp), %xmm1
movq -0x88(%rbp), %rax
subss (%rax), %xmm1
movss -0x64(%rbp), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
movss 0x4385d(%rip), %xmm2    # 0x5b024
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss 0x43841(%rip), %xmm1    # 0x5b018
subss -0x64(%rbp), %xmm1
divss %xmm1, %xmm0
callq 0xa1d0
movss %xmm0, -0x94(%rbp)
movss -0x94(%rbp), %xmm0
movss -0x6c(%rbp), %xmm1
mulss %xmm1, %xmm0
movss 0x4381e(%rip), %xmm1    # 0x5b024
addss %xmm1, %xmm0
cvttss2si %xmm0, %eax
cvtsi2ss %eax, %xmm0
movss %xmm0, -0x54(%rbp)
testb $0x1, -0x9(%rbp)
je 0x1782d
movss -0x54(%rbp), %xmm0
movq -0x8(%rbp), %rax
movss %xmm0, 0x4c(%rax)
jmp 0x1783b
movss -0x54(%rbp), %xmm0
movq -0x8(%rbp), %rax
movss %xmm0, 0x50(%rax)
movss -0x54(%rbp), %xmm0
divss -0x6c(%rbp), %xmm0
callq 0xa1d0
movss %xmm0, -0x70(%rbp)
movss -0x70(%rbp), %xmm0
movss -0x50(%rbp), %xmm1
subss -0x60(%rbp), %xmm1
mulss %xmm1, %xmm0
divss -0x50(%rbp), %xmm0
movss %xmm0, -0x74(%rbp)
testb $0x1, -0x8d(%rbp)
je 0x178af
movss -0x8c(%rbp), %xmm1
subss -0x74(%rbp), %xmm1
movss -0x64(%rbp), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
movss 0x43788(%rip), %xmm2    # 0x5b024
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movq -0x88(%rbp), %rax
movss %xmm0, (%rax)
jmp 0x178b1
movq -0x8(%rbp), %rax
movq %rax, -0x120(%rbp)
testb $0x1, -0x65(%rbp)
je 0x178cf
movl $0x10, %eax
movl %eax, -0x124(%rbp)
jmp 0x178e8
movb -0x66(%rbp), %dl
movl $0xe, %eax
movl $0xf, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0x124(%rbp)
movq -0x120(%rbp), %rdi
movl -0x124(%rbp), %esi
movss 0x4371b(%rip), %xmm0    # 0x5b018
callq 0x2ea40
movl %eax, -0x98(%rbp)
testb $0x1, -0x9(%rbp)
je 0x179a7
movq -0x8(%rbp), %rax
movq 0x270(%rax), %rax
movq %rax, -0x130(%rbp)
movss -0x4c(%rbp), %xmm0
movss -0x44(%rbp), %xmm1
movss -0x74(%rbp), %xmm2
callq 0x20750
movss -0x48(%rbp), %xmm1
leaq -0xa0(%rbp), %rdi
callq 0x2d280
movss -0x4c(%rbp), %xmm0
movss -0x44(%rbp), %xmm1
movss -0x74(%rbp), %xmm2
callq 0x20750
addss -0x60(%rbp), %xmm0
movss -0x40(%rbp), %xmm1
leaq -0xa8(%rbp), %rdi
callq 0x2d280
movq -0x130(%rbp), %rdi
movl -0x98(%rbp), %ecx
movq -0x20(%rbp), %rax
movss 0x54(%rax), %xmm0
leaq -0xa0(%rbp), %rsi
leaq -0xa8(%rbp), %rdx
movl $0xf, %r8d
callq 0x40670
jmp 0x17a5d
movq -0x8(%rbp), %rax
movq 0x270(%rax), %rax
movq %rax, -0x138(%rbp)
movss -0x4c(%rbp), %xmm0
movss %xmm0, -0x140(%rbp)
movss -0x48(%rbp), %xmm0
movss -0x40(%rbp), %xmm1
movss -0x74(%rbp), %xmm2
callq 0x20750
movaps %xmm0, %xmm1
movss -0x140(%rbp), %xmm0
leaq -0xb0(%rbp), %rdi
callq 0x2d280
movss -0x44(%rbp), %xmm0
movss %xmm0, -0x13c(%rbp)
movss -0x48(%rbp), %xmm0
movss -0x40(%rbp), %xmm1
movss -0x74(%rbp), %xmm2
callq 0x20750
movaps %xmm0, %xmm1
movss -0x13c(%rbp), %xmm0
addss -0x60(%rbp), %xmm1
leaq -0xb8(%rbp), %rdi
callq 0x2d280
movq -0x138(%rbp), %rdi
movl -0x98(%rbp), %ecx
movq -0x20(%rbp), %rax
movss 0x54(%rax), %xmm0
leaq -0xb0(%rbp), %rsi
leaq -0xb8(%rbp), %rdx
movl $0xf, %r8d
callq 0x40670
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq
nopw %cs:(%rax,%rax)