#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 *, ...);
double trapezoid(double (*)(double), double, double, int);
void error_table(double (*fp)(double), double a, double b, int nrows,
                 int nvals[], double int_true) {
  double last_error = 0.0, error, int_trap, ratio;
  printf("%8s %22s %13s %13s\n", "n", "trapezoid", "error", "ratio");
  for (int i = 0; i < nrows; ++i) {
    int_trap = trapezoid(fp, a, b, nvals[i]);
    error = fabs(int_trap - int_true);
    ratio = last_error / error;
    last_error = error;
    printf("%8d %22.14e %13.3e %13.3e\n", nvals[i], int_trap, error, ratio);
  }
}


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)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
lea    0xebf(%rip),%rdi
lea    0xecc(%rip),%rsi
lea    0xec7(%rip),%rdx
lea    0xeca(%rip),%rcx
lea    0xec9(%rip),%r8
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x54(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1213 <error_table+0xf3>
mov    -0x8(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
mov    -0x28(%rbp),%rax
movslq -0x54(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
call   1030 <trapezoid@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
movaps 0xe45(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
divsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x54(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
movsd  -0x48(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
movsd  -0x50(%rbp),%xmm2
lea    0xe3e(%rip),%rdi
mov    $0x3,%al
call   1040 <printf@plt>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    117b <error_table+0x5b>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<error_table>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
movsd  %xmm2,0x10(%rsp)
mov    %rdx,%rbx
mov    %esi,%ebp
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,(%rsp)
mov    %rdi,%r14
lea    0xec4(%rip),%rdi
lea    0xed1(%rip),%rsi
lea    0xecc(%rip),%rdx
lea    0xecf(%rip),%rcx
lea    0xece(%rip),%r8
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebp,%ebp
jle    11e9 <error_table+0xc9>
mov    %ebp,%r12d
xorps  %xmm0,%xmm0
xor    %ebp,%ebp
lea    0xeba(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsd  %xmm0,0x18(%rsp)
mov    (%rbx,%rbp,4),%esi
mov    %r14,%rdi
movsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
call   1030 <trapezoid@plt>
movapd %xmm0,%xmm1
subsd  0x10(%rsp),%xmm1
andpd  0xe42(%rip),%xmm1
movapd %xmm1,0x20(%rsp)
movsd  0x18(%rsp),%xmm2
divsd  %xmm1,%xmm2
mov    (%rbx,%rbp,4),%esi
mov    %r15,%rdi
mov    $0x3,%al
call   1040 <printf@plt>
add    $0x1,%rbp
movaps 0x20(%rsp),%xmm0
cmp    %rbp,%r12
jne    1190 <error_table+0x70>
add    $0x30,%rsp
pop    %rbx
pop    %r12
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) {
%7 = alloca double (double)*
%8 = alloca double
%9 = alloca double
%10 = alloca i32
%11 = alloca i32*
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca double
%17 = alloca i32
store double (double)* %0, double (double)** %7
store double %1, double* %8
store double %2, double* %9
store i32 %3, i32* %10
store i32* %4, i32** %11
store double %5, double* %12
store double 0.000000e+00, double* %13
%18 = 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 %19
19: ; preds = %50, %6
%20 = load i32, i32* %17
%21 = load i32, i32* %10
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %53
23: ; preds = %19
%24 = load double (double)*, double (double)** %7
%25 = load double, double* %8
%26 = load double, double* %9
%27 = load i32*, i32** %11
%28 = load i32, i32* %17
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32, i32* %27, i64 %29
%31 = load i32, i32* %30
%32 = call double @trapezoid(double (double)* %24, double %25, double %26, i32 %31)
store double %32, double* %15
%33 = load double, double* %15
%34 = load double, double* %12
%35 = fsub double %33, %34
%36 = call double @llvm.fabs.f64(double %35)
store double %36, double* %14
%37 = load double, double* %13
%38 = load double, double* %14
%39 = fdiv double %37, %38
store double %39, double* %16
%40 = load double, double* %14
store double %40, double* %13
%41 = load i32*, i32** %11
%42 = load i32, i32* %17
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i32, i32* %41, i64 %43
%45 = load i32, i32* %44
%46 = load double, double* %15
%47 = load double, double* %14
%48 = load double, double* %16
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i32 %45, double %46, double %47, double %48)
br label %50
50: ; preds = %23
%51 = load i32, i32* %17
%52 = add nsw i32 %51, 1
store i32 %52, i32* %17
br label %19
53: ; preds = %19
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) {
%7 = 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))
%8 = icmp sgt i32 %3, 0
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = zext i32 %3 to i64
br label %12
11: ; preds = %12, %6
ret void
12: ; preds = %9, %12
%13 = phi i64 [ 0, %9 ], [ %23, %12 ]
%14 = phi double [ 0.000000e+00, %9 ], [ %19, %12 ]
%15 = getelementptr inbounds i32, i32* %4, i64 %13
%16 = load i32, i32* %15
%17 = tail call double @trapezoid(double (double)* %0, double %1, double %2, i32 %16)
%18 = fsub double %17, %5
%19 = tail call double @llvm.fabs.f64(double %18)
%20 = fdiv double %14, %19
%21 = load i32, i32* %15
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i32 %21, double %17, double %19, double %20)
%23 = add nuw nsw i64 %13, 1
%24 = icmp eq i64 %23, %10
br i1 %24, label %11, label %12
}