#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(float);
float qtrap(float (*func)(float), float a, float b) {
  float trapzd(float (*func)(float), float a, float b, int n);
  void nrerror(char error_text[]);
  int j;
  float s, olds;
  olds = -1.0e30;
  for (j = 1; j <= 20; j++) {
    s = trapzd(func, a, b, j);
    if (fabs(s - olds) < 1.0e-5 * fabs(olds))
      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    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movss  %xmm0,-0x14(%rbp)
movss  %xmm1,-0x18(%rbp)
movss  0xeb2(%rip),%xmm0
movss  %xmm0,-0x24(%rbp)
movl   $0x1,-0x1c(%rbp)
cmpl   $0x14,-0x1c(%rbp)
jg     11e2 <qtrap+0xb2>
mov    -0x10(%rbp),%rdi
movss  -0x14(%rbp),%xmm0
movss  -0x18(%rbp),%xmm1
mov    -0x1c(%rbp),%esi
call   1040 <trapzd@plt>
movss  %xmm0,-0x20(%rbp)
movss  -0x20(%rbp),%xmm0
subss  -0x24(%rbp),%xmm0
call   1050 <fabs@plt>
movsd  %xmm0,-0x30(%rbp)
movss  -0x24(%rbp),%xmm0
call   1050 <fabs@plt>
movsd  -0x30(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  0xe5b(%rip),%xmm0
mulsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jbe    11ca <qtrap+0x9a>
movss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    11f6 <qtrap+0xc6>
movss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115a <qtrap+0x2a>
lea    0xe27(%rip),%rdi
call   1030 <nrerror@plt>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<qtrap>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
movss  %xmm1,0xc(%rsp)
movss  %xmm0,0x8(%rsp)
mov    %rdi,%rbx
mov    $0x1,%ebp
movss  0xeae(%rip),%xmm0
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movss  %xmm0,0x4(%rsp)
mov    %rbx,%rdi
movss  0x8(%rsp),%xmm0
movss  0xc(%rsp),%xmm1
mov    %ebp,%esi
call   1040 <trapzd@plt>
movss  %xmm0,(%rsp)
subss  0x4(%rsp),%xmm0
call   1050 <fabs@plt>
movsd  %xmm0,0x10(%rsp)
movss  0x4(%rsp),%xmm0
call   1050 <fabs@plt>
mulsd  0xe63(%rip),%xmm0
ucomisd 0x10(%rsp),%xmm0
ja     11cb <qtrap+0x9b>
add    $0x1,%ebp
cmp    $0x15,%ebp
movss  (%rsp),%xmm0
jne    1160 <qtrap+0x30>
lea    0xe4f(%rip),%rdi
call   1030 <nrerror@plt>
xorps  %xmm0,%xmm0
jmp    11d0 <qtrap+0xa0>
movss  (%rsp),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

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

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