double qsimp(double (*func)(double, void *), double a, double b, int n,
             void *params) {
  int i;
  double x;
  double h;
  double sum;
  double w;
  sum = 0.0;
  h = (b - a) / (double)(n - 1);
  w = 1.0;
  for (i = 1; i < n - 1; i++) {
    x = a + i * h;
    w = ((i % 2) == 0) ? 2.0 : 4.0;
    sum += w * func(x, params);
  }
  sum += (func(a, params) + func(b, params));
  sum *= (h / 3.0);
  return sum;
}


x86 assembly (clang, -O0):
<qsimp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %esi,-0x1c(%rbp)
mov    %rdx,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xeb6(%rip),%xmm0
movsd  %xmm0,-0x50(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1206 <qsimp+0x106>
movsd  -0x10(%rbp),%xmm1
cvtsi2sdl -0x2c(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x2c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
movsd  0xe7a(%rip),%xmm0
movsd  0xe7a(%rip),%xmm1
movsd  %xmm1,-0x60(%rbp)
cmp    $0x0,%edx
movsd  %xmm0,-0x58(%rbp)
je     11bb <qsimp+0xbb>
movsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
mov    -0x8(%rbp),%rax
movsd  -0x38(%rbp),%xmm0
mov    -0x28(%rbp),%rdi
call   *%rax
movaps %xmm0,%xmm2
movsd  -0x68(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1156 <qsimp+0x56>
mov    -0x8(%rbp),%rax
movsd  -0x10(%rbp),%xmm0
mov    -0x28(%rbp),%rdi
call   *%rax
movsd  %xmm0,-0x70(%rbp)
mov    -0x8(%rbp),%rax
movsd  -0x18(%rbp),%xmm0
mov    -0x28(%rbp),%rdi
call   *%rax
movaps %xmm0,%xmm1
movsd  -0x70(%rbp),%xmm0
addsd  %xmm1,%xmm0
addsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  0xdbc(%rip),%xmm1
divsd  %xmm1,%xmm0
mulsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<qsimp>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%r14
movapd %xmm0,%xmm2
mov    %rdi,%r15
movsd  %xmm1,0x18(%rsp)
lea    -0x1(%rsi),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
subsd  %xmm2,%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
xorpd  %xmm0,%xmm0
cmp    $0x3,%esi
jl     11d8 <qsimp+0xd8>
mov    $0x2,%r13d
sub    %esi,%r13d
mov    $0x1,%ebx
movsd  0xea7(%rip),%xmm1
xorpd  %xmm0,%xmm0
lea    0xeac(%rip),%r12
movsd  %xmm2,0x20(%rsp)
nopw   0x0(%rax,%rax,1)
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,(%rsp)
movapd %xmm1,%xmm0
mulsd  0x10(%rsp),%xmm0
addsd  %xmm2,%xmm0
xor    %ebp,%ebp
test   $0x1,%bl
sete   %bpl
mov    %r14,%rdi
call   *%r15
movsd  0x20(%rsp),%xmm2
mulsd  (%r12,%rbp,8),%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  0x8(%rsp),%xmm1
movsd  (%rsp),%xmm0
addsd  0xe3b(%rip),%xmm1
lea    (%rbx,%r13,1),%eax
add    $0x1,%eax
mov    %ebx,%ecx
add    $0x1,%ecx
mov    %ecx,%ebx
cmp    $0x1,%eax
jne    1170 <qsimp+0x70>
movsd  %xmm0,(%rsp)
movapd %xmm2,%xmm0
mov    %r14,%rdi
call   *%r15
movsd  %xmm0,0x8(%rsp)
movsd  0x18(%rsp),%xmm0
mov    %r14,%rdi
call   *%r15
addsd  0x8(%rsp),%xmm0
addsd  (%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
divsd  0xdf6(%rip),%xmm1
mulsd  %xmm1,%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define double @qsimp(double (double, i8*)* nocapture %0, double %1, double %2, i32 %3, i8* %4) {
%6 = fsub double %2, %1
%7 = add i32 %3, -1
%8 = sitofp i32 %7 to double
%9 = fdiv double %6, %8
%10 = icmp sgt i32 %3, 2
br i1 %10, label %11, label %23
11: ; preds = %5, %11
%12 = phi double [ %20, %11 ], [ 0.000000e+00, %5 ]
%13 = phi i32 [ %21, %11 ], [ 1, %5 ]
%14 = sitofp i32 %13 to double
%15 = tail call double @llvm.fmuladd.f64(double %14, double %9, double %1)
%16 = and i32 %13, 1
%17 = icmp eq i32 %16, 0
%18 = select i1 %17, double 2.000000e+00, double 4.000000e+00
%19 = tail call double %0(double %15, i8* %4)
%20 = tail call double @llvm.fmuladd.f64(double %18, double %19, double %12)
%21 = add nuw nsw i32 %13, 1
%22 = icmp eq i32 %21, %7
br i1 %22, label %23, label %11
23: ; preds = %11, %5
%24 = phi double [ 0.000000e+00, %5 ], [ %20, %11 ]
%25 = tail call double %0(double %1, i8* %4)
%26 = tail call double %0(double %2, i8* %4)
%27 = fadd double %25, %26
%28 = fadd double %24, %27
%29 = fdiv double %9, 3.000000e+00
%30 = fmul double %29, %28
ret double %30
}