// File: /workspace/github_c_makefile_star2_O2/stetre[P]moonnuklear/src/./nuklear/nuklear.h
// Function: nk_scrollbar_behavior
NK_LIB float
nk_scrollbar_behavior(nk_flags *state, struct nk_input *in,
    int has_scrolling, const struct nk_rect *scroll,
    const struct nk_rect *cursor, const struct nk_rect *empty0,
    const struct nk_rect *empty1, float scroll_offset,
    float target, float scroll_step, enum nk_orientation o)
{
    nk_flags ws = 0;
    int left_mouse_down;
    unsigned int left_mouse_clicked;
    int left_mouse_click_in_cursor;
    float scroll_delta;

    nk_widget_state_reset(state);
    if (!in) return scroll_offset;

    left_mouse_down = in->mouse.buttons[NK_BUTTON_LEFT].down;
    left_mouse_clicked = in->mouse.buttons[NK_BUTTON_LEFT].clicked;
    left_mouse_click_in_cursor = nk_input_has_mouse_click_down_in_rect(in,
        NK_BUTTON_LEFT, *cursor, nk_true);
    if (nk_input_is_mouse_hovering_rect(in, *scroll))
        *state = NK_WIDGET_STATE_HOVERED;

    scroll_delta = (o == NK_VERTICAL) ? in->mouse.scroll_delta.y: in->mouse.scroll_delta.x;
    if (left_mouse_down && left_mouse_click_in_cursor && !left_mouse_clicked) {
        /* update cursor by mouse dragging */
        float pixel, delta;
        *state = NK_WIDGET_STATE_ACTIVE;
        if (o == NK_VERTICAL) {
            float cursor_y;
            pixel = in->mouse.delta.y;
            delta = (pixel / scroll->h) * target;
            scroll_offset = NK_CLAMP(0, scroll_offset + delta, target - scroll->h);
            cursor_y = scroll->y + ((scroll_offset/target) * scroll->h);
            in->mouse.buttons[NK_BUTTON_LEFT].clicked_pos.y = cursor_y + cursor->h/2.0f;
        } else {
            float cursor_x;
            pixel = in->mouse.delta.x;
            delta = (pixel / scroll->w) * target;
            scroll_offset = NK_CLAMP(0, scroll_offset + delta, target - scroll->w);
            cursor_x = scroll->x + ((scroll_offset/target) * scroll->w);
            in->mouse.buttons[NK_BUTTON_LEFT].clicked_pos.x = cursor_x + cursor->w/2.0f;
        }
    } else if ((nk_input_is_key_pressed(in, NK_KEY_SCROLL_UP) && o == NK_VERTICAL && has_scrolling)||
            nk_button_behavior(&ws, *empty0, in, NK_BUTTON_DEFAULT)) {
        /* scroll page up by click on empty space or shortcut */
        if (o == NK_VERTICAL)
            scroll_offset = NK_MAX(0, scroll_offset - scroll->h);
        else scroll_offset = NK_MAX(0, scroll_offset - scroll->w);
    } else if ((nk_input_is_key_pressed(in, NK_KEY_SCROLL_DOWN) && o == NK_VERTICAL && has_scrolling) ||
        nk_button_behavior(&ws, *empty1, in, NK_BUTTON_DEFAULT)) {
        /* scroll page down by click on empty space or shortcut */
        if (o == NK_VERTICAL)
            scroll_offset = NK_MIN(scroll_offset + scroll->h, target - scroll->h);
        else scroll_offset = NK_MIN(scroll_offset + scroll->w, target - scroll->w);
    } else if (has_scrolling) {
        if ((scroll_delta < 0 || (scroll_delta > 0))) {
            /* update cursor by mouse scrolling */
            scroll_offset = scroll_offset + scroll_step * (-scroll_delta);
            if (o == NK_VERTICAL)
                scroll_offset = NK_CLAMP(0, scroll_offset, target - scroll->h);
            else scroll_offset = NK_CLAMP(0, scroll_offset, target - scroll->w);
        } else if (nk_input_is_key_pressed(in, NK_KEY_SCROLL_START)) {
            /* update cursor to the beginning  */
            if (o == NK_VERTICAL) scroll_offset = 0;
        } else if (nk_input_is_key_pressed(in, NK_KEY_SCROLL_END)) {
            /* update cursor to the end */
            if (o == NK_VERTICAL) scroll_offset = target - scroll->h;
        }
    }
    if (*state & NK_WIDGET_STATE_HOVER && !nk_input_is_mouse_prev_hovering_rect(in, *scroll))
        *state |= NK_WIDGET_STATE_ENTERED;
    else if (nk_input_is_mouse_prev_hovering_rect(in, *scroll))
        *state |= NK_WIDGET_STATE_LEFT;
    return scroll_offset;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
andl $0x0, 0x2c(%rsp)
movl (%rdi), %r15d
andl $0x2, %r15d
orl $0x4, %r15d
movl %r15d, (%rdi)
testq %rsi, %rsi
je 0x52127
movq %r8, %r13
movq %rsi, %r14
movl %edx, 0x28(%rsp)
movq %r9, 0x68(%rsp)
movss %xmm2, 0x48(%rsp)
movss %xmm1, 0xc(%rsp)
movss %xmm0, 0x8(%rsp)
movq %rdi, 0x10(%rsp)
movl 0x104(%rsi), %ebp
movq %rcx, %r12
movl 0x108(%rsi), %eax
movl %eax, 0x4c(%rsp)
movsd (%r8), %xmm0
movsd 0x8(%r8), %xmm1
pushq $0x1
popq %rdx
movq %rsi, %rdi
xorl %esi, %esi
movaps %xmm1, 0x80(%rsp)
callq 0x12750
movl %eax, %ebx
movsd (%r12), %xmm0
movq %r12, 0x30(%rsp)
movsd 0x8(%r12), %xmm1
movaps %xmm1, %xmm2
shufps $0x55, %xmm1, %xmm2     # xmm2 = xmm2[1,1],xmm1[1,1]
movaps %xmm2, 0x50(%rsp)
movq %r14, %rdi
movaps %xmm0, 0x70(%rsp)
callq 0x143d0
testl %eax, %eax
je 0x51ee6
movq 0x10(%rsp), %rax
movl $0x12, (%rax)
pushq $0x12
popq %r15
xorl %eax, %eax
movl 0xd8(%rsp), %ecx
testl %ecx, %ecx
sete %al
movss 0x15c(%r14,%rax,4), %xmm0
testl %ebp, %ebp
je 0x51fa2
testl %ebx, %ebx
je 0x51fa2
cmpl $0x0, 0x4c(%rsp)
jne 0x51fa2
movq 0x10(%rsp), %rbx
movl $0x22, (%rbx)
testl %ecx, %ecx
movss 0xc(%rsp), %xmm3
je 0x5204d
movss 0x154(%r14), %xmm0
movq 0x30(%rsp), %r12
movss 0x8(%r12), %xmm1
divss %xmm1, %xmm0
mulss %xmm3, %xmm0
addss 0x8(%rsp), %xmm0
movaps %xmm3, %xmm2
subss %xmm1, %xmm2
minss %xmm2, %xmm0
xorps %xmm2, %xmm2
maxss %xmm0, %xmm2
movss %xmm2, 0x8(%rsp)
movaps %xmm2, %xmm0
divss %xmm3, %xmm0
mulss %xmm1, %xmm0
addss (%r12), %xmm0
movss 0x8(%r13), %xmm1
mulss 0x148a4(%rip), %xmm1    # 0x66830
addss %xmm0, %xmm1
movss %xmm1, 0x10c(%r14)
pushq $0x22
popq %r15
jmp 0x520c3
cmpl $0x0, 0xe8(%r14)
movl 0xec(%r14), %eax
je 0x51fd6
testl %eax, %eax
movss 0x8(%rsp), %xmm1
movq 0x30(%rsp), %r12
movl 0x28(%rsp), %edx
je 0x51fea
testl %ecx, %ecx
sete %al
testl %edx, %edx
setne %bl
testb %al, %bl
je 0x51fef
jmp 0x52033
cmpl $0x1, %eax
movss 0x8(%rsp), %xmm1
movq 0x30(%rsp), %r12
movl 0x28(%rsp), %edx
ja 0x51fc6
testl %edx, %edx
setne %bl
movss %xmm0, 0x30(%rsp)
movq 0x68(%rsp), %rax
movsd (%rax), %xmm0
movsd 0x8(%rax), %xmm1
leaq 0x2c(%rsp), %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x4c99d
testl %eax, %eax
je 0x52139
cmpl $0x0, 0xd8(%rsp)
movss 0x8(%rsp), %xmm1
je 0x52033
subss 0x8(%r12), %xmm1
jmp 0x52039
subss 0x50(%rsp), %xmm1
xorps %xmm0, %xmm0
maxss %xmm0, %xmm1
movss %xmm1, 0x8(%rsp)
movq 0x10(%rsp), %rbx
jmp 0x520c3
movaps 0x80(%rsp), %xmm4
shufps $0x55, %xmm4, %xmm4     # xmm4 = xmm4[1,1,1,1]
movaps 0x70(%rsp), %xmm5
shufps $0x55, %xmm5, %xmm5     # xmm5 = xmm5[1,1,1,1]
movss 0x158(%r14), %xmm0
movaps 0x50(%rsp), %xmm2
divss %xmm2, %xmm0
mulss %xmm3, %xmm0
addss 0x8(%rsp), %xmm0
movaps %xmm3, %xmm1
subss %xmm2, %xmm1
minss %xmm1, %xmm0
xorps %xmm1, %xmm1
maxss %xmm0, %xmm1
movss %xmm1, 0x8(%rsp)
movaps %xmm1, %xmm0
divss %xmm3, %xmm0
mulss %xmm2, %xmm0
mulss 0x14787(%rip), %xmm4    # 0x66830
addss %xmm5, %xmm0
addss %xmm0, %xmm4
movss %xmm4, 0x110(%r14)
pushq $0x22
popq %r15
movq 0x30(%rsp), %r12
movsd (%r12), %xmm0
movsd 0x8(%r12), %xmm1
testb $0x10, %r15b
je 0x52100
movq %r14, %rdi
movaps %xmm0, 0x10(%rsp)
movaps 0x10(%rsp), %xmm0
movaps %xmm1, 0x30(%rsp)
movaps 0x30(%rsp), %xmm1
callq 0x13d20
movaps 0x30(%rsp), %xmm1
movaps 0x10(%rsp), %xmm0
testl %eax, %eax
je 0x52118
movq %r14, %rdi
callq 0x13d20
testl %eax, %eax
je 0x52110
pushq $0x40
jmp 0x5211a
movss 0x8(%rsp), %xmm0
jmp 0x52127
pushq $0x8
popq %rax
movss 0x8(%rsp), %xmm0
orl %eax, %r15d
movl %r15d, (%rbx)
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x0, 0xe0(%r14)
movl 0xe4(%r14), %eax
movl 0xd8(%rsp), %ecx
je 0x5215d
testl %ecx, %ecx
sete %cl
testl %eax, %eax
setne %al
jmp 0x52168
testl %ecx, %ecx
sete %cl
cmpl $0x2, %eax
setae %al
andb %cl, %al
testb %bl, %al
je 0x52196
movss 0x8(%rsp), %xmm0
movaps 0x50(%rsp), %xmm2
addss %xmm2, %xmm0
movss 0xc(%rsp), %xmm1
subss %xmm2, %xmm1
minss %xmm1, %xmm0
movss %xmm0, 0x8(%rsp)
jmp 0x52046
movq 0xd0(%rsp), %rax
movsd (%rax), %xmm0
movsd 0x8(%rax), %xmm1
leaq 0x2c(%rsp), %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x4c99d
testl %eax, %eax
je 0x521e8
cmpl $0x0, 0xd8(%rsp)
je 0x5216e
movss 0x8(%r12), %xmm0
movss 0x8(%rsp), %xmm1
addss %xmm0, %xmm1
movss 0xc(%rsp), %xmm2
subss %xmm0, %xmm2
minss %xmm2, %xmm1
jmp 0x52040
testb %bl, %bl
movl 0xd8(%rsp), %ecx
je 0x52046
xorps %xmm0, %xmm0
movss 0x30(%rsp), %xmm2
ucomiss %xmm0, %xmm2
movq 0x10(%rsp), %rbx
movss 0x8(%rsp), %xmm1
je 0x52231
movss 0x48(%rsp), %xmm0
mulss %xmm2, %xmm0
subss %xmm0, %xmm1
testl %ecx, %ecx
movss 0xc(%rsp), %xmm0
je 0x52259
subss 0x8(%r12), %xmm0
jmp 0x5225f
cmpl $0x0, 0xd0(%r14)
movl 0xd4(%r14), %eax
movss 0xc(%rsp), %xmm0
je 0x52276
testl %eax, %eax
je 0x5227b
testl %ecx, %ecx
jne 0x520c3
xorps %xmm0, %xmm0
jmp 0x522b9
subss 0x50(%rsp), %xmm0
minss %xmm0, %xmm1
xorps %xmm0, %xmm0
ucomiss %xmm1, %xmm0
ja 0x522b9
movss %xmm1, 0x8(%rsp)
jmp 0x520c3
cmpl $0x2, %eax
jae 0x5224c
cmpl $0x0, 0xd8(%r14)
movl 0xdc(%r14), %eax
je 0x522a0
testl %ecx, %ecx
sete %cl
testl %eax, %eax
setne %al
testb %al, %cl
je 0x520c3
jmp 0x522b3
testl %ecx, %ecx
setne %cl
cmpl $0x2, %eax
setb %al
orb %cl, %al
jne 0x520c3
subss 0x50(%rsp), %xmm0
movss %xmm0, 0x8(%rsp)
jmp 0x520c3