double int_rightrect(double from, double to, int n, double (*func)()) {
  double h = (to - from) / n;
  double sum = 0.0, x;
  for (x = from; x <= (to - h); x += h)
    sum += func(x + h);
  return h * sum;
}


x86 assembly (clang, -O0):
<int_rightrect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%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)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     118c <int_rightrect+0x8c>
mov    -0x20(%rbp),%rcx
movsd  -0x38(%rbp),%xmm0
addsd  -0x28(%rbp),%xmm0
mov    $0x1,%al
call   *%rcx
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    1143 <int_rightrect+0x43>
movsd  -0x28(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<int_rightrect>:
push   %rbx
sub    $0x20,%rsp
movapd %xmm0,%xmm3
movapd %xmm1,%xmm2
subsd  %xmm0,%xmm2
xorps  %xmm0,%xmm0
cvtsi2sd %edi,%xmm0
divsd  %xmm0,%xmm2
subsd  %xmm2,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm3,%xmm1
jb     1182 <int_rightrect+0x82>
mov    %rsi,%rbx
xorpd  %xmm0,%xmm0
movsd  %xmm2,0x10(%rsp)
movsd  %xmm1,0x8(%rsp)
nopl   (%rax)
movsd  %xmm0,(%rsp)
addsd  %xmm2,%xmm3
movsd  %xmm3,0x18(%rsp)
movapd %xmm3,%xmm0
mov    $0x1,%al
call   *%rbx
movsd  0x18(%rsp),%xmm3
movsd  0x8(%rsp),%xmm1
movsd  0x10(%rsp),%xmm2
movsd  (%rsp),%xmm4
addsd  %xmm0,%xmm4
movsd  %xmm4,(%rsp)
movsd  (%rsp),%xmm0
ucomisd %xmm3,%xmm1
jae    1140 <int_rightrect+0x40>
mulsd  %xmm0,%xmm2
movapd %xmm2,%xmm0
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @int_rightrect(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
store double %0, double* %5
store double %1, double* %6
store i32 %2, i32* %7
store double (...)* %3, double (...)** %8
%12 = load double, double* %6
%13 = load double, double* %5
%14 = fsub double %12, %13
%15 = load i32, i32* %7
%16 = sitofp i32 %15 to double
%17 = fdiv double %14, %16
store double %17, double* %9
store double 0.000000e+00, double* %10
%18 = load double, double* %5
store double %18, double* %11
br label %19
19: ; preds = %34, %4
%20 = load double, double* %11
%21 = load double, double* %6
%22 = load double, double* %9
%23 = fsub double %21, %22
%24 = fcmp ole double %20, %23
br i1 %24, label %25, label %38
25: ; preds = %19
%26 = load double (...)*, double (...)** %8
%27 = load double, double* %11
%28 = load double, double* %9
%29 = fadd double %27, %28
%30 = bitcast double (...)* %26 to double (double, ...)*
%31 = call double (double, ...) %30(double %29)
%32 = load double, double* %10
%33 = fadd double %32, %31
store double %33, double* %10
br label %34
34: ; preds = %25
%35 = load double, double* %9
%36 = load double, double* %11
%37 = fadd double %36, %35
store double %37, double* %11
br label %19
38: ; preds = %19
%39 = load double, double* %9
%40 = load double, double* %10
%41 = fmul double %39, %40
ret double %41
}

LLVM IR (-O2):
define double @int_rightrect(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 = fsub double %1, %7
%9 = fcmp ult double %8, %0
br i1 %9, label %19, label %10
10: ; preds = %4
%11 = bitcast double (...)* %3 to double (double, ...)*
br label %12
12: ; preds = %10, %12
%13 = phi double [ %0, %10 ], [ %15, %12 ]
%14 = phi double [ 0.000000e+00, %10 ], [ %17, %12 ]
%15 = fadd double %7, %13
%16 = tail call double (double, ...) %11(double %15)
%17 = fadd double %14, %16
%18 = fcmp ugt double %15, %8
br i1 %18, label %19, label %12
19: ; preds = %12, %4
%20 = phi double [ 0.000000e+00, %4 ], [ %17, %12 ]
%21 = fmul double %7, %20
ret double %21
}