#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*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
double stub1(double, double, double);
double stub2(double, double, double);
double stub3(double, double, double);
double bisection3(double (*func)(double, double, double), double x1, double x2,
                  double p1, double p2, double acc) {
  int j;
  double val, val2;
  double diff, mid;
  double root;
  val = (*func)(x1, p1, p2);
  val2 = (*func)(x2, p1, p2);
  if (val == 0.0)
    return (x1);
  if (val2 == 0.0)
    return (x2);
  if (val * val2 > 0.0) {
    fprintf(stderr, "Function not bracketed in bisection2");
    exit(1);
  }
  if (val < 0.0) {
    root = x1;
    diff = x2 - x1;
  } else {
    root = x2;
    diff = x1 - x2;
  }
  for (j = 1; j <= 10000; j++) {
    diff /= 2.0;
    mid = root + diff;
    val2 = (*func)(mid, p1, p2);
    if (val2 <= 0.0)
      root = mid;
    if (fabs(diff) < acc || val2 == 0.0)
      return (root);
  }
  fprintf(stderr, "Too many steps in bisection2");
  exit(1);
}


x86 assembly (clang, -O0):
<bisection3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
movsd  %xmm2,-0x28(%rbp)
movsd  %xmm3,-0x30(%rbp)
movsd  %xmm4,-0x38(%rbp)
mov    -0x10(%rbp),%rax
movsd  -0x18(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm2
call   *%rax
movsd  %xmm0,-0x48(%rbp)
mov    -0x10(%rbp),%rax
movsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm2
call   *%rax
movsd  %xmm0,-0x50(%rbp)
movsd  -0x48(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11a0 <bisection3+0x80>
jp     11a0 <bisection3+0x80>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1325 <bisection3+0x205>
movsd  -0x50(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11c7 <bisection3+0xa7>
jp     11c7 <bisection3+0xa7>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1325 <bisection3+0x205>
movsd  -0x48(%rbp),%xmm0
mulsd  -0x50(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11fd <bisection3+0xdd>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
lea    0xe32(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
xorps  %xmm0,%xmm0
ucomisd -0x48(%rbp),%xmm0
jbe    1229 <bisection3+0x109>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x20(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
jmp    1242 <bisection3+0x122>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movl   $0x1,-0x3c(%rbp)
cmpl   $0x2710,-0x3c(%rbp)
jg     1306 <bisection3+0x1e6>
movsd  -0x58(%rbp),%xmm0
movsd  0xd9d(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x68(%rbp),%xmm0
addsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x10(%rbp),%rax
movsd  -0x60(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm2
call   *%rax
movsd  %xmm0,-0x50(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x50(%rbp),%xmm0
jb     12ad <bisection3+0x18d>
movsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x58(%rbp),%xmm1
movaps 0xd57(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
ucomisd %xmm1,%xmm0
ja     12e4 <bisection3+0x1c4>
movsd  -0x50(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    12f3 <bisection3+0x1d3>
jp     12f3 <bisection3+0x1d3>
movsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1325 <bisection3+0x205>
jmp    12f8 <bisection3+0x1d8>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1249 <bisection3+0x129>
mov    0x2cd3(%rip),%rax
mov    (%rax),%edi
lea    0xd2f(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
movsd  -0x8(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bisection3>:
push   %rbp
push   %rbx
sub    $0x48,%rsp
movsd  %xmm4,0x40(%rsp)
movsd  %xmm3,0x8(%rsp)
movsd  %xmm2,(%rsp)
movaps %xmm1,0x10(%rsp)
mov    %rdi,%rbx
movaps %xmm0,0x20(%rsp)
movaps %xmm2,%xmm1
movapd %xmm3,%xmm2
call   *%rdi
movaps %xmm0,0x30(%rsp)
movapd 0x10(%rsp),%xmm0
movsd  (%rsp),%xmm1
movsd  0x8(%rsp),%xmm2
call   *%rbx
movapd 0x30(%rsp),%xmm6
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm6
jne    117f <bisection3+0x5f>
jp     117f <bisection3+0x5f>
movapd 0x20(%rsp),%xmm4
jmp    1191 <bisection3+0x71>
movapd 0x10(%rsp),%xmm5
ucomisd %xmm1,%xmm0
jne    119c <bisection3+0x7c>
jp     119c <bisection3+0x7c>
movapd %xmm5,%xmm4
movapd %xmm4,%xmm0
add    $0x48,%rsp
pop    %rbx
pop    %rbp
ret
mulsd  %xmm6,%xmm0
xorpd  %xmm3,%xmm3
ucomisd %xmm3,%xmm0
ja     12a6 <bisection3+0x186>
ucomisd %xmm6,%xmm3
movapd 0x20(%rsp),%xmm4
movsd  0x8(%rsp),%xmm2
movsd  (%rsp),%xmm1
movapd %xmm5,%xmm0
ja     11d3 <bisection3+0xb3>
movapd %xmm4,%xmm5
subsd  %xmm0,%xmm5
jmp    11db <bisection3+0xbb>
movapd %xmm0,%xmm5
subsd  %xmm4,%xmm5
cmpltsd %xmm3,%xmm6
andpd  %xmm6,%xmm4
andnpd %xmm0,%xmm6
orpd   %xmm6,%xmm4
mov    $0x2710,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movapd %xmm4,0x20(%rsp)
mulsd  0xdf2(%rip),%xmm5
movapd %xmm5,0x10(%rsp)
addsd  %xmm5,%xmm4
movapd %xmm4,0x30(%rsp)
movapd %xmm4,%xmm0
call   *%rbx
movapd 0x10(%rsp),%xmm5
movapd %xmm0,%xmm4
xorpd  %xmm6,%xmm6
cmpnlesd %xmm6,%xmm4
movapd %xmm4,%xmm2
andnpd 0x30(%rsp),%xmm2
andpd  0x20(%rsp),%xmm4
orpd   %xmm2,%xmm4
movapd %xmm5,%xmm1
andpd  0xdb9(%rip),%xmm1
movsd  0x40(%rsp),%xmm3
ucomisd %xmm1,%xmm3
ja     1191 <bisection3+0x71>
ucomisd %xmm6,%xmm0
jne    1273 <bisection3+0x153>
jnp    1191 <bisection3+0x71>
add    $0xffffffff,%ebp
movsd  0x8(%rsp),%xmm2
movsd  (%rsp),%xmm1
jne    1200 <bisection3+0xe0>
mov    0x2d52(%rip),%rax
mov    (%rax),%edi
lea    0xdae(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
mov    0x2d33(%rip),%rax
mov    (%rax),%edi
lea    0xd6a(%rip),%rsi
jmp    1297 <bisection3+0x177>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [37 x i8] c"Function not bracketed in bisection2\00"
@.str.1 = [29 x i8] c"Too many steps in bisection2\00"
define double @bisection3(double (double, double, double)* %0, double %1, double %2, double %3, double %4, double %5) {
%7 = alloca double
%8 = alloca double (double, double, double)*
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca i32
%15 = alloca double
%16 = alloca double
%17 = alloca double
%18 = alloca double
%19 = alloca double
store double (double, double, double)* %0, double (double, double, double)** %8
store double %1, double* %9
store double %2, double* %10
store double %3, double* %11
store double %4, double* %12
store double %5, double* %13
%20 = load double (double, double, double)*, double (double, double, double)** %8
%21 = load double, double* %9
%22 = load double, double* %11
%23 = load double, double* %12
%24 = call double %20(double %21, double %22, double %23)
store double %24, double* %15
%25 = load double (double, double, double)*, double (double, double, double)** %8
%26 = load double, double* %10
%27 = load double, double* %11
%28 = load double, double* %12
%29 = call double %25(double %26, double %27, double %28)
store double %29, double* %16
%30 = load double, double* %15
%31 = fcmp oeq double %30, 0.000000e+00
br i1 %31, label %32, label %34
32: ; preds = %6
%33 = load double, double* %9
store double %33, double* %7
br label %98
34: ; preds = %6
%35 = load double, double* %16
%36 = fcmp oeq double %35, 0.000000e+00
br i1 %36, label %37, label %39
37: ; preds = %34
%38 = load double, double* %10
store double %38, double* %7
br label %98
39: ; preds = %34
%40 = load double, double* %15
%41 = load double, double* %16
%42 = fmul double %40, %41
%43 = fcmp ogt double %42, 0.000000e+00
br i1 %43, label %44, label %48
44: ; preds = %39
%45 = load i32, i32* @stderr
%46 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %39
%49 = load double, double* %15
%50 = fcmp olt double %49, 0.000000e+00
br i1 %50, label %51, label %56
51: ; preds = %48
%52 = load double, double* %9
store double %52, double* %19
%53 = load double, double* %10
%54 = load double, double* %9
%55 = fsub double %53, %54
store double %55, double* %17
br label %61
56: ; preds = %48
%57 = load double, double* %10
store double %57, double* %19
%58 = load double, double* %9
%59 = load double, double* %10
%60 = fsub double %58, %59
store double %60, double* %17
br label %61
61: ; preds = %56, %51
store i32 1, i32* %14
br label %62
62: ; preds = %91, %61
%63 = load i32, i32* %14
%64 = icmp sle i32 %63, 10000
br i1 %64, label %65, label %94
65: ; preds = %62
%66 = load double, double* %17
%67 = fdiv double %66, 2.000000e+00
store double %67, double* %17
%68 = load double, double* %19
%69 = load double, double* %17
%70 = fadd double %68, %69
store double %70, double* %18
%71 = load double (double, double, double)*, double (double, double, double)** %8
%72 = load double, double* %18
%73 = load double, double* %11
%74 = load double, double* %12
%75 = call double %71(double %72, double %73, double %74)
store double %75, double* %16
%76 = load double, double* %16
%77 = fcmp ole double %76, 0.000000e+00
br i1 %77, label %78, label %80
78: ; preds = %65
%79 = load double, double* %18
store double %79, double* %19
br label %80
80: ; preds = %78, %65
%81 = load double, double* %17
%82 = call double @llvm.fabs.f64(double %81)
%83 = load double, double* %13
%84 = fcmp olt double %82, %83
br i1 %84, label %88, label %85
85: ; preds = %80
%86 = load double, double* %16
%87 = fcmp oeq double %86, 0.000000e+00
br i1 %87, label %88, label %90
88: ; preds = %85, %80
%89 = load double, double* %19
store double %89, double* %7
br label %98
90: ; preds = %85
br label %91
91: ; preds = %90
%92 = load i32, i32* %14
%93 = add nsw i32 %92, 1
store i32 %93, i32* %14
br label %62
94: ; preds = %62
%95 = load i32, i32* @stderr
%96 = call i32 @fprintf(i32 %95, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%97 = call i32 @exit(i32 1)
unreachable
98: ; preds = %88, %37, %32
%99 = load double, double* %7
ret double %99
}

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