double pi_bpp(int n) {
  double lead = 1.;
  double sum = 0.;
  for (int i = 0; i <= n; i++) {
    sum += lead * ((4. / (8. * i + 1.)) - (2. / (8. * i + 4.)) -
                   (1. / (8. * i + 5.)) - (1. / (8. * i + 6.)));
    lead *= 1. / 16.;
  }
  return sum;
}


x86 assembly (clang, -O0):
<pi_bpp>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
movsd  0xef1(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     1216 <pi_bpp+0x116>
movsd  -0x10(%rbp),%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm1
movsd  0xecf(%rip),%xmm2
mulsd  %xmm2,%xmm1
movsd  0xeb3(%rip),%xmm2
addsd  %xmm2,%xmm1
movsd  0xed7(%rip),%xmm2
divsd  %xmm1,%xmm2
cvtsi2sdl -0x1c(%rbp),%xmm3
movsd  0xea6(%rip),%xmm1
mulsd  %xmm1,%xmm3
movsd  0xeba(%rip),%xmm1
addsd  %xmm1,%xmm3
movsd  0xea6(%rip),%xmm1
divsd  %xmm3,%xmm1
subsd  %xmm1,%xmm2
cvtsi2sdl -0x1c(%rbp),%xmm3
movsd  0xe79(%rip),%xmm1
mulsd  %xmm1,%xmm3
movsd  0xe7d(%rip),%xmm1
addsd  %xmm1,%xmm3
movsd  0xe51(%rip),%xmm1
divsd  %xmm3,%xmm1
subsd  %xmm1,%xmm2
cvtsi2sdl -0x1c(%rbp),%xmm3
movsd  0xe4c(%rip),%xmm1
mulsd  %xmm1,%xmm3
movsd  0xe48(%rip),%xmm1
addsd  %xmm1,%xmm3
movsd  0xe24(%rip),%xmm1
divsd  %xmm3,%xmm1
subsd  %xmm1,%xmm2
movsd  -0x18(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe0a(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1123 <pi_bpp+0x23>
movsd  -0x18(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<pi_bpp>:
test   %edi,%edi
js     11aa <pi_bpp+0xaa>
add    $0x1,%edi
movsd  0xeed(%rip),%xmm1
xorpd  %xmm0,%xmm0
xor    %eax,%eax
movsd  0xee6(%rip),%xmm8
movapd 0xef5(%rip),%xmm9
movapd 0xefc(%rip),%xmm10
movapd 0xf04(%rip),%xmm5
movapd 0xf0c(%rip),%xmm6
movsd  0xec4(%rip),%xmm7
nopl   0x0(%rax)
xorps  %xmm2,%xmm2
cvtsi2sd %eax,%xmm2
mulsd  %xmm8,%xmm2
unpcklpd %xmm2,%xmm2
movapd %xmm2,%xmm3
addpd  %xmm9,%xmm3
movapd %xmm10,%xmm4
divpd  %xmm3,%xmm4
addpd  %xmm5,%xmm2
movapd %xmm6,%xmm3
divpd  %xmm2,%xmm3
movapd %xmm4,%xmm2
unpckhpd %xmm4,%xmm2
subsd  %xmm2,%xmm4
subsd  %xmm3,%xmm4
unpckhpd %xmm3,%xmm3
subsd  %xmm3,%xmm4
mulsd  %xmm1,%xmm4
addsd  %xmm4,%xmm0
mulsd  %xmm7,%xmm1
add    $0x1,%eax
cmp    %eax,%edi
jne    1150 <pi_bpp+0x50>
ret
xorps  %xmm0,%xmm0
ret

LLVM IR (-O0):
define double @pi_bpp(i32 %0) {
%2 = alloca i32
%3 = alloca double
%4 = alloca double
%5 = alloca i32
store i32 %0, i32* %2
store double 1.000000e+00, double* %3
store double 0.000000e+00, double* %4
store i32 0, i32* %5
br label %6
6: ; preds = %35, %1
%7 = load i32, i32* %5
%8 = load i32, i32* %2
%9 = icmp sle i32 %7, %8
br i1 %9, label %10, label %38
10: ; preds = %6
%11 = load double, double* %3
%12 = load i32, i32* %5
%13 = sitofp i32 %12 to double
%14 = call double @llvm.fmuladd.f64(double 8.000000e+00, double %13, double 1.000000e+00)
%15 = fdiv double 4.000000e+00, %14
%16 = load i32, i32* %5
%17 = sitofp i32 %16 to double
%18 = call double @llvm.fmuladd.f64(double 8.000000e+00, double %17, double 4.000000e+00)
%19 = fdiv double 2.000000e+00, %18
%20 = fsub double %15, %19
%21 = load i32, i32* %5
%22 = sitofp i32 %21 to double
%23 = call double @llvm.fmuladd.f64(double 8.000000e+00, double %22, double 5.000000e+00)
%24 = fdiv double 1.000000e+00, %23
%25 = fsub double %20, %24
%26 = load i32, i32* %5
%27 = sitofp i32 %26 to double
%28 = call double @llvm.fmuladd.f64(double 8.000000e+00, double %27, double 6.000000e+00)
%29 = fdiv double 1.000000e+00, %28
%30 = fsub double %25, %29
%31 = load double, double* %4
%32 = call double @llvm.fmuladd.f64(double %11, double %30, double %31)
store double %32, double* %4
%33 = load double, double* %3
%34 = fmul double %33, 6.250000e-02
store double %34, double* %3
br label %35
35: ; preds = %10
%36 = load i32, i32* %5
%37 = add nsw i32 %36, 1
store i32 %37, i32* %5
br label %6
38: ; preds = %6
%39 = load double, double* %4
ret double %39
}

LLVM IR (-O2):
define double @pi_bpp(i32 %0) {
%2 = icmp slt i32 %0, 0
br i1 %2, label %3, label %5
3: ; preds = %5, %1
%4 = phi double [ 0.000000e+00, %1 ], [ %22, %5 ]
ret double %4
5: ; preds = %1, %5
%6 = phi i32 [ %24, %5 ], [ 0, %1 ]
%7 = phi double [ %22, %5 ], [ 0.000000e+00, %1 ]
%8 = phi double [ %23, %5 ], [ 1.000000e+00, %1 ]
%9 = sitofp i32 %6 to double
%10 = insertelement <2 x double> poison, double %9, i64 0
%11 = shufflevector <2 x double> %10, <2 x double> poison, <2 x i32> zeroinitializer
%12 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %11, <2 x double> <double 8.000000e+00, double 8.000000e+00>, <2 x double> <double 1.000000e+00, double 4.000000e+00>)
%13 = fdiv <2 x double> <double 4.000000e+00, double 2.000000e+00>, %12
%14 = shufflevector <2 x double> %13, <2 x double> poison, <2 x i32> <i32 1, i32 undef>
%15 = fsub <2 x double> %13, %14
%16 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %11, <2 x double> <double 8.000000e+00, double 8.000000e+00>, <2 x double> <double 5.000000e+00, double 6.000000e+00>)
%17 = fdiv <2 x double> <double 1.000000e+00, double 1.000000e+00>, %16
%18 = fsub <2 x double> %15, %17
%19 = shufflevector <2 x double> %17, <2 x double> poison, <2 x i32> <i32 1, i32 undef>
%20 = fsub <2 x double> %18, %19
%21 = extractelement <2 x double> %20, i64 0
%22 = tail call double @llvm.fmuladd.f64(double %8, double %21, double %7)
%23 = fmul double %8, 6.250000e-02
%24 = add nuw i32 %6, 1
%25 = icmp eq i32 %6, %0
br i1 %25, label %3, label %5
}