// File: /workspace/github_cpp_makefile_star2_O2/Ciaxur[P]yagb-emu/include/imgui/imgui_widgets.cpp
// Function: long long ImGui::ScaleValueFromRatioT<long long, long long, double>(int, float, long long, long long, bool, float, float)
TYPE ImGui::ScaleValueFromRatioT(ImGuiDataType data_type, float t, TYPE v_min, TYPE v_max, bool is_logarithmic, float logarithmic_zero_epsilon, float zero_deadzone_halfsize)
{
    if (v_min == v_max)
        return (TYPE)0.0f;
    const bool is_decimal = (data_type == ImGuiDataType_Float) || (data_type == ImGuiDataType_Double);

    TYPE result;
    if (is_logarithmic)
    {
        // We special-case the extents because otherwise our fudging can lead to "mathematically correct" but non-intuitive behaviors like a fully-left slider not actually reaching the minimum value
        if (t <= 0.0f)
            result = v_min;
        else if (t >= 1.0f)
            result = v_max;
        else
        {
            bool flipped = v_max < v_min; // Check if range is "backwards"

            // Fudge min/max to avoid getting silly results close to zero
            FLOATTYPE v_min_fudged = (ImAbs((FLOATTYPE)v_min) < logarithmic_zero_epsilon) ? ((v_min < 0.0f) ? -logarithmic_zero_epsilon : logarithmic_zero_epsilon) : (FLOATTYPE)v_min;
            FLOATTYPE v_max_fudged = (ImAbs((FLOATTYPE)v_max) < logarithmic_zero_epsilon) ? ((v_max < 0.0f) ? -logarithmic_zero_epsilon : logarithmic_zero_epsilon) : (FLOATTYPE)v_max;

            if (flipped)
                ImSwap(v_min_fudged, v_max_fudged);

            // Awkward special case - we need ranges of the form (-100 .. 0) to convert to (-100 .. -epsilon), not (-100 .. epsilon)
            if ((v_max == 0.0f) && (v_min < 0.0f))
                v_max_fudged = -logarithmic_zero_epsilon;

            float t_with_flip = flipped ? (1.0f - t) : t; // t, but flipped if necessary to account for us flipping the range

            if ((v_min * v_max) < 0.0f) // Range crosses zero, so we have to do this in two parts
            {
                float zero_point_center = (-(float)ImMin(v_min, v_max)) / ImAbs((float)v_max - (float)v_min); // The zero point in parametric space
                float zero_point_snap_L = zero_point_center - zero_deadzone_halfsize;
                float zero_point_snap_R = zero_point_center + zero_deadzone_halfsize;
                if (t_with_flip >= zero_point_snap_L && t_with_flip <= zero_point_snap_R)
                    result = (TYPE)0.0f; // Special case to make getting exactly zero possible (the epsilon prevents it otherwise)
                else if (t_with_flip < zero_point_center)
                    result = (TYPE)-(logarithmic_zero_epsilon * ImPow(-v_min_fudged / logarithmic_zero_epsilon, (FLOATTYPE)(1.0f - (t_with_flip / zero_point_snap_L))));
                else
                    result = (TYPE)(logarithmic_zero_epsilon * ImPow(v_max_fudged / logarithmic_zero_epsilon, (FLOATTYPE)((t_with_flip - zero_point_snap_R) / (1.0f - zero_point_snap_R))));
            }
            else if ((v_min < 0.0f) || (v_max < 0.0f)) // Entirely negative slider
                result = (TYPE)-(-v_max_fudged * ImPow(-v_min_fudged / -v_max_fudged, (FLOATTYPE)(1.0f - t_with_flip)));
            else
                result = (TYPE)(v_min_fudged * ImPow(v_max_fudged / v_min_fudged, (FLOATTYPE)t_with_flip));
        }
    }
    else
    {
        // Linear slider
        if (is_decimal)
        {
            result = ImLerp(v_min, v_max, t);
        }
        else
        {
            // - For integer values we want the clicking position to match the grab box so we round above
            //   This code is carefully tuned to work with large values (e.g. high ranges of U64) while preserving this property..
            // - Not doing a *1.0 multiply at the end of a range as it tends to be lossy. While absolute aiming at a large s64/u64
            //   range is going to be imprecise anyway, with this check we at least make the edge values matches expected limits.
            if (t < 1.0)
            {
                FLOATTYPE v_new_off_f = (SIGNEDTYPE)(v_max - v_min) * t;
                result = (TYPE)((SIGNEDTYPE)v_min + (SIGNEDTYPE)(v_new_off_f + (FLOATTYPE)(v_min > v_max ? -0.5 : 0.5)));
            }
            else
            {
                result = v_max;
            }
        }
    }

    return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movq %rdx, %rax
subq %rsi, %rdx
jne 0x93f3a
xorl %eax, %eax
addq $0x10, %rsp
popq %rbp
retq
testb %cl, %cl
je 0x93f74
xorps %xmm3, %xmm3
ucomiss %xmm0, %xmm3
jae 0x93f95
ucomiss 0x80ab(%rip), %xmm0     # 0x9bff8
jae 0x93f34
cvtsi2sd %rsi, %xmm4
movapd 0x241e4(%rip), %xmm3    # 0xb8140
andpd %xmm4, %xmm3
cvtss2sd %xmm1, %xmm6
ucomisd %xmm3, %xmm6
jbe 0x93fe3
testq %rsi, %rsi
js 0x93fd5
movaps %xmm1, %xmm3
jmp 0x93fdf
andl $-0x2, %edi
cmpl $0x8, %edi
jne 0x93f9a
cvtsi2ss %rsi, %xmm1
cvtsi2ss %rdx, %xmm2
mulss %xmm0, %xmm2
addss %xmm1, %xmm2
cvttss2si %xmm2, %rax
jmp 0x93f34
movq %rsi, %rax
jmp 0x93f34
movss 0x8056(%rip), %xmm1     # 0x9bff8
ucomiss %xmm0, %xmm1
jbe 0x93f34
xorl %ecx, %ecx
subq %rsi, %rax
setl %cl
cvtsi2ss %rax, %xmm1
mulss %xmm0, %xmm1
cvtss2sd %xmm1, %xmm0
leaq 0x2419d(%rip), %rax     # 0xb8160
addsd (%rax,%rcx,8), %xmm0
cvttsd2si %xmm0, %rax
addq %rsi, %rax
jmp 0x93f34
movaps 0x8004(%rip), %xmm3     # 0x9bfe0
xorps %xmm1, %xmm3
cvtss2sd %xmm3, %xmm4
cvtsi2sd %rax, %xmm3
movapd 0x24150(%rip), %xmm5    # 0xb8140
andpd %xmm3, %xmm5
ucomisd %xmm5, %xmm6
jbe 0x94015
movaps 0x7fdf(%rip), %xmm5     # 0x9bfe0
xorps %xmm1, %xmm5
movaps %xmm5, %xmm3
testq %rax, %rax
js 0x9400f
movaps %xmm1, %xmm3
cvtss2sd %xmm3, %xmm3
jmp 0x9401f
xorps 0x7fc4(%rip), %xmm1     # 0x9bfe0
movaps %xmm1, %xmm5
cmpq %rsi, %rax
jl 0x9402a
movapd %xmm4, %xmm7
jmp 0x94032
movapd %xmm3, %xmm7
movapd %xmm4, %xmm3
movss 0x7fbe(%rip), %xmm1     # 0x9bff8
jge 0x94046
movaps %xmm1, %xmm4
subss %xmm0, %xmm4
movaps %xmm4, %xmm0
testq %rax, %rax
je 0x94052
movapd %xmm3, %xmm8
jmp 0x94057
cvtss2sd %xmm5, %xmm8
testq %rsi, %rsi
js 0x94061
movapd %xmm3, %xmm8
movq %rax, %rcx
imulq %rsi, %rcx
testq %rcx, %rcx
js 0x9408e
orq %rsi, %rax
js 0x94108
divsd %xmm7, %xmm8
cvtss2sd %xmm0, %xmm1
movapd %xmm8, %xmm0
movapd %xmm7, -0x10(%rbp)
jmp 0x9413b
cvtsi2ss %rax, %xmm4
cmpq %rax, %rsi
cmovlq %rsi, %rax
cvtsi2ss %rax, %xmm3
xorps 0x7f3a(%rip), %xmm3     # 0x9bfe0
cvtsi2ss %rsi, %xmm5
subss %xmm5, %xmm4
andps 0x873a(%rip), %xmm4     # 0x9c7f0
divss %xmm4, %xmm3
movaps %xmm3, %xmm4
subss %xmm2, %xmm4
addss %xmm3, %xmm2
ucomiss %xmm4, %xmm0
jb 0x940d3
ucomiss %xmm0, %xmm2
jae 0x93f32
ucomiss %xmm0, %xmm3
movsd %xmm6, -0x10(%rbp)
jbe 0x94121
xorpd 0x2406b(%rip), %xmm7    # 0xb8150
divsd %xmm6, %xmm7
divss %xmm4, %xmm0
subss %xmm0, %xmm1
cvtss2sd %xmm1, %xmm1
movapd %xmm7, %xmm0
callq 0xc300
xorpd 0x2404a(%rip), %xmm0    # 0xb8150
jmp 0x94140
divsd %xmm8, %xmm7
subss %xmm0, %xmm1
cvtss2sd %xmm1, %xmm1
movapd %xmm7, %xmm0
movsd %xmm8, -0x10(%rbp)
jmp 0x9413b
divsd %xmm6, %xmm8
subss %xmm2, %xmm0
subss %xmm2, %xmm1
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm1
movapd %xmm8, %xmm0
callq 0xc300
mulsd -0x10(%rbp), %xmm0
cvttsd2si %xmm0, %rax
jmp 0x93f34