double trapezoidal(double a, double b, double accuracy, double (*f)(double x)) {
  double integraln = 0, integralnminus1, interval = b - a, ei = exp(1);
  int i = 1, j;
  printf("TRAPEZOIDAL "
         "METHOD:\n\ni\t|dx|\t\tI(dx)\t\t|ei|\t\t|log(ei)/log(e(i-1))|\n");
  do {
    integralnminus1 = integraln;
    integraln = f(a) / 2 + f(b) / 2;
    interval /= 2;
    j = 1;
    do
      integraln += f(a + j * interval);
    while (a + (++j) * interval < b);
    integraln = interval * integraln;
    printf("%02d\t%+09g\t%+09g\t%+09g\t%+09g\n", i++, interval, integraln,
           abslt(integraln - integralnminus1),
           abslt(log(abslt(integraln - integralnminus1)) / log(ei)));
    ei = abslt(integraln - integralnminus1);
  } while (abslt(integraln - integralnminus1) > accuracy);
  return integraln;
}


x86 assembly (clang, -O0):
<trapezoidal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
mov    %rdi,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xe83(%rip),%xmm0
call   1050 <exp@plt>
movsd  %xmm0,-0x40(%rbp)
movl   $0x1,-0x44(%rbp)
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x20(%rbp),%rax
movsd  -0x8(%rbp),%xmm0
call   *%rax
movsd  0xe4f(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x20(%rbp),%rax
movsd  -0x10(%rbp),%xmm0
call   *%rax
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
movsd  0xe2b(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  0xe11(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x1,-0x48(%rbp)
mov    -0x20(%rbp),%rax
movsd  -0x8(%rbp),%xmm1
cvtsi2sdl -0x48(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   *%rax
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x8(%rbp),%xmm0
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
cvtsi2sd %eax,%xmm1
movsd  -0x38(%rbp),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
ja     1207 <trapezoidal+0xc7>
movsd  -0x38(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x44(%rbp),%eax
mov    %eax,-0x6c(%rbp)
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x28(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
mov    $0x1,%al
call   1030 <abslt@plt>
mov    %eax,-0x54(%rbp)
movsd  -0x28(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
mov    $0x1,%al
call   1030 <abslt@plt>
cvtsi2sd %eax,%xmm0
call   1060 <log@plt>
movsd  %xmm0,-0x78(%rbp)
movsd  -0x40(%rbp),%xmm0
call   1060 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x78(%rbp),%xmm0
divsd  %xmm1,%xmm0
mov    $0x1,%al
call   1030 <abslt@plt>
mov    -0x6c(%rbp),%esi
movsd  -0x68(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm1
mov    -0x54(%rbp),%edx
mov    %eax,%ecx
lea    0xd5d(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
movsd  -0x28(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
mov    $0x1,%al
call   1030 <abslt@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x28(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
mov    $0x1,%al
call   1030 <abslt@plt>
cvtsi2sd %eax,%xmm0
ucomisd -0x18(%rbp),%xmm0
ja     119c <trapezoidal+0x5c>
movsd  -0x28(%rbp),%xmm0
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trapezoidal>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x40,%rsp
mov    %rdi,%rbx
movsd  %xmm2,0x30(%rsp)
movsd  %xmm1,0x28(%rsp)
movsd  %xmm0,0x18(%rsp)
subsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
lea    0xebc(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%r15d
movsd  0xe7b(%rip),%xmm0
movsd  %xmm0,0x20(%rsp)
xorpd  %xmm1,%xmm1
lea    0xe7a(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
movsd  %xmm1,0x10(%rsp)
movsd  0x18(%rsp),%xmm0
call   *%rbx
movapd %xmm0,%xmm1
movsd  0xe4e(%rip),%xmm0
mulsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  0x28(%rsp),%xmm0
call   *%rbx
movsd  0x18(%rsp),%xmm1
movapd %xmm0,%xmm2
movsd  0xe2b(%rip),%xmm3
mulsd  %xmm3,%xmm2
addsd  (%rsp),%xmm2
movsd  0x8(%rsp),%xmm0
mulsd  %xmm3,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    $0x2,%ebp
nopl   0x0(%rax,%rax,1)
movsd  %xmm2,(%rsp)
lea    -0x1(%rbp),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0x8(%rsp),%xmm0
addsd  %xmm1,%xmm0
call   *%rbx
movsd  (%rsp),%xmm2
movsd  0x18(%rsp),%xmm1
addsd  %xmm0,%xmm2
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
mulsd  0x8(%rsp),%xmm0
addsd  %xmm1,%xmm0
add    $0x1,%ebp
movsd  0x28(%rsp),%xmm3
ucomisd %xmm0,%xmm3
ja     1200 <trapezoidal+0xc0>
mulsd  0x8(%rsp),%xmm2
movsd  %xmm2,(%rsp)
lea    0x1(%r15),%r12d
subsd  0x10(%rsp),%xmm2
movsd  %xmm2,0x10(%rsp)
movapd %xmm2,%xmm0
mov    $0x1,%al
call   1030 <abslt@plt>
mov    %eax,%ebp
movsd  0x10(%rsp),%xmm0
mov    $0x1,%al
call   1030 <abslt@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
call   1060 <log@plt>
movsd  %xmm0,0x38(%rsp)
movsd  0x20(%rsp),%xmm0
call   1060 <log@plt>
movsd  0x38(%rsp),%xmm1
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
mov    $0x1,%al
call   1030 <abslt@plt>
mov    %r14,%rdi
mov    %r15d,%esi
movsd  0x8(%rsp),%xmm0
movsd  (%rsp),%xmm1
mov    %ebp,%edx
mov    %eax,%ecx
mov    $0x2,%al
call   1050 <printf@plt>
movsd  0x10(%rsp),%xmm0
mov    $0x1,%al
call   1030 <abslt@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x20(%rsp)
movsd  0x10(%rsp),%xmm0
mov    $0x1,%al
call   1030 <abslt@plt>
movsd  (%rsp),%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
ucomisd 0x30(%rsp),%xmm1
movapd %xmm0,%xmm1
mov    %r12d,%r15d
ja     11a0 <trapezoidal+0x60>
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [65 x i8] c"TRAPEZOIDAL METHOD:\0A\0Ai\09|dx|\09\09I(dx)\09\09|ei|\09\09|log(ei)/log(e(i-1))|\0A\00"
@.str.1 = [30 x i8] c"%02d\09%+09g\09%+09g\09%+09g\09%+09g\0A\00"
define double @trapezoidal(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 double
%12 = alloca double
%13 = alloca i32
%14 = alloca i32
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
store double (double)* %3, double (double)** %8
store double 0.000000e+00, double* %9
%15 = load double, double* %6
%16 = load double, double* %5
%17 = fsub double %15, %16
store double %17, double* %11
%18 = call double @exp(double 1.000000e+00)
store double %18, double* %12
store i32 1, i32* %13
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %80, %4
%21 = load double, double* %9
store double %21, double* %10
%22 = load double (double)*, double (double)** %8
%23 = load double, double* %5
%24 = call double %22(double %23)
%25 = fdiv double %24, 2.000000e+00
%26 = load double (double)*, double (double)** %8
%27 = load double, double* %6
%28 = call double %26(double %27)
%29 = fdiv double %28, 2.000000e+00
%30 = fadd double %25, %29
store double %30, double* %9
%31 = load double, double* %11
%32 = fdiv double %31, 2.000000e+00
store double %32, double* %11
store i32 1, i32* %14
br label %33
33: ; preds = %43, %20
%34 = load double (double)*, double (double)** %8
%35 = load double, double* %5
%36 = load i32, i32* %14
%37 = sitofp i32 %36 to double
%38 = load double, double* %11
%39 = call double @llvm.fmuladd.f64(double %37, double %38, double %35)
%40 = call double %34(double %39)
%41 = load double, double* %9
%42 = fadd double %41, %40
store double %42, double* %9
br label %43
43: ; preds = %33
%44 = load double, double* %5
%45 = load i32, i32* %14
%46 = add nsw i32 %45, 1
store i32 %46, i32* %14
%47 = sitofp i32 %46 to double
%48 = load double, double* %11
%49 = call double @llvm.fmuladd.f64(double %47, double %48, double %44)
%50 = load double, double* %6
%51 = fcmp olt double %49, %50
br i1 %51, label %33, label %52
52: ; preds = %43
%53 = load double, double* %11
%54 = load double, double* %9
%55 = fmul double %53, %54
store double %55, double* %9
%56 = load i32, i32* %13
%57 = add nsw i32 %56, 1
store i32 %57, i32* %13
%58 = load double, double* %11
%59 = load double, double* %9
%60 = load double, double* %9
%61 = load double, double* %10
%62 = fsub double %60, %61
%63 = call i32 (double, ...) bitcast (i32 (...)* @abslt to i32 (double, ...)*)(double %62)
%64 = load double, double* %9
%65 = load double, double* %10
%66 = fsub double %64, %65
%67 = call i32 (double, ...) bitcast (i32 (...)* @abslt to i32 (double, ...)*)(double %66)
%68 = sitofp i32 %67 to double
%69 = call double @log(double %68)
%70 = load double, double* %12
%71 = call double @log(double %70)
%72 = fdiv double %69, %71
%73 = call i32 (double, ...) bitcast (i32 (...)* @abslt to i32 (double, ...)*)(double %72)
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %56, double %58, double %59, i32 %63, i32 %73)
%75 = load double, double* %9
%76 = load double, double* %10
%77 = fsub double %75, %76
%78 = call i32 (double, ...) bitcast (i32 (...)* @abslt to i32 (double, ...)*)(double %77)
%79 = sitofp i32 %78 to double
store double %79, double* %12
br label %80
80: ; preds = %52
%81 = load double, double* %9
%82 = load double, double* %10
%83 = fsub double %81, %82
%84 = call i32 (double, ...) bitcast (i32 (...)* @abslt to i32 (double, ...)*)(double %83)
%85 = sitofp i32 %84 to double
%86 = load double, double* %7
%87 = fcmp ogt double %85, %86
br i1 %87, label %20, label %88
88: ; preds = %80
%89 = load double, double* %9
ret double %89
}

LLVM IR (-O2):
@.str.1 = [30 x i8] c"%02d\09%+09g\09%+09g\09%+09g\09%+09g\0A\00"
@str = [64 x i8] c"TRAPEZOIDAL METHOD:\0A\0Ai\09|dx|\09\09I(dx)\09\09|ei|\09\09|log(ei)/log(e(i-1))|\00"
define double @trapezoidal(double %0, double %1, double %2, double (double)* nocapture %3) {
%5 = fsub double %1, %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @str, i64 0, i64 0))
br label %7
7: ; preds = %29, %4
%8 = phi double [ 0.000000e+00, %4 ], [ %30, %29 ]
%9 = phi double [ %5, %4 ], [ %17, %29 ]
%10 = phi double [ 0x4005BF0A8B145769, %4 ], [ %42, %29 ]
%11 = phi i32 [ 1, %4 ], [ %31, %29 ]
%12 = tail call double %3(double %0)
%13 = fmul double %12, 5.000000e-01
%14 = tail call double %3(double %1)
%15 = fmul double %14, 5.000000e-01
%16 = fadd double %13, %15
%17 = fmul double %9, 5.000000e-01
br label %18
18: ; preds = %18, %7
%19 = phi double [ %16, %7 ], [ %24, %18 ]
%20 = phi i32 [ 1, %7 ], [ %25, %18 ]
%21 = sitofp i32 %20 to double
%22 = tail call double @llvm.fmuladd.f64(double %21, double %17, double %0)
%23 = tail call double %3(double %22)
%24 = fadd double %19, %23
%25 = add nuw nsw i32 %20, 1
%26 = sitofp i32 %25 to double
%27 = tail call double @llvm.fmuladd.f64(double %26, double %17, double %0)
%28 = fcmp olt double %27, %1
br i1 %28, label %18, label %29
29: ; preds = %18
%30 = fmul double %17, %24
%31 = add nuw nsw i32 %11, 1
%32 = fsub double %30, %8
%33 = tail call i32 (double, ...) bitcast (i32 (...)* @abslt to i32 (double, ...)*)(double %32)
%34 = tail call i32 (double, ...) bitcast (i32 (...)* @abslt to i32 (double, ...)*)(double %32)
%35 = sitofp i32 %34 to double
%36 = tail call double @log(double %35)
%37 = tail call double @log(double %10)
%38 = fdiv double %36, %37
%39 = tail call i32 (double, ...) bitcast (i32 (...)* @abslt to i32 (double, ...)*)(double %38)
%40 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %11, double %17, double %30, i32 %33, i32 %39)
%41 = tail call i32 (double, ...) bitcast (i32 (...)* @abslt to i32 (double, ...)*)(double %32)
%42 = sitofp i32 %41 to double
%43 = tail call i32 (double, ...) bitcast (i32 (...)* @abslt to i32 (double, ...)*)(double %32)
%44 = sitofp i32 %43 to double
%45 = fcmp ogt double %44, %2
br i1 %45, label %7, label %46
46: ; preds = %29
ret double %30
}