long double simpsons38(long double (*f)(long double), long double a,
                       long double b, int n) {
  long double h = (b - a) / n;
  long double sum = f(a) + f(b);
  while (n - 3) {
    sum += ((3 * (f((n - 1) * h) + f((n - 2) * h))) + 2 * f((n - 3) * h));
    n = n - 3;
  }
  sum += (3 * (f((n - 1) * h) + f((n - 2) * h)));
  return sum *= ((3 * h) / 8);
}


x86 assembly (clang, -O0):
<simpsons38>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
fldt   0x20(%rbp)
fldt   0x10(%rbp)
mov    %rdi,-0x8(%rbp)
fstpt  -0x20(%rbp)
fstpt  -0x30(%rbp)
mov    %esi,-0x34(%rbp)
fldt   -0x30(%rbp)
fldt   -0x20(%rbp)
fsubrp %st,%st(1)
mov    -0x34(%rbp),%eax
mov    %eax,-0x64(%rbp)
fildl  -0x64(%rbp)
fdivrp %st,%st(1)
fstpt  -0x50(%rbp)
mov    -0x8(%rbp),%rax
fldt   -0x20(%rbp)
mov    %rsp,%rcx
fstpt  (%rcx)
call   *%rax
fstpt  -0x84(%rbp)
mov    -0x8(%rbp),%rax
fldt   -0x30(%rbp)
mov    %rsp,%rcx
fstpt  (%rcx)
call   *%rax
fldt   -0x84(%rbp)
faddp  %st,%st(1)
fstpt  -0x60(%rbp)
mov    -0x34(%rbp),%eax
sub    $0x3,%eax
cmp    $0x0,%eax
je     1202 <simpsons38+0x102>
mov    -0x8(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x78(%rbp)
fildl  -0x78(%rbp)
fldt   -0x50(%rbp)
fmulp  %st,%st(1)
mov    %rsp,%rcx
fstpt  (%rcx)
call   *%rax
fstpt  -0x9c(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0xfffffffe,%ecx
mov    %ecx,-0x74(%rbp)
fildl  -0x74(%rbp)
fldt   -0x50(%rbp)
fmulp  %st,%st(1)
mov    %rsp,%rcx
fstpt  (%rcx)
call   *%rax
fldt   -0x9c(%rbp)
faddp  %st,%st(1)
fstpt  -0x90(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0xfffffffd,%ecx
mov    %ecx,-0x70(%rbp)
fildl  -0x70(%rbp)
fldt   -0x50(%rbp)
fmulp  %st,%st(1)
mov    %rsp,%rcx
fstpt  (%rcx)
call   *%rax
fldt   -0x90(%rbp)
fxch   %st(1)
fadd   %st,%st(0)
flds   0xe18(%rip)
fmulp  %st,%st(2)
faddp  %st,%st(1)
fldt   -0x60(%rbp)
faddp  %st,%st(1)
fstpt  -0x60(%rbp)
mov    -0x34(%rbp),%eax
sub    $0x3,%eax
mov    %eax,-0x34(%rbp)
jmp    1161 <simpsons38+0x61>
mov    -0x8(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x6c(%rbp)
fildl  -0x6c(%rbp)
fldt   -0x50(%rbp)
fmulp  %st,%st(1)
mov    %rsp,%rcx
fstpt  (%rcx)
call   *%rax
fstpt  -0xa8(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0xfffffffe,%ecx
mov    %ecx,-0x68(%rbp)
fildl  -0x68(%rbp)
fldt   -0x50(%rbp)
fmulp  %st,%st(1)
mov    %rsp,%rcx
fstpt  (%rcx)
call   *%rax
fldt   -0xa8(%rbp)
faddp  %st,%st(1)
fldt   -0x60(%rbp)
flds   0xdaf(%rip)
fmul   %st,%st(2)
fxch   %st(2)
faddp  %st,%st(1)
fstpt  -0x60(%rbp)
fldt   -0x50(%rbp)
fmulp  %st,%st(1)
flds   0xd9f(%rip)
fdivrp %st,%st(1)
fldt   -0x60(%rbp)
fmulp  %st,%st(1)
fld    %st(0)
fstpt  -0x60(%rbp)
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<simpsons38>:
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    %esi,%ebx
mov    %rdi,%r14
fldt   0x60(%rsp)
fldt   0x70(%rsp)
fld    %st(0)
fstpt  0x2c(%rsp)
fsub   %st(1),%st
mov    %esi,0x44(%rsp)
fidivl 0x44(%rsp)
fstpt  0x14(%rsp)
fstpt  (%rsp)
call   *%rdi
fstpt  0x20(%rsp)
fldt   0x2c(%rsp)
fstpt  (%rsp)
call   *%r14
fldt   0x20(%rsp)
faddp  %st,%st(1)
add    $0xfffffffd,%ebx
fstpt  0x2c(%rsp)
je     11bb <simpsons38+0xbb>
fldt   0x14(%rsp)
fstp   %st(0)
lea    0x2(%rbx),%eax
mov    %eax,0x40(%rsp)
fldt   0x14(%rsp)
fimull 0x40(%rsp)
fstpt  (%rsp)
call   *%r14
fstpt  0x20(%rsp)
lea    0x1(%rbx),%eax
mov    %eax,0x3c(%rsp)
fldt   0x14(%rsp)
fimull 0x3c(%rsp)
fstpt  (%rsp)
call   *%r14
fldt   0x20(%rsp)
faddp  %st,%st(1)
fstpt  0x20(%rsp)
mov    %ebx,0x38(%rsp)
fldt   0x14(%rsp)
fimull 0x38(%rsp)
fstpt  (%rsp)
call   *%r14
fldt   0x20(%rsp)
fmuls  0xe5c(%rip)
fxch   %st(1)
fadd   %st,%st(0)
faddp  %st,%st(1)
fldt   0x2c(%rsp)
faddp  %st,%st(1)
fstpt  0x2c(%rsp)
add    $0xfffffffd,%ebx
jne    1150 <simpsons38+0x50>
jmp    11c1 <simpsons38+0xc1>
fldt   0x14(%rsp)
fstp   %st(0)
fldt   0x14(%rsp)
fadd   %st,%st(0)
fstpt  (%rsp)
call   *%r14
fstpt  0x20(%rsp)
fldt   0x14(%rsp)
fstpt  (%rsp)
call   *%r14
fldt   0x20(%rsp)
faddp  %st,%st(1)
flds   0xe19(%rip)
fmul   %st,%st(1)
fldt   0x2c(%rsp)
faddp  %st,%st(2)
fldt   0x14(%rsp)
fmulp  %st,%st(1)
fmuls  0xe09(%rip)
fmulp  %st,%st(1)
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define x86_fp80 @simpsons38(x86_fp80 (x86_fp80)* %0, x86_fp80 %1, x86_fp80 %2, i32 %3) {
%5 = alloca x86_fp80 (x86_fp80)*
%6 = alloca x86_fp80
%7 = alloca x86_fp80
%8 = alloca i32
%9 = alloca x86_fp80
%10 = alloca x86_fp80
store x86_fp80 (x86_fp80)* %0, x86_fp80 (x86_fp80)** %5
store x86_fp80 %1, x86_fp80* %6
store x86_fp80 %2, x86_fp80* %7
store i32 %3, i32* %8
%11 = load x86_fp80, x86_fp80* %7
%12 = load x86_fp80, x86_fp80* %6
%13 = fsub x86_fp80 %11, %12
%14 = load i32, i32* %8
%15 = sitofp i32 %14 to x86_fp80
%16 = fdiv x86_fp80 %13, %15
store x86_fp80 %16, x86_fp80* %9
%17 = load x86_fp80 (x86_fp80)*, x86_fp80 (x86_fp80)** %5
%18 = load x86_fp80, x86_fp80* %6
%19 = call x86_fp80 %17(x86_fp80 %18)
%20 = load x86_fp80 (x86_fp80)*, x86_fp80 (x86_fp80)** %5
%21 = load x86_fp80, x86_fp80* %7
%22 = call x86_fp80 %20(x86_fp80 %21)
%23 = fadd x86_fp80 %19, %22
store x86_fp80 %23, x86_fp80* %10
br label %24
24: ; preds = %28, %4
%25 = load i32, i32* %8
%26 = sub nsw i32 %25, 3
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %57
28: ; preds = %24
%29 = load x86_fp80 (x86_fp80)*, x86_fp80 (x86_fp80)** %5
%30 = load i32, i32* %8
%31 = sub nsw i32 %30, 1
%32 = sitofp i32 %31 to x86_fp80
%33 = load x86_fp80, x86_fp80* %9
%34 = fmul x86_fp80 %32, %33
%35 = call x86_fp80 %29(x86_fp80 %34)
%36 = load x86_fp80 (x86_fp80)*, x86_fp80 (x86_fp80)** %5
%37 = load i32, i32* %8
%38 = sub nsw i32 %37, 2
%39 = sitofp i32 %38 to x86_fp80
%40 = load x86_fp80, x86_fp80* %9
%41 = fmul x86_fp80 %39, %40
%42 = call x86_fp80 %36(x86_fp80 %41)
%43 = fadd x86_fp80 %35, %42
%44 = load x86_fp80 (x86_fp80)*, x86_fp80 (x86_fp80)** %5
%45 = load i32, i32* %8
%46 = sub nsw i32 %45, 3
%47 = sitofp i32 %46 to x86_fp80
%48 = load x86_fp80, x86_fp80* %9
%49 = fmul x86_fp80 %47, %48
%50 = call x86_fp80 %44(x86_fp80 %49)
%51 = fmul x86_fp80 0xK40008000000000000000, %50
%52 = call x86_fp80 @llvm.fmuladd.f80(x86_fp80 0xK4000C000000000000000, x86_fp80 %43, x86_fp80 %51)
%53 = load x86_fp80, x86_fp80* %10
%54 = fadd x86_fp80 %53, %52
store x86_fp80 %54, x86_fp80* %10
%55 = load i32, i32* %8
%56 = sub nsw i32 %55, 3
store i32 %56, i32* %8
br label %24
57: ; preds = %24
%58 = load x86_fp80 (x86_fp80)*, x86_fp80 (x86_fp80)** %5
%59 = load i32, i32* %8
%60 = sub nsw i32 %59, 1
%61 = sitofp i32 %60 to x86_fp80
%62 = load x86_fp80, x86_fp80* %9
%63 = fmul x86_fp80 %61, %62
%64 = call x86_fp80 %58(x86_fp80 %63)
%65 = load x86_fp80 (x86_fp80)*, x86_fp80 (x86_fp80)** %5
%66 = load i32, i32* %8
%67 = sub nsw i32 %66, 2
%68 = sitofp i32 %67 to x86_fp80
%69 = load x86_fp80, x86_fp80* %9
%70 = fmul x86_fp80 %68, %69
%71 = call x86_fp80 %65(x86_fp80 %70)
%72 = fadd x86_fp80 %64, %71
%73 = load x86_fp80, x86_fp80* %10
%74 = call x86_fp80 @llvm.fmuladd.f80(x86_fp80 0xK4000C000000000000000, x86_fp80 %72, x86_fp80 %73)
store x86_fp80 %74, x86_fp80* %10
%75 = load x86_fp80, x86_fp80* %9
%76 = fmul x86_fp80 0xK4000C000000000000000, %75
%77 = fdiv x86_fp80 %76, 0xK40028000000000000000
%78 = load x86_fp80, x86_fp80* %10
%79 = fmul x86_fp80 %78, %77
store x86_fp80 %79, x86_fp80* %10
ret x86_fp80 %79
}

LLVM IR (-O2):
define x86_fp80 @simpsons38(x86_fp80 (x86_fp80)* nocapture %0, x86_fp80 %1, x86_fp80 %2, i32 %3) {
%5 = fsub x86_fp80 %2, %1
%6 = sitofp i32 %3 to x86_fp80
%7 = fdiv x86_fp80 %5, %6
%8 = tail call x86_fp80 %0(x86_fp80 %1)
%9 = tail call x86_fp80 %0(x86_fp80 %2)
%10 = fadd x86_fp80 %8, %9
%11 = add nsw i32 %3, -3
%12 = icmp eq i32 %11, 0
br i1 %12, label %34, label %13
13: ; preds = %4, %13
%14 = phi i32 [ %32, %13 ], [ %11, %4 ]
%15 = phi x86_fp80 [ %31, %13 ], [ %10, %4 ]
%16 = phi i32 [ %14, %13 ], [ %3, %4 ]
%17 = add nsw i32 %16, -1
%18 = sitofp i32 %17 to x86_fp80
%19 = fmul x86_fp80 %7, %18
%20 = tail call x86_fp80 %0(x86_fp80 %19)
%21 = add nsw i32 %16, -2
%22 = sitofp i32 %21 to x86_fp80
%23 = fmul x86_fp80 %7, %22
%24 = tail call x86_fp80 %0(x86_fp80 %23)
%25 = fadd x86_fp80 %20, %24
%26 = sitofp i32 %14 to x86_fp80
%27 = fmul x86_fp80 %7, %26
%28 = tail call x86_fp80 %0(x86_fp80 %27)
%29 = fmul x86_fp80 %28, 0xK40008000000000000000
%30 = tail call x86_fp80 @llvm.fmuladd.f80(x86_fp80 %25, x86_fp80 0xK4000C000000000000000, x86_fp80 %29)
%31 = fadd x86_fp80 %15, %30
%32 = add nsw i32 %14, -3
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %13
34: ; preds = %13, %4
%35 = phi x86_fp80 [ %10, %4 ], [ %31, %13 ]
%36 = fmul x86_fp80 %7, 0xK40008000000000000000
%37 = tail call x86_fp80 %0(x86_fp80 %36)
%38 = tail call x86_fp80 %0(x86_fp80 %7)
%39 = fadd x86_fp80 %37, %38
%40 = tail call x86_fp80 @llvm.fmuladd.f80(x86_fp80 %39, x86_fp80 0xK4000C000000000000000, x86_fp80 %35)
%41 = fmul x86_fp80 %7, 0xK4000C000000000000000
%42 = fmul x86_fp80 %41, 0xK3FFC8000000000000000
%43 = fmul x86_fp80 %42, %40
ret x86_fp80 %43
}