double bspline(unsigned int n, unsigned int i, unsigned int p,
               const double tau[n + 1], double u) {
  assert(i + p < n);
  assert(tau[i] <= tau[i + 1]);
  assert((tau[0] <= u) && (u <= tau[n]));
  if (0 == p)
    return ((tau[i] <= u) && (u < tau[i + 1])) ? 1. : 0.;
  assert(tau[i] <= tau[i + p + 1]);
  double a = frac(u - tau[i], tau[i + p] - tau[i]);
  double b = frac(tau[i + p + 1] - u, tau[i + p + 1] - tau[i + 1]);
  return a * bspline(n, i, p - 1, tau, u) +
         b * bspline(n, i + 1, p - 1, tau, u);
}


x86 assembly (clang, -O0):
<bspline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
setb   %al
and    $0x1,%al
movzbl %al,%edi
mov    $0x0,%al
call   1040 <assert@plt>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%ecx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,%ecx
movsd  (%rax,%rcx,8),%xmm0
ucomisd %xmm1,%xmm0
setae  %al
and    $0x1,%al
movzbl %al,%edi
mov    $0x0,%al
call   1040 <assert@plt>
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm1
movsd  -0x28(%rbp),%xmm0
xor    %eax,%eax
ucomisd %xmm1,%xmm0
mov    %al,-0x39(%rbp)
jb     11c9 <bspline+0x99>
movsd  -0x28(%rbp),%xmm1
mov    -0x20(%rbp),%rax
mov    -0xc(%rbp),%ecx
movsd  (%rax,%rcx,8),%xmm0
ucomisd %xmm1,%xmm0
setae  %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
mov    $0x0,%al
call   1040 <assert@plt>
xor    %eax,%eax
cmp    -0x14(%rbp),%eax
jne    125c <bspline+0x12c>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%ecx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x28(%rbp),%xmm0
xor    %eax,%eax
ucomisd %xmm1,%xmm0
mov    %al,-0x3a(%rbp)
jb     1223 <bspline+0xf3>
movsd  -0x28(%rbp),%xmm1
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,%ecx
movsd  (%rax,%rcx,8),%xmm0
ucomisd %xmm1,%xmm0
seta   %al
mov    %al,-0x3a(%rbp)
mov    -0x3a(%rbp),%al
movsd  0xdd2(%rip),%xmm0
xorps  %xmm1,%xmm1
movsd  %xmm1,-0x50(%rbp)
test   $0x1,%al
movsd  %xmm0,-0x48(%rbp)
jne    124d <bspline+0x11d>
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    138e <bspline+0x25e>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%ecx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    -0x14(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,%ecx
movsd  (%rax,%rcx,8),%xmm0
ucomisd %xmm1,%xmm0
setae  %al
and    $0x1,%al
movzbl %al,%edi
mov    $0x0,%al
call   1040 <assert@plt>
movsd  -0x28(%rbp),%xmm0
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%ecx
subsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    -0x14(%rbp),%ecx
mov    %ecx,%ecx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%ecx
subsd  (%rax,%rcx,8),%xmm1
mov    $0x2,%al
call   1050 <frac@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    -0x14(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,%ecx
movsd  (%rax,%rcx,8),%xmm0
subsd  -0x28(%rbp),%xmm0
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    -0x14(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,%ecx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,%ecx
subsd  (%rax,%rcx,8),%xmm1
mov    $0x2,%al
call   1050 <frac@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
mov    -0x20(%rbp),%rcx
movsd  -0x28(%rbp),%xmm0
call   1030 <bspline@plt>
movsd  %xmm0,-0x60(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
add    $0x1,%esi
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
mov    -0x20(%rbp),%rcx
movsd  -0x28(%rbp),%xmm0
call   1030 <bspline@plt>
movsd  -0x68(%rbp),%xmm1
movsd  -0x60(%rbp),%xmm2
movaps %xmm0,%xmm3
movsd  -0x58(%rbp),%xmm0
mulsd  %xmm3,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bspline>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
movaps %xmm0,0x10(%rsp)
mov    %rcx,%rbx
mov    %edx,%r14d
mov    %esi,%r13d
mov    %edi,%eax
lea    (%r14,%r13,1),%r12d
xor    %edi,%edi
mov    %eax,0xc(%rsp)
cmp    %eax,%r12d
setb   %dil
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <assert@plt>
mov    %r13d,%r15d
lea    0x1(%r13),%eax
mov    %rax,0x28(%rsp)
movsd  (%rbx,%rax,8),%xmm0
xor    %edi,%edi
ucomisd (%rbx,%r15,8),%xmm0
setae  %dil
xor    %eax,%eax
call   1040 <assert@plt>
movapd 0x10(%rsp),%xmm1
ucomisd (%rbx),%xmm1
jb     11ab <bspline+0x7b>
mov    0xc(%rsp),%eax
movsd  (%rbx,%rax,8),%xmm0
xor    %ebp,%ebp
ucomisd %xmm1,%xmm0
setae  %bpl
mov    %ebp,%edi
xor    %eax,%eax
call   1040 <assert@plt>
movsd  (%rbx,%r15,8),%xmm1
test   %r14d,%r14d
je     128d <bspline+0x15d>
lea    0x1(%r12),%ebp
movsd  (%rbx,%rbp,8),%xmm0
xor    %edi,%edi
ucomisd %xmm1,%xmm0
setae  %dil
xor    %eax,%eax
call   1040 <assert@plt>
movsd  (%rbx,%r15,8),%xmm2
movapd 0x10(%rsp),%xmm0
subsd  %xmm2,%xmm0
mov    %r12d,%eax
movsd  (%rbx,%rax,8),%xmm1
subsd  %xmm2,%xmm1
mov    $0x2,%al
call   1050 <frac@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x40(%rsp)
movsd  (%rbx,%rbp,8),%xmm1
movapd %xmm1,%xmm0
subsd  0x10(%rsp),%xmm0
mov    0x28(%rsp),%r15
subsd  (%rbx,%r15,8),%xmm1
mov    $0x2,%al
call   1050 <frac@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x38(%rsp)
add    $0xffffffff,%r14d
mov    0xc(%rsp),%ebp
mov    %ebp,%edi
mov    %r13d,%esi
mov    %r14d,%edx
mov    %rbx,%rcx
movaps 0x10(%rsp),%xmm0
call   1030 <bspline@plt>
movsd  %xmm0,0x30(%rsp)
mov    %ebp,%edi
mov    %r15d,%esi
mov    %r14d,%edx
mov    %rbx,%rcx
movapd 0x10(%rsp),%xmm0
call   1030 <bspline@plt>
mulsd  0x38(%rsp),%xmm0
movsd  0x30(%rsp),%xmm1
mulsd  0x40(%rsp),%xmm1
addsd  %xmm1,%xmm0
jmp    12b8 <bspline+0x188>
xorpd  %xmm0,%xmm0
movapd 0x10(%rsp),%xmm2
ucomisd %xmm1,%xmm2
jb     12b8 <bspline+0x188>
movapd %xmm2,%xmm1
mov    0x28(%rsp),%rax
cmpltsd (%rbx,%rax,8),%xmm1
movsd  0xd4c(%rip),%xmm0
andpd  %xmm1,%xmm0
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @bspline(i32 %0, i32 %1, i32 %2, double* %3, double %4) {
%6 = alloca double
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca double*
%11 = alloca double
%12 = alloca double
%13 = alloca double
store i32 %0, i32* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store double* %3, double** %10
store double %4, double* %11
%14 = load i32, i32* %7
%15 = add i32 %14, 1
%16 = zext i32 %15 to i64
%17 = load i32, i32* %8
%18 = load i32, i32* %9
%19 = add i32 %17, %18
%20 = load i32, i32* %7
%21 = icmp ult i32 %19, %20
%22 = zext i1 %21 to i32
%23 = call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %22)
%24 = load double*, double** %10
%25 = load i32, i32* %8
%26 = zext i32 %25 to i64
%27 = getelementptr inbounds double, double* %24, i64 %26
%28 = load double, double* %27
%29 = load double*, double** %10
%30 = load i32, i32* %8
%31 = add i32 %30, 1
%32 = zext i32 %31 to i64
%33 = getelementptr inbounds double, double* %29, i64 %32
%34 = load double, double* %33
%35 = fcmp ole double %28, %34
%36 = zext i1 %35 to i32
%37 = call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %36)
%38 = load double*, double** %10
%39 = getelementptr inbounds double, double* %38, i64 0
%40 = load double, double* %39
%41 = load double, double* %11
%42 = fcmp ole double %40, %41
br i1 %42, label %43, label %51
43: ; preds = %5
%44 = load double, double* %11
%45 = load double*, double** %10
%46 = load i32, i32* %7
%47 = zext i32 %46 to i64
%48 = getelementptr inbounds double, double* %45, i64 %47
%49 = load double, double* %48
%50 = fcmp ole double %44, %49
br label %51
51: ; preds = %43, %5
%52 = phi i1 [ false, %5 ], [ %50, %43 ]
%53 = zext i1 %52 to i32
%54 = call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %53)
%55 = load i32, i32* %9
%56 = icmp eq i32 0, %55
br i1 %56, label %57, label %78
57: ; preds = %51
%58 = load double*, double** %10
%59 = load i32, i32* %8
%60 = zext i32 %59 to i64
%61 = getelementptr inbounds double, double* %58, i64 %60
%62 = load double, double* %61
%63 = load double, double* %11
%64 = fcmp ole double %62, %63
br i1 %64, label %65, label %74
65: ; preds = %57
%66 = load double, double* %11
%67 = load double*, double** %10
%68 = load i32, i32* %8
%69 = add i32 %68, 1
%70 = zext i32 %69 to i64
%71 = getelementptr inbounds double, double* %67, i64 %70
%72 = load double, double* %71
%73 = fcmp olt double %66, %72
br label %74
74: ; preds = %65, %57
%75 = phi i1 [ false, %57 ], [ %73, %65 ]
%76 = zext i1 %75 to i64
%77 = select i1 %75, double 1.000000e+00, double 0.000000e+00
store double %77, double* %6
br label %163
78: ; preds = %51
%79 = load double*, double** %10
%80 = load i32, i32* %8
%81 = zext i32 %80 to i64
%82 = getelementptr inbounds double, double* %79, i64 %81
%83 = load double, double* %82
%84 = load double*, double** %10
%85 = load i32, i32* %8
%86 = load i32, i32* %9
%87 = add i32 %85, %86
%88 = add i32 %87, 1
%89 = zext i32 %88 to i64
%90 = getelementptr inbounds double, double* %84, i64 %89
%91 = load double, double* %90
%92 = fcmp ole double %83, %91
%93 = zext i1 %92 to i32
%94 = call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %93)
%95 = load double, double* %11
%96 = load double*, double** %10
%97 = load i32, i32* %8
%98 = zext i32 %97 to i64
%99 = getelementptr inbounds double, double* %96, i64 %98
%100 = load double, double* %99
%101 = fsub double %95, %100
%102 = load double*, double** %10
%103 = load i32, i32* %8
%104 = load i32, i32* %9
%105 = add i32 %103, %104
%106 = zext i32 %105 to i64
%107 = getelementptr inbounds double, double* %102, i64 %106
%108 = load double, double* %107
%109 = load double*, double** %10
%110 = load i32, i32* %8
%111 = zext i32 %110 to i64
%112 = getelementptr inbounds double, double* %109, i64 %111
%113 = load double, double* %112
%114 = fsub double %108, %113
%115 = call i32 (double, double, ...) bitcast (i32 (...)* @frac to i32 (double, double, ...)*)(double %101, double %114)
%116 = sitofp i32 %115 to double
store double %116, double* %12
%117 = load double*, double** %10
%118 = load i32, i32* %8
%119 = load i32, i32* %9
%120 = add i32 %118, %119
%121 = add i32 %120, 1
%122 = zext i32 %121 to i64
%123 = getelementptr inbounds double, double* %117, i64 %122
%124 = load double, double* %123
%125 = load double, double* %11
%126 = fsub double %124, %125
%127 = load double*, double** %10
%128 = load i32, i32* %8
%129 = load i32, i32* %9
%130 = add i32 %128, %129
%131 = add i32 %130, 1
%132 = zext i32 %131 to i64
%133 = getelementptr inbounds double, double* %127, i64 %132
%134 = load double, double* %133
%135 = load double*, double** %10
%136 = load i32, i32* %8
%137 = add i32 %136, 1
%138 = zext i32 %137 to i64
%139 = getelementptr inbounds double, double* %135, i64 %138
%140 = load double, double* %139
%141 = fsub double %134, %140
%142 = call i32 (double, double, ...) bitcast (i32 (...)* @frac to i32 (double, double, ...)*)(double %126, double %141)
%143 = sitofp i32 %142 to double
store double %143, double* %13
%144 = load double, double* %12
%145 = load i32, i32* %7
%146 = load i32, i32* %8
%147 = load i32, i32* %9
%148 = sub i32 %147, 1
%149 = load double*, double** %10
%150 = load double, double* %11
%151 = call double @bspline(i32 %145, i32 %146, i32 %148, double* %149, double %150)
%152 = load double, double* %13
%153 = load i32, i32* %7
%154 = load i32, i32* %8
%155 = add i32 %154, 1
%156 = load i32, i32* %9
%157 = sub i32 %156, 1
%158 = load double*, double** %10
%159 = load double, double* %11
%160 = call double @bspline(i32 %153, i32 %155, i32 %157, double* %158, double %159)
%161 = fmul double %152, %160
%162 = call double @llvm.fmuladd.f64(double %144, double %151, double %161)
store double %162, double* %6
br label %163
163: ; preds = %78, %74
%164 = load double, double* %6
ret double %164
}

