double root_in_range(double poly[3], double min, double max, double fallback) {
  const double delta = poly[1] * poly[1] - 4.0 * poly[0] * poly[2];
  if (delta) {
    const double q = -0.5 * (poly[1] + sign(poly[1]) * sqrt(delta));
    const double x1 = q / poly[0];
    if (x1 >= min && x1 <= max) {
      return x1;
    }
    const double x2 = poly[2] / q;
    if (x2 >= min && x2 <= max) {
      return x2;
    }
  }
  return fallback;
}


x86 assembly (clang, -O0):
<root_in_range>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
movsd  %xmm2,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm2
mov    -0x10(%rbp),%rax
movsd  0xea7(%rip),%xmm1
mulsd  (%rax),%xmm1
mov    -0x10(%rbp),%rax
mulsd  0x10(%rax),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11a7 <root_in_range+0x87>
jp     11a7 <root_in_range+0x87>
jmp    128e <root_in_range+0x16e>
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    $0x1,%al
call   1030 <sign@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1040 <sqrt@plt>
movsd  -0x58(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x50(%rbp),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe13(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
mov    -0x10(%rbp),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jb     1243 <root_in_range+0x123>
movsd  -0x40(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     1243 <root_in_range+0x123>
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1298 <root_in_range+0x178>
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm0
divsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jb     1289 <root_in_range+0x169>
movsd  -0x48(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     1289 <root_in_range+0x169>
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1298 <root_in_range+0x178>
jmp    128e <root_in_range+0x16e>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<root_in_range>:
push   %rbx
sub    $0x30,%rsp
movsd  (%rdi),%xmm3
mulsd  0xecf(%rip),%xmm3
movsd  0x8(%rdi),%xmm4
mulsd  0x10(%rdi),%xmm3
movapd %xmm4,%xmm5
mulsd  %xmm4,%xmm5
addsd  %xmm3,%xmm5
xorpd  %xmm3,%xmm3
ucomisd %xmm3,%xmm5
jne    1157 <root_in_range+0x37>
jnp    1206 <root_in_range+0xe6>
mov    %rdi,%rbx
movsd  %xmm0,0x18(%rsp)
movsd  %xmm1,0x20(%rsp)
movsd  %xmm2,0x28(%rsp)
movsd  %xmm4,0x10(%rsp)
movapd %xmm4,%xmm0
mov    $0x1,%al
movsd  %xmm5,0x8(%rsp)
call   1030 <sign@plt>
movsd  0x8(%rsp),%xmm0
xorps  %xmm5,%xmm5
cvtsi2sd %eax,%xmm5
ucomisd 0xe78(%rip),%xmm0
jb     11a0 <root_in_range+0x80>
sqrtsd %xmm0,%xmm0
jmp    11b1 <root_in_range+0x91>
movsd  %xmm5,0x8(%rsp)
call   1040 <sqrt@plt>
movsd  0x8(%rsp),%xmm5
movsd  0x28(%rsp),%xmm2
movsd  0x20(%rsp),%xmm1
movsd  0x18(%rsp),%xmm3
movsd  0x10(%rsp),%xmm4
mulsd  %xmm0,%xmm5
addsd  %xmm4,%xmm5
mulsd  0xe2f(%rip),%xmm5
movapd %xmm5,%xmm0
divsd  (%rbx),%xmm0
ucomisd %xmm3,%xmm0
jb     11ed <root_in_range+0xcd>
ucomisd %xmm0,%xmm1
jae    1202 <root_in_range+0xe2>
movsd  0x10(%rbx),%xmm0
divsd  %xmm5,%xmm0
ucomisd %xmm3,%xmm0
jb     1206 <root_in_range+0xe6>
ucomisd %xmm0,%xmm1
jb     1206 <root_in_range+0xe6>
movapd %xmm0,%xmm2
movapd %xmm2,%xmm0
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @root_in_range(double* %0, double %1, double %2, double %3) {
%5 = alloca double
%6 = alloca double*
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
store double* %0, double** %6
store double %1, double* %7
store double %2, double* %8
store double %3, double* %9
%14 = load double*, double** %6
%15 = getelementptr inbounds double, double* %14, i64 1
%16 = load double, double* %15
%17 = load double*, double** %6
%18 = getelementptr inbounds double, double* %17, i64 1
%19 = load double, double* %18
%20 = load double*, double** %6
%21 = getelementptr inbounds double, double* %20, i64 0
%22 = load double, double* %21
%23 = fmul double 4.000000e+00, %22
%24 = load double*, double** %6
%25 = getelementptr inbounds double, double* %24, i64 2
%26 = load double, double* %25
%27 = fmul double %23, %26
%28 = fneg double %27
%29 = call double @llvm.fmuladd.f64(double %16, double %19, double %28)
store double %29, double* %10
%30 = load double, double* %10
%31 = fcmp une double %30, 0.000000e+00
br i1 %31, label %32, label %75
32: ; preds = %4
%33 = load double*, double** %6
%34 = getelementptr inbounds double, double* %33, i64 1
%35 = load double, double* %34
%36 = load double*, double** %6
%37 = getelementptr inbounds double, double* %36, i64 1
%38 = load double, double* %37
%39 = call i32 (double, ...) bitcast (i32 (...)* @sign to i32 (double, ...)*)(double %38)
%40 = sitofp i32 %39 to double
%41 = load double, double* %10
%42 = call double @sqrt(double %41)
%43 = call double @llvm.fmuladd.f64(double %40, double %42, double %35)
%44 = fmul double -5.000000e-01, %43
store double %44, double* %11
%45 = load double, double* %11
%46 = load double*, double** %6
%47 = getelementptr inbounds double, double* %46, i64 0
%48 = load double, double* %47
%49 = fdiv double %45, %48
store double %49, double* %12
%50 = load double, double* %12
%51 = load double, double* %7
%52 = fcmp oge double %50, %51
br i1 %52, label %53, label %59
53: ; preds = %32
%54 = load double, double* %12
%55 = load double, double* %8
%56 = fcmp ole double %54, %55
br i1 %56, label %57, label %59
57: ; preds = %53
%58 = load double, double* %12
store double %58, double* %5
br label %77
59: ; preds = %53, %32
%60 = load double*, double** %6
%61 = getelementptr inbounds double, double* %60, i64 2
%62 = load double, double* %61
%63 = load double, double* %11
%64 = fdiv double %62, %63
store double %64, double* %13
%65 = load double, double* %13
%66 = load double, double* %7
%67 = fcmp oge double %65, %66
br i1 %67, label %68, label %74
68: ; preds = %59
%69 = load double, double* %13
%70 = load double, double* %8
%71 = fcmp ole double %69, %70
br i1 %71, label %72, label %74
72: ; preds = %68
%73 = load double, double* %13
store double %73, double* %5
br label %77
74: ; preds = %68, %59
br label %75
75: ; preds = %74, %4
%76 = load double, double* %9
store double %76, double* %5
br label %77
77: ; preds = %75, %72, %57
%78 = load double, double* %5
ret double %78
}

LLVM IR (-O2):
define double @root_in_range(double* nocapture %0, double %1, double %2, double %3) {
%5 = getelementptr inbounds double, double* %0, i64 1
%6 = load double, double* %5
%7 = load double, double* %0
%8 = getelementptr inbounds double, double* %0, i64 2
%9 = load double, double* %8
%10 = fmul double %7, -4.000000e+00
%11 = fmul double %10, %9
%12 = tail call double @llvm.fmuladd.f64(double %6, double %6, double %11)
%13 = fcmp une double %12, 0.000000e+00
br i1 %13, label %14, label %33
14: ; preds = %4
%15 = tail call i32 (double, ...) bitcast (i32 (...)* @sign to i32 (double, ...)*)(double %6)
%16 = sitofp i32 %15 to double
%17 = tail call double @sqrt(double %12)
%18 = tail call double @llvm.fmuladd.f64(double %16, double %17, double %6)
%19 = fmul double %18, -5.000000e-01
%20 = load double, double* %0
%21 = fdiv double %19, %20
%22 = fcmp ult double %21, %1
%23 = fcmp ugt double %21, %2
%24 = or i1 %22, %23
br i1 %24, label %25, label %31
25: ; preds = %14
%26 = load double, double* %8
%27 = fdiv double %26, %19
%28 = fcmp ult double %27, %1
%29 = fcmp ugt double %27, %2
%30 = or i1 %28, %29
br i1 %30, label %33, label %31
31: ; preds = %25, %14
%32 = phi double [ %21, %14 ], [ %27, %25 ]
br label %33
33: ; preds = %4, %25, %31
%34 = phi double [ %32, %31 ], [ %3, %25 ], [ %3, %4 ]
ret double %34
}