#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 NAN;
double fabs(double);
int isnan(double);
double stub1(double);
double stub2(double);
double stub3(double);
double rtbis(double (*func)(double), double x1, double x2, double xacc) {
  void nrerror(char error_text[]);
  int j;
  double dx, f, fmid, xmid, rtb;
  f = (*func)(x1);
  fmid = (*func)(x2);
  if (isnan(f) == 1 || isnan(fmid) == 1)
    return NAN;
  if (f * fmid >= 0.0)
    nrerror("Root must be bracketed for bisection in rtbis");
  rtb = f < 0.0 ? (dx = x2 - x1, x1) : (dx = x1 - x2, x2);
  for (j = 1; j <= 40; j++) {
    fmid = (*func)(xmid = rtb + (dx *= 0.5));
    if (fmid <= 0.0)
      rtb = xmid;
    if (fabs(dx) < xacc || fmid == 0.0)
      return rtb;
  }
  return NAN;
}


x86 assembly (clang, -O0):
<rtbis>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
movsd  %xmm2,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movsd  -0x18(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x40(%rbp)
mov    -0x10(%rbp),%rax
movsd  -0x20(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x48(%rbp)
movsd  -0x40(%rbp),%xmm0
call   1040 <isnan@plt>
cmp    $0x1,%eax
je     1181 <rtbis+0x61>
movsd  -0x48(%rbp),%xmm0
call   1040 <isnan@plt>
cmp    $0x1,%eax
jne    1196 <rtbis+0x76>
mov    0x2e70(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12c5 <rtbis+0x1a5>
movsd  -0x40(%rbp),%xmm0
mulsd  -0x48(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11b9 <rtbis+0x99>
lea    0xe6c(%rip),%rdi
call   1030 <nrerror@plt>
xorps  %xmm0,%xmm0
ucomisd -0x40(%rbp),%xmm0
jbe    11e5 <rtbis+0xc5>
movsd  -0x20(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
jmp    11fe <rtbis+0xde>
movsd  -0x18(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movl   $0x1,-0x2c(%rbp)
cmpl   $0x28,-0x2c(%rbp)
jg     12b5 <rtbis+0x195>
mov    -0x10(%rbp),%rax
movsd  -0x58(%rbp),%xmm0
movsd  0xdd6(%rip),%xmm1
mulsd  -0x38(%rbp),%xmm1
movsd  %xmm1,-0x38(%rbp)
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
call   *%rax
movsd  %xmm0,-0x48(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x48(%rbp),%xmm0
jb     125c <rtbis+0x13c>
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x38(%rbp),%xmm1
movaps 0xda8(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
ja     1293 <rtbis+0x173>
movsd  -0x48(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    12a2 <rtbis+0x182>
jp     12a2 <rtbis+0x182>
movsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12c5 <rtbis+0x1a5>
jmp    12a7 <rtbis+0x187>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    120f <rtbis+0xef>
mov    0x2d3c(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rtbis>:
push   %rbp
push   %rbx
sub    $0x58,%rsp
movsd  %xmm2,0x38(%rsp)
movapd %xmm1,(%rsp)
mov    %rdi,%rbx
movaps %xmm0,0x40(%rsp)
call   *%rdi
movaps %xmm0,0x10(%rsp)
movaps (%rsp),%xmm0
call   *%rbx
movsd  %xmm0,0x20(%rsp)
movapd 0x10(%rsp),%xmm0
call   1040 <isnan@plt>
cmp    $0x1,%eax
je     1262 <rtbis+0x142>
movsd  0x20(%rsp),%xmm0
call   1040 <isnan@plt>
cmp    $0x1,%eax
je     1262 <rtbis+0x142>
movapd 0x10(%rsp),%xmm2
movsd  0x20(%rsp),%xmm0
mulsd  %xmm2,%xmm0
xorpd  %xmm3,%xmm3
ucomisd %xmm3,%xmm0
jb     11a4 <rtbis+0x84>
lea    0xe8b(%rip),%rdi
call   1030 <nrerror@plt>
xorpd  %xmm3,%xmm3
movapd 0x10(%rsp),%xmm2
ucomisd %xmm2,%xmm3
ja     11bf <rtbis+0x9f>
movapd 0x40(%rsp),%xmm0
movapd %xmm0,%xmm4
movapd (%rsp),%xmm1
subsd  %xmm1,%xmm4
jmp    11d2 <rtbis+0xb2>
movapd (%rsp),%xmm1
movapd %xmm1,%xmm4
movapd 0x40(%rsp),%xmm0
subsd  %xmm0,%xmm4
cmpltsd %xmm3,%xmm2
andpd  %xmm2,%xmm0
andnpd %xmm1,%xmm2
orpd   %xmm0,%xmm2
mov    $0x28,%ebp
nopl   0x0(%rax,%rax,1)
movapd %xmm2,0x10(%rsp)
mulsd  0xe02(%rip),%xmm4
movapd %xmm4,(%rsp)
movapd %xmm4,%xmm0
addsd  %xmm2,%xmm0
movapd %xmm0,0x20(%rsp)
call   *%rbx
xorpd  %xmm5,%xmm5
movapd (%rsp),%xmm4
movapd %xmm0,%xmm1
cmpnlesd %xmm5,%xmm1
movapd %xmm1,%xmm2
andnpd 0x20(%rsp),%xmm2
andpd  0x10(%rsp),%xmm1
orpd   %xmm2,%xmm1
movapd %xmm1,%xmm2
movapd %xmm4,%xmm1
andpd  0xdc7(%rip),%xmm1
movsd  0x38(%rsp),%xmm3
ucomisd %xmm1,%xmm3
ja     126d <rtbis+0x14d>
ucomisd %xmm5,%xmm0
jne    125d <rtbis+0x13d>
jnp    126d <rtbis+0x14d>
add    $0xffffffff,%ebp
jne    11f0 <rtbis+0xd0>
mov    0x2d8f(%rip),%rax
movsd  (%rax),%xmm2
movapd %xmm2,%xmm0
add    $0x58,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@NAN = global double 0.000000e+00
@.str = [46 x i8] c"Root must be bracketed for bisection in rtbis\00"
define double @rtbis(double (double)* %0, double %1, double %2, double %3) {
%5 = alloca double
%6 = alloca double (double)*
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca i32
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double
store double (double)* %0, double (double)** %6
store double %1, double* %7
store double %2, double* %8
store double %3, double* %9
%16 = load double (double)*, double (double)** %6
%17 = load double, double* %7
%18 = call double %16(double %17)
store double %18, double* %12
%19 = load double (double)*, double (double)** %6
%20 = load double, double* %8
%21 = call double %19(double %20)
store double %21, double* %13
%22 = load double, double* %12
%23 = call i32 @isnan(double %22)
%24 = icmp eq i32 %23, 1
br i1 %24, label %29, label %25
25: ; preds = %4
%26 = load double, double* %13
%27 = call i32 @isnan(double %26)
%28 = icmp eq i32 %27, 1
br i1 %28, label %29, label %31
29: ; preds = %25, %4
%30 = load double, double* @NAN
store double %30, double* %5
br label %82
31: ; preds = %25
%32 = load double, double* %12
%33 = load double, double* %13
%34 = fmul double %32, %33
%35 = fcmp oge double %34, 0.000000e+00
br i1 %35, label %36, label %37
36: ; preds = %31
br label %37
37: ; preds = %36, %31
%38 = load double, double* %12
%39 = fcmp olt double %38, 0.000000e+00
br i1 %39, label %40, label %45
40: ; preds = %37
%41 = load double, double* %8
%42 = load double, double* %7
%43 = fsub double %41, %42
store double %43, double* %11
%44 = load double, double* %7
br label %50
45: ; preds = %37
%46 = load double, double* %7
%47 = load double, double* %8
%48 = fsub double %46, %47
store double %48, double* %11
%49 = load double, double* %8
br label %50
50: ; preds = %45, %40
%51 = phi double [ %44, %40 ], [ %49, %45 ]
store double %51, double* %15
store i32 1, i32* %10
br label %52
52: ; preds = %77, %50
%53 = load i32, i32* %10
%54 = icmp sle i32 %53, 40
br i1 %54, label %55, label %80
55: ; preds = %52
%56 = load double (double)*, double (double)** %6
%57 = load double, double* %15
%58 = load double, double* %11
%59 = fmul double %58, 5.000000e-01
store double %59, double* %11
%60 = fadd double %57, %59
store double %60, double* %14
%61 = call double %56(double %60)
store double %61, double* %13
%62 = load double, double* %13
%63 = fcmp ole double %62, 0.000000e+00
br i1 %63, label %64, label %66
64: ; preds = %55
%65 = load double, double* %14
store double %65, double* %15
br label %66
66: ; preds = %64, %55
%67 = load double, double* %11
%68 = call double @llvm.fabs.f64(double %67)
%69 = load double, double* %9
%70 = fcmp olt double %68, %69
br i1 %70, label %74, label %71
71: ; preds = %66
%72 = load double, double* %13
%73 = fcmp oeq double %72, 0.000000e+00
br i1 %73, label %74, label %76
74: ; preds = %71, %66
%75 = load double, double* %15
store double %75, double* %5
br label %82
76: ; preds = %71
br label %77
77: ; preds = %76
%78 = load i32, i32* %10
%79 = add nsw i32 %78, 1
store i32 %79, i32* %10
br label %52
80: ; preds = %52
%81 = load double, double* @NAN
store double %81, double* %5
br label %82
82: ; preds = %80, %74, %29
%83 = load double, double* %5
ret double %83
}

LLVM IR (-O2):
@NAN = global double 0.000000e+00
@.str = [46 x i8] c"Root must be bracketed for bisection in rtbis\00"
define double @rtbis(double (double)* nocapture %0, double %1, double %2, double %3) {
%5 = tail call double %0(double %1)
%6 = tail call double %0(double %2)
%7 = tail call i32 @isnan(double %5)
%8 = icmp eq i32 %7, 1
br i1 %8, label %12, label %9
9: ; preds = %4
%10 = tail call i32 @isnan(double %6)
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %14
12: ; preds = %9, %4
%13 = load double, double* @NAN
br label %42
14: ; preds = %9
%15 = fmul double %5, %6
%16 = fcmp ult double %15, 0.000000e+00
br i1 %16, label %18, label %17
17: ; preds = %14
tail call void @nrerror(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %17, %14
%19 = fcmp olt double %5, 0.000000e+00
%20 = fsub double %2, %1
%21 = fsub double %1, %2
%22 = select i1 %19, double %20, double %21
%23 = select i1 %19, double %1, double %2
br label %27
24: ; preds = %27
%25 = add nuw nsw i32 %29, 1
%26 = icmp eq i32 %25, 41
br i1 %26, label %40, label %27
27: ; preds = %18, %24
%28 = phi double [ %23, %18 ], [ %35, %24 ]
%29 = phi i32 [ 1, %18 ], [ %25, %24 ]
%30 = phi double [ %22, %18 ], [ %31, %24 ]
%31 = fmul double %30, 5.000000e-01
%32 = fadd double %31, %28
%33 = tail call double %0(double %32)
%34 = fcmp ugt double %33, 0.000000e+00
%35 = select i1 %34, double %28, double %32
%36 = tail call double @llvm.fabs.f64(double %31)
%37 = fcmp olt double %36, %3
%38 = fcmp oeq double %33, 0.000000e+00
%39 = select i1 %37, i1 true, i1 %38
br i1 %39, label %42, label %24
40: ; preds = %24
%41 = load double, double* @NAN
br label %42
42: ; preds = %27, %40, %12
%43 = phi double [ %13, %12 ], [ %41, %40 ], [ %35, %27 ]
ret double %43
}