#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 = 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    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movss  %xmm0,-0x14(%rbp)
movss  %xmm1,-0x18(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x24(%rbp)
movl   $0x1,-0x1c(%rbp)
cmpl   $0x14,-0x1c(%rbp)
jg     1224 <qtrap+0xf4>
mov    -0x10(%rbp),%rdi
movss  -0x14(%rbp),%xmm0
movss  -0x18(%rbp),%xmm1
mov    -0x1c(%rbp),%esi
call   1040 <trapzd@plt>
movss  %xmm0,-0x20(%rbp)
cmpl   $0x5,-0x1c(%rbp)
jle    120c <qtrap+0xdc>
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  0xe4e(%rip),%xmm0
mulsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
ja     11f8 <qtrap+0xc8>
movss  -0x20(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1207 <qtrap+0xd7>
jp     1207 <qtrap+0xd7>
movss  -0x24(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1207 <qtrap+0xd7>
jp     1207 <qtrap+0xd7>
movss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1238 <qtrap+0x108>
jmp    120c <qtrap+0xdc>
movss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1155 <qtrap+0x25>
lea    0xddd(%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
xorps  %xmm0,%xmm0
jmp    1158 <qtrap+0x28>
nop
add    $0x1,%ebp
cmp    $0x15,%ebp
je     11cb <qtrap+0x9b>
movss  %xmm0,(%rsp)
mov    %rbx,%rdi
movss  0x8(%rsp),%xmm0
movss  0xc(%rsp),%xmm1
mov    %ebp,%esi
call   1040 <trapzd@plt>
cmp    $0x6,%ebp
jb     1150 <qtrap+0x20>
movss  %xmm0,0x4(%rsp)
subss  (%rsp),%xmm0
call   1050 <fabs@plt>
movsd  %xmm0,0x10(%rsp)
movss  (%rsp),%xmm0
call   1050 <fabs@plt>
mulsd  0xe60(%rip),%xmm0
ucomisd 0x10(%rsp),%xmm0
ja     11dc <qtrap+0xac>
movss  (%rsp),%xmm0
ucomiss 0xe54(%rip),%xmm0
movss  0x4(%rsp),%xmm0
jne    1150 <qtrap+0x20>
jp     1150 <qtrap+0x20>
ucomiss 0xe43(%rip),%xmm0
jne    1150 <qtrap+0x20>
jp     1150 <qtrap+0x20>
jmp    11e2 <qtrap+0xb2>
lea    0xe3a(%rip),%rdi
call   1030 <nrerror@plt>
xorps  %xmm0,%xmm0
jmp    11e2 <qtrap+0xb2>
movss  0x4(%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 0.000000e+00, float* %10
store i32 1, i32* %8
br label %11
11: ; preds = %44, %3
%12 = load i32, i32* %8
%13 = icmp sle i32 %12, 20
br i1 %13, label %14, label %47
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 i32, i32* %8
%21 = icmp sgt i32 %20, 5
br i1 %21, label %22, label %42
22: ; preds = %14
%23 = load float, float* %9
%24 = load float, float* %10
%25 = fsub float %23, %24
%26 = call double @fabs(float %25)
%27 = load float, float* %10
%28 = call double @fabs(float %27)
%29 = fmul double 1.000000e-05, %28
%30 = fcmp olt double %26, %29
br i1 %30, label %39, label %31
31: ; preds = %22
%32 = load float, float* %9
%33 = fpext float %32 to double
%34 = fcmp oeq double %33, 0.000000e+00
br i1 %34, label %35, label %41
35: ; preds = %31
%36 = load float, float* %10
%37 = fpext float %36 to double
%38 = fcmp oeq double %37, 0.000000e+00
br i1 %38, label %39, label %41
39: ; preds = %35, %22
%40 = load float, float* %9
store float %40, float* %4
br label %48
41: ; preds = %35, %31
br label %42
42: ; preds = %41, %14
%43 = load float, float* %9
store float %43, float* %10
br label %44
44: ; preds = %42
%45 = load i32, i32* %8
%46 = add nsw i32 %45, 1
store i32 %46, i32* %8
br label %11
47: ; preds = %11
store float 0.000000e+00, float* %4
br label %48
48: ; preds = %47, %39
%49 = load float, float* %4
ret float %49
}

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 %4
4: ; preds = %3, %19
%5 = phi float [ 0.000000e+00, %3 ], [ %7, %19 ]
%6 = phi i32 [ 1, %3 ], [ %20, %19 ]
%7 = tail call float @trapzd(float (float)* %0, float %1, float %2, i32 %6)
%8 = icmp ugt i32 %6, 5
br i1 %8, label %9, label %19
9: ; preds = %4
%10 = fsub float %7, %5
%11 = tail call double @fabs(float %10)
%12 = tail call double @fabs(float %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 float %7, 0.000000e+00
%17 = fcmp oeq float %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 float [ 0.000000e+00, %22 ], [ %7, %15 ], [ %7, %9 ]
ret float %24
}