// File: Ciaxur[P]yagb-emu/include/imgui/imgui_widgets.cpp
// Function: bool ImGui::DragBehaviorT<unsigned long long, long long, double>(int, unsigned long long*, float, unsigned long long, unsigned long long, 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
subq $0xd0, %rsp
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movss %xmm0, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movl %r9d, -0x34(%rbp)
leaq 0xb5da2(%rip), %rax     # 0x212f40
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movl -0x34(%rbp), %edx
andl $0x100000, %edx         # imm = 0x100000
xorl %eax, %eax
movl $0x1, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0x44(%rbp)
movb $0x1, %al
cmpl $0x8, -0x8(%rbp)
movb %al, -0x89(%rbp)
je 0x15d1d9
cmpl $0x9, -0x8(%rbp)
sete %al
movb %al, -0x89(%rbp)
movb -0x89(%rbp), %al
andb $0x1, %al
movb %al, -0x45(%rbp)
movq -0x20(%rbp), %rax
cmpq -0x28(%rbp), %rax
setb %al
andb $0x1, %al
movb %al, -0x46(%rbp)
movl -0x34(%rbp), %ecx
andl $0x20, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x8a(%rbp)
je 0x15d210
movb -0x45(%rbp), %al
movb %al, -0x8a(%rbp)
movb -0x8a(%rbp), %al
andb $0x1, %al
movb %al, -0x47(%rbp)
movss -0x14(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x15d302
jp 0x15d302
testb $0x1, -0x46(%rbp)
je 0x15d302
movq -0x28(%rbp), %rax
movq -0x20(%rbp), %rcx
subq %rcx, %rax
movq %rax, %rdx
shrq %rdx
movl %eax, %ecx
andl $0x1, %ecx
orq %rdx, %rcx
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
cvtsi2ss %rax, %xmm1
movss %xmm1, -0x94(%rbp)
testq %rax, %rax
movss %xmm0, -0x90(%rbp)
js 0x15d288
movss -0x94(%rbp), %xmm0
movss %xmm0, -0x90(%rbp)
movss -0x90(%rbp), %xmm1
movss 0x14d1c(%rip), %xmm0    # 0x171fb4
ucomiss %xmm1, %xmm0
jbe 0x15d302
movq -0x28(%rbp), %rax
movq -0x20(%rbp), %rcx
subq %rcx, %rax
movq %rax, %rdx
shrq %rdx
movl %eax, %ecx
andl $0x1, %ecx
orq %rdx, %rcx
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
cvtsi2ss %rax, %xmm1
movss %xmm1, -0x9c(%rbp)
testq %rax, %rax
movss %xmm0, -0x98(%rbp)
js 0x15d2e9
movss -0x9c(%rbp), %xmm0
movss %xmm0, -0x98(%rbp)
movss -0x98(%rbp), %xmm0
movq -0x40(%rbp), %rax
mulss 0x30a0(%rax), %xmm0
movss %xmm0, -0x14(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x4c(%rbp)
movq -0x40(%rbp), %rax
cmpl $0x1, 0x1b68(%rax)
jne 0x15d3af
xorl %eax, %eax
movl %eax, %edi
callq 0xcb710
testb $0x1, %al
jne 0x15d32d
jmp 0x15d3af
movq -0x40(%rbp), %rax
movss 0x14c9f(%rip), %xmm0    # 0x171fd8
mulss 0x38(%rax), %xmm0
xorl %edi, %edi
callq 0xd4f40
testb $0x1, %al
jne 0x15d34b
jmp 0x15d3af
movq -0x40(%rbp), %rdi
addq $0x8, %rdi
addq $0x3b0, %rdi            # imm = 0x3B0
movslq -0x44(%rbp), %rsi
callq 0x15bb20
movss (%rax), %xmm0
movss %xmm0, -0x4c(%rbp)
movq -0x40(%rbp), %rax
testb $0x1, 0x142(%rax)
je 0x15d38b
movss 0x1b23f(%rip), %xmm0    # 0x1785c0
mulss -0x4c(%rbp), %xmm0
movss %xmm0, -0x4c(%rbp)
movq -0x40(%rbp), %rax
testb $0x1, 0x141(%rax)
je 0x15d3aa
movss 0x14c3c(%rip), %xmm0    # 0x171fdc
mulss -0x4c(%rbp), %xmm0
movss %xmm0, -0x4c(%rbp)
jmp 0x15d455
movq -0x40(%rbp), %rax
cmpl $0x2, 0x1b68(%rax)
jne 0x15d453
testb $0x1, -0x45(%rbp)
je 0x15d3dc
movq -0x30(%rbp), %rdi
movl $0x3, %esi
callq 0x145670
movl %eax, -0xa0(%rbp)
jmp 0x15d3e6
xorl %eax, %eax
movl %eax, -0xa0(%rbp)
jmp 0x15d3e6
movl -0xa0(%rbp), %eax
movl %eax, -0x50(%rbp)
movl $0x3, %edi
movl $0x5, %esi
movss 0x1537b(%rip), %xmm0    # 0x17277c
movss 0x14bd3(%rip), %xmm1    # 0x171fdc
callq 0xdf970
movlpd %xmm0, -0x58(%rbp)
movslq -0x44(%rbp), %rsi
leaq -0x58(%rbp), %rdi
callq 0x15bb20
movss (%rax), %xmm0
movss %xmm0, -0x4c(%rbp)
movss -0x14(%rbp), %xmm0
movss %xmm0, -0xa4(%rbp)
movl -0x50(%rbp), %edi
callq 0x15b160
movaps %xmm0, %xmm1
movss -0xa4(%rbp), %xmm0
callq 0x139050
movss %xmm0, -0x14(%rbp)
jmp 0x15d455
movss -0x14(%rbp), %xmm0
mulss -0x4c(%rbp), %xmm0
movss %xmm0, -0x4c(%rbp)
cmpl $0x1, -0x44(%rbp)
jne 0x15d481
movss -0x4c(%rbp), %xmm0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
movss %xmm0, -0x4c(%rbp)
testb $0x1, -0x47(%rbp)
je 0x15d5b3
movq -0x28(%rbp), %rax
movq -0x20(%rbp), %rcx
subq %rcx, %rax
movq %rax, %rdx
shrq %rdx
movl %eax, %ecx
andl $0x1, %ecx
orq %rdx, %rcx
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
cvtsi2ss %rax, %xmm1
movss %xmm1, -0xac(%rbp)
testq %rax, %rax
movss %xmm0, -0xa8(%rbp)
js 0x15d4d7
movss -0xac(%rbp), %xmm0
movss %xmm0, -0xa8(%rbp)
movss -0xa8(%rbp), %xmm1
movss 0x14acd(%rip), %xmm0    # 0x171fb4
ucomiss %xmm1, %xmm0
jbe 0x15d5b3
movq -0x28(%rbp), %rax
movq -0x20(%rbp), %rcx
subq %rcx, %rax
movq %rax, %rdx
shrq %rdx
movl %eax, %ecx
andl $0x1, %ecx
orq %rdx, %rcx
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
cvtsi2ss %rax, %xmm1
movss %xmm1, -0xb4(%rbp)
testq %rax, %rax
movss %xmm0, -0xb0(%rbp)
js 0x15d53c
movss -0xb4(%rbp), %xmm0
movss %xmm0, -0xb0(%rbp)
movss -0xb0(%rbp), %xmm0
movss 0x30c9c(%rip), %xmm1    # 0x18e1e8
ucomiss %xmm1, %xmm0
jbe 0x15d5b3
movq -0x28(%rbp), %rax
movq -0x20(%rbp), %rcx
subq %rcx, %rax
movq %rax, %rdx
shrq %rdx
movl %eax, %ecx
andl $0x1, %ecx
orq %rdx, %rcx
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
cvtsi2ss %rax, %xmm1
movss %xmm1, -0xbc(%rbp)
testq %rax, %rax
movss %xmm0, -0xb8(%rbp)
js 0x15d59d
movss -0xbc(%rbp), %xmm0
movss %xmm0, -0xb8(%rbp)
movss -0xb8(%rbp), %xmm1
movss -0x4c(%rbp), %xmm0
divss %xmm1, %xmm0
movss %xmm0, -0x4c(%rbp)
movq -0x40(%rbp), %rax
movb 0x1b3c(%rax), %al
andb $0x1, %al
movb %al, -0x59(%rbp)
xorl %eax, %eax
testb $0x1, -0x46(%rbp)
movb %al, -0xbd(%rbp)
je 0x15d62f
movq -0x10(%rbp), %rax
movq (%rax), %rax
cmpq -0x28(%rbp), %rax
jb 0x15d5f2
movss -0x4c(%rbp), %xmm0
movb $0x1, %al
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
movb %al, -0xbe(%rbp)
ja 0x15d623
movq -0x10(%rbp), %rax
movq (%rax), %rcx
xorl %eax, %eax
cmpq -0x20(%rbp), %rcx
movb %al, -0xbf(%rbp)
ja 0x15d617
xorps %xmm0, %xmm0
ucomiss -0x4c(%rbp), %xmm0
seta %al
movb %al, -0xbf(%rbp)
movb -0xbf(%rbp), %al
movb %al, -0xbe(%rbp)
movb -0xbe(%rbp), %al
movb %al, -0xbd(%rbp)
movb -0xbd(%rbp), %al
andb $0x1, %al
movb %al, -0x5a(%rbp)
testb $0x1, -0x59(%rbp)
jne 0x15d646
testb $0x1, -0x5a(%rbp)
je 0x15d662
movq -0x40(%rbp), %rax
xorps %xmm0, %xmm0
movss %xmm0, 0x309c(%rax)
movq -0x40(%rbp), %rax
movb $0x0, 0x3099(%rax)
jmp 0x15d699
movss -0x4c(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x15d673
jp 0x15d673
jmp 0x15d697
movss -0x4c(%rbp), %xmm0
movq -0x40(%rbp), %rax
addss 0x309c(%rax), %xmm0
movss %xmm0, 0x309c(%rax)
movq -0x40(%rbp), %rax
movb $0x1, 0x3099(%rax)
jmp 0x15d699
movq -0x40(%rbp), %rax
testb $0x1, 0x3099(%rax)
jne 0x15d6af
movb $0x0, -0x1(%rbp)
jmp 0x15d913
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x68(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x70(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x74(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x78(%rbp)
testb $0x1, -0x47(%rbp)
je 0x15d7a4
testb $0x1, -0x45(%rbp)
je 0x15d6f8
movq -0x30(%rbp), %rdi
movl $0x3, %esi
callq 0x145670
movl %eax, -0xc4(%rbp)
jmp 0x15d705
movl $0x1, %eax
movl %eax, -0xc4(%rbp)
jmp 0x15d705
movl -0xc4(%rbp), %eax
movl %eax, -0x7c(%rbp)
cvtsi2ssl -0x7c(%rbp), %xmm1
movss 0x15061(%rip), %xmm0    # 0x17277c
callq 0x15b1d0
movss %xmm0, -0x74(%rbp)
movl -0x8(%rbp), %edi
movq -0x68(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
movb -0x47(%rbp), %al
movss -0x74(%rbp), %xmm0
xorps %xmm1, %xmm1
andb $0x1, %al
movzbl %al, %r8d
callq 0x165190
movss %xmm0, -0x80(%rbp)
movss -0x80(%rbp), %xmm0
movq -0x40(%rbp), %rax
addss 0x309c(%rax), %xmm0
movss %xmm0, -0x84(%rbp)
movl -0x8(%rbp), %edi
movss -0x84(%rbp), %xmm0
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movb -0x47(%rbp), %al
movss -0x74(%rbp), %xmm1
xorps %xmm2, %xmm2
andb $0x1, %al
movzbl %al, %ecx
callq 0x165c20
movq %rax, -0x68(%rbp)
movss -0x80(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x70(%rbp)
jmp 0x15d7b9
movq -0x40(%rbp), %rax
cvttss2si 0x309c(%rax), %rax
addq -0x68(%rbp), %rax
movq %rax, -0x68(%rbp)
movl -0x34(%rbp), %eax
andl $0x40, %eax
cmpl $0x0, %eax
jne 0x15d7d8
movq -0x30(%rbp), %rdi
movl -0x8(%rbp), %esi
movq -0x68(%rbp), %rdx
callq 0x166560
movq %rax, -0x68(%rbp)
movq -0x40(%rbp), %rax
movb $0x0, 0x3099(%rax)
testb $0x1, -0x47(%rbp)
je 0x15d845
movl -0x8(%rbp), %edi
movq -0x68(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
movb -0x47(%rbp), %al
movss -0x74(%rbp), %xmm0
xorps %xmm1, %xmm1
andb $0x1, %al
movzbl %al, %r8d
callq 0x165190
movss %xmm0, -0x88(%rbp)
movss -0x88(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
subsd -0x70(%rbp), %xmm0
cvtsd2ss %xmm0, %xmm1
movq -0x40(%rbp), %rax
movss 0x309c(%rax), %xmm0
subss %xmm1, %xmm0
movss %xmm0, 0x309c(%rax)
jmp 0x15d86d
movq -0x68(%rbp), %rax
movq -0x10(%rbp), %rcx
subq (%rcx), %rax
cvtsi2ss %rax, %xmm1
movq -0x40(%rbp), %rax
movss 0x309c(%rax), %xmm0
subss %xmm1, %xmm0
movss %xmm0, 0x309c(%rax)
cmpq $0x0, -0x68(%rbp)
jne 0x15d87c
movq $0x0, -0x68(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
cmpq -0x68(%rbp), %rax
je 0x15d8f1
testb $0x1, -0x46(%rbp)
je 0x15d8f1
movq -0x68(%rbp), %rax
cmpq -0x20(%rbp), %rax
jb 0x15d8b5
movq -0x68(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
jbe 0x15d8bd
xorps %xmm0, %xmm0
ucomiss -0x4c(%rbp), %xmm0
jbe 0x15d8bd
testb $0x1, -0x45(%rbp)
jne 0x15d8bd
movq -0x20(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
cmpq -0x28(%rbp), %rax
ja 0x15d8e7
movq -0x68(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x15d8ef
movss -0x4c(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x15d8ef
testb $0x1, -0x45(%rbp)
jne 0x15d8ef
movq -0x28(%rbp), %rax
movq %rax, -0x68(%rbp)
jmp 0x15d8f1
movq -0x10(%rbp), %rax
movq (%rax), %rax
cmpq -0x68(%rbp), %rax
jne 0x15d904
movb $0x0, -0x1(%rbp)
jmp 0x15d913
movq -0x68(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0xd0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)