double int_simpson(double from, double to, int n, double (*func)()) {
  double h = (to - from) / n;
  double sum1 = 0.0;
  double sum2 = 0.0;
  int i;
  double x;
  for (i = 0; i < n; i++)
    sum1 += func(from + h * i + h / 2.0);
  for (i = 1; i < n; i++)
    sum2 += func(from + h * i);
  return h / 6.0 * (func(from) + func(to) + 4.0 * sum1 + 2.0 * sum2);
}


x86 assembly (clang, -O0):
<int_simpson>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %edi,-0x14(%rbp)
mov    %rsi,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
cvtsi2sdl -0x14(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11a0 <int_simpson+0xa0>
mov    -0x20(%rbp),%rcx
movsd  -0x8(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
cvtsi2sdl -0x3c(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  0xe94(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
mov    $0x1,%al
call   *%rcx
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1148 <int_simpson+0x48>
movl   $0x1,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11ea <int_simpson+0xea>
mov    -0x20(%rbp),%rcx
movsd  -0x8(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
cvtsi2sdl -0x3c(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    $0x1,%al
call   *%rcx
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11a7 <int_simpson+0xa7>
movsd  -0x28(%rbp),%xmm0
movsd  0xe11(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x20(%rbp),%rcx
movsd  -0x8(%rbp),%xmm0
mov    $0x1,%al
call   *%rcx
movsd  %xmm0,-0x58(%rbp)
mov    -0x20(%rbp),%rcx
movsd  -0x10(%rbp),%xmm0
mov    $0x1,%al
call   *%rcx
movsd  -0x58(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x50(%rbp),%xmm0
addsd  %xmm2,%xmm1
movsd  -0x30(%rbp),%xmm2
movsd  0xdc3(%rip),%xmm3
mulsd  %xmm3,%xmm2
addsd  %xmm1,%xmm2
movsd  -0x38(%rbp),%xmm1
addsd  %xmm1,%xmm1
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<int_simpson>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %rsi,%r14
movapd %xmm0,%xmm3
movapd %xmm1,%xmm2
subsd  %xmm0,%xmm2
xorps  %xmm0,%xmm0
cvtsi2sd %edi,%xmm0
divsd  %xmm0,%xmm2
test   %edi,%edi
movsd  %xmm1,0x28(%rsp)
jle    1216 <int_simpson+0x116>
mov    %edi,%ebx
movsd  0xec6(%rip),%xmm0
mulsd  %xmm2,%xmm0
movsd  %xmm0,0x20(%rsp)
xorpd  %xmm1,%xmm1
mov    %edi,%ebp
xorpd  %xmm4,%xmm4
movsd  %xmm2,0x10(%rsp)
movsd  %xmm3,0x8(%rsp)
nopw   0x0(%rax,%rax,1)
movsd  %xmm4,(%rsp)
movsd  %xmm1,0x18(%rsp)
movapd %xmm2,%xmm0
mulsd  %xmm4,%xmm0
addsd  %xmm3,%xmm0
addsd  0x20(%rsp),%xmm0
mov    $0x1,%al
call   *%r14
movsd  (%rsp),%xmm4
movsd  0x18(%rsp),%xmm1
movsd  0x8(%rsp),%xmm3
movsd  0x10(%rsp),%xmm2
addsd  %xmm0,%xmm1
movsd  0xe63(%rip),%xmm0
addsd  %xmm0,%xmm4
add    $0xffffffff,%ebp
jne    1160 <int_simpson+0x60>
movsd  %xmm1,0x18(%rsp)
cmp    $0x2,%ebx
jl     1220 <int_simpson+0x120>
add    $0xffffffff,%ebx
xorpd  %xmm1,%xmm1
movsd  %xmm1,(%rsp)
movapd %xmm0,%xmm1
nopl   0x0(%rax)
movsd  %xmm1,0x20(%rsp)
movapd %xmm2,%xmm0
mulsd  %xmm1,%xmm0
addsd  %xmm3,%xmm0
mov    $0x1,%al
call   *%r14
movsd  0x8(%rsp),%xmm3
movsd  0x10(%rsp),%xmm2
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  0x20(%rsp),%xmm1
addsd  0xdf9(%rip),%xmm1
add    $0xffffffff,%ebx
jne    11d0 <int_simpson+0xd0>
jmp    1229 <int_simpson+0x129>
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x18(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
divsd  0xddf(%rip),%xmm2
movsd  %xmm2,0x10(%rsp)
movapd %xmm3,%xmm0
mov    $0x1,%al
call   *%r14
movsd  %xmm0,0x8(%rsp)
movsd  0x28(%rsp),%xmm0
mov    $0x1,%al
call   *%r14
addsd  0x8(%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
mulsd  0xdb3(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm1,%xmm1
addsd  %xmm1,%xmm0
mulsd  0x10(%rsp),%xmm0
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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