#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 qsimp(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, 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-5 * 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    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
movl   $0x1,-0x24(%rbp)
cmpl   $0x14,-0x24(%rbp)
jg     125f <qsimp+0x13f>
mov    -0x10(%rbp),%rdi
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
mov    -0x24(%rbp),%esi
call   1040 <trapzd@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
movsd  0xe6d(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe55(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
cmpl   $0x5,-0x24(%rbp)
jle    123d <qsimp+0x11d>
movsd  -0x30(%rbp),%xmm1
subsd  -0x48(%rbp),%xmm1
movaps 0xe51(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm2
movaps 0xe41(%rip),%xmm0
pand   %xmm0,%xmm2
movsd  0xe25(%rip),%xmm0
mulsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
ja     1229 <qsimp+0x109>
movsd  -0x30(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1238 <qsimp+0x118>
jp     1238 <qsimp+0x118>
movsd  -0x48(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1238 <qsimp+0x118>
jp     1238 <qsimp+0x118>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1273 <qsimp+0x153>
jmp    123d <qsimp+0x11d>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    114d <qsimp+0x2d>
lea    0xdca(%rip),%rdi
call   1030 <nrerror@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<qsimp>:
push   %rbp
push   %rbx
sub    $0x38,%rsp
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
mov    %rdi,%rbx
mov    $0x1,%ebp
xorpd  %xmm0,%xmm0
xorpd  %xmm1,%xmm1
jmp    115c <qsimp+0x3c>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%ebp
cmp    $0x15,%ebp
je     11f7 <qsimp+0xd7>
movsd  %xmm1,0x18(%rsp)
movapd %xmm0,0x20(%rsp)
mov    %rbx,%rdi
movsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
mov    %ebp,%esi
call   1040 <trapzd@plt>
movapd %xmm0,%xmm1
mulsd  0xe76(%rip),%xmm0
subsd  0x18(%rsp),%xmm0
divsd  0xe70(%rip),%xmm0
cmp    $0x6,%ebp
jb     1150 <qsimp+0x30>
movapd %xmm0,%xmm2
movapd 0x20(%rsp),%xmm5
subsd  %xmm5,%xmm2
movapd 0xe6d(%rip),%xmm4
andpd  %xmm4,%xmm2
movapd %xmm5,%xmm3
andpd  %xmm4,%xmm3
mulsd  0xe49(%rip),%xmm3
ucomisd %xmm2,%xmm3
ja     1207 <qsimp+0xe7>
ucomisd 0xe43(%rip),%xmm5
jne    1150 <qsimp+0x30>
jp     1150 <qsimp+0x30>
ucomisd 0xe2f(%rip),%xmm0
jne    1150 <qsimp+0x30>
jp     1150 <qsimp+0x30>
jmp    1207 <qsimp+0xe7>
lea    0xe32(%rip),%rdi
call   1030 <nrerror@plt>
xorpd  %xmm0,%xmm0
add    $0x38,%rsp
pop    %rbx
pop    %rbp
ret

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

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