LLVM IR (-O2):
define double @bspline(i32 %0, i32 %1, i32 %2, double* %3, double %4) {
%6 = add i32 %2, %1
%7 = icmp ult i32 %6, %0
%8 = zext i1 %7 to i32
%9 = tail call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %8)
%10 = zext i32 %1 to i64
%11 = getelementptr inbounds double, double* %3, i64 %10
%12 = load double, double* %11
%13 = add i32 %1, 1
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds double, double* %3, i64 %14
%16 = load double, double* %15
%17 = fcmp ole double %12, %16
%18 = zext i1 %17 to i32
%19 = tail call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %18)
%20 = load double, double* %3
%21 = fcmp ugt double %20, %4
br i1 %21, label %28, label %22
22: ; preds = %5
%23 = zext i32 %0 to i64
%24 = getelementptr inbounds double, double* %3, i64 %23
%25 = load double, double* %24
%26 = fcmp oge double %25, %4
%27 = zext i1 %26 to i32
br label %28
28: ; preds = %22, %5
%29 = phi i32 [ 0, %5 ], [ %27, %22 ]
%30 = tail call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %29)
%31 = icmp eq i32 %2, 0
%32 = load double, double* %11
br i1 %31, label %33, label %41
33: ; preds = %28
%34 = fcmp ugt double %32, %4
br i1 %34, label %39, label %35
35: ; preds = %33
%36 = load double, double* %15
%37 = fcmp ogt double %36, %4
%38 = select i1 %37, double 1.000000e+00, double 0.000000e+00
br label %39
39: ; preds = %35, %33, %41
%40 = phi double [ %67, %41 ], [ 0.000000e+00, %33 ], [ %38, %35 ]
ret double %40
41: ; preds = %28
%42 = add i32 %6, 1
%43 = zext i32 %42 to i64
%44 = getelementptr inbounds double, double* %3, i64 %43
%45 = load double, double* %44
%46 = fcmp ole double %32, %45
%47 = zext i1 %46 to i32
%48 = tail call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %47)
%49 = load double, double* %11
%50 = fsub double %4, %49
%51 = zext i32 %6 to i64
%52 = getelementptr inbounds double, double* %3, i64 %51
%53 = load double, double* %52
%54 = fsub double %53, %49
%55 = tail call i32 (double, double, ...) bitcast (i32 (...)* @frac to i32 (double, double, ...)*)(double %50, double %54)
%56 = sitofp i32 %55 to double
%57 = load double, double* %44
%58 = fsub double %57, %4
%59 = load double, double* %15
%60 = fsub double %57, %59
%61 = tail call i32 (double, double, ...) bitcast (i32 (...)* @frac to i32 (double, double, ...)*)(double %58, double %60)
%62 = sitofp i32 %61 to double
%63 = add i32 %2, -1
%64 = tail call double @bspline(i32 %0, i32 %1, i32 %63, double* %3, double %4)
%65 = tail call double @bspline(i32 %0, i32 %13, i32 %63, double* %3, double %4)
%66 = fmul double %65, %62
%67 = tail call double @llvm.fmuladd.f64(double %56, double %64, double %66)
br label %39
}