double simpson(double a, double b, int sdiv, double (*f)(double, void *),
               void *info) {
  double k, sum1 = 0, sum2 = 0;
  int i;
  k = ((double)b - a) / ((double)2 * sdiv);
  for (i = 1; i < sdiv; i++) {
    sum1 += f(a + k * 2 * i, info);
    sum2 += f(a + k * (2 * i - 1), info);
  }
  sum2 += f(a + k * (2 * i - 1), info);
  return ((double)(k / 3) * (f(a, info) + f(b, info) + 2 * sum1 + 4 * sum2));
}


x86 assembly (clang, -O0):
<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)
mov    %rdx,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
cvtsi2sdl -0x14(%rbp),%xmm2
movsd  0xebc(%rip),%xmm1
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x1,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11d8 <simpson+0xd8>
mov    -0x20(%rbp),%rax
movsd  -0x8(%rbp),%xmm1
movsd  0xe8b(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
cvtsi2sdl -0x44(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x28(%rbp),%rdi
call   *%rax
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x20(%rbp),%rax
movsd  -0x8(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm0
mov    -0x44(%rbp),%ecx
shl    $0x1,%ecx
sub    $0x1,%ecx
cvtsi2sd %ecx,%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x28(%rbp),%rdi
call   *%rax
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1158 <simpson+0x58>
mov    -0x20(%rbp),%rax
movsd  -0x8(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm0
mov    -0x44(%rbp),%ecx
shl    $0x1,%ecx
sub    $0x1,%ecx
cvtsi2sd %ecx,%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x28(%rbp),%rdi
call   *%rax
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xdf8(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x20(%rbp),%rax
movsd  -0x8(%rbp),%xmm0
mov    -0x28(%rbp),%rdi
call   *%rax
movsd  %xmm0,-0x58(%rbp)
mov    -0x20(%rbp),%rax
movsd  -0x10(%rbp),%xmm0
mov    -0x28(%rbp),%rdi
call   *%rax
movsd  -0x58(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x50(%rbp),%xmm0
addsd  %xmm2,%xmm1
movsd  -0x38(%rbp),%xmm2
addsd  %xmm2,%xmm2
addsd  %xmm1,%xmm2
movsd  -0x40(%rbp),%xmm1
movsd  0xd99(%rip),%xmm3
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<simpson>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x40,%rsp
mov    %rdx,%r14
mov    %rsi,%r12
movapd %xmm0,%xmm2
movsd  %xmm1,0x28(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %edi,%xmm0
subsd  %xmm2,%xmm1
addsd  %xmm0,%xmm0
divsd  %xmm0,%xmm1
cmp    $0x2,%edi
movsd  %xmm2,0x18(%rsp)
movsd  %xmm1,0x10(%rsp)
jl     1205 <simpson+0x105>
mov    %edi,%r15d
movapd %xmm1,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x30(%rsp)
lea    -0x1(%r15),%ebp
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0xe95(%rip),%xmm3
mov    $0x1,%ebx
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x20(%rsp)
nopw   0x0(%rax,%rax,1)
movsd  %xmm3,0x38(%rsp)
movsd  0x30(%rsp),%xmm0
mulsd  %xmm3,%xmm0
addsd  %xmm2,%xmm0
mov    %r14,%rdi
call   *%r12
movsd  0x20(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x20(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
mulsd  0x10(%rsp),%xmm0
addsd  0x18(%rsp),%xmm0
mov    %r14,%rdi
call   *%r12
movsd  0x38(%rsp),%xmm3
movsd  0x18(%rsp),%xmm2
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
addsd  0xe19(%rip),%xmm3
add    $0x2,%ebx
add    $0xffffffff,%ebp
jne    1180 <simpson+0x80>
lea    (%r15,%r15,1),%eax
add    $0xffffffff,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0x10(%rsp),%xmm1
jmp    1221 <simpson+0x121>
movsd  0xdf3(%rip),%xmm0
xorpd  %xmm3,%xmm3
movsd  %xmm3,0x20(%rsp)
xorpd  %xmm3,%xmm3
movsd  %xmm3,0x8(%rsp)
mulsd  %xmm1,%xmm0
addsd  %xmm2,%xmm0
mov    %r14,%rdi
call   *%r12
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
divsd  0xdbf(%rip),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x18(%rsp),%xmm0
mov    %r14,%rdi
call   *%r12
movsd  %xmm0,0x18(%rsp)
movsd  0x28(%rsp),%xmm0
mov    %r14,%rdi
call   *%r12
addsd  0x18(%rsp),%xmm0
movsd  0x20(%rsp),%xmm1
addsd  %xmm1,%xmm1
addsd  %xmm1,%xmm0
movsd  0x8(%rsp),%xmm1
mulsd  0xd81(%rip),%xmm1
addsd  %xmm1,%xmm0
mulsd  0x10(%rsp),%xmm0
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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