#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 trapzd(double (*func)(double), double a, double b, int n);
  void nrerror(char error_text[]);
  int j;
  double s, olds = 0.0;
  for (j = 1; j <= 20; j++) {
    s = trapzd(func, a, b, j);
    if (j > 5)
      if (fabs(s - olds) < 1.0e-5 * fabs(olds) || (s == 0.0 && olds == 0.0))
        return s;
    olds = s;
  }
  nrerror("Too many steps in routine qtrap");
  return 0.0;
}


x86 assembly (clang, -O0):
<qtrap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x1,-0x24(%rbp)
cmpl   $0x14,-0x24(%rbp)
jg     120b <qtrap+0xeb>
mov    -0x10(%rbp),%rdi
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
mov    -0x24(%rbp),%esi
call   1040 <trapzd@plt>
movsd  %xmm0,-0x30(%rbp)
cmpl   $0x5,-0x24(%rbp)
jle    11f3 <qtrap+0xd3>
movsd  -0x30(%rbp),%xmm1
subsd  -0x38(%rbp),%xmm1
movaps 0xe8b(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm2
movaps 0xe7b(%rip),%xmm0
pand   %xmm0,%xmm2
movsd  0xe5f(%rip),%xmm0
mulsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
ja     11df <qtrap+0xbf>
movsd  -0x30(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11ee <qtrap+0xce>
jp     11ee <qtrap+0xce>
movsd  -0x38(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11ee <qtrap+0xce>
jp     11ee <qtrap+0xce>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    121f <qtrap+0xff>
jmp    11f3 <qtrap+0xd3>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1145 <qtrap+0x25>
lea    0xe0e(%rip),%rdi
call   1030 <nrerror@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<qtrap>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,(%rsp)
mov    %rdi,%rbx
mov    $0x1,%ebp
xorpd  %xmm0,%xmm0
jmp    1148 <qtrap+0x28>
nop
add    $0x1,%ebp
cmp    $0x15,%ebp
je     11b2 <qtrap+0x92>
movapd %xmm0,0x10(%rsp)
mov    %rbx,%rdi
movsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
mov    %ebp,%esi
call   1040 <trapzd@plt>
cmp    $0x6,%ebp
jb     1140 <qtrap+0x20>
movapd %xmm0,%xmm1
movapd 0x10(%rsp),%xmm4
subsd  %xmm4,%xmm1
movapd 0xe82(%rip),%xmm3
andpd  %xmm3,%xmm1
movapd %xmm4,%xmm2
andpd  %xmm3,%xmm2
mulsd  0xe7e(%rip),%xmm2
ucomisd %xmm1,%xmm2
ja     11c2 <qtrap+0xa2>
ucomisd 0xe78(%rip),%xmm4
jne    1140 <qtrap+0x20>
jp     1140 <qtrap+0x20>
ucomisd 0xe6c(%rip),%xmm0
jne    1140 <qtrap+0x20>
jp     1140 <qtrap+0x20>
jmp    11c2 <qtrap+0xa2>
lea    0xe67(%rip),%rdi
call   1030 <nrerror@plt>
xorpd  %xmm0,%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [32 x i8] c"Too many steps in routine qtrap\00"
define double @qtrap(double (double)* %0, double %1, double %2) {
br label %4
4: ; preds = %3, %19
%5 = phi double [ 0.000000e+00, %3 ], [ %7, %19 ]
%6 = phi i32 [ 1, %3 ], [ %20, %19 ]
%7 = tail call double @trapzd(double (double)* %0, double %1, double %2, i32 %6)
%8 = icmp ugt i32 %6, 5
br i1 %8, label %9, label %19
9: ; preds = %4
%10 = fsub double %7, %5
%11 = tail call double @llvm.fabs.f64(double %10)
%12 = tail call double @llvm.fabs.f64(double %5)
%13 = fmul double %12, 1.000000e-05
%14 = fcmp olt double %11, %13
br i1 %14, label %23, label %15
15: ; preds = %9
%16 = fcmp oeq double %7, 0.000000e+00
%17 = fcmp oeq double %5, 0.000000e+00
%18 = and i1 %17, %16
br i1 %18, label %23, label %19
19: ; preds = %15, %4
%20 = add nuw nsw i32 %6, 1
%21 = icmp eq i32 %20, 21
br i1 %21, label %22, label %4
22: ; preds = %19
tail call void @nrerror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %9, %15, %22
%24 = phi double [ 0.000000e+00, %22 ], [ %7, %15 ], [ %7, %9 ]
ret double %24
}