double pi_bbp(int n) {
  double term = 0.;
  double nterm;
  double d = 0;
  double f = 16;
  for (int i = 0; i < n; i++) {
    f = (1. / 16.) * f;
    d = 8. * ((double)i);
    nterm = f * ((4. / (d + 1.)) - (2. / (d + 4.)) - (1. / (d + 5.)) -
                 (1. / (d + 6.)));
    term = nterm + term;
  }
  return term;
}


x86 assembly (clang, -O0):
<pi_bbp>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xee1(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11fa <pi_bbp+0xfa>
movsd  0xef9(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
cvtsi2sdl -0x2c(%rbp),%xmm1
movsd  0xeda(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  0xe9c(%rip),%xmm2
addsd  -0x20(%rbp),%xmm2
movsd  0xeaf(%rip),%xmm1
divsd  %xmm2,%xmm1
movsd  0xea3(%rip),%xmm3
addsd  -0x20(%rbp),%xmm3
movsd  0xe8e(%rip),%xmm2
divsd  %xmm3,%xmm2
subsd  %xmm2,%xmm1
movsd  0xe76(%rip),%xmm3
addsd  -0x20(%rbp),%xmm3
movsd  0xe59(%rip),%xmm2
divsd  %xmm3,%xmm2
subsd  %xmm2,%xmm1
movsd  0xe51(%rip),%xmm3
addsd  -0x20(%rbp),%xmm3
movsd  0xe3c(%rip),%xmm2
divsd  %xmm3,%xmm2
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    112b <pi_bbp+0x2b>
movsd  -0x10(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<pi_bbp>:
test   %edi,%edi
jle    11bb <pi_bbp+0xbb>
movsd  0xef0(%rip),%xmm1
xorpd  %xmm5,%xmm5
movsd  0xeeb(%rip),%xmm8
movsd  0xeea(%rip),%xmm9
movapd 0xef1(%rip),%xmm10
movapd 0xef8(%rip),%xmm11
movapd 0xeff(%rip),%xmm12
movapd 0xf07(%rip),%xmm3
movsd  0xec7(%rip),%xmm4
xorpd  %xmm0,%xmm0
cs nopw 0x0(%rax,%rax,1)
nop
mulsd  %xmm8,%xmm1
movapd %xmm5,%xmm2
mulsd  %xmm9,%xmm2
unpcklpd %xmm2,%xmm2
movapd %xmm2,%xmm6
addpd  %xmm10,%xmm6
movapd %xmm11,%xmm7
divpd  %xmm6,%xmm7
addpd  %xmm12,%xmm2
movapd %xmm3,%xmm6
divpd  %xmm2,%xmm6
movapd %xmm7,%xmm2
unpckhpd %xmm7,%xmm2
subsd  %xmm2,%xmm7
subsd  %xmm6,%xmm7
unpckhpd %xmm6,%xmm6
subsd  %xmm6,%xmm7
mulsd  %xmm1,%xmm7
addsd  %xmm7,%xmm0
addsd  %xmm4,%xmm5
add    $0xffffffff,%edi
jne    1160 <pi_bbp+0x60>
ret
xorps  %xmm0,%xmm0
ret

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

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