// File: /workspace/github_cpp_makefile_star2_O1/Ciaxur[P]yagb-emu/include/imgui/imgui_widgets.cpp
// Function: float ImGui::ScaleRatioFromValueT<double, double, double>(int, double, double, double, bool, float, float)
float ImGui::ScaleRatioFromValueT(ImGuiDataType data_type, TYPE v, TYPE v_min, TYPE v_max, bool is_logarithmic, float logarithmic_zero_epsilon, float zero_deadzone_halfsize)
{
    if (v_min == v_max)
        return 0.0f;
    IM_UNUSED(data_type);

    const TYPE v_clamped = (v_min < v_max) ? ImClamp(v, v_min, v_max) : ImClamp(v, v_max, v_min);
    if (is_logarithmic)
    {
        bool flipped = v_max < v_min;

        if (flipped) // Handle the case where the range is backwards
            ImSwap(v_min, v_max);

        // Fudge min/max to avoid getting close to log(0)
        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;

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

        float result;

        if (v_clamped <= v_min_fudged)
            result = 0.0f; // Workaround for values that are in-range but below our fudge
        else if (v_clamped >= v_max_fudged)
            result = 1.0f; // Workaround for values that are in-range but above our fudge
        else if ((v_min * v_max) < 0.0f) // Range crosses zero, so split into two portions
        {
            float zero_point_center = (-(float)v_min) / ((float)v_max - (float)v_min); // The zero point in parametric space.  There's an argument we should take the logarithmic nature into account when calculating this, but for now this should do (and the most common case of a symmetrical range works fine)
            float zero_point_snap_L = zero_point_center - zero_deadzone_halfsize;
            float zero_point_snap_R = zero_point_center + zero_deadzone_halfsize;
            if (v == 0.0f)
                result = zero_point_center; // Special case for exactly zero
            else if (v < 0.0f)
                result = (1.0f - (float)(ImLog(-(FLOATTYPE)v_clamped / logarithmic_zero_epsilon) / ImLog(-v_min_fudged / logarithmic_zero_epsilon))) * zero_point_snap_L;
            else
                result = zero_point_snap_R + ((float)(ImLog((FLOATTYPE)v_clamped / logarithmic_zero_epsilon) / ImLog(v_max_fudged / logarithmic_zero_epsilon)) * (1.0f - zero_point_snap_R));
        }
        else if ((v_min < 0.0f) || (v_max < 0.0f)) // Entirely negative slider
            result = 1.0f - (float)(ImLog(-(FLOATTYPE)v_clamped / -v_max_fudged) / ImLog(-v_min_fudged / -v_max_fudged));
        else
            result = (float)(ImLog((FLOATTYPE)v_clamped / v_min_fudged) / ImLog(v_max_fudged / v_min_fudged));

        return flipped ? (1.0f - result) : result;
    }

    // Linear slider
    return (float)((FLOATTYPE)(SIGNEDTYPE)(v_clamped - v_min) / (FLOATTYPE)(SIGNEDTYPE)(v_max - v_min));
}

