#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);
double qtrap(double (*func)(double), double a, double b, double EPS) {
  double trapzd(double (*func)(double), double a, double b, int n);
  int j;
  double s, olds, t1, t2;
  olds = -1.0e30;
  for (j = 1; j <= 20; j++) {
    s = trapzd(func, a, b, j);
    if (fabs(s - olds) < EPS * fabs(olds))
      return s;
    olds = s;
  }
  return s;
}


x86 assembly (clang, -O0):
<qtrap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
movsd  %xmm2,-0x28(%rbp)
movsd  0xecd(%rip),%xmm0
movsd  %xmm0,-0x40(%rbp)
movl   $0x1,-0x2c(%rbp)
cmpl   $0x14,-0x2c(%rbp)
jg     11c3 <qtrap+0xb3>
mov    -0x10(%rbp),%rdi
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
mov    -0x2c(%rbp),%esi
call   1030 <trapzd@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm1
subsd  -0x40(%rbp),%xmm1
movaps 0xe9b(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm2
movaps 0xe86(%rip),%xmm3
pand   %xmm3,%xmm2
mulsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jbe    11ab <qtrap+0x9b>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11cd <qtrap+0xbd>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    113f <qtrap+0x2f>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<qtrap>:
push   %r14
push   %rbx
sub    $0x38,%rsp
movsd  %xmm2,0x18(%rsp)
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
mov    %rdi,%r14
movsd  0xecc(%rip),%xmm0
mov    $0x1,%ebx
nopl   0x0(%rax)
movapd %xmm0,0x20(%rsp)
mov    %r14,%rdi
movsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
mov    %ebx,%esi
call   1030 <trapzd@plt>
movapd %xmm0,%xmm1
movapd 0x20(%rsp),%xmm3
subsd  %xmm3,%xmm1
movapd 0xe9e(%rip),%xmm2
andpd  %xmm2,%xmm1
andpd  %xmm2,%xmm3
mulsd  0x18(%rsp),%xmm3
ucomisd %xmm1,%xmm3
ja     1190 <qtrap+0x80>
lea    0x1(%rbx),%eax
cmp    $0x14,%ebx
mov    %eax,%ebx
jne    1140 <qtrap+0x30>
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define double @qtrap(double (double)* %0, double %1, double %2, double %3) {
%5 = alloca double
%6 = alloca double (double)*
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca i32
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
store double (double)* %0, double (double)** %6
store double %1, double* %7
store double %2, double* %8
store double %3, double* %9
store double -1.000000e+30, double* %12
store i32 1, i32* %10
br label %15
15: ; preds = %37, %4
%16 = load i32, i32* %10
%17 = icmp sle i32 %16, 20
br i1 %17, label %18, label %40
18: ; preds = %15
%19 = load double (double)*, double (double)** %6
%20 = load double, double* %7
%21 = load double, double* %8
%22 = load i32, i32* %10
%23 = call double @trapzd(double (double)* %19, double %20, double %21, i32 %22)
store double %23, double* %11
%24 = load double, double* %11
%25 = load double, double* %12
%26 = fsub double %24, %25
%27 = call double @llvm.fabs.f64(double %26)
%28 = load double, double* %9
%29 = load double, double* %12
%30 = call double @llvm.fabs.f64(double %29)
%31 = fmul double %28, %30
%32 = fcmp olt double %27, %31
br i1 %32, label %33, label %35
33: ; preds = %18
%34 = load double, double* %11
store double %34, double* %5
br label %42
35: ; preds = %18
%36 = load double, double* %11
store double %36, double* %12
br label %37
37: ; preds = %35
%38 = load i32, i32* %10
%39 = add nsw i32 %38, 1
store i32 %39, i32* %10
br label %15
40: ; preds = %15
%41 = load double, double* %11
store double %41, double* %5
br label %42
42: ; preds = %40, %33
%43 = load double, double* %5
ret double %43
}

LLVM IR (-O2):
define double @qtrap(double (double)* %0, double %1, double %2, double %3) {
br label %5
5: ; preds = %5, %4
%6 = phi i32 [ 1, %4 ], [ %14, %5 ]
%7 = phi double [ -1.000000e+30, %4 ], [ %8, %5 ]
%8 = tail call double @trapzd(double (double)* %0, double %1, double %2, i32 %6)
%9 = fsub double %8, %7
%10 = tail call double @llvm.fabs.f64(double %9)
%11 = tail call double @llvm.fabs.f64(double %7)
%12 = fmul double %11, %3
%13 = fcmp olt double %10, %12
%14 = add nuw nsw i32 %6, 1
%15 = icmp eq i32 %14, 21
%16 = select i1 %13, i1 true, i1 %15
br i1 %16, label %17, label %5
17: ; preds = %5
ret double %8
}