#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 qsimp(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, st, ost = 0.0, os = 0.0;
  for (j = 1; j <= 20; j++) {
    st = trapzd(func, a, b, j);
    s = (4.0 * st - ost) / 3.0;
    if (j > 5)
      if (fabs(s - os) < 1.0e-6 * fabs(os) || (s == 0.0 && os == 0.0))
        return s;
    os = s;
    ost = st;
  }
  nrerror("Too many steps in routine qsimp");
  return 0.0;
}


x86 assembly (clang, -O0):
<qsimp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movss  %xmm0,-0x14(%rbp)
movss  %xmm1,-0x18(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x2c(%rbp)
movl   $0x1,-0x1c(%rbp)
cmpl   $0x14,-0x1c(%rbp)
jg     1284 <qsimp+0x154>
mov    -0x10(%rbp),%rdi
movss  -0x14(%rbp),%xmm0
movss  -0x18(%rbp),%xmm1
mov    -0x1c(%rbp),%esi
call   1040 <trapzd@plt>
movss  %xmm0,-0x24(%rbp)
movss  -0x24(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0x28(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
movsd  0xe55(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe3d(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x20(%rbp)
cmpl   $0x5,-0x1c(%rbp)
jle    1262 <qsimp+0x132>
movss  -0x20(%rbp),%xmm0
subss  -0x2c(%rbp),%xmm0
call   1050 <fabs@plt>
movsd  %xmm0,-0x38(%rbp)
movss  -0x2c(%rbp),%xmm0
call   1050 <fabs@plt>
movsd  -0x38(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  0xe08(%rip),%xmm0
mulsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
ja     124e <qsimp+0x11e>
movss  -0x20(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    125d <qsimp+0x12d>
jp     125d <qsimp+0x12d>
movss  -0x2c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    125d <qsimp+0x12d>
jp     125d <qsimp+0x12d>
movss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1298 <qsimp+0x168>
jmp    1262 <qsimp+0x132>
movss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x2c(%rbp)
movss  -0x24(%rbp),%xmm0
movss  %xmm0,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115d <qsimp+0x2d>
lea    0xd8d(%rip),%rdi
call   1030 <nrerror@plt>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<qsimp>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
movss  %xmm1,0x1c(%rsp)
movss  %xmm0,0x18(%rsp)
mov    %rdi,%rbx
mov    $0x1,%ebp
xorps  %xmm0,%xmm0
xorps  %xmm2,%xmm2
jmp    116c <qsimp+0x3c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%ebp
cmp    $0x15,%ebp
je     122e <qsimp+0xfe>
movss  %xmm2,0xc(%rsp)
movss  %xmm0,0x10(%rsp)
mov    %rbx,%rdi
movss  0x18(%rsp),%xmm0
movss  0x1c(%rsp),%xmm1
mov    %ebp,%esi
call   1040 <trapzd@plt>
movaps %xmm0,%xmm2
cvtss2sd %xmm0,%xmm0
movss  0xc(%rsp),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  0xe59(%rip),%xmm0
subsd  %xmm1,%xmm0
divsd  0xe55(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
cmp    $0x6,%ebp
jb     1160 <qsimp+0x30>
movss  %xmm2,0x14(%rsp)
movss  %xmm0,0xc(%rsp)
subss  0x10(%rsp),%xmm0
call   1050 <fabs@plt>
movsd  %xmm0,0x20(%rsp)
movss  0x10(%rsp),%xmm0
call   1050 <fabs@plt>
mulsd  0xe24(%rip),%xmm0
ucomisd 0x20(%rsp),%xmm0
ja     123f <qsimp+0x10f>
movss  0x10(%rsp),%xmm0
ucomiss 0xe17(%rip),%xmm0
movss  0xc(%rsp),%xmm0
movss  0x14(%rsp),%xmm2
jne    1160 <qsimp+0x30>
jp     1160 <qsimp+0x30>
ucomiss 0xdf8(%rip),%xmm0
jne    1160 <qsimp+0x30>
jp     1160 <qsimp+0x30>
jmp    1245 <qsimp+0x115>
lea    0xde7(%rip),%rdi
call   1030 <nrerror@plt>
xorps  %xmm0,%xmm0
jmp    1245 <qsimp+0x115>
movss  0xc(%rsp),%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Too many steps in routine qsimp\00"
define float @qsimp(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
%11 = alloca float
%12 = 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* %11
store float 0.000000e+00, float* %12
store i32 1, i32* %8
br label %13
13: ; preds = %55, %3
%14 = load i32, i32* %8
%15 = icmp sle i32 %14, 20
br i1 %15, label %16, label %58
16: ; preds = %13
%17 = load float (float)*, float (float)** %5
%18 = load float, float* %6
%19 = load float, float* %7
%20 = load i32, i32* %8
%21 = call float @trapzd(float (float)* %17, float %18, float %19, i32 %20)
store float %21, float* %10
%22 = load float, float* %10
%23 = fpext float %22 to double
%24 = load float, float* %11
%25 = fpext float %24 to double
%26 = fneg double %25
%27 = call double @llvm.fmuladd.f64(double 4.000000e+00, double %23, double %26)
%28 = fdiv double %27, 3.000000e+00
%29 = fptrunc double %28 to float
store float %29, float* %9
%30 = load i32, i32* %8
%31 = icmp sgt i32 %30, 5
br i1 %31, label %32, label %52
32: ; preds = %16
%33 = load float, float* %9
%34 = load float, float* %12
%35 = fsub float %33, %34
%36 = call double @fabs(float %35)
%37 = load float, float* %12
%38 = call double @fabs(float %37)
%39 = fmul double 0x3EB0C6F7A0B5ED8D, %38
%40 = fcmp olt double %36, %39
br i1 %40, label %49, label %41
41: ; preds = %32
%42 = load float, float* %9
%43 = fpext float %42 to double
%44 = fcmp oeq double %43, 0.000000e+00
br i1 %44, label %45, label %51
45: ; preds = %41
%46 = load float, float* %12
%47 = fpext float %46 to double
%48 = fcmp oeq double %47, 0.000000e+00
br i1 %48, label %49, label %51
49: ; preds = %45, %32
%50 = load float, float* %9
store float %50, float* %4
br label %59
51: ; preds = %45, %41
br label %52
52: ; preds = %51, %16
%53 = load float, float* %9
store float %53, float* %12
%54 = load float, float* %10
store float %54, float* %11
br label %55
55: ; preds = %52
%56 = load i32, i32* %8
%57 = add nsw i32 %56, 1
store i32 %57, i32* %8
br label %13
58: ; preds = %13
store float 0.000000e+00, float* %4
br label %59
59: ; preds = %58, %49
%60 = load float, float* %4
ret float %60
}

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