#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, os;
  ost = os = -1.0e30;
  for (j = 1; j <= 20; j++) {
    st = trapzd(func, a, b, j);
    s = (4.0 * st - ost) / 3.0;
    if (fabs(s - os) < 1.0e-6 * fabs(os))
      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)
movss  0xeb2(%rip),%xmm0
movss  %xmm0,-0x2c(%rbp)
movss  0xea5(%rip),%xmm0
movss  %xmm0,-0x28(%rbp)
movl   $0x1,-0x1c(%rbp)
cmpl   $0x14,-0x1c(%rbp)
jg     1247 <qsimp+0x117>
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  0xe5b(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe43(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x20(%rbp)
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  0xe00(%rip),%xmm0
mulsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jbe    1225 <qsimp+0xf5>
movss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    125b <qsimp+0x12b>
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    1167 <qsimp+0x37>
lea    0xdd2(%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,0x20(%rsp)
movss  %xmm0,0x1c(%rsp)
mov    %rdi,%rbx
mov    $0x1,%ebp
movss  0xeae(%rip),%xmm0
movaps %xmm0,%xmm1
cs nopw 0x0(%rax,%rax,1)
nop
movss  %xmm1,0x10(%rsp)
movss  %xmm0,0xc(%rsp)
mov    %rbx,%rdi
movss  0x1c(%rsp),%xmm0
movss  0x20(%rsp),%xmm1
mov    %ebp,%esi
call   1040 <trapzd@plt>
movss  %xmm0,0x24(%rsp)
cvtss2sd %xmm0,%xmm0
movss  0x10(%rsp),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  0xe6a(%rip),%xmm0
subsd  %xmm1,%xmm0
divsd  0xe66(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0x8(%rsp)
subss  0xc(%rsp),%xmm0
call   1050 <fabs@plt>
movsd  %xmm0,0x10(%rsp)
movss  0xc(%rsp),%xmm0
call   1050 <fabs@plt>
mulsd  0xe40(%rip),%xmm0
ucomisd 0x10(%rsp),%xmm0
ja     1209 <qsimp+0xd9>
add    $0x1,%ebp
movss  0x24(%rsp),%xmm1
cmp    $0x15,%ebp
movss  0x8(%rsp),%xmm0
jne    1160 <qsimp+0x30>
lea    0xe21(%rip),%rdi
call   1030 <nrerror@plt>
xorps  %xmm0,%xmm0
jmp    120f <qsimp+0xdf>
movss  0x8(%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 0xC6293E5940000000, float* %12
store float 0xC6293E5940000000, float* %11
store i32 1, i32* %8
br label %13
13: ; preds = %43, %3
%14 = load i32, i32* %8
%15 = icmp sle i32 %14, 20
br i1 %15, label %16, label %46
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 float, float* %9
%31 = load float, float* %12
%32 = fsub float %30, %31
%33 = call double @fabs(float %32)
%34 = load float, float* %12
%35 = call double @fabs(float %34)
%36 = fmul double 0x3EB0C6F7A0B5ED8D, %35
%37 = fcmp olt double %33, %36
br i1 %37, label %38, label %40
38: ; preds = %16
%39 = load float, float* %9
store float %39, float* %4
br label %47
40: ; preds = %16
%41 = load float, float* %9
store float %41, float* %12
%42 = load float, float* %10
store float %42, float* %11
br label %43
43: ; preds = %40
%44 = load i32, i32* %8
%45 = add nsw i32 %44, 1
store i32 %45, i32* %8
br label %13
46: ; preds = %13
store float 0.000000e+00, float* %4
br label %47
47: ; preds = %46, %38
%48 = load float, float* %4
ret float %48
}

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 %7
4: ; preds = %7
%5 = add nuw nsw i32 %10, 1
%6 = icmp eq i32 %5, 21
br i1 %6, label %23, label %7
7: ; preds = %3, %4
%8 = phi float [ 0xC6293E5940000000, %3 ], [ %17, %4 ]
%9 = phi float [ 0xC6293E5940000000, %3 ], [ %11, %4 ]
%10 = phi i32 [ 1, %3 ], [ %5, %4 ]
%11 = tail call float @trapzd(float (float)* %0, float %1, float %2, i32 %10)
%12 = fpext float %11 to double
%13 = fpext float %9 to double
%14 = fneg double %13
%15 = tail call double @llvm.fmuladd.f64(double %12, double 4.000000e+00, double %14)
%16 = fdiv double %15, 3.000000e+00
%17 = fptrunc double %16 to float
%18 = fsub float %17, %8
%19 = tail call double @fabs(float %18)
%20 = tail call double @fabs(float %8)
%21 = fmul double %20, 0x3EB0C6F7A0B5ED8D
%22 = fcmp olt double %19, %21
br i1 %22, label %24, label %4
23: ; preds = %4
tail call void @nrerror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %7, %23
%25 = phi float [ 0.000000e+00, %23 ], [ %17, %7 ]
ret float %25
}