// File: /workspace/github_cpp_makefile_star2_O1/Ciaxur[P]yagb-emu/include/imgui/imgui_widgets.cpp
// Function: bool ImGui::DragBehaviorT<unsigned int, int, float>(int, unsigned int*, float, unsigned int, unsigned int, char const*, int)
bool ImGui::DragBehaviorT(ImGuiDataType data_type, TYPE* v, float v_speed, const TYPE v_min, const TYPE v_max, const char* format, ImGuiSliderFlags flags)
{
    ImGuiContext& g = *GImGui;
    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_clamped = (v_min < v_max);
    const bool is_logarithmic = (flags & ImGuiSliderFlags_Logarithmic) && is_decimal;

    // Default tweak speed
    if (v_speed == 0.0f && is_clamped && (v_max - v_min < FLT_MAX))
        v_speed = (float)((v_max - v_min) * g.DragSpeedDefaultRatio);

    // Inputs accumulates into g.DragCurrentAccum, which is flushed into the current value as soon as it makes a difference with our precision settings
    float adjust_delta = 0.0f;
    if (g.ActiveIdSource == ImGuiInputSource_Mouse && IsMousePosValid() && IsMouseDragPastThreshold(0, g.IO.MouseDragThreshold * DRAG_MOUSE_THRESHOLD_FACTOR))
    {
        adjust_delta = g.IO.MouseDelta[axis];
        if (g.IO.KeyAlt)
            adjust_delta *= 1.0f / 100.0f;
        if (g.IO.KeyShift)
            adjust_delta *= 10.0f;
    }
    else if (g.ActiveIdSource == ImGuiInputSource_Nav)
    {
        int decimal_precision = is_decimal ? ImParseFormatPrecision(format, 3) : 0;
        adjust_delta = GetNavInputAmount2d(ImGuiNavDirSourceFlags_Keyboard | ImGuiNavDirSourceFlags_PadDPad, ImGuiInputReadMode_RepeatFast, 1.0f / 10.0f, 10.0f)[axis];
        v_speed = ImMax(v_speed, GetMinimumStepAtDecimalPrecision(decimal_precision));
    }
    adjust_delta *= v_speed;

    // For vertical drag we currently assume that Up=higher value (like we do with vertical sliders). This may become a parameter.
    if (axis == ImGuiAxis_Y)
        adjust_delta = -adjust_delta;

    // For logarithmic use our range is effectively 0..1 so scale the delta into that range
    if (is_logarithmic && (v_max - v_min < FLT_MAX) && ((v_max - v_min) > 0.000001f)) // Epsilon to avoid /0
        adjust_delta /= (float)(v_max - v_min);

    // Clear current value on activation
    // Avoid altering values and clamping when we are _already_ past the limits and heading in the same direction, so e.g. if range is 0..255, current value is 300 and we are pushing to the right side, keep the 300.
    bool is_just_activated = g.ActiveIdIsJustActivated;
    bool is_already_past_limits_and_pushing_outward = is_clamped && ((*v >= v_max && adjust_delta > 0.0f) || (*v <= v_min && adjust_delta < 0.0f));
    if (is_just_activated || is_already_past_limits_and_pushing_outward)
    {
        g.DragCurrentAccum = 0.0f;
        g.DragCurrentAccumDirty = false;
    }
    else if (adjust_delta != 0.0f)
    {
        g.DragCurrentAccum += adjust_delta;
        g.DragCurrentAccumDirty = true;
    }

    if (!g.DragCurrentAccumDirty)
        return false;

    TYPE v_cur = *v;
    FLOATTYPE v_old_ref_for_accum_remainder = (FLOATTYPE)0.0f;

    float logarithmic_zero_epsilon = 0.0f; // Only valid when is_logarithmic is true
    const float zero_deadzone_halfsize = 0.0f; // Drag widgets have no deadzone (as it doesn't make sense)
    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);

        // Convert to parametric space, apply delta, convert back
        float v_old_parametric = ScaleRatioFromValueT<TYPE, SIGNEDTYPE, FLOATTYPE>(data_type, v_cur, v_min, v_max, is_logarithmic, logarithmic_zero_epsilon, zero_deadzone_halfsize);
        float v_new_parametric = v_old_parametric + g.DragCurrentAccum;
        v_cur = ScaleValueFromRatioT<TYPE, SIGNEDTYPE, FLOATTYPE>(data_type, v_new_parametric, v_min, v_max, is_logarithmic, logarithmic_zero_epsilon, zero_deadzone_halfsize);
        v_old_ref_for_accum_remainder = v_old_parametric;
    }
    else
    {
        v_cur += (SIGNEDTYPE)g.DragCurrentAccum;
    }

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

    // Preserve remainder after rounding has been applied. This also allow slow tweaking of values.
    g.DragCurrentAccumDirty = false;
    if (is_logarithmic)
    {
        // Convert to parametric space, apply delta, convert back
        float v_new_parametric = ScaleRatioFromValueT<TYPE, SIGNEDTYPE, FLOATTYPE>(data_type, v_cur, v_min, v_max, is_logarithmic, logarithmic_zero_epsilon, zero_deadzone_halfsize);
        g.DragCurrentAccum -= (float)(v_new_parametric - v_old_ref_for_accum_remainder);
    }
    else
    {
        g.DragCurrentAccum -= (float)((SIGNEDTYPE)v_cur - (SIGNEDTYPE)*v);
    }

    // Lose zero sign for float/double
    if (v_cur == (TYPE)-0)
        v_cur = (TYPE)0;

    // Clamp values (+ handle overflow/wrap-around for integer types)
    if (*v != v_cur && is_clamped)
    {
        if (v_cur < v_min || (v_cur > *v && adjust_delta < 0.0f && !is_decimal))
            v_cur = v_min;
        if (v_cur > v_max || (v_cur < *v && adjust_delta > 0.0f && !is_decimal))
            v_cur = v_max;
    }

    // Apply result
    if (*v == v_cur)
        return false;
    *v = v_cur;
    return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %r9d, %r12d
