double simpson(double x, double dx, double (*dfdx)(double x)) {
  double y1, y2, y3;
  y1 = dx * (*dfdx)(x);
  y2 = dx * (*dfdx)(x + dx / 2);
  y3 = dx * (*dfdx)(x + dx);
  return (y1 + 4 * y2 + y3) / 6;
}


x86 assembly (clang, -O0):
<simpson>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x18(%rbp),%rax
movsd  -0x8(%rbp),%xmm0
call   *%rax
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x18(%rbp),%rax
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  0xeb4(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
call   *%rax
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x18(%rbp),%rax
movsd  -0x8(%rbp),%xmm0
addsd  -0x10(%rbp),%xmm0
call   *%rax
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
movsd  0xe54(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  0xe37(%rip),%xmm1
divsd  %xmm1,%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<simpson>:
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
movsd  %xmm1,(%rsp)
movsd  %xmm0,0x8(%rsp)
call   *%rdi
movsd  (%rsp),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,0x18(%rsp)
movsd  0xed4(%rip),%xmm0
mulsd  %xmm1,%xmm0
addsd  0x8(%rsp),%xmm0
call   *%rbx
movsd  (%rsp),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
addsd  %xmm1,%xmm0
call   *%rbx
mulsd  (%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
mulsd  0xea2(%rip),%xmm1
addsd  0x18(%rsp),%xmm1
addsd  %xmm1,%xmm0
divsd  0xe98(%rip),%xmm0
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @simpson(double %0, double %1, double (double)* %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca double (double)*
%7 = alloca double
%8 = alloca double
%9 = alloca double
store double %0, double* %4
store double %1, double* %5
store double (double)* %2, double (double)** %6
%10 = load double, double* %5
%11 = load double (double)*, double (double)** %6
%12 = load double, double* %4
%13 = call double %11(double %12)
%14 = fmul double %10, %13
store double %14, double* %7
%15 = load double, double* %5
%16 = load double (double)*, double (double)** %6
%17 = load double, double* %4
%18 = load double, double* %5
%19 = fdiv double %18, 2.000000e+00
%20 = fadd double %17, %19
%21 = call double %16(double %20)
%22 = fmul double %15, %21
store double %22, double* %8
%23 = load double, double* %5
%24 = load double (double)*, double (double)** %6
%25 = load double, double* %4
%26 = load double, double* %5
%27 = fadd double %25, %26
%28 = call double %24(double %27)
%29 = fmul double %23, %28
store double %29, double* %9
%30 = load double, double* %7
%31 = load double, double* %8
%32 = call double @llvm.fmuladd.f64(double 4.000000e+00, double %31, double %30)
%33 = load double, double* %9
%34 = fadd double %32, %33
%35 = fdiv double %34, 6.000000e+00
ret double %35
}

LLVM IR (-O2):
define double @simpson(double %0, double %1, double (double)* nocapture %2) {
%4 = tail call double %2(double %0)
%5 = fmul double %4, %1
%6 = fmul double %1, 5.000000e-01
%7 = fadd double %6, %0
%8 = tail call double %2(double %7)
%9 = fmul double %8, %1
%10 = fadd double %0, %1
%11 = tail call double %2(double %10)
%12 = fmul double %11, %1
%13 = tail call double @llvm.fmuladd.f64(double %9, double 4.000000e+00, double %5)
%14 = fadd double %13, %12
%15 = fdiv double %14, 6.000000e+00
ret double %15
}