double simpson_helper(double (*f)(double), double from, double to, int steps) {
  double result = 0.0;
  double acc = 0.0;
  double h = (to - from) / steps;
  result += (*f)(from) + (*f)(to);
  acc = 0.0;
  for (int i = 1, limit = steps / 2; i <= limit; i++) {
    acc += (*f)(from + (2 * i - 1) * h);
  }
  result += 4 * acc;
  acc = 0.0;
  for (int i = 1, limit = steps / 2 - 1; i <= limit; i++) {
    acc += (*f)(from + 2 * i * h);
  }
  result += 2 * acc;
  return (h / 3) * result;
}


x86 assembly (clang, -O0):
<simpson_helper>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %esi,-0x1c(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x8(%rbp),%rax
movsd  -0x10(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x50(%rbp)
mov    -0x8(%rbp),%rax
movsd  -0x18(%rbp),%xmm0
call   *%rax
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
addsd  %xmm1,%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x40(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x40(%rbp),%eax
jg     11d8 <simpson_helper+0xd8>
mov    -0x8(%rbp),%rax
movsd  -0x10(%rbp),%xmm1
mov    -0x3c(%rbp),%ecx
shl    $0x1,%ecx
sub    $0x1,%ecx
cvtsi2sd %ecx,%xmm0
movsd  -0x38(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   *%rax
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    118f <simpson_helper+0x8f>
movsd  -0x30(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  0xe16(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x1,-0x44(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
sub    $0x1,%eax
mov    %eax,-0x48(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x48(%rbp),%eax
jg     125d <simpson_helper+0x15d>
mov    -0x8(%rbp),%rax
movsd  -0x10(%rbp),%xmm1
mov    -0x44(%rbp),%ecx
shl    $0x1,%ecx
cvtsi2sd %ecx,%xmm0
movsd  -0x38(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   *%rax
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1217 <simpson_helper+0x117>
movsd  -0x30(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  0xd87(%rip),%xmm1
divsd  %xmm1,%xmm0
mulsd  -0x28(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<simpson_helper>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %esi,%r14d
movsd  %xmm1,(%rsp)
mov    %rdi,%r12
movapd %xmm1,%xmm3
subsd  %xmm0,%xmm3
cvtsi2sd %esi,%xmm2
divsd  %xmm2,%xmm3
movsd  %xmm3,0x8(%rsp)
movsd  %xmm0,0x18(%rsp)
call   *%rdi
movsd  %xmm0,0x20(%rsp)
movsd  (%rsp),%xmm0
call   *%r12
xorpd  %xmm1,%xmm1
xorpd  %xmm3,%xmm3
xorpd  %xmm4,%xmm4
cmp    $0x2,%r14d
jl     1219 <simpson_helper+0x119>
movsd  %xmm0,0x10(%rsp)
mov    %r14d,%r15d
shr    $0x1f,%r15d
add    %r14d,%r15d
sar    %r15d
xorpd  %xmm3,%xmm3
mov    $0x1,%ebp
mov    %r15d,%ebx
nopl   0x0(%rax,%rax,1)
movsd  %xmm3,(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
mulsd  0x8(%rsp),%xmm0
addsd  0x18(%rsp),%xmm0
call   *%r12
movsd  (%rsp),%xmm3
addsd  %xmm0,%xmm3
add    $0x2,%ebp
add    $0xffffffff,%ebx
jne    1180 <simpson_helper+0x80>
xorpd  %xmm4,%xmm4
cmp    $0x4,%r14d
jl     120f <simpson_helper+0x10f>
movsd  %xmm3,(%rsp)
cmp    $0x3,%r15d
mov    $0x2,%ebp
cmovl  %ebp,%r15d
add    %r15d,%r15d
xorpd  %xmm4,%xmm4
nop
movsd  %xmm4,0x28(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
mulsd  0x8(%rsp),%xmm0
addsd  0x18(%rsp),%xmm0
call   *%r12
movsd  0x28(%rsp),%xmm4
addsd  %xmm0,%xmm4
add    $0x2,%ebp
cmp    %ebp,%r15d
jne    11d0 <simpson_helper+0xd0>
xorpd  %xmm1,%xmm1
movsd  0x10(%rsp),%xmm0
movsd  (%rsp),%xmm3
jmp    1219 <simpson_helper+0x119>
xorpd  %xmm1,%xmm1
movsd  0x10(%rsp),%xmm0
movsd  0x20(%rsp),%xmm2
addsd  %xmm0,%xmm2
addsd  %xmm1,%xmm2
mulsd  0xdd1(%rip),%xmm3
addsd  %xmm2,%xmm3
addsd  %xmm4,%xmm4
addsd  %xmm3,%xmm4
movsd  0x8(%rsp),%xmm0
divsd  0xdbf(%rip),%xmm0
mulsd  %xmm4,%xmm0
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define double @simpson_helper(double (double)* nocapture %0, double %1, double %2, i32 %3) {
%5 = fsub double %2, %1
%6 = sitofp i32 %3 to double
%7 = fdiv double %5, %6
%8 = tail call double %0(double %1)
%9 = tail call double %0(double %2)
%10 = sdiv i32 %3, 2
%11 = icmp slt i32 %3, 2
br i1 %11, label %27, label %16
12: ; preds = %16
%13 = icmp sgt i32 %3, 3
br i1 %13, label %14, label %27
14: ; preds = %12
%15 = call i32 @llvm.smax.i32(i32 %10, i32 2)
br label %36
16: ; preds = %4, %16
%17 = phi double [ %24, %16 ], [ 0.000000e+00, %4 ]
%18 = phi i32 [ %25, %16 ], [ 1, %4 ]
%19 = shl nuw nsw i32 %18, 1
%20 = add nsw i32 %19, -1
%21 = sitofp i32 %20 to double
%22 = tail call double @llvm.fmuladd.f64(double %21, double %7, double %1)
%23 = tail call double %0(double %22)
%24 = fadd double %17, %23
%25 = add nuw nsw i32 %18, 1
%26 = icmp eq i32 %18, %10
br i1 %26, label %12, label %16
27: ; preds = %36, %4, %12
%28 = phi double [ %24, %12 ], [ 0.000000e+00, %4 ], [ %24, %36 ]
%29 = phi double [ 0.000000e+00, %12 ], [ 0.000000e+00, %4 ], [ %43, %36 ]
%30 = fadd double %8, %9
%31 = fadd double %30, 0.000000e+00
%32 = tail call double @llvm.fmuladd.f64(double %28, double 4.000000e+00, double %31)
%33 = tail call double @llvm.fmuladd.f64(double %29, double 2.000000e+00, double %32)
%34 = fdiv double %7, 3.000000e+00
%35 = fmul double %34, %33
ret double %35
36: ; preds = %14, %36
%37 = phi i32 [ %44, %36 ], [ 1, %14 ]
%38 = phi double [ %43, %36 ], [ 0.000000e+00, %14 ]
%39 = shl nuw nsw i32 %37, 1
%40 = sitofp i32 %39 to double
%41 = tail call double @llvm.fmuladd.f64(double %40, double %7, double %1)
%42 = tail call double %0(double %41)
%43 = fadd double %38, %42
%44 = add nuw nsw i32 %37, 1
%45 = icmp eq i32 %44, %15
br i1 %45, label %27, label %36
}