movq %r8, -0x60(%rbp)
movaps %xmm0, %xmm2
movq %rsi, -0x58(%rbp)
leaq 0x548aa(%rip), %rax     # 0xfdcd0
movq (%rax), %r13
movl %r9d, %r14d
andl $0x100000, %r14d        # imm = 0x100000
movl %edi, -0x3c(%rbp)
movl %edi, %eax
andl $-0x2, %eax
movl %eax, -0x38(%rbp)
cmpl $0x8, %eax
sete %bl
movl %ecx, -0x30(%rbp)
movl %ecx, %esi
movl %edx, -0x34(%rbp)
subl %edx, %esi
setbe %al
movl %r9d, -0x64(%rbp)
andl $0x20, %r12d
shrl $0x5, %r12d
xorps %xmm0, %xmm0
ucomiss %xmm0, %xmm2
setp %cl
setne %dl
orb %cl, %dl
orb %al, %dl
jne 0xa9480
xorps %xmm2, %xmm2
cvtsi2ss %rsi, %xmm2
mulss 0x30a0(%r13), %xmm2
movq %rsi, -0x70(%rbp)
movl %r14d, %r15d
shrl $0x14, %r15d
cmpl $0x1, 0x1b68(%r13)
movaps %xmm2, -0x50(%rbp)
jne 0xa9503
xorl %edi, %edi
callq 0x4806b
movaps -0x50(%rbp), %xmm2
testb %al, %al
je 0xa9503
movss 0x38(%r13), %xmm0
mulss 0xdb4e(%rip), %xmm0     # 0xb7004
xorl %edi, %edi
callq 0x52739
movaps -0x50(%rbp), %xmm2
testb %al, %al
je 0xa9503
movl %r15d, %eax
movss 0x3b8(%r13,%rax,4), %xmm3
cmpb $0x0, 0x142(%r13)
je 0xa94e4
mulss 0x13a30(%rip), %xmm3    # 0xbcf14
movl -0x30(%rbp), %r15d
cmpb $0x1, 0x141(%r13)
jne 0xa95c4
mulss 0xdb0a(%rip), %xmm3     # 0xb7008
jmp 0xa95c4
xorps %xmm3, %xmm3
cmpl $0x2, 0x1b68(%r13)
jne 0xa9574
movb %bl, -0x29(%rbp)
xorl %ebx, %ebx
cmpl $0x8, -0x38(%rbp)
jne 0xa952b
movq -0x60(%rbp), %rdi
movl $0x3, %esi
callq 0x9993e
movl %eax, %ebx
movss 0xe355(%rip), %xmm0     # 0xb7888
movss 0xdacd(%rip), %xmm1     # 0xb7008
movl $0x3, %edi
movl $0x5, %esi
callq 0x59117
movlps %xmm0, -0x78(%rbp)
movl %r15d, %eax
movss -0x78(%rbp,%rax,4), %xmm3
testl %ebx, %ebx
js 0xa957a
cmpl $0x9, %ebx
movl -0x30(%rbp), %r15d
jg 0xa9588
movl %ebx, %eax
leaq 0x29b63(%rip), %rcx     # 0xd30d0
movss (%rcx,%rax,4), %xmm0
jmp 0xa95ac
movl -0x30(%rbp), %r15d
jmp 0xa95c4
movss 0x278d6(%rip), %xmm0    # 0xd0e58
movl -0x30(%rbp), %r15d
jmp 0xa95ac
negl %ebx
xorps %xmm1, %xmm1
cvtsi2ss %ebx, %xmm1
movss 0xda6f(%rip), %xmm0     # 0xb7008
movaps %xmm3, -0x90(%rbp)
callq 0xc730
movaps -0x90(%rbp), %xmm3
movaps -0x50(%rbp), %xmm2
movaps %xmm0, %xmm1
cmpless %xmm2, %xmm1
andps %xmm1, %xmm2
andnps %xmm0, %xmm1
orps %xmm1, %xmm2
movb -0x29(%rbp), %bl
andb %r12b, %bl
mulss %xmm2, %xmm3
testl %r14d, %r14d
je 0xa95d7
xorps 0xd9e9(%rip), %xmm3     # 0xb6fc0
movq -0x58(%rbp), %r14
movl -0x34(%rbp), %r12d
testb %bl, %bl
jne 0xa95e8
movaps %xmm3, %xmm1
jmp 0xa95f8
xorps %xmm0, %xmm0
cvtsi2ssq -0x70(%rbp), %xmm0
movaps %xmm3, %xmm1
divss %xmm0, %xmm1
xorl %eax, %eax
cmpl %r12d, %r15d
jne 0xa9602
movaps %xmm3, %xmm1
movb 0x1b3c(%r13), %cl
jbe 0xa962e
movl (%r14), %edx
cmpl %r15d, %edx
jb 0xa961d
movb $0x1, %al
xorps %xmm0, %xmm0
ucomiss %xmm0, %xmm1
ja 0xa962e
cmpl %r12d, %edx
setbe %dl
xorps %xmm0, %xmm0
ucomiss %xmm1, %xmm0
seta %al
andb %dl, %al
testb %cl, %cl
jne 0xa965a
testb %al, %al
jne 0xa965a
xorps %xmm0, %xmm0
ucomiss %xmm0, %xmm1
jne 0xa9640
jnp 0xa966e
movss 0x309c(%r13), %xmm0
addss %xmm1, %xmm0
movss %xmm0, 0x309c(%r13)
movb $0x1, %al
jmp 0xa9667
movl $0x0, 0x309c(%r13)
xorl %eax, %eax
movb %al, 0x3099(%r13)
cmpb $0x1, 0x3099(%r13)
jne 0xa973c
movl %ebx, %eax
movl (%r14), %ebx
movb %al, -0x29(%rbp)
testb %al, %al
movss %xmm1, -0x58(%rbp)
je 0xa9743
movq -0x60(%rbp), %rdi
movl $0x3, %esi
callq 0x9993e
xorps %xmm1, %xmm1
cvtsi2ss %eax, %xmm1
movss 0xe1da(%rip), %xmm0     # 0xb7888
callq 0xc730
xorps %xmm1, %xmm1
movl -0x3c(%rbp), %edi
movl %ebx, %esi
movl %r12d, %edx
movl %r15d, %ecx
movl $0x1, %r8d
movss %xmm0, -0x50(%rbp)
callq 0xadc2d
xorl %ebx, %ebx
cmpl %r12d, %r15d
movss %xmm0, -0x30(%rbp)
je 0xa975b
movaps %xmm0, %xmm1
addss 0x309c(%r13), %xmm1
xorps %xmm2, %xmm2
ucomiss %xmm1, %xmm2
jae 0xa9826
ucomiss 0xd8e8(%rip), %xmm1     # 0xb6fe4
jae 0xa982e
movl %r12d, %eax
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
movss -0x50(%rbp), %xmm4
movaps %xmm4, %xmm2
movl %r15d, %eax
xorps %xmm3, %xmm3
cvtsi2ss %rax, %xmm3
maxss %xmm0, %xmm2
movaps %xmm4, %xmm0
maxss %xmm3, %xmm0
cmpl %r12d, %r15d
jb 0xa9836
movaps %xmm2, %xmm3
jmp 0xa983c
xorl %eax, %eax
jmp 0xa9817
cvttss2si 0x309c(%r13), %eax
addl %eax, %ebx
xorps %xmm0, %xmm0
movss %xmm0, -0x30(%rbp)
movss %xmm0, -0x50(%rbp)
testb $0x40, -0x64(%rbp)
jne 0xa9771
movq -0x60(%rbp), %rdi
movl -0x3c(%rbp), %esi
movl %ebx, %edx
callq 0xaddff
movl %eax, %ebx
movb $0x0, 0x3099(%r13)
cmpb $0x0, -0x29(%rbp)
je 0xa97a4
xorps %xmm1, %xmm1
movl -0x3c(%rbp), %edi
movl %ebx, %esi
movl %r12d, %edx
movl %r15d, %ecx
movl $0x1, %r8d
movss -0x50(%rbp), %xmm0
callq 0xadc2d
subss -0x30(%rbp), %xmm0
jmp 0xa97b0
movl %ebx, %eax
subl (%r14), %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
movss 0x309c(%r13), %xmm1
subss %xmm0, %xmm1
movss %xmm1, 0x309c(%r13)
movl (%r14), %eax
cmpl %r12d, %r15d
jbe 0xa980b
cmpl %ebx, %eax
je 0xa980b
cmpl %r12d, %ebx
movss -0x58(%rbp), %xmm1
jb 0xa97ee
cmpl $0x8, -0x38(%rbp)
je 0xa97f1
cmpl %eax, %ebx
jbe 0xa97f1
xorps %xmm0, %xmm0
ucomiss %xmm1, %xmm0
jbe 0xa97f1
movl %r12d, %ebx
cmpl %r15d, %ebx
ja 0xa9808
cmpl $0x8, -0x38(%rbp)
je 0xa980b
cmpl %eax, %ebx
jae 0xa980b
xorps %xmm0, %xmm0
ucomiss %xmm0, %xmm1
jbe 0xa980b
movl %r15d, %ebx
cmpl %ebx, %eax
setne %al
je 0xa9817
movl %ebx, (%r14)
movb $0x1, %al
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r12d, %ebx
jmp 0xa975b
movl %r15d, %ebx
jmp 0xa975b
movaps %xmm0, %xmm3
movaps %xmm2, %xmm0
jae 0xa984d
movss 0xd79e(%rip), %xmm2     # 0xb6fe4
subss %xmm1, %xmm2
movaps %xmm2, %xmm1
divss %xmm3, %xmm0
movss %xmm3, -0x34(%rbp)
callq 0xc730
mulss -0x34(%rbp), %xmm0
cvttss2si %xmm0, %rbx
jmp 0xa975b