// File: /workspace/github_cpp_makefile_star2_O3/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, %r15d
movq %r8, -0x68(%rbp)
movaps %xmm0, %xmm2
movq %rsi, %rbx
leaq 0x54389(%rip), %rax     # 0xfbcd0
movq (%rax), %rsi
movl %r9d, %r13d
andl $0x100000, %r13d        # imm = 0x100000
movl %edi, -0x44(%rbp)
movl %edi, %eax
andl $-0x2, %eax
movl %eax, -0x48(%rbp)
cmpl $0x8, %eax
sete %dil
movl %ecx, -0x34(%rbp)
movl %ecx, %r14d
movl %edx, -0x30(%rbp)
subl %edx, %r14d
setbe %al
movl %r9d, -0x6c(%rbp)
andl $0x20, %r15d
shrl $0x5, %r15d
xorps %xmm0, %xmm0
ucomiss %xmm0, %xmm2
setp %cl
setne %dl
orb %cl, %dl
orb %al, %dl
jne 0xa79a3
xorps %xmm2, %xmm2
cvtsi2ss %r14, %xmm2
mulss 0x30a0(%rsi), %xmm2
movl %r13d, %r12d
shrl $0x14, %r12d
movl 0x1b68(%rsi), %eax
cmpl $0x1, %eax
movq %rbx, -0x40(%rbp)
movb %dil, -0x29(%rbp)
movaps %xmm2, -0x60(%rbp)
jne 0xa7a4a
movq %rsi, %rbx
xorl %edi, %edi
callq 0x4750f
testb %al, %al
je 0xa7a35
movss 0x38(%rbx), %xmm0
mulss 0xd624(%rip), %xmm0     # 0xb5004
xorl %edi, %edi
callq 0x5174b
testb %al, %al
je 0xa7a35
movl %r12d, %eax
movq %rbx, %rsi
movss 0x3b8(%rbx,%rax,4), %xmm3
cmpb $0x0, 0x142(%rbx)
je 0xa7a0b
mulss 0x134d9(%rip), %xmm3    # 0xbaee4
movl -0x30(%rbp), %r12d
movb -0x29(%rbp), %dil
movq -0x40(%rbp), %rbx
movaps -0x60(%rbp), %xmm2
cmpb $0x1, 0x141(%rsi)
jne 0xa7b10
mulss 0xd5d8(%rip), %xmm3     # 0xb5008
jmp 0xa7b10
movq %rbx, %rsi
movl 0x1b68(%rbx), %eax
movb -0x29(%rbp), %dil
movq -0x40(%rbp), %rbx
movaps -0x60(%rbp), %xmm2
xorps %xmm3, %xmm3
cmpl $0x2, %eax
jne 0xa7ab7
movq %rsi, -0x50(%rbp)
xorl %ebx, %ebx
cmpl $0x8, -0x48(%rbp)
jne 0xa7a6e
movq -0x68(%rbp), %rdi
movl $0x3, %esi
callq 0x97b86
movl %eax, %ebx
movss 0xde12(%rip), %xmm0     # 0xb5888
movss 0xd58a(%rip), %xmm1     # 0xb5008
movl $0x3, %edi
movl $0x5, %esi
callq 0x57fa4
movlps %xmm0, -0x78(%rbp)
movl %r12d, %eax
movss -0x78(%rbp,%rax,4), %xmm3
testl %ebx, %ebx
js 0xa7abd
cmpl $0x9, %ebx
movl -0x30(%rbp), %r12d
ja 0xa7acb
movl %ebx, %eax
leaq 0x294f0(%rip), %rcx     # 0xd0fa0
movss (%rcx,%rax,4), %xmm0
jmp 0xa7aef
movl -0x30(%rbp), %r12d
jmp 0xa7b10
movss 0x2735b(%rip), %xmm0    # 0xcee20
movl -0x30(%rbp), %r12d
jmp 0xa7aef
negl %ebx
xorps %xmm1, %xmm1
cvtsi2ss %ebx, %xmm1
movss 0xd52c(%rip), %xmm0     # 0xb5008
movaps %xmm3, -0x90(%rbp)
callq 0xc730
movaps -0x90(%rbp), %xmm3
movq -0x50(%rbp), %rsi
movb -0x29(%rbp), %dil
movaps -0x60(%rbp), %xmm2
movaps %xmm0, %xmm1
cmpless %xmm2, %xmm1
andps %xmm1, %xmm2
andnps %xmm0, %xmm1
orps %xmm1, %xmm2
movq -0x40(%rbp), %rbx
andb %r15b, %dil
mulss %xmm2, %xmm3
testl %r13d, %r13d
je 0xa7b23
xorps 0xd49d(%rip), %xmm3     # 0xb4fc0
movl -0x34(%rbp), %r15d
testb %dil, %dil
jne 0xa7b31
movaps %xmm3, %xmm1
jmp 0xa7b40
xorps %xmm0, %xmm0
cvtsi2ss %r14, %xmm0
movaps %xmm3, %xmm1
divss %xmm0, %xmm1
xorl %ecx, %ecx
cmpl %r12d, %r15d
jne 0xa7b4a
movaps %xmm3, %xmm1
movb 0x1b3c(%rsi), %al
jbe 0xa7b72
movl (%rbx), %ecx
cmpl %r15d, %ecx
jb 0xa7b61
xorps %xmm0, %xmm0
ucomiss %xmm0, %xmm1
ja 0xa7ba1
cmpl %r12d, %ecx
setbe %dl
xorps %xmm0, %xmm0
ucomiss %xmm1, %xmm0
seta %cl
andb %dl, %cl
testb %al, %al
jne 0xa7ba1
testb %cl, %cl
jne 0xa7ba1
xorps %xmm0, %xmm0
ucomiss %xmm0, %xmm1
jne 0xa7b84
jnp 0xa7bc3
movss 0x309c(%rsi), %xmm0
addss %xmm1, %xmm0
movss %xmm0, 0x309c(%rsi)
movb $0x1, 0x3099(%rsi)
jmp 0xa7bcc
movl $0x0, 0x309c(%rsi)
movb $0x0, 0x3099(%rsi)
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testb $0x1, 0x3099(%rsi)
je 0xa7bb2
movl (%rbx), %ebx
testb %dil, %dil
movss %xmm1, -0x34(%rbp)
je 0xa7c38
movb %dil, -0x29(%rbp)
movq %rsi, %r13
movq -0x68(%rbp), %rdi
movl $0x3, %esi
callq 0x97b86
xorps %xmm1, %xmm1
cvtsi2ss %eax, %xmm1
movss 0xdc8c(%rip), %xmm0     # 0xb5888
callq 0xc730
xorps %xmm1, %xmm1
movl -0x44(%rbp), %edi
movl %ebx, %esi
movl %r12d, %edx
movl %r15d, %ecx
movl $0x1, %r8d
movss %xmm0, -0x30(%rbp)
callq 0xac60e
xorl %ebx, %ebx
cmpl %r12d, %r15d
movss %xmm0, -0x60(%rbp)
jne 0xa7d3d
movq %r13, %rsi
movb -0x29(%rbp), %dil
jmp 0xa7c4f
cvttss2si 0x309c(%rsi), %eax
addl %eax, %ebx
xorps %xmm0, %xmm0
movss %xmm0, -0x60(%rbp)
movss %xmm0, -0x30(%rbp)
testb $0x40, -0x6c(%rbp)
jne 0xa7c71
movl %edi, %r14d
movq -0x68(%rbp), %rdi
movq %rsi, %r13
movl -0x44(%rbp), %esi
movl %ebx, %edx
callq 0xac7e0
movl %r14d, %edi
movq %r13, %rsi
movl %eax, %ebx
movb $0x0, 0x3099(%rsi)
testb %dil, %dil
je 0xa7cc1
xorps %xmm1, %xmm1
movl -0x44(%rbp), %edi
movq %rsi, %r13
movl %ebx, %esi
movl %r12d, %edx
movl %r15d, %ecx
movl $0x1, %r8d
movss -0x30(%rbp), %xmm0
callq 0xac60e
subss -0x60(%rbp), %xmm0
movss 0x309c(%r13), %xmm1
subss %xmm0, %xmm1
movss %xmm1, 0x309c(%r13)
movq -0x40(%rbp), %rax
movl (%rax), %eax
jmp 0xa7ce6
movq -0x40(%rbp), %rax
movl (%rax), %eax
movl %ebx, %ecx
subl %eax, %ecx
xorps %xmm0, %xmm0
cvtsi2ss %ecx, %xmm0
movss 0x309c(%rsi), %xmm1
subss %xmm0, %xmm1
movss %xmm1, 0x309c(%rsi)
cmpl %r12d, %r15d
movss -0x34(%rbp), %xmm1
jbe 0xa7d28
cmpl %ebx, %eax
je 0xa7d28
cmpl %r12d, %ebx
jb 0xa7d0b
cmpl $0x8, -0x48(%rbp)
je 0xa7d0e
cmpl %eax, %ebx
jbe 0xa7d0e
xorps %xmm0, %xmm0
ucomiss %xmm1, %xmm0
jbe 0xa7d0e
movl %r12d, %ebx
cmpl %r15d, %ebx
ja 0xa7d25
cmpl $0x8, -0x48(%rbp)
je 0xa7d28
cmpl %eax, %ebx
jae 0xa7d28
xorps %xmm0, %xmm0
ucomiss %xmm0, %xmm1
jbe 0xa7d28
movl %r15d, %ebx
cmpl %ebx, %eax
je 0xa7bb2
movq -0x40(%rbp), %rax
movl %ebx, (%rax)
movb $0x1, %al
jmp 0xa7bb4
movaps %xmm0, %xmm1
movq %r13, %rsi
addss 0x309c(%r13), %xmm1
xorps %xmm2, %xmm2
ucomiss %xmm1, %xmm2
movb -0x29(%rbp), %dil
jae 0xa7d94
ucomiss 0xd285(%rip), %xmm1     # 0xb4fe4
jae 0xa7d9c
movl %r12d, %eax
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
movss -0x30(%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 0xa7da4
movaps %xmm2, %xmm3
jmp 0xa7daa
movl %r12d, %ebx
jmp 0xa7c4f
movl %r15d, %ebx
jmp 0xa7c4f
movaps %xmm0, %xmm3
movaps %xmm2, %xmm0
jae 0xa7dbb
movss 0xd230(%rip), %xmm2     # 0xb4fe4
subss %xmm1, %xmm2
movaps %xmm2, %xmm1
divss %xmm3, %xmm0
movss %xmm3, -0x50(%rbp)
callq 0xc730
mulss -0x50(%rbp), %xmm0
cvttss2si %xmm0, %rbx
jmp 0xa7c2f