float normalize(float note) {
  const float min = -48;
  const float max = 48;
  const float left = 4;
  const float right = 0.125;
  if (note < min)
    return left;
  if (note > max)
    return right;
  float ans = (note - min) * ((right - left) / (max - min)) + left;
  if (ans > 4)
    return 4;
  if (ans < 0.125)
    return 0.125;
  return ans;
}


x86 assembly (clang, -O0):
<normalize>:
push   %rbp
mov    %rsp,%rbp
movss  %xmm0,-0x8(%rbp)
movss  0xeef(%rip),%xmm0
movss  %xmm0,-0xc(%rbp)
movss  0xeee(%rip),%xmm0
movss  %xmm0,-0x10(%rbp)
movss  0xedd(%rip),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  0xecc(%rip),%xmm0
movss  %xmm0,-0x18(%rbp)
movss  0xebb(%rip),%xmm0
ucomiss -0x8(%rbp),%xmm0
jbe    1161 <normalize+0x61>
movss  0xeb1(%rip),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1216 <normalize+0x116>
movss  -0x8(%rbp),%xmm0
movss  0xe9e(%rip),%xmm1
ucomiss %xmm1,%xmm0
jbe    1189 <normalize+0x89>
movss  0xe85(%rip),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1216 <normalize+0x116>
movss  -0x8(%rbp),%xmm0
movss  0xe6a(%rip),%xmm1
subss  %xmm1,%xmm0
movss  0xe6e(%rip),%xmm1
mulss  %xmm1,%xmm0
movss  0xe5a(%rip),%xmm1
addss  %xmm1,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
movss  0xe44(%rip),%xmm1
ucomiss %xmm1,%xmm0
jbe    11df <normalize+0xdf>
movss  0xe33(%rip),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1216 <normalize+0x116>
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe28(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    120c <normalize+0x10c>
movss  0xe02(%rip),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1216 <normalize+0x116>
movss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<normalize>:
movss  0xefc(%rip),%xmm1
ucomiss %xmm0,%xmm1
jbe    1116 <normalize+0x16>
movss  0xeeb(%rip),%xmm0
ret
ucomiss 0xeef(%rip),%xmm0
jbe    1128 <normalize+0x28>
movss  0xee1(%rip),%xmm0
ret
addss  0xedc(%rip),%xmm0
mulss  0xed8(%rip),%xmm0
movss  0xec0(%rip),%xmm2
addss  %xmm2,%xmm0
movss  0xebc(%rip),%xmm3
maxss  %xmm0,%xmm3
movaps %xmm2,%xmm1
cmpltss %xmm0,%xmm1
movaps %xmm1,%xmm0
andnps %xmm3,%xmm0
andps  %xmm2,%xmm1
orps   %xmm0,%xmm1
movaps %xmm1,%xmm0
ret

LLVM IR (-O0):
define float @normalize(float %0) {
%2 = alloca float
%3 = alloca float
%4 = alloca float
%5 = alloca float
%6 = alloca float
%7 = alloca float
%8 = alloca float
store float %0, float* %3
store float -4.800000e+01, float* %4
store float 4.800000e+01, float* %5
store float 4.000000e+00, float* %6
store float 1.250000e-01, float* %7
%9 = load float, float* %3
%10 = fcmp olt float %9, -4.800000e+01
br i1 %10, label %11, label %12
11: ; preds = %1
store float 4.000000e+00, float* %2
br label %30
12: ; preds = %1
%13 = load float, float* %3
%14 = fcmp ogt float %13, 4.800000e+01
br i1 %14, label %15, label %16
15: ; preds = %12
store float 1.250000e-01, float* %2
br label %30
16: ; preds = %12
%17 = load float, float* %3
%18 = fsub float %17, -4.800000e+01
%19 = call float @llvm.fmuladd.f32(float %18, float 0xBFA4AAAAA0000000, float 4.000000e+00)
store float %19, float* %8
%20 = load float, float* %8
%21 = fcmp ogt float %20, 4.000000e+00
br i1 %21, label %22, label %23
22: ; preds = %16
store float 4.000000e+00, float* %2
br label %30
23: ; preds = %16
%24 = load float, float* %8
%25 = fpext float %24 to double
%26 = fcmp olt double %25, 1.250000e-01
br i1 %26, label %27, label %28
27: ; preds = %23
store float 1.250000e-01, float* %2
br label %30
28: ; preds = %23
%29 = load float, float* %8
store float %29, float* %2
br label %30
30: ; preds = %28, %27, %22, %15, %11
%31 = load float, float* %2
ret float %31
}

LLVM IR (-O2):
define float @normalize(float %0) {
%2 = fcmp olt float %0, -4.800000e+01
br i1 %2, label %12, label %3
3: ; preds = %1
%4 = fcmp ogt float %0, 4.800000e+01
br i1 %4, label %12, label %5
5: ; preds = %3
%6 = fadd float %0, 4.800000e+01
%7 = tail call float @llvm.fmuladd.f32(float %6, float 0xBFA4AAAAA0000000, float 4.000000e+00)
%8 = fcmp ogt float %7, 4.000000e+00
%9 = fcmp olt float %7, 1.250000e-01
%10 = select i1 %9, float 1.250000e-01, float %7
%11 = select i1 %8, float 4.000000e+00, float %10
br label %12
12: ; preds = %3, %1, %5
%13 = phi float [ %11, %5 ], [ 4.000000e+00, %1 ], [ 1.250000e-01, %3 ]
ret float %13
}