double ld_linear(int n, double gam[], double rho) {
  if (rho == 0.)
    return 1 + .5 * gam[0];
  else if (rho < 1.)
    return (1.0 + gam[0] * (1.5 * sqrt(1.0 - ((rho) * (rho))) - 1.0));
  else
    return 1. - gam[0];
}


x86 assembly (clang, -O0):
<ld_linear>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1166 <ld_linear+0x56>
jp     1166 <ld_linear+0x56>
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
movsd  0xecc(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xea8(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    120b <ld_linear+0xfb>
movsd  0xe92(%rip),%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    11f6 <ld_linear+0xe6>
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm1,%xmm0
movsd  0xe4d(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1030 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
movsd  0xe3c(%rip),%xmm2
mulsd  %xmm2,%xmm1
movsd  0xe38(%rip),%xmm2
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe18(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    120b <ld_linear+0xfb>
mov    -0x18(%rbp),%rax
movsd  0xdfe(%rip),%xmm0
subsd  (%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ld_linear>:
push   %rax
movapd %xmm0,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    1137 <ld_linear+0x27>
jp     1137 <ld_linear+0x27>
movsd  (%rsi),%xmm0
mulsd  0xeeb(%rip),%xmm0
addsd  0xecb(%rip),%xmm0
pop    %rax
ret
movsd  0xec1(%rip),%xmm0
ucomisd %xmm1,%xmm0
movsd  (%rsi),%xmm2
jbe    1161 <ld_linear+0x51>
mulsd  %xmm1,%xmm1
subsd  %xmm1,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1167 <ld_linear+0x57>
sqrtsd %xmm0,%xmm0
jmp    1176 <ld_linear+0x66>
subsd  %xmm2,%xmm0
pop    %rax
ret
movsd  %xmm2,(%rsp)
call   1030 <sqrt@plt>
movsd  (%rsp),%xmm2
mulsd  0xe8a(%rip),%xmm0
addsd  0xe8a(%rip),%xmm0
mulsd  %xmm0,%xmm2
addsd  0xe6e(%rip),%xmm2
movapd %xmm2,%xmm0
pop    %rax
ret

LLVM IR (-O0):
define double @ld_linear(i32 %0, double* %1, double %2) {
%4 = alloca double
%5 = alloca i32
%6 = alloca double*
%7 = alloca double
store i32 %0, i32* %5
store double* %1, double** %6
store double %2, double* %7
%8 = load double, double* %7
%9 = fcmp oeq double %8, 0.000000e+00
br i1 %9, label %10, label %15
10: ; preds = %3
%11 = load double*, double** %6
%12 = getelementptr inbounds double, double* %11, i64 0
%13 = load double, double* %12
%14 = call double @llvm.fmuladd.f64(double 5.000000e-01, double %13, double 1.000000e+00)
store double %14, double* %4
br label %34
15: ; preds = %3
%16 = load double, double* %7
%17 = fcmp olt double %16, 1.000000e+00
br i1 %17, label %18, label %29
18: ; preds = %15
%19 = load double*, double** %6
%20 = getelementptr inbounds double, double* %19, i64 0
%21 = load double, double* %20
%22 = load double, double* %7
%23 = load double, double* %7
%24 = fneg double %22
%25 = call double @llvm.fmuladd.f64(double %24, double %23, double 1.000000e+00)
%26 = call double @sqrt(double %25)
%27 = call double @llvm.fmuladd.f64(double 1.500000e+00, double %26, double -1.000000e+00)
%28 = call double @llvm.fmuladd.f64(double %21, double %27, double 1.000000e+00)
store double %28, double* %4
br label %34
29: ; preds = %15
%30 = load double*, double** %6
%31 = getelementptr inbounds double, double* %30, i64 0
%32 = load double, double* %31
%33 = fsub double 1.000000e+00, %32
store double %33, double* %4
br label %34
34: ; preds = %29, %18, %10
%35 = load double, double* %4
ret double %35
}

LLVM IR (-O2):
define double @ld_linear(i32 %0, double* nocapture %1, double %2) {
%4 = fcmp oeq double %2, 0.000000e+00
br i1 %4, label %5, label %8
5: ; preds = %3
%6 = load double, double* %1
%7 = tail call double @llvm.fmuladd.f64(double %6, double 5.000000e-01, double 1.000000e+00)
br label %19
8: ; preds = %3
%9 = fcmp olt double %2, 1.000000e+00
%10 = load double, double* %1
br i1 %9, label %11, label %17
11: ; preds = %8
%12 = fneg double %2
%13 = tail call double @llvm.fmuladd.f64(double %12, double %2, double 1.000000e+00)
%14 = tail call double @sqrt(double %13)
%15 = tail call double @llvm.fmuladd.f64(double %14, double 1.500000e+00, double -1.000000e+00)
%16 = tail call double @llvm.fmuladd.f64(double %10, double %15, double 1.000000e+00)
br label %19
17: ; preds = %8
%18 = fsub double 1.000000e+00, %10
br label %19
19: ; preds = %17, %11, %5
%20 = phi double [ %7, %5 ], [ %16, %11 ], [ %18, %17 ]
ret double %20
}