#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
double fabs(double);
int /*<<< orphan*/ printf(char *, ...);
void error_table(double (*fp)(double), double a, double b, int nrows,
                 int nvals[], double int_true,
                 double (*method)(double (*)(double), double, double, int)) {
  double ratio, last = 1.0;
  printf("%8s %22s %13s %13s\n", "n", "trapezoid", "error", "ratio");
  for (int m = 0; m < nrows; m++) {
    double val = method(fp, a, b, nvals[m]);
    double err = fabs(val - int_true);
    ratio = last / err;
    last = err;
    printf("%8d %22.14e %13.3e %13.3e\n", nvals[m], val, err, ratio);
  }
  return;
}


x86 assembly (clang, -O0):
<error_table>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %esi,-0x1c(%rbp)
mov    %rdx,-0x28(%rbp)
movsd  %xmm2,-0x30(%rbp)
mov    %rcx,-0x38(%rbp)
movsd  0xec2(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
lea    0xed6(%rip),%rdi
lea    0xee3(%rip),%rsi
lea    0xede(%rip),%rdx
lea    0xee1(%rip),%rcx
lea    0xee0(%rip),%r8
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    120d <error_table+0xfd>
mov    -0x38(%rbp),%rax
mov    -0x8(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
mov    -0x28(%rbp),%rcx
movslq -0x4c(%rbp),%rdx
mov    (%rcx,%rdx,4),%esi
call   *%rax
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
movaps 0xe5b(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x48(%rbp),%xmm0
divsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x4c(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
movsd  -0x58(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm1
movsd  -0x40(%rbp),%xmm2
lea    0xe54(%rip),%rdi
mov    $0x3,%al
call   1030 <printf@plt>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    1174 <error_table+0x64>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<error_table>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rcx,%r14
movsd  %xmm2,0x10(%rsp)
mov    %rdx,%rbx
mov    %esi,%ebp
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,(%rsp)
mov    %rdi,%r15
lea    0xedf(%rip),%rdi
lea    0xeec(%rip),%rsi
lea    0xee7(%rip),%rdx
lea    0xeea(%rip),%rcx
lea    0xee9(%rip),%r8
xor    %eax,%eax
call   1030 <printf@plt>
test   %ebp,%ebp
jle    11d7 <error_table+0xc7>
mov    %ebp,%r13d
movsd  0xe8d(%rip),%xmm0
xor    %ebp,%ebp
lea    0xed0(%rip),%r12
nopl   0x0(%rax)
movsd  %xmm0,0x18(%rsp)
mov    (%rbx,%rbp,4),%esi
mov    %r15,%rdi
movsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
call   *%r14
movapd %xmm0,%xmm1
subsd  0x10(%rsp),%xmm1
andpd  0xe64(%rip),%xmm1
movapd %xmm1,0x20(%rsp)
movsd  0x18(%rsp),%xmm2
divsd  %xmm1,%xmm2
mov    (%rbx,%rbp,4),%esi
mov    %r12,%rdi
mov    $0x3,%al
call   1030 <printf@plt>
add    $0x1,%rbp
movaps 0x20(%rsp),%xmm0
cmp    %rbp,%r13
jne    1180 <error_table+0x70>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"%8s %22s %13s %13s\0A\00"
@.str.1 = [2 x i8] c"n\00"
@.str.2 = [10 x i8] c"trapezoid\00"
@.str.3 = [6 x i8] c"error\00"
@.str.4 = [6 x i8] c"ratio\00"
@.str.5 = [27 x i8] c"%8d %22.14e %13.3e %13.3e\0A\00"
define void @error_table(double (double)* %0, double %1, double %2, i32 %3, i32* %4, double %5, double (double (double)*, double, double, i32)* %6) {
%8 = alloca double (double)*
%9 = alloca double
%10 = alloca double
%11 = alloca i32
%12 = alloca i32*
%13 = alloca double
%14 = alloca double (double (double)*, double, double, i32)*
%15 = alloca double
%16 = alloca double
%17 = alloca i32
%18 = alloca double
%19 = alloca double
store double (double)* %0, double (double)** %8
store double %1, double* %9
store double %2, double* %10
store i32 %3, i32* %11
store i32* %4, i32** %12
store double %5, double* %13
store double (double (double)*, double, double, i32)* %6, double (double (double)*, double, double, i32)** %14
store double 1.000000e+00, double* %16
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %17
br label %21
21: ; preds = %53, %7
%22 = load i32, i32* %17
%23 = load i32, i32* %11
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %56
25: ; preds = %21
%26 = load double (double (double)*, double, double, i32)*, double (double (double)*, double, double, i32)** %14
%27 = load double (double)*, double (double)** %8
%28 = load double, double* %9
%29 = load double, double* %10
%30 = load i32*, i32** %12
%31 = load i32, i32* %17
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %30, i64 %32
%34 = load i32, i32* %33
%35 = call double %26(double (double)* %27, double %28, double %29, i32 %34)
store double %35, double* %18
%36 = load double, double* %18
%37 = load double, double* %13
%38 = fsub double %36, %37
%39 = call double @llvm.fabs.f64(double %38)
store double %39, double* %19
%40 = load double, double* %16
%41 = load double, double* %19
%42 = fdiv double %40, %41
store double %42, double* %15
%43 = load double, double* %19
store double %43, double* %16
%44 = load i32*, i32** %12
%45 = load i32, i32* %17
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i32, i32* %44, i64 %46
%48 = load i32, i32* %47
%49 = load double, double* %18
%50 = load double, double* %19
%51 = load double, double* %15
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i32 %48, double %49, double %50, double %51)
br label %53
53: ; preds = %25
%54 = load i32, i32* %17
%55 = add nsw i32 %54, 1
store i32 %55, i32* %17
br label %21
56: ; preds = %21
ret void
}

LLVM IR (-O2):
@.str = [20 x i8] c"%8s %22s %13s %13s\0A\00"
@.str.1 = [2 x i8] c"n\00"
@.str.2 = [10 x i8] c"trapezoid\00"
@.str.3 = [6 x i8] c"error\00"
@.str.4 = [6 x i8] c"ratio\00"
@.str.5 = [27 x i8] c"%8d %22.14e %13.3e %13.3e\0A\00"
define void @error_table(double (double)* %0, double %1, double %2, i32 %3, i32* nocapture %4, double %5, double (double (double)*, double, double, i32)* nocapture %6) {
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%9 = icmp sgt i32 %3, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = zext i32 %3 to i64
br label %13
12: ; preds = %13, %7
ret void
13: ; preds = %10, %13
%14 = phi i64 [ 0, %10 ], [ %24, %13 ]
%15 = phi double [ 1.000000e+00, %10 ], [ %20, %13 ]
%16 = getelementptr inbounds i32, i32* %4, i64 %14
%17 = load i32, i32* %16
%18 = tail call double %6(double (double)* %0, double %1, double %2, i32 %17)
%19 = fsub double %18, %5
%20 = tail call double @llvm.fabs.f64(double %19)
%21 = fdiv double %15, %20
%22 = load i32, i32* %16
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i32 %22, double %18, double %20, double %21)
%24 = add nuw nsw i64 %14, 1
%25 = icmp eq i64 %24, %11
br i1 %25, label %12, label %13
}