#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 */
int /*<<< orphan*/ exit(int);
double fabs(double);
int /*<<< orphan*/ printf(char *, ...);
double stub1(double);
double stub2(double);
double stub3(double);
double rtbis(double (*func)(double), double x1, double x2, double xacc) {
  int j;
  double dx, f, fmid, xmid, rtb;
  f = (*func)(x1);
  fmid = (*func)(x2);
  if (f * fmid >= 0.0) {
    printf("\n\nError in function rtbis():");
    printf("\nroot in function must be within");
    printf("x1 = %f  and x2 = %f\n", x1, x2);
    exit(1);
  }
  rtb = f < 0.0 ? (dx = x2 - x1, x1) : (dx = x1 - x2, x2);
  for (j = 0; 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;
  }
  printf("\n\nError in function rtbis():");
  printf("\nToo many bisections!!!\n");
  exit(1);
}


x86 assembly (clang, -O0):
<rtbis>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movsd  -0x10(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x38(%rbp)
mov    -0x8(%rbp),%rax
movsd  -0x18(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
mulsd  -0x40(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11b0 <rtbis+0x90>
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
lea    0xebf(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
xorps  %xmm0,%xmm0
ucomisd -0x38(%rbp),%xmm0
jbe    11dc <rtbis+0xbc>
movsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
jmp    11f5 <rtbis+0xd5>
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x28,-0x24(%rbp)
jge    12a8 <rtbis+0x188>
mov    -0x8(%rbp),%rax
movsd  -0x50(%rbp),%xmm0
movsd  0xddf(%rip),%xmm1
mulsd  -0x30(%rbp),%xmm1
movsd  %xmm1,-0x30(%rbp)
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
call   *%rax
movsd  %xmm0,-0x40(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x40(%rbp),%xmm0
jb     1253 <rtbis+0x133>
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x30(%rbp),%xmm1
movaps 0xdb1(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
ja     128a <rtbis+0x16a>
movsd  -0x40(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1295 <rtbis+0x175>
jp     1295 <rtbis+0x175>
movsd  -0x50(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret
jmp    129a <rtbis+0x17a>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1206 <rtbis+0xe6>
lea    0xd71(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>

x86 assembly (clang, -O2):
<rtbis>:
push   %rbp
push   %rbx
sub    $0x38,%rsp
movsd  %xmm2,0x30(%rsp)
movapd %xmm1,(%rsp)
mov    %rdi,%rbx
movaps %xmm0,0x10(%rsp)
call   *%rdi
movaps %xmm0,0x20(%rsp)
movapd (%rsp),%xmm0
call   *%rbx
movapd 0x20(%rsp),%xmm3
mulsd  %xmm3,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jae    125d <rtbis+0x12d>
ucomisd %xmm3,%xmm1
ja     118a <rtbis+0x5a>
movapd 0x10(%rsp),%xmm2
movapd %xmm2,%xmm4
movapd (%rsp),%xmm0
subsd  %xmm0,%xmm4
jmp    119d <rtbis+0x6d>
movapd (%rsp),%xmm0
movapd %xmm0,%xmm4
movapd 0x10(%rsp),%xmm2
subsd  %xmm2,%xmm4
cmpltsd %xmm1,%xmm3
andpd  %xmm3,%xmm2
andnpd %xmm0,%xmm3
orpd   %xmm2,%xmm3
mov    $0x28,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movapd %xmm3,0x20(%rsp)
mulsd  0xe32(%rip),%xmm4
movapd %xmm4,(%rsp)
movapd %xmm4,%xmm0
addsd  %xmm3,%xmm0
movapd %xmm0,0x10(%rsp)
call   *%rbx
movapd (%rsp),%xmm4
movapd %xmm0,%xmm3
xorpd  %xmm5,%xmm5
cmpnlesd %xmm5,%xmm3
movapd %xmm3,%xmm2
andnpd 0x10(%rsp),%xmm2
andpd  0x20(%rsp),%xmm3
orpd   %xmm2,%xmm3
movapd %xmm4,%xmm1
andpd  0xdfb(%rip),%xmm1
movsd  0x30(%rsp),%xmm2
ucomisd %xmm1,%xmm2
ja     1252 <rtbis+0x122>
ucomisd %xmm5,%xmm0
jne    1229 <rtbis+0xf9>
jnp    1252 <rtbis+0x122>
add    $0xffffffff,%ebp
jne    11c0 <rtbis+0x90>
lea    0xdeb(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe31(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
movapd %xmm3,%xmm0
add    $0x38,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xdbc(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xdcb(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xdde(%rip),%rdi
movaps 0x10(%rsp),%xmm0
movaps (%rsp),%xmm1
mov    $0x2,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

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

LLVM IR (-O2):
@.str = [29 x i8] c"\0A\0AError in function rtbis():\00"
@.str.1 = [33 x i8] c"\0Aroot in function must be within\00"
@.str.2 = [22 x i8] c"x1 = %f and x2 = %f\0A\00"
@str = [24 x i8] c"\0AToo many bisections!!!\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 = fmul double %5, %6
%8 = fcmp ult double %7, 0.000000e+00
br i1 %8, label %14, label %9
9: ; preds = %4
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), double %1, double %2)
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %4
%15 = fcmp olt double %5, 0.000000e+00
%16 = fsub double %2, %1
%17 = fsub double %1, %2
%18 = select i1 %15, double %16, double %17
%19 = select i1 %15, double %1, double %2
br label %23
20: ; preds = %23
%21 = add nuw nsw i32 %25, 1
%22 = icmp eq i32 %21, 40
br i1 %22, label %37, label %23
23: ; preds = %14, %20
%24 = phi double [ %19, %14 ], [ %31, %20 ]
%25 = phi i32 [ 0, %14 ], [ %21, %20 ]
%26 = phi double [ %18, %14 ], [ %27, %20 ]
%27 = fmul double %26, 5.000000e-01
%28 = fadd double %27, %24
%29 = tail call double %0(double %28)
%30 = fcmp ugt double %29, 0.000000e+00
%31 = select i1 %30, double %24, double %28
%32 = tail call double @llvm.fabs.f64(double %27)
%33 = fcmp olt double %32, %3
%34 = fcmp oeq double %29, 0.000000e+00
%35 = select i1 %33, i1 true, i1 %34
br i1 %35, label %36, label %20
36: ; preds = %23
ret double %31
37: ; preds = %20
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%39 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%40 = tail call i32 @exit(i32 1)
unreachable
}