double int_leftrect(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);
  return h * sum;
}


x86 assembly (clang, -O0):
<int_leftrect>:
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     1187 <int_leftrect+0x87>
mov    -0x20(%rbp),%rcx
movsd  -0x38(%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_leftrect+0x43>
movsd  -0x28(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<int_leftrect>:
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_leftrect+0x82>
mov    %rsi,%rbx
xorpd  %xmm0,%xmm0
movsd  %xmm2,0x10(%rsp)
movsd  %xmm1,0x8(%rsp)
nopl   (%rax)
movsd  %xmm0,(%rsp)
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
addsd  %xmm2,%xmm3
ucomisd %xmm3,%xmm1
jae    1140 <int_leftrect+0x40>
mulsd  %xmm0,%xmm2
movapd %xmm2,%xmm0
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @int_leftrect(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 = %32, %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 %36
25: ; preds = %19
%26 = load double (...)*, double (...)** %8
%27 = load double, double* %11
%28 = bitcast double (...)* %26 to double (double, ...)*
%29 = call double (double, ...) %28(double %27)
%30 = load double, double* %10
%31 = fadd double %30, %29
store double %31, double* %10
br label %32
32: ; preds = %25
%33 = load double, double* %9
%34 = load double, double* %11
%35 = fadd double %34, %33
store double %35, double* %11
br label %19
36: ; preds = %19
%37 = load double, double* %9
%38 = load double, double* %10
%39 = fmul double %37, %38
ret double %39
}

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