// Assembly:
xorps %xmm11, %xmm11
ucomisd %xmm2, %xmm1
jne 0xaee61
jnp 0xaf187
movapd %xmm0, %xmm8
movapd %xmm1, %xmm6
minsd %xmm2, %xmm6
movapd %xmm2, %xmm5
maxsd %xmm1, %xmm5
minsd %xmm0, %xmm5
cmpltsd %xmm6, %xmm0
andpd %xmm0, %xmm6
andnpd %xmm5, %xmm0
orpd %xmm6, %xmm0
testb %sil, %sil
je 0xaeecc
movapd %xmm2, %xmm5
minsd %xmm1, %xmm5
movapd %xmm1, %xmm7
maxsd %xmm2, %xmm7
movapd 0x24058(%rip), %xmm6    # 0xd2f00
andpd %xmm5, %xmm6
cvtss2sd %xmm3, %xmm9
ucomisd %xmm6, %xmm9
movapd %xmm5, %xmm10
jbe 0xaeef9
xorpd %xmm6, %xmm6
ucomisd %xmm5, %xmm6
ja 0xaeee6
movaps %xmm3, %xmm6
jmp 0xaeef0
subsd %xmm1, %xmm0
subsd %xmm1, %xmm2
divsd %xmm2, %xmm0
xorps %xmm11, %xmm11
cvtsd2ss %xmm0, %xmm11
jmp 0xaf187
movaps 0x80d3(%rip), %xmm6     # 0xb6fc0
xorps %xmm3, %xmm6
xorps %xmm10, %xmm10
cvtss2sd %xmm6, %xmm10
movapd 0x23fff(%rip), %xmm6    # 0xd2f00
andpd %xmm7, %xmm6
ucomisd %xmm6, %xmm9
movapd %xmm7, %xmm12
jbe 0xaef33
xorpd %xmm6, %xmm6
ucomisd %xmm7, %xmm6
ja 0xaef20
movaps %xmm3, %xmm6
jmp 0xaef2a
movaps 0x8099(%rip), %xmm6     # 0xb6fc0
xorps %xmm3, %xmm6
xorps %xmm12, %xmm12
cvtss2sd %xmm6, %xmm12
xorpd %xmm6, %xmm6
ucomisd %xmm6, %xmm5
jne 0xaef57
jp 0xaef57
ucomisd %xmm7, %xmm6
jbe 0xaef57
xorps 0x8074(%rip), %xmm3     # 0xb6fc0
xorps %xmm10, %xmm10
cvtss2sd %xmm3, %xmm10
jmp 0xaef75
ucomisd %xmm6, %xmm7
jne 0xaef75
jp 0xaef75
ucomisd %xmm5, %xmm6
jbe 0xaef75
xorps 0x8054(%rip), %xmm3     # 0xb6fc0
xorps %xmm12, %xmm12
cvtss2sd %xmm3, %xmm12
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
xorps %xmm11, %xmm11
ucomisd %xmm0, %xmm10
jae 0xaf16b
ucomisd %xmm12, %xmm0
jae 0xaf061
movapd %xmm1, %xmm6
mulsd %xmm2, %xmm6
xorps %xmm3, %xmm3
ucomisd %xmm6, %xmm3
jbe 0xaf06f
cvtsd2ss %xmm5, %xmm5
movaps 0x8008(%rip), %xmm11    # 0xb6fc0
xorps %xmm5, %xmm11
xorps %xmm6, %xmm6
cvtsd2ss %xmm7, %xmm6
subss %xmm5, %xmm6
divss %xmm6, %xmm11
ucomisd %xmm3, %xmm8
jne 0xaefd9
jnp 0xaf16b
movsd %xmm1, -0x10(%rbp)
movsd %xmm2, -0x18(%rbp)
xorpd %xmm2, %xmm2
ucomisd %xmm8, %xmm2
movsd %xmm9, -0x48(%rbp)
jbe 0xaf108
subss %xmm4, %xmm11
movaps %xmm11, -0x30(%rbp)
xorpd 0x23f06(%rip), %xmm0    # 0xd2f10
divsd %xmm9, %xmm0
movapd %xmm10, -0x40(%rbp)
callq 0xc150
movsd %xmm0, -0x8(%rbp)
movapd -0x40(%rbp), %xmm0
xorpd 0x23ee4(%rip), %xmm0    # 0xd2f10
divsd -0x48(%rbp), %xmm0
callq 0xc150
movaps -0x30(%rbp), %xmm11
movsd -0x8(%rbp), %xmm1
divsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
movss 0x7f91(%rip), %xmm1     # 0xb6fe4
subss %xmm0, %xmm1
mulss %xmm1, %xmm11
jmp 0xaf161
movss 0x7f7a(%rip), %xmm11    # 0xb6fe4
jmp 0xaf16b
movsd %xmm1, -0x10(%rbp)
movsd %xmm2, -0x18(%rbp)
ucomisd %xmm5, %xmm3
movapd %xmm10, -0x40(%rbp)
movsd %xmm12, -0x8(%rbp)
ja 0xaf0ca
xorpd %xmm1, %xmm1
ucomisd %xmm7, %xmm1
ja 0xaf0ca
divsd %xmm10, %xmm0
callq 0xc150
movsd %xmm0, -0x30(%rbp)
movsd -0x8(%rbp), %xmm0
divsd -0x40(%rbp), %xmm0
callq 0xc150
movsd -0x30(%rbp), %xmm1
divsd %xmm0, %xmm1
xorps %xmm11, %xmm11
cvtsd2ss %xmm1, %xmm11
jmp 0xaf161
divsd %xmm12, %xmm0
callq 0xc150
movsd %xmm0, -0x30(%rbp)
movapd -0x40(%rbp), %xmm0
divsd -0x8(%rbp), %xmm0
callq 0xc150
movsd -0x30(%rbp), %xmm1
divsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
movss 0x7ee3(%rip), %xmm11    # 0xb6fe4
subss %xmm0, %xmm11
jmp 0xaf161
addss %xmm4, %xmm11
movaps %xmm11, -0x30(%rbp)
divsd %xmm9, %xmm0
movsd %xmm12, -0x8(%rbp)
callq 0xc150
movsd %xmm0, -0x40(%rbp)
movsd -0x8(%rbp), %xmm0
divsd -0x48(%rbp), %xmm0
callq 0xc150
movaps -0x30(%rbp), %xmm11
movsd -0x40(%rbp), %xmm1
divsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
movss 0x7e91(%rip), %xmm1     # 0xb6fe4
subss %xmm11, %xmm1
mulss %xmm0, %xmm1
addss %xmm1, %xmm11
movsd -0x18(%rbp), %xmm2
movsd -0x10(%rbp), %xmm1
ucomisd %xmm2, %xmm1
jbe 0xaf182
movss 0x7e6b(%rip), %xmm0     # 0xb6fe4
subss %xmm11, %xmm0
movaps %xmm0, %xmm11
addq $0x50, %rsp
popq %rbp
movaps %xmm11, %xmm0
retq