double integral_rectangle(double a, double b, double step,
                          double (*f)(double)) {
  double fragment = (b - a) / step;
  double res = step * (f(a) + f(b)) / 6.0;
  int i;
  for (i = 1; i <= fragment; ++i)
    res += 4.0 / 6.0 * step * f(a + step * (i - 0.5));
  for (i = 1; i <= fragment - 1; ++i)
    res += 2.0 / 6.0 * step * f(a + step * i);
  return (res);
}


x86 assembly (clang, -O0):
<integral_rectangle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
mov    %rdi,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x20(%rbp),%rax
movsd  -0x8(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x48(%rbp)
mov    -0x20(%rbp),%rax
movsd  -0x10(%rbp),%xmm0
call   *%rax
movsd  -0x48(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x40(%rbp),%xmm0
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe8f(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x1,-0x34(%rbp)
cvtsi2sdl -0x34(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     11f8 <integral_rectangle+0xf8>
movsd  0xe83(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x20(%rbp),%rax
movsd  -0x8(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
cvtsi2sdl -0x34(%rbp),%xmm2
movsd  0xe56(%rip),%xmm3
subsd  %xmm3,%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   *%rax
movaps %xmm0,%xmm2
movsd  -0x50(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1181 <integral_rectangle+0x81>
movl   $0x1,-0x34(%rbp)
cvtsi2sdl -0x34(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
movsd  0xdf7(%rip),%xmm2
subsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jb     1276 <integral_rectangle+0x176>
movsd  0xde9(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x20(%rbp),%rax
movsd  -0x8(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
cvtsi2sdl -0x34(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   *%rax
movaps %xmm0,%xmm2
movsd  -0x58(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11ff <integral_rectangle+0xff>
movsd  -0x30(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<integral_rectangle>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%rbx
movsd  %xmm2,0x18(%rsp)
movsd  %xmm1,0x8(%rsp)
subsd  %xmm0,%xmm1
divsd  %xmm2,%xmm1
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x20(%rsp)
call   *%rdi
movsd  %xmm0,(%rsp)
movsd  0x8(%rsp),%xmm0
call   *%rbx
movsd  0x10(%rsp),%xmm1
movsd  0x18(%rsp),%xmm2
movapd %xmm0,%xmm3
addsd  (%rsp),%xmm3
mulsd  %xmm2,%xmm3
divsd  0xea7(%rip),%xmm3
ucomisd 0xea7(%rip),%xmm1
jb     11d9 <integral_rectangle+0xd9>
movsd  0xea5(%rip),%xmm0
mulsd  %xmm2,%xmm0
movsd  %xmm0,(%rsp)
movsd  0xe8c(%rip),%xmm0
mov    $0x2,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  %xmm3,0x8(%rsp)
addsd  0xe7a(%rip),%xmm0
mulsd  %xmm2,%xmm0
addsd  0x20(%rsp),%xmm0
call   *%rbx
movsd  0x8(%rsp),%xmm3
movsd  0x18(%rsp),%xmm2
movapd %xmm0,%xmm1
mulsd  (%rsp),%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
addsd  %xmm1,%xmm3
movsd  0x10(%rsp),%xmm1
add    $0x1,%ebp
ucomisd %xmm0,%xmm1
jae    1190 <integral_rectangle+0x90>
addsd  0xe3f(%rip),%xmm1
ucomisd 0xe1f(%rip),%xmm1
jb     1251 <integral_rectangle+0x151>
movsd  0xe35(%rip),%xmm0
mulsd  %xmm2,%xmm0
movsd  %xmm0,(%rsp)
movsd  0xe04(%rip),%xmm0
mov    $0x2,%ebp
movsd  %xmm1,0x10(%rsp)
nop
movsd  %xmm3,0x8(%rsp)
mulsd  %xmm2,%xmm0
addsd  0x20(%rsp),%xmm0
call   *%rbx
movsd  0x8(%rsp),%xmm3
movsd  0x18(%rsp),%xmm2
movapd %xmm0,%xmm1
mulsd  (%rsp),%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
addsd  %xmm1,%xmm3
movsd  0x10(%rsp),%xmm1
add    $0x1,%ebp
ucomisd %xmm0,%xmm1
jae    1210 <integral_rectangle+0x110>
movapd %xmm3,%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

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

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