// File: /workspace/github_cpp_makefile_star2_O3/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 0xacb50
xorl %eax, %eax
addq $0x10, %rsp
popq %rbp
retq
testb %cl, %cl
je 0xacb8e
xorps %xmm3, %xmm3
ucomiss %xmm0, %xmm3
jae 0xacbb5
ucomiss 0x8481(%rip), %xmm0     # 0xb4fe4
jae 0xacb4a
cvtsi2sd %rsi, %xmm4
movapd 0x2425e(%rip), %xmm3    # 0xd0dd0
andpd %xmm4, %xmm3
cvtss2sd %xmm1, %xmm6
ucomisd %xmm3, %xmm6
jbe 0xacc0c
testq %rsi, %rsi
js 0xacbfb
movaps %xmm1, %xmm3
jmp 0xacc05
andl $-0x2, %edi
cmpl $0x8, %edi
jne 0xacbba
xorps %xmm1, %xmm1
cvtsi2ss %rsi, %xmm1
xorps %xmm2, %xmm2
cvtsi2ss %rdx, %xmm2
mulss %xmm0, %xmm2
addss %xmm1, %xmm2
cvttss2si %xmm2, %rax
jmp 0xacb4a
movq %rsi, %rax
jmp 0xacb4a
movss 0x8422(%rip), %xmm1     # 0xb4fe4
ucomiss %xmm0, %xmm1
jbe 0xacb4a
xorl %ecx, %ecx
subq %rsi, %rax
setl %cl
xorps %xmm1, %xmm1
cvtsi2ss %rax, %xmm1
mulss %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtss2sd %xmm1, %xmm0
leaq 0x24207(%rip), %rax     # 0xd0df0
addsd (%rax,%rcx,8), %xmm0
cvttsd2si %xmm0, %rax
addq %rsi, %rax
jmp 0xacb4a
movaps 0x83be(%rip), %xmm3     # 0xb4fc0
xorps %xmm1, %xmm3
xorps %xmm4, %xmm4
cvtss2sd %xmm3, %xmm4
xorps %xmm3, %xmm3
cvtsi2sd %rax, %xmm3
movapd 0x241b4(%rip), %xmm5    # 0xd0dd0
andpd %xmm3, %xmm5
ucomisd %xmm5, %xmm6
jbe 0xacc41
movaps 0x8393(%rip), %xmm5     # 0xb4fc0
xorps %xmm1, %xmm5
movaps %xmm5, %xmm3
testq %rax, %rax
js 0xacc3b
movaps %xmm1, %xmm3
cvtss2sd %xmm3, %xmm3
jmp 0xacc4b
xorps 0x8378(%rip), %xmm1     # 0xb4fc0
movaps %xmm1, %xmm5
cmpq %rsi, %rax
jl 0xacc56
movapd %xmm4, %xmm7
jmp 0xacc5e
movapd %xmm3, %xmm7
movapd %xmm4, %xmm3
movss 0x837e(%rip), %xmm1     # 0xb4fe4
jge 0xacc72
movaps %xmm1, %xmm4
subss %xmm0, %xmm4
movaps %xmm4, %xmm0
testq %rax, %rax
je 0xacc7e
movapd %xmm3, %xmm8
jmp 0xacc83
cvtss2sd %xmm5, %xmm8
testq %rsi, %rsi
js 0xacc8d
movapd %xmm3, %xmm8
movq %rax, %rcx
imulq %rsi, %rcx
testq %rcx, %rcx
js 0xaccbd
orq %rsi, %rax
js 0xacd40
divsd %xmm7, %xmm8
xorps %xmm1, %xmm1
cvtss2sd %xmm0, %xmm1
movapd %xmm8, %xmm0
movapd %xmm7, -0x10(%rbp)
jmp 0xacd76
xorps %xmm4, %xmm4
cvtsi2ss %rax, %xmm4
cmpq %rax, %rsi
cmovlq %rsi, %rax
xorps %xmm3, %xmm3
cvtsi2ss %rax, %xmm3
xorps 0x82e5(%rip), %xmm3     # 0xb4fc0
xorps %xmm5, %xmm5
cvtsi2ss %rsi, %xmm5
subss %xmm5, %xmm4
andps 0x8ae2(%rip), %xmm4     # 0xb57d0
divss %xmm4, %xmm3
movaps %xmm3, %xmm4
subss %xmm2, %xmm4
addss %xmm3, %xmm2
ucomiss %xmm4, %xmm0
jb 0xacd0b
ucomiss %xmm0, %xmm2
jae 0xacb48
ucomiss %xmm0, %xmm3
movsd %xmm6, -0x10(%rbp)
jbe 0xacd59
xorpd 0x240c3(%rip), %xmm7    # 0xd0de0
divsd %xmm6, %xmm7
divss %xmm4, %xmm0
subss %xmm0, %xmm1
cvtss2sd %xmm1, %xmm1
movapd %xmm7, %xmm0
callq 0xc2e0
xorpd 0x240a2(%rip), %xmm0    # 0xd0de0
jmp 0xacd7b
divsd %xmm8, %xmm7
subss %xmm0, %xmm1
cvtss2sd %xmm1, %xmm1
movapd %xmm7, %xmm0
movsd %xmm8, -0x10(%rbp)
jmp 0xacd76
divsd %xmm6, %xmm8
subss %xmm2, %xmm0
subss %xmm2, %xmm1
divss %xmm1, %xmm0
xorps %xmm1, %xmm1
cvtss2sd %xmm0, %xmm1
movapd %xmm8, %xmm0
callq 0xc2e0
mulsd -0x10(%rbp), %xmm0
cvttsd2si %xmm0, %rax
jmp 0xacb4a