double simpsons(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("SIMPSON ONE-THIRD "
         "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) + f(b);
    interval /= 3;
    j = 1;
    do {
      if (j % 2 == 0)
        integraln += 2 * f(a + j * interval);
      else
        integraln += 4 * f(a + j * interval);
    } while (a + (++j) * interval < b);
    integraln = interval * integraln / 3;
    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):
<simpsons>:
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    0xe83(%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  %xmm0,-0x50(%rbp)
mov    -0x20(%rbp),%rax
movsd  -0x10(%rbp),%xmm0
call   *%rax
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  0xe29(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x1,-0x48(%rbp)
mov    -0x48(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1237 <simpsons+0xf7>
mov    -0x20(%rbp),%rax
movsd  -0x8(%rbp),%xmm1
cvtsi2sdl -0x48(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   *%rax
movsd  -0x28(%rbp),%xmm1
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    126e <simpsons+0x12e>
mov    -0x20(%rbp),%rax
movsd  -0x8(%rbp),%xmm1
cvtsi2sdl -0x48(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   *%rax
movsd  -0x28(%rbp),%xmm1
movsd  0xdaf(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    1273 <simpsons+0x133>
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     11ef <simpsons+0xaf>
movsd  -0x38(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  0xd55(%rip),%xmm1
divsd  %xmm1,%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    0xd1a(%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 <simpsons+0x5c>
movsd  -0x28(%rbp),%xmm0
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<simpsons>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rdi,%r13
movsd  %xmm2,0x38(%rsp)
movsd  %xmm1,0x30(%rsp)
movsd  %xmm0,0x20(%rsp)
subsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
lea    0xeca(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%r15d
movsd  0xe79(%rip),%xmm0
movsd  %xmm0,0x28(%rsp)
xorpd  %xmm1,%xmm1
lea    0xe78(%rip),%r14
nopl   0x0(%rax,%rax,1)
movsd  %xmm1,0x18(%rsp)
movsd  0x20(%rsp),%xmm0
call   *%r13
movsd  %xmm0,0x8(%rsp)
movsd  0x30(%rsp),%xmm0
call   *%r13
movsd  0x20(%rsp),%xmm1
movapd %xmm0,%xmm2
addsd  0x8(%rsp),%xmm2
movsd  0x10(%rsp),%xmm0
divsd  0xe2c(%rip),%xmm0
movsd  %xmm0,0x10(%rsp)
mov    $0x1,%ebp
nopw   0x0(%rax,%rax,1)
movsd  %xmm2,0x8(%rsp)
xor    %ebx,%ebx
test   $0x1,%bpl
sete   %bl
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
mulsd  0x10(%rsp),%xmm0
addsd  %xmm1,%xmm0
call   *%r13
movsd  0x8(%rsp),%xmm2
movsd  0x20(%rsp),%xmm1
mulsd  (%r14,%rbx,8),%xmm0
addsd  %xmm0,%xmm2
add    $0x1,%ebp
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
mulsd  0x10(%rsp),%xmm0
addsd  %xmm1,%xmm0
movsd  0x30(%rsp),%xmm3
ucomisd %xmm0,%xmm3
ja     11f0 <simpsons+0xb0>
mulsd  0x10(%rsp),%xmm2
movsd  0xdb1(%rip),%xmm0
divsd  %xmm0,%xmm2
movsd  %xmm2,0x8(%rsp)
lea    0x1(%r15),%ebx
subsd  0x18(%rsp),%xmm2
movsd  %xmm2,0x18(%rsp)
movapd %xmm2,%xmm0
mov    $0x1,%al
call   1030 <abslt@plt>
mov    %eax,%r12d
movsd  0x18(%rsp),%xmm0
mov    $0x1,%al
call   1030 <abslt@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
call   1060 <log@plt>
movsd  %xmm0,0x40(%rsp)
movsd  0x28(%rsp),%xmm0
call   1060 <log@plt>
movsd  0x40(%rsp),%xmm1
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
mov    $0x1,%al
call   1030 <abslt@plt>
lea    0xd5b(%rip),%rdi
mov    %r15d,%esi
movsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
mov    %r12d,%edx
mov    %eax,%ecx
mov    $0x2,%al
call   1050 <printf@plt>
movsd  0x18(%rsp),%xmm0
mov    $0x1,%al
call   1030 <abslt@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x28(%rsp)
movsd  0x18(%rsp),%xmm0
mov    $0x1,%al
call   1030 <abslt@plt>
movsd  0x8(%rsp),%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
ucomisd 0x38(%rsp),%xmm1
movapd %xmm0,%xmm1
mov    %ebx,%r15d
ja     11a0 <simpsons+0x60>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [71 x i8] c"SIMPSON ONE-THIRD 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 @simpsons(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 ([71 x i8], [71 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %94, %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 = load double (double)*, double (double)** %8
%26 = load double, double* %6
%27 = call double %25(double %26)
%28 = fadd double %24, %27
store double %28, double* %9
%29 = load double, double* %11
%30 = fdiv double %29, 3.000000e+00
store double %30, double* %11
store i32 1, i32* %14
br label %31
31: ; preds = %56, %20
%32 = load i32, i32* %14
%33 = srem i32 %32, 2
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %45
35: ; preds = %31
%36 = load double (double)*, double (double)** %8
%37 = load double, double* %5
%38 = load i32, i32* %14
%39 = sitofp i32 %38 to double
%40 = load double, double* %11
%41 = call double @llvm.fmuladd.f64(double %39, double %40, double %37)
%42 = call double %36(double %41)
%43 = load double, double* %9
%44 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %42, double %43)
store double %44, double* %9
br label %55
45: ; preds = %31
%46 = load double (double)*, double (double)** %8
%47 = load double, double* %5
%48 = load i32, i32* %14
%49 = sitofp i32 %48 to double
%50 = load double, double* %11
%51 = call double @llvm.fmuladd.f64(double %49, double %50, double %47)
%52 = call double %46(double %51)
%53 = load double, double* %9
%54 = call double @llvm.fmuladd.f64(double 4.000000e+00, double %52, double %53)
store double %54, double* %9
br label %55
55: ; preds = %45, %35
br label %56
56: ; preds = %55
%57 = load double, double* %5
%58 = load i32, i32* %14
%59 = add nsw i32 %58, 1
store i32 %59, i32* %14
%60 = sitofp i32 %59 to double
%61 = load double, double* %11
%62 = call double @llvm.fmuladd.f64(double %60, double %61, double %57)
%63 = load double, double* %6
%64 = fcmp olt double %62, %63
br i1 %64, label %31, label %65
65: ; preds = %56
%66 = load double, double* %11
%67 = load double, double* %9
%68 = fmul double %66, %67
%69 = fdiv double %68, 3.000000e+00
store double %69, double* %9
%70 = load i32, i32* %13
%71 = add nsw i32 %70, 1
store i32 %71, i32* %13
%72 = load double, double* %11
%73 = load double, double* %9
%74 = load double, double* %9
%75 = load double, double* %10
%76 = fsub double %74, %75
%77 = call i32 (double, ...) bitcast (i32 (...)* @abslt to i32 (double, ...)*)(double %76)
%78 = load double, double* %9
%79 = load double, double* %10
%80 = fsub double %78, %79
%81 = call i32 (double, ...) bitcast (i32 (...)* @abslt to i32 (double, ...)*)(double %80)
%82 = sitofp i32 %81 to double
%83 = call double @log(double %82)
%84 = load double, double* %12
%85 = call double @log(double %84)
%86 = fdiv double %83, %85
%87 = call i32 (double, ...) bitcast (i32 (...)* @abslt to i32 (double, ...)*)(double %86)
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %70, double %72, double %73, i32 %77, i32 %87)
%89 = load double, double* %9
%90 = load double, double* %10
%91 = fsub double %89, %90
%92 = call i32 (double, ...) bitcast (i32 (...)* @abslt to i32 (double, ...)*)(double %91)
%93 = sitofp i32 %92 to double
store double %93, double* %12
br label %94
94: ; preds = %65
%95 = load double, double* %9
%96 = load double, double* %10
%97 = fsub double %95, %96
%98 = call i32 (double, ...) bitcast (i32 (...)* @abslt to i32 (double, ...)*)(double %97)
%99 = sitofp i32 %98 to double
%100 = load double, double* %7
%101 = fcmp ogt double %99, %100
br i1 %101, label %20, label %102
102: ; preds = %94
%103 = load double, double* %9
ret double %103
}

LLVM IR (-O2):
@.str.1 = [30 x i8] c"%02d\09%+09g\09%+09g\09%+09g\09%+09g\0A\00"
@str = [70 x i8] c"SIMPSON ONE-THIRD METHOD:\0A\0Ai\09|dx|\09\09I(dx)\09\09|ei|\09\09|log(ei)/log(e(i-1))|\00"
define double @simpsons(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 ([70 x i8], [70 x i8]* @str, i64 0, i64 0))
br label %7
7: ; preds = %31, %4
%8 = phi double [ 0.000000e+00, %4 ], [ %33, %31 ]
%9 = phi double [ %5, %4 ], [ %15, %31 ]
%10 = phi double [ 0x4005BF0A8B145769, %4 ], [ %45, %31 ]
%11 = phi i32 [ 1, %4 ], [ %34, %31 ]
%12 = tail call double %3(double %0)
%13 = tail call double %3(double %1)
%14 = fadd double %12, %13
%15 = fdiv double %9, 3.000000e+00
br label %16
16: ; preds = %16, %7
%17 = phi double [ %14, %7 ], [ %26, %16 ]
%18 = phi i32 [ 1, %7 ], [ %27, %16 ]
%19 = and i32 %18, 1
%20 = icmp eq i32 %19, 0
%21 = sitofp i32 %18 to double
%22 = tail call double @llvm.fmuladd.f64(double %21, double %15, double %0)
%23 = tail call double %3(double %22)
%24 = tail call double @llvm.fmuladd.f64(double %23, double 2.000000e+00, double %17)
%25 = tail call double @llvm.fmuladd.f64(double %23, double 4.000000e+00, double %17)
%26 = select i1 %20, double %24, double %25
%27 = add nuw nsw i32 %18, 1
%28 = sitofp i32 %27 to double
%29 = tail call double @llvm.fmuladd.f64(double %28, double %15, double %0)
%30 = fcmp olt double %29, %1
br i1 %30, label %16, label %31
31: ; preds = %16
%32 = fmul double %15, %26
%33 = fdiv double %32, 3.000000e+00
%34 = add nuw nsw i32 %11, 1
%35 = fsub double %33, %8
%36 = tail call i32 (double, ...) bitcast (i32 (...)* @abslt to i32 (double, ...)*)(double %35)
%37 = tail call i32 (double, ...) bitcast (i32 (...)* @abslt to i32 (double, ...)*)(double %35)
%38 = sitofp i32 %37 to double
%39 = tail call double @log(double %38)
%40 = tail call double @log(double %10)
%41 = fdiv double %39, %40
%42 = tail call i32 (double, ...) bitcast (i32 (...)* @abslt to i32 (double, ...)*)(double %41)
%43 = 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 %15, double %33, i32 %36, i32 %42)
%44 = tail call i32 (double, ...) bitcast (i32 (...)* @abslt to i32 (double, ...)*)(double %35)
%45 = sitofp i32 %44 to double
%46 = tail call i32 (double, ...) bitcast (i32 (...)* @abslt to i32 (double, ...)*)(double %35)
%47 = sitofp i32 %46 to double
%48 = fcmp ogt double %47, %2
br i1 %48, label %7, label %49
49: ; preds = %31
ret double %33
}