// File: /workspace/github_cpp_makefile_star2_O1/Ciaxur[P]yagb-emu/include/imgui/imgui_widgets.cpp
// Function: bool ImGui::SliderBehaviorT<unsigned long long, long long, double>(ImRect const&, unsigned int, int, unsigned long long*, unsigned long long, unsigned long long, char const*, int, ImRect*)
bool ImGui::SliderBehaviorT(const ImRect& bb, ImGuiID id, ImGuiDataType data_type, TYPE* v, const TYPE v_min, const TYPE v_max, const char* format, ImGuiSliderFlags flags, ImRect* out_grab_bb)
{
    ImGuiContext& g = *GImGui;
    const ImGuiStyle& style = g.Style;

    const ImGuiAxis axis = (flags & ImGuiSliderFlags_Vertical) ? ImGuiAxis_Y : ImGuiAxis_X;
    const bool is_decimal = (data_type == ImGuiDataType_Float) || (data_type == ImGuiDataType_Double);
    const bool is_logarithmic = (flags & ImGuiSliderFlags_Logarithmic) && is_decimal;

    const float grab_padding = 2.0f;
    const float slider_sz = (bb.Max[axis] - bb.Min[axis]) - grab_padding * 2.0f;
    float grab_sz = style.GrabMinSize;
    SIGNEDTYPE v_range = (v_min < v_max ? v_max - v_min : v_min - v_max);
    if (!is_decimal && v_range >= 0)                                             // v_range < 0 may happen on integer overflows
        grab_sz = ImMax((float)(slider_sz / (v_range + 1)), style.GrabMinSize);  // For integer sliders: if possible have the grab size represent 1 unit
    grab_sz = ImMin(grab_sz, slider_sz);
    const float slider_usable_sz = slider_sz - grab_sz;
    const float slider_usable_pos_min = bb.Min[axis] + grab_padding + grab_sz * 0.5f;
    const float slider_usable_pos_max = bb.Max[axis] - grab_padding - grab_sz * 0.5f;

    float logarithmic_zero_epsilon = 0.0f; // Only valid when is_logarithmic is true
    float zero_deadzone_halfsize = 0.0f; // Only valid when is_logarithmic is true
    if (is_logarithmic)
    {
        // When using logarithmic sliders, we need to clamp to avoid hitting zero, but our choice of clamp value greatly affects slider precision. We attempt to use the specified precision to estimate a good lower bound.
        const int decimal_precision = is_decimal ? ImParseFormatPrecision(format, 3) : 1;
        logarithmic_zero_epsilon = ImPow(0.1f, (float)decimal_precision);
        zero_deadzone_halfsize = (style.LogSliderDeadzone * 0.5f) / ImMax(slider_usable_sz, 1.0f);
    }

    // Process interacting with the slider
    bool value_changed = false;
    if (g.ActiveId == id)
    {
        bool set_new_value = false;
        float clicked_t = 0.0f;
        if (g.ActiveIdSource == ImGuiInputSource_Mouse)
        {
            if (!g.IO.MouseDown[0])
            {
                ClearActiveID();
            }
            else
            {
                const float mouse_abs_pos = g.IO.MousePos[axis];
                clicked_t = (slider_usable_sz > 0.0f) ? ImClamp((mouse_abs_pos - slider_usable_pos_min) / slider_usable_sz, 0.0f, 1.0f) : 0.0f;
                if (axis == ImGuiAxis_Y)
                    clicked_t = 1.0f - clicked_t;
                set_new_value = true;
            }
        }
        else if (g.ActiveIdSource == ImGuiInputSource_Nav)
        {
            if (g.ActiveIdIsJustActivated)
            {
                g.SliderCurrentAccum = 0.0f; // Reset any stored nav delta upon activation
                g.SliderCurrentAccumDirty = false;
            }

            const ImVec2 input_delta2 = GetNavInputAmount2d(ImGuiNavDirSourceFlags_Keyboard | ImGuiNavDirSourceFlags_PadDPad, ImGuiInputReadMode_RepeatFast, 0.0f, 0.0f);
            float input_delta = (axis == ImGuiAxis_X) ? input_delta2.x : -input_delta2.y;
            if (input_delta != 0.0f)
            {
                const int decimal_precision = is_decimal ? ImParseFormatPrecision(format, 3) : 0;
                if (decimal_precision > 0)
                {
                    input_delta /= 100.0f;    // Gamepad/keyboard tweak speeds in % of slider bounds
                    if (IsNavInputDown(ImGuiNavInput_TweakSlow))
                        input_delta /= 10.0f;
                }
                else
                {
                    if ((v_range >= -100.0f && v_range <= 100.0f) || IsNavInputDown(ImGuiNavInput_TweakSlow))
                        input_delta = ((input_delta < 0.0f) ? -1.0f : +1.0f) / (float)v_range; // Gamepad/keyboard tweak speeds in integer steps
                    else
                        input_delta /= 100.0f;
                }
                if (IsNavInputDown(ImGuiNavInput_TweakFast))
                    input_delta *= 10.0f;

                g.SliderCurrentAccum += input_delta;
                g.SliderCurrentAccumDirty = true;
            }

            float delta = g.SliderCurrentAccum;
            if (g.NavActivatePressedId == id && !g.ActiveIdIsJustActivated)
            {
                ClearActiveID();
            }
            else if (g.SliderCurrentAccumDirty)
            {
                clicked_t = ScaleRatioFromValueT<TYPE, SIGNEDTYPE, FLOATTYPE>(data_type, *v, v_min, v_max, is_logarithmic, logarithmic_zero_epsilon, zero_deadzone_halfsize);

                if ((clicked_t >= 1.0f && delta > 0.0f) || (clicked_t <= 0.0f && delta < 0.0f)) // This is to avoid applying the saturation when already past the limits
                {
                    set_new_value = false;
                    g.SliderCurrentAccum = 0.0f; // If pushing up against the limits, don't continue to accumulate
                }
                else
                {
                    set_new_value = true;
                    float old_clicked_t = clicked_t;
                    clicked_t = ImSaturate(clicked_t + delta);

                    // Calculate what our "new" clicked_t will be, and thus how far we actually moved the slider, and subtract this from the accumulator
                    TYPE v_new = ScaleValueFromRatioT<TYPE, SIGNEDTYPE, FLOATTYPE>(data_type, clicked_t, v_min, v_max, is_logarithmic, logarithmic_zero_epsilon, zero_deadzone_halfsize);
                    if (!(flags & ImGuiSliderFlags_NoRoundToFormat))
                        v_new = RoundScalarWithFormatT<TYPE, SIGNEDTYPE>(format, data_type, v_new);
                    float new_clicked_t = ScaleRatioFromValueT<TYPE, SIGNEDTYPE, FLOATTYPE>(data_type, v_new, v_min, v_max, is_logarithmic, logarithmic_zero_epsilon, zero_deadzone_halfsize);

                    if (delta > 0)
                        g.SliderCurrentAccum -= ImMin(new_clicked_t - old_clicked_t, delta);
                    else
                        g.SliderCurrentAccum -= ImMax(new_clicked_t - old_clicked_t, delta);
                }

                g.SliderCurrentAccumDirty = false;
            }
        }

        if (set_new_value)
        {
            TYPE v_new = ScaleValueFromRatioT<TYPE, SIGNEDTYPE, FLOATTYPE>(data_type, clicked_t, v_min, v_max, is_logarithmic, logarithmic_zero_epsilon, zero_deadzone_halfsize);

            // Round to user desired precision based on format string
            if (!(flags & ImGuiSliderFlags_NoRoundToFormat))
                v_new = RoundScalarWithFormatT<TYPE, SIGNEDTYPE>(format, data_type, v_new);

            // Apply result
            if (*v != v_new)
            {
                *v = v_new;
                value_changed = true;
            }
        }
    }

    if (slider_sz < 1.0f)
    {
        *out_grab_bb = ImRect(bb.Min, bb.Min);
    }
    else
    {
        // Output grab position so it can be displayed by the caller
        float grab_t = ScaleRatioFromValueT<TYPE, SIGNEDTYPE, FLOATTYPE>(data_type, *v, v_min, v_max, is_logarithmic, logarithmic_zero_epsilon, zero_deadzone_halfsize);
        if (axis == ImGuiAxis_Y)
            grab_t = 1.0f - grab_t;
        const float grab_pos = ImLerp(slider_usable_pos_min, slider_usable_pos_max, grab_t);
        if (axis == ImGuiAxis_X)
            *out_grab_bb = ImRect(grab_pos - grab_sz * 0.5f, bb.Min.y + grab_padding, grab_pos + grab_sz * 0.5f, bb.Max.y - grab_padding);
        else
            *out_grab_bb = ImRect(bb.Min.x + grab_padding, grab_pos - grab_sz * 0.5f, bb.Max.x - grab_padding, grab_pos + grab_sz * 0.5f);
    }

    return value_changed;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %r8, %rbx
movq %rcx, -0x88(%rbp)
movq %r8, %rax
subq %r9, %rax
negq %rax
movq %r8, -0x78(%rbp)
movq %r9, -0x80(%rbp)
subq %r9, %rbx
movl 0x18(%rbp), %r14d
cmovbq %rax, %rbx
leaq 0x51d2f(%rip), %r13     # 0xfdcd0
movl %r14d, %r12d
andl $0x100000, %r12d        # imm = 0x100000
movl %edx, -0x3c(%rbp)
andl $-0x2, %edx
movl %edx, -0xa0(%rbp)
cmpl $0x8, %edx
sete %al
movl %r12d, %ecx
shrl $0x12, %ecx
movss (%rdi,%rcx), %xmm4
movq %rdi, -0x48(%rbp)
movss 0x8(%rdi,%rcx), %xmm2
andl $0x20, %r14d
shrl $0x5, %r14d
andb %al, %r14b
testq %rbx, %rbx
sets %cl
orb %al, %cl
movq (%r13), %r15
movaps %xmm2, %xmm5
subss %xmm4, %xmm5
addss 0xb868(%rip), %xmm5     # 0xb7860
movss 0x15d8(%r15), %xmm3
jne 0xac027
leaq 0x1(%rbx), %rax
cvtsi2ss %rax, %xmm0
movaps %xmm5, %xmm1
divss %xmm0, %xmm1
movaps %xmm3, %xmm0
cmpless %xmm1, %xmm0
andps %xmm0, %xmm1
andnps %xmm3, %xmm0
orps %xmm1, %xmm0
movaps %xmm0, %xmm3
minss %xmm5, %xmm3
movaps %xmm5, %xmm8
subss %xmm3, %xmm8
addss 0xb82c(%rip), %xmm4     # 0xb7868
movss 0xafc0(%rip), %xmm6     # 0xb7004
mulss %xmm3, %xmm6
xorps %xmm7, %xmm7
xorps %xmm1, %xmm1
testb %r14b, %r14b
movaps %xmm3, -0x70(%rbp)
movss %xmm2, -0x30(%rbp)
movss %xmm5, -0x60(%rbp)
movss %xmm6, -0x34(%rbp)
je 0xac0f8
movq 0x10(%rbp), %rdi
movl %r14d, %r13d
movq %r15, %r14
movl %r12d, %r15d
movl %esi, %r12d
movl $0x3, %esi
movss %xmm4, -0x40(%rbp)
movss %xmm8, -0x2c(%rbp)
callq 0x9993e
xorps %xmm1, %xmm1
cvtsi2ss %eax, %xmm1
movss 0xb7ea(%rip), %xmm0     # 0xb7888
callq 0xc730
movss -0x2c(%rbp), %xmm8
movl %r12d, %esi
movl %r15d, %r12d
movq %r14, %r15
movl %r13d, %r14d
leaq 0x51c14(%rip), %r13     # 0xfdcd0
movss -0x34(%rbp), %xmm6
movss -0x60(%rbp), %xmm5
movss -0x40(%rbp), %xmm4
movaps -0x70(%rbp), %xmm3
movss -0x30(%rbp), %xmm2
movaps %xmm0, %xmm1
movss 0x15e0(%r15), %xmm7
mulss 0xaf1c(%rip), %xmm7     # 0xb7004
movaps %xmm8, %xmm0
maxss 0xaef0(%rip), %xmm0     # 0xb6fe4
divss %xmm0, %xmm7
addss %xmm6, %xmm4
cmpl %esi, 0x1b30(%r15)
movss %xmm4, -0x40(%rbp)
jne 0xac1a8
movl 0x1b68(%r15), %eax
cmpl $0x2, %eax
movss %xmm7, -0x2c(%rbp)
movss %xmm1, -0x38(%rbp)
je 0xac1b4
xorps %xmm0, %xmm0
cmpl $0x1, %eax
jne 0xac27b
cmpb $0x0, 0x130(%r15)
movl -0x3c(%rbp), %ebx
je 0xac289
ucomiss %xmm0, %xmm8
jbe 0xac186
movl %r12d, %eax
shrl $0x14, %eax
movss 0x128(%r15,%rax,4), %xmm0
subss %xmm4, %xmm0
divss %xmm8, %xmm0
movss 0xae77(%rip), %xmm9     # 0xb6fe4
minss %xmm0, %xmm9
movaps %xmm1, %xmm8
xorps %xmm1, %xmm1
cmpltss %xmm1, %xmm0
movaps %xmm8, %xmm1
andnps %xmm9, %xmm0
testl %r12d, %r12d
je 0xac19d
movss 0xae50(%rip), %xmm8     # 0xb6fe4
subss %xmm0, %xmm8
movaps %xmm8, %xmm0
movq -0x48(%rbp), %r15
movb $0x1, %al
jmp 0xac500
xorl %r13d, %r13d
movq -0x48(%rbp), %r15
jmp 0xac56f
movl %esi, -0xb0(%rbp)
cmpb $0x1, 0x1b3c(%r15)
jne 0xac1d7
movl $0x0, 0x3094(%r15)
movb $0x0, 0x3098(%r15)
xorps %xmm0, %xmm0
xorps %xmm1, %xmm1
movl $0x3, %edi
movl $0x5, %esi
callq 0x59117
testl %r12d, %r12d
je 0xac1fc
shufps $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
xorps 0xadc4(%rip), %xmm0     # 0xb6fc0
ucomiss 0xb641(%rip), %xmm0     # 0xb7844
movss -0x2c(%rbp), %xmm7
movl -0xb0(%rbp), %edx
jne 0xac216
jnp 0xac342
cmpl $0x8, -0xa0(%rbp)
jne 0xac2b9
movq 0x10(%rbp), %rdi
movl $0x3, %esi
movaps %xmm0, -0xa0(%rbp)
callq 0x9993e
movaps -0xa0(%rbp), %xmm0
movl -0xb0(%rbp), %edx
movss -0x2c(%rbp), %xmm7
testl %eax, %eax
jle 0xac2b9
divss 0xb62e(%rip), %xmm0     # 0xb7884
movq (%r13), %rax
movss 0x37c(%rax), %xmm2
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm2
jbe 0xac306
divss 0xad92(%rip), %xmm0     # 0xb7008
jmp 0xac306
xorl %eax, %eax
movq -0x48(%rbp), %r15
movl -0x3c(%rbp), %ebx
jmp 0xac500
callq 0x46c46
xorps %xmm0, %xmm0
movss -0x38(%rbp), %xmm1
movss -0x2c(%rbp), %xmm7
movss -0x34(%rbp), %xmm6
movss -0x60(%rbp), %xmm5
movaps -0x70(%rbp), %xmm3
movss -0x30(%rbp), %xmm2
xorl %eax, %eax
movq -0x48(%rbp), %r15
jmp 0xac500
leaq 0x64(%rbx), %rax
cmpq $0xc9, %rax
jb 0xac2d9
movq (%r13), %rax
movss 0x37c(%rax), %xmm2
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm2
jbe 0xac2fe
xorps %xmm2, %xmm2
cvtsi2ss %rbx, %xmm2
xorps %xmm1, %xmm1
xorl %eax, %eax
ucomiss %xmm0, %xmm1
seta %al
leaq 0x10ddd(%rip), %rcx     # 0xbd0d0
movss (%rcx,%rax,4), %xmm0
divss %xmm2, %xmm0
jmp 0xac306
divss 0xb57e(%rip), %xmm0     # 0xb7884
movq (%r13), %rax
movss 0xacf6(%rip), %xmm2     # 0xb7008
cmpltss 0x380(%rax), %xmm1
mulss %xmm0, %xmm2
andps %xmm1, %xmm2
andnps %xmm0, %xmm1
orps %xmm2, %xmm1
addss 0x3094(%r15), %xmm1
movss %xmm1, 0x3094(%r15)
movb $0x1, 0x3098(%r15)
movss 0x3094(%r15), %xmm2
cmpl %edx, 0x1ca8(%r15)
jne 0xac35e
cmpb $0x0, 0x1b3c(%r15)
je 0xac3dd
cmpb $0x1, 0x3098(%r15)
movl -0x3c(%rbp), %ebx
jne 0xac3c9
movq -0x88(%rbp), %rax
movq (%rax), %rsi
movzbl %r14b, %r13d
movl %ebx, %edi
movq -0x78(%rbp), %rdx
movq -0x80(%rbp), %rcx
movl %r13d, %r8d
movss -0x38(%rbp), %xmm0
movaps %xmm7, %xmm1
movaps %xmm2, -0xa0(%rbp)
callq 0xae480
movaps -0xa0(%rbp), %xmm3
ucomiss 0xac3c(%rip), %xmm0     # 0xb6fe4
jb 0xac3b2
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm3
ja 0xac3c2
xorps %xmm1, %xmm1
ucomiss %xmm0, %xmm1
jb 0xac40b
xorps %xmm2, %xmm2
ucomiss %xmm3, %xmm2
jbe 0xac40b
xorl %eax, %eax
jmp 0xac4ce
xorps %xmm0, %xmm0
xorl %eax, %eax
movq -0x48(%rbp), %r15
movss -0x30(%rbp), %xmm2
movaps -0x70(%rbp), %xmm3
jmp 0xac3fc
callq 0x46c46
movss -0x2c(%rbp), %xmm7
xorps %xmm0, %xmm0
xorl %eax, %eax
movq -0x48(%rbp), %r15
movss -0x30(%rbp), %xmm2
movaps -0x70(%rbp), %xmm3
movl -0x3c(%rbp), %ebx
movss -0x60(%rbp), %xmm5
movss -0x34(%rbp), %xmm6
jmp 0xac4fb
movaps %xmm0, -0xb0(%rbp)
addss %xmm0, %xmm3
movss 0xabc6(%rip), %xmm0     # 0xb6fe4
minss %xmm3, %xmm0
cmpltss %xmm1, %xmm3
andnps %xmm0, %xmm3
movl %ebx, %edi
movaps %xmm3, -0xc0(%rbp)
movaps %xmm3, %xmm0
movq -0x78(%rbp), %rsi
movq -0x80(%rbp), %rdx
movl %r13d, %ecx
movss -0x38(%rbp), %xmm1
movss -0x2c(%rbp), %xmm2
callq 0xae5cf
movl 0x18(%rbp), %ecx
testb $0x40, %cl
jne 0xac466
movq 0x10(%rbp), %rdi
movl %ebx, %esi
movq %rax, %rdx
callq 0xae77a
movl %ebx, %edi
movq %rax, %rsi
movq -0x78(%rbp), %rdx
movq -0x80(%rbp), %rcx
movl %r13d, %r8d
movss -0x38(%rbp), %xmm0
movss -0x2c(%rbp), %xmm1
callq 0xae480
movaps -0xa0(%rbp), %xmm3
ucomiss 0xb3b1(%rip), %xmm3     # 0xb7844
subss -0xb0(%rbp), %xmm0
movss 0x3094(%r15), %xmm1
jbe 0xac4b0
minss %xmm3, %xmm0
subss %xmm0, %xmm1
jmp 0xac4c5
movaps %xmm3, %xmm2
cmpless %xmm0, %xmm2
andps %xmm2, %xmm0
andnps %xmm3, %xmm2
orps %xmm0, %xmm2
subss %xmm2, %xmm1
movb $0x1, %al
movaps -0xc0(%rbp), %xmm0
movss -0x30(%rbp), %xmm2
movaps -0x70(%rbp), %xmm3
movss -0x60(%rbp), %xmm5
movss -0x34(%rbp), %xmm6
movss -0x2c(%rbp), %xmm7
movss %xmm1, 0x3094(%r15)
movb $0x0, 0x3098(%r15)
movq -0x48(%rbp), %r15
movss -0x38(%rbp), %xmm1
testb %al, %al
je 0xac56c
movzbl %r14b, %ecx
movl %ebx, %edi
movq -0x78(%rbp), %rsi
movq -0x80(%rbp), %rdx
movaps %xmm7, %xmm2
callq 0xae5cf
movl 0x18(%rbp), %ecx
testb $0x40, %cl
jne 0xac530
movq 0x10(%rbp), %rdi
movl %ebx, %esi
movq %rax, %rdx
callq 0xae77a
movss -0x30(%rbp), %xmm2
movaps -0x70(%rbp), %xmm3
movss -0x60(%rbp), %xmm5
movss -0x34(%rbp), %xmm6
movq -0x88(%rbp), %rcx
cmpq %rax, (%rcx)
setne %r13b
movss -0x2c(%rbp), %xmm7
movss -0x38(%rbp), %xmm1
je 0xac56f
movq -0x88(%rbp), %rcx
movq %rax, (%rcx)
movb $0x1, %r13b
jmp 0xac56f
xorl %r13d, %r13d
movq 0x20(%rbp), %rbx
movss 0xaa69(%rip), %xmm0     # 0xb6fe4
ucomiss %xmm5, %xmm0
jbe 0xac58f
movq (%r15), %rax
movq %rax, (%rbx)
movq %rax, 0x8(%rbx)
jmp 0xac69d
addss 0xb2f5(%rip), %xmm2     # 0xb788c
movaps 0xaa22(%rip), %xmm0     # 0xb6fc0
xorps %xmm3, %xmm0
movaps %xmm0, -0x60(%rbp)
subss %xmm6, %xmm2
movss %xmm2, -0x30(%rbp)
movq -0x88(%rbp), %rax
movq (%rax), %rsi
movzbl %r14b, %r8d
movl -0x3c(%rbp), %edi
movq -0x78(%rbp), %rdx
movq -0x80(%rbp), %rcx
movaps %xmm1, %xmm0
movaps %xmm7, %xmm1
callq 0xae480
testl %r12d, %r12d
je 0xac5e6
movss 0xaa05(%rip), %xmm1     # 0xb6fe4
subss %xmm0, %xmm1
movaps %xmm1, %xmm0
movss -0x40(%rbp), %xmm1
movss -0x30(%rbp), %xmm3
subss %xmm1, %xmm3
mulss %xmm0, %xmm3
addss %xmm1, %xmm3
jne 0xac64f
movss 0xa9fe(%rip), %xmm0     # 0xb7004
movaps -0x60(%rbp), %xmm5
mulss %xmm0, %xmm5
addss %xmm3, %xmm5
movss 0x4(%r15), %xmm1
movss 0xc(%r15), %xmm2
addss 0xb242(%rip), %xmm1     # 0xb7868
movaps -0x70(%rbp), %xmm4
mulss %xmm0, %xmm4
addss %xmm3, %xmm4
addss 0xb252(%rip), %xmm2     # 0xb788c
movss %xmm5, (%rbx)
movss %xmm1, 0x4(%rbx)
movss %xmm4, 0x8(%rbx)
movss %xmm2, 0xc(%rbx)
jmp 0xac69d
movss (%r15), %xmm0
addss 0xb20c(%rip), %xmm0     # 0xb7868
movss 0x8(%r15), %xmm1
movss 0xa99a(%rip), %xmm2     # 0xb7004
movaps -0x60(%rbp), %xmm5
mulss %xmm2, %xmm5
addss %xmm3, %xmm5
addss 0xb20e(%rip), %xmm1     # 0xb788c
movaps -0x70(%rbp), %xmm4
mulss %xmm2, %xmm4
addss %xmm3, %xmm4
movss %xmm0, (%rbx)
movss %xmm5, 0x4(%rbx)
movss %xmm1, 0x8(%rbx)
movss %xmm4, 0xc(%rbx)
movl %r13d, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq