// File: /workspace/github_cpp_makefile_star2_O1/Ciaxur[P]yagb-emu/include/imgui/imgui_widgets.cpp
// Function: double ImGui::ScaleValueFromRatioT<double, double, double>(int, float, double, double, 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
xorps %xmm5, %xmm5
ucomisd %xmm2, %xmm1
jne 0xaf1a8
jp 0xaf1a8
movaps %xmm5, %xmm0
addq $0x10, %rsp
popq %rbp
retq
testb %sil, %sil
je 0xaf1e9
xorps %xmm5, %xmm5
ucomiss %xmm0, %xmm5
jae 0xaf203
ucomiss 0x7e28(%rip), %xmm0     # 0xb6fe4
jae 0xaf23b
movapd 0x23d3a(%rip), %xmm5    # 0xd2f00
andpd %xmm1, %xmm5
cvtss2sd %xmm3, %xmm9
ucomisd %xmm5, %xmm9
movapd %xmm1, %xmm5
jbe 0xaf252
xorpd %xmm5, %xmm5
ucomisd %xmm1, %xmm5
ja 0xaf244
movaps %xmm3, %xmm5
jmp 0xaf24e
andl $-0x2, %edi
cmpl $0x8, %edi
jne 0xaf209
subsd %xmm1, %xmm2
cvtss2sd %xmm0, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
jmp 0xaf1a2
movapd %xmm1, %xmm5
jmp 0xaf19f
movss 0x7dd3(%rip), %xmm3     # 0xb6fe4
ucomiss %xmm0, %xmm3
jbe 0xaf23b
xorl %eax, %eax
ucomisd %xmm2, %xmm1
seta %al
cvtss2sd %xmm0, %xmm0
subsd %xmm1, %xmm2
mulsd %xmm0, %xmm2
leaq 0x23cee(%rip), %rcx     # 0xd2f20
addsd (%rcx,%rax,8), %xmm2
addsd %xmm1, %xmm2
movapd %xmm2, %xmm5
jmp 0xaf19f
movaps 0x7d75(%rip), %xmm5     # 0xb6fc0
xorps %xmm3, %xmm5
cvtss2sd %xmm5, %xmm5
movapd 0x23ca6(%rip), %xmm6    # 0xd2f00
andpd %xmm2, %xmm6
ucomisd %xmm6, %xmm9
movapd %xmm2, %xmm6
jbe 0xaf286
xorpd %xmm6, %xmm6
ucomisd %xmm2, %xmm6
ja 0xaf278
movaps %xmm3, %xmm6
jmp 0xaf282
movaps 0x7d41(%rip), %xmm6     # 0xb6fc0
xorps %xmm3, %xmm6
cvtss2sd %xmm6, %xmm6
ucomisd %xmm2, %xmm1
movapd %xmm2, %xmm10
cmpltsd %xmm1, %xmm10
movapd %xmm10, %xmm7
andpd %xmm6, %xmm7
andnpd %xmm5, %xmm10
ja 0xaf2a9
movapd %xmm6, %xmm5
xorps 0x7d10(%rip), %xmm3     # 0xb6fc0
orpd %xmm7, %xmm10
cvtss2sd %xmm3, %xmm3
xorpd %xmm6, %xmm6
movapd %xmm1, %xmm7
cmpltsd %xmm6, %xmm7
movapd %xmm2, %xmm11
cmpeqsd %xmm6, %xmm11
movapd %xmm11, %xmm8
andnpd %xmm5, %xmm8
andpd %xmm3, %xmm11
orpd %xmm8, %xmm11
andpd %xmm7, %xmm11
andnpd %xmm5, %xmm7
orpd %xmm7, %xmm11
movss 0x7ce9(%rip), %xmm3     # 0xb6fe4
jbe 0xaf307
movaps %xmm3, %xmm5
subss %xmm0, %xmm5
movaps %xmm5, %xmm0
movapd %xmm1, %xmm5
mulsd %xmm2, %xmm5
ucomisd %xmm5, %xmm6
jbe 0xaf3a4
xorps %xmm5, %xmm5
cvtsd2ss %xmm1, %xmm5
minsd %xmm2, %xmm1
xorps %xmm6, %xmm6
cvtsd2ss %xmm1, %xmm6
xorps 0x7c8e(%rip), %xmm6     # 0xb6fc0
xorps %xmm1, %xmm1
cvtsd2ss %xmm2, %xmm1
subss %xmm5, %xmm1
andps 0x848c(%rip), %xmm1     # 0xb77d0
divss %xmm1, %xmm6
movaps %xmm6, %xmm1
subss %xmm4, %xmm1
addss %xmm6, %xmm4
ucomiss %xmm1, %xmm0
jb 0xaf364
xorps %xmm5, %xmm5
ucomiss %xmm0, %xmm4
jae 0xaf19f
ucomiss %xmm0, %xmm6
movsd %xmm9, -0x10(%rbp)
jbe 0xaf3ea
xorpd 0x23b98(%rip), %xmm10   # 0xd2f10
divsd %xmm9, %xmm10
divss %xmm1, %xmm0
subss %xmm0, %xmm3
xorps %xmm1, %xmm1
cvtss2sd %xmm3, %xmm1
movapd %xmm10, %xmm0
callq 0xc2e0
movapd %xmm0, %xmm5
xorpd 0x23b6e(%rip), %xmm5    # 0xd2f10
jmp 0xaf410
xorpd %xmm4, %xmm4
ucomisd %xmm1, %xmm4
ja 0xaf3cd
ucomisd %xmm2, %xmm4
ja 0xaf3cd
divsd %xmm10, %xmm11
xorps %xmm1, %xmm1
cvtss2sd %xmm0, %xmm1
movapd %xmm11, %xmm0
movapd %xmm10, -0x10(%rbp)
jmp 0xaf407
divsd %xmm11, %xmm10
subss %xmm0, %xmm3
xorps %xmm1, %xmm1
cvtss2sd %xmm3, %xmm1
movapd %xmm10, %xmm0
movapd %xmm11, -0x10(%rbp)
jmp 0xaf407
divsd %xmm9, %xmm11
subss %xmm4, %xmm0
subss %xmm4, %xmm3
divss %xmm3, %xmm0
xorps %xmm1, %xmm1
cvtss2sd %xmm0, %xmm1
movapd %xmm11, %xmm0
callq 0xc2e0
movapd %xmm0, %xmm5
mulsd -0x10(%rbp), %xmm5
jmp 0xaf19f