double integral(double (*f)(double), double x0, double x1) {
  double step = (x1 - x0) / 128.;
  const int q_of_layers = (int)((x1 - x0) / step) + 1;
  int k;
  double res = (*f)(x0) + (*f)((double)(q_of_layers - 1) * step + x0);
  for (k = 1; k < q_of_layers - 1; k++) {
    res += 2. * (double)(1 + k % 2) * (*f)((double)k * step + x0);
  }
  return step / 3. * res;
}


x86 assembly (clang, -O0):
<integral>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  0xed8(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
cvttsd2si %xmm0,%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
movsd  -0x10(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x38(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
cvtsi2sd %ecx,%xmm0
movsd  -0x20(%rbp),%xmm2
movsd  -0x10(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   *%rax
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x1,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    120d <integral+0x10d>
mov    -0x28(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
cvtsi2sd %edx,%xmm1
movsd  0xe51(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x8(%rbp),%rax
cvtsi2sdl -0x28(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
movsd  -0x10(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   *%rax
movaps %xmm0,%xmm2
movsd  -0x40(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1194 <integral+0x94>
movsd  -0x20(%rbp),%xmm0
movsd  0xdee(%rip),%xmm1
divsd  %xmm1,%xmm0
mulsd  -0x30(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<integral>:
push   %rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
movsd  %xmm0,0x18(%rsp)
mov    %rdi,%r14
subsd  %xmm0,%xmm1
movsd  0xee3(%rip),%xmm2
mulsd  %xmm1,%xmm2
movsd  %xmm2,0x10(%rsp)
divsd  %xmm2,%xmm1
movapd %xmm1,0x20(%rsp)
cvttsd2si %xmm1,%ebp
call   *%rdi
movsd  %xmm0,0x8(%rsp)
cvttpd2dq 0x20(%rsp),%xmm0
cvtdq2pd %xmm0,%xmm0
mulsd  0x10(%rsp),%xmm0
addsd  0x18(%rsp),%xmm0
call   *%r14
addsd  0x8(%rsp),%xmm0
cmp    $0x2,%ebp
jl     11d9 <integral+0xd9>
mov    $0x1,%ebx
movsd  0xe9a(%rip),%xmm1
xchg   %ax,%ax
movsd  %xmm1,0x20(%rsp)
movsd  %xmm0,0x8(%rsp)
mov    %ebx,%eax
and    $0x1,%eax
add    $0x1,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
addsd  %xmm0,%xmm0
movsd  %xmm0,0x38(%rsp)
movapd %xmm1,%xmm0
mulsd  0x10(%rsp),%xmm0
addsd  0x18(%rsp),%xmm0
call   *%r14
mulsd  0x38(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x20(%rsp),%xmm1
movsd  0x8(%rsp),%xmm0
addsd  0xe36(%rip),%xmm1
add    $0x1,%ebx
cmp    %ebx,%ebp
jne    1170 <integral+0x70>
movsd  0x10(%rsp),%xmm1
divsd  0xe29(%rip),%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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