#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);
int /*<<< orphan*/ printf(char *, double, double, ...);
double bisect(double x_left, double x_right, double epsilon,
              double f(double farg)) {
  double x_mid, f_left, f_mid, f_right;
  int root_found;
  f_left = f(x_left);
  f_right = f(x_right);
  if (f_left * f_right > 0) {
    printf("\nMay be no root in [%.7f, %.7f]", x_left, x_right);
    return -99999.0;
  }
  root_found = 0;
  while (fabs(x_right - x_left) > epsilon && !root_found) {
    x_mid = (x_left + x_right) / 2.0;
    f_mid = f(x_mid);
    if (f_mid == 0.0) {
      root_found = 1;
    } else if (f_left * f_mid < 0.0) {
      x_right = x_mid;
    } else {
      x_left = x_mid;
    }
    if (root_found)
      printf("\nRoot found at x = %.7f, midpoint of [%.7f, %.7f]", x_mid,
             x_left, x_right);
    else
      printf("\nNew interval is [%.7f, %.7f]", x_left, x_right);
  }
  return ((x_left + x_right) / 2.0);
}


x86 assembly (clang, -O0):
<bisect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
mov    %rdi,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsd  -0x10(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x38(%rbp)
mov    -0x28(%rbp),%rax
movsd  -0x18(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x48(%rbp)
movsd  -0x38(%rbp),%xmm0
mulsd  -0x48(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    118c <bisect+0x7c>
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
lea    0xead(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
movsd  0xe96(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12bc <bisect+0x1ac>
movl   $0x0,-0x4c(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movaps 0xe5c(%rip),%xmm1
pand   %xmm1,%xmm0
xor    %eax,%eax
ucomisd -0x20(%rbp),%xmm0
mov    %al,-0x4d(%rbp)
jbe    11c4 <bisect+0xb4>
cmpl   $0x0,-0x4c(%rbp)
setne  %al
xor    $0xff,%al
mov    %al,-0x4d(%rbp)
mov    -0x4d(%rbp),%al
test   $0x1,%al
jne    11d4 <bisect+0xc4>
jmp    12a1 <bisect+0x191>
movsd  -0x10(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  0xe2a(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x28(%rbp),%rax
movsd  -0x30(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1223 <bisect+0x113>
jp     1223 <bisect+0x113>
movl   $0x1,-0x4c(%rbp)
jmp    1258 <bisect+0x148>
movsd  -0x38(%rbp),%xmm1
mulsd  -0x40(%rbp),%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    1249 <bisect+0x139>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1253 <bisect+0x143>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    1258 <bisect+0x148>
cmpl   $0x0,-0x4c(%rbp)
je     1284 <bisect+0x174>
movsd  -0x30(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm2
lea    0xdc8(%rip),%rdi
mov    $0x3,%al
call   1030 <printf@plt>
jmp    129c <bisect+0x18c>
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
lea    0xddd(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
jmp    1193 <bisect+0x83>
movsd  -0x10(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  0xd5d(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bisect>:
push   %r14
push   %rbx
sub    $0x58,%rsp
mov    %rdi,%rbx
movsd  %xmm2,0x30(%rsp)
movapd %xmm1,(%rsp)
movsd  %xmm0,0x20(%rsp)
call   *%rdi
movsd  %xmm0,0x38(%rsp)
movapd (%rsp),%xmm0
call   *%rbx
mulsd  0x38(%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1170 <bisect+0x60>
lea    0xecf(%rip),%rdi
movsd  0x20(%rsp),%xmm0
movapd (%rsp),%xmm1
mov    $0x2,%al
call   1030 <printf@plt>
movsd  0xead(%rip),%xmm0
jmp    12ee <bisect+0x1de>
movapd (%rsp),%xmm1
movapd %xmm1,%xmm0
movsd  0x20(%rsp),%xmm3
subsd  %xmm3,%xmm0
andpd  0xe75(%rip),%xmm0
movsd  0x30(%rsp),%xmm4
ucomisd %xmm4,%xmm0
jbe    12b3 <bisect+0x1a3>
lea    0xed0(%rip),%r14
movapd %xmm3,%xmm2
cs nopw 0x0(%rax,%rax,1)
movsd  %xmm2,0x18(%rsp)
movapd %xmm1,(%rsp)
movapd %xmm1,%xmm0
movsd  %xmm3,0x20(%rsp)
addsd  %xmm3,%xmm0
mulsd  0xe3f(%rip),%xmm0
movapd %xmm0,0x40(%rsp)
call   *%rbx
movapd 0x40(%rsp),%xmm5
xorpd  %xmm1,%xmm1
movsd  0x18(%rsp),%xmm2
movsd  0x38(%rsp),%xmm3
mulsd  %xmm0,%xmm3
ucomisd %xmm3,%xmm1
ja     11fd <bisect+0xed>
movapd %xmm5,%xmm2
ucomisd %xmm1,%xmm0
cmpltsd %xmm1,%xmm3
movapd %xmm3,%xmm4
andpd  %xmm5,%xmm4
movapd (%rsp),%xmm1
andnpd %xmm1,%xmm3
orpd   %xmm4,%xmm3
movapd %xmm3,%xmm6
jne    122b <bisect+0x11b>
movapd %xmm3,%xmm6
jp     122b <bisect+0x11b>
movapd %xmm1,%xmm6
movsd  0x20(%rsp),%xmm4
jne    1239 <bisect+0x129>
jp     1239 <bisect+0x129>
movapd %xmm4,%xmm2
movsd  %xmm2,0x18(%rsp)
jne    1243 <bisect+0x133>
jnp    12bd <bisect+0x1ad>
movsd  %xmm0,0x40(%rsp)
movapd %xmm3,(%rsp)
mov    %r14,%rdi
movapd %xmm2,%xmm0
movapd %xmm6,%xmm1
mov    $0x2,%al
movapd %xmm6,0x20(%rsp)
call   1030 <printf@plt>
movsd  0x18(%rsp),%xmm2
movapd 0x20(%rsp),%xmm0
subsd  %xmm2,%xmm0
andpd  0xd82(%rip),%xmm0
movsd  0x30(%rsp),%xmm4
ucomisd %xmm4,%xmm0
jbe    12dd <bisect+0x1cd>
xorpd  %xmm0,%xmm0
movsd  0x40(%rsp),%xmm1
ucomisd %xmm0,%xmm1
movapd %xmm2,%xmm3
movapd (%rsp),%xmm0
movapd %xmm0,%xmm1
jne    11b0 <bisect+0xa0>
jp     11b0 <bisect+0xa0>
jmp    12e2 <bisect+0x1d2>
movapd %xmm1,%xmm0
movapd %xmm3,%xmm2
jmp    12e2 <bisect+0x1d2>
lea    0xd7c(%rip),%rdi
movapd %xmm5,%xmm0
movapd %xmm2,%xmm1
movapd %xmm6,%xmm2
mov    $0x3,%al
call   1030 <printf@plt>
movsd  0x18(%rsp),%xmm2
movapd (%rsp),%xmm0
addsd  %xmm2,%xmm0
mulsd  0xd22(%rip),%xmm0
add    $0x58,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [32 x i8] c"\0AMay be no root in [%.7f, %.7f]\00"
@.str.1 = [50 x i8] c"\0ARoot found at x = %.7f, midpoint of [%.7f, %.7f]\00"
@.str.2 = [30 x i8] c"\0ANew interval is [%.7f, %.7f]\00"
define double @bisect(double %0, double %1, double %2, double (double)* %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double (double)*
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca i32
store double %0, double* %6
store double %1, double* %7
store double %2, double* %8
store double (double)* %3, double (double)** %9
%15 = load double (double)*, double (double)** %9
%16 = load double, double* %6
%17 = call double %15(double %16)
store double %17, double* %11
%18 = load double (double)*, double (double)** %9
%19 = load double, double* %7
%20 = call double %18(double %19)
store double %20, double* %13
%21 = load double, double* %11
%22 = load double, double* %13
%23 = fmul double %21, %22
%24 = fcmp ogt double %23, 0.000000e+00
br i1 %24, label %25, label %29
25: ; preds = %4
%26 = load double, double* %6
%27 = load double, double* %7
%28 = call i32 (i8*, double, double, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), double %26, double %27)
store double -9.999900e+04, double* %5
br label %82
29: ; preds = %4
store i32 0, i32* %14
br label %30
30: ; preds = %76, %29
%31 = load double, double* %7
%32 = load double, double* %6
%33 = fsub double %31, %32
%34 = call double @llvm.fabs.f64(double %33)
%35 = load double, double* %8
%36 = fcmp ogt double %34, %35
br i1 %36, label %37, label %41
37: ; preds = %30
%38 = load i32, i32* %14
%39 = icmp ne i32 %38, 0
%40 = xor i1 %39, true
br label %41
41: ; preds = %37, %30
%42 = phi i1 [ false, %30 ], [ %40, %37 ]
br i1 %42, label %43, label %77
43: ; preds = %41
%44 = load double, double* %6
%45 = load double, double* %7
%46 = fadd double %44, %45
%47 = fdiv double %46, 2.000000e+00
store double %47, double* %10
%48 = load double (double)*, double (double)** %9
%49 = load double, double* %10
%50 = call double %48(double %49)
store double %50, double* %12
%51 = load double, double* %12
%52 = fcmp oeq double %51, 0.000000e+00
br i1 %52, label %53, label %54
53: ; preds = %43
store i32 1, i32* %14
br label %64
54: ; preds = %43
%55 = load double, double* %11
%56 = load double, double* %12
%57 = fmul double %55, %56
%58 = fcmp olt double %57, 0.000000e+00
br i1 %58, label %59, label %61
59: ; preds = %54
%60 = load double, double* %10
store double %60, double* %7
br label %63
61: ; preds = %54
%62 = load double, double* %10
store double %62, double* %6
br label %63
63: ; preds = %61, %59
br label %64
64: ; preds = %63, %53
%65 = load i32, i32* %14
%66 = icmp ne i32 %65, 0
br i1 %66, label %67, label %72
67: ; preds = %64
%68 = load double, double* %10
%69 = load double, double* %6
%70 = load double, double* %7
%71 = call i32 (i8*, double, double, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), double %68, double %69, double %70)
br label %76
72: ; preds = %64
%73 = load double, double* %6
%74 = load double, double* %7
%75 = call i32 (i8*, double, double, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), double %73, double %74)
br label %76
76: ; preds = %72, %67
br label %30
77: ; preds = %41
%78 = load double, double* %6
%79 = load double, double* %7
%80 = fadd double %78, %79
%81 = fdiv double %80, 2.000000e+00
store double %81, double* %5
br label %82
82: ; preds = %77, %25
%83 = load double, double* %5
ret double %83
}

LLVM IR (-O2):
@.str = [32 x i8] c"\0AMay be no root in [%.7f, %.7f]\00"
@.str.1 = [50 x i8] c"\0ARoot found at x = %.7f, midpoint of [%.7f, %.7f]\00"
@.str.2 = [30 x i8] c"\0ANew interval is [%.7f, %.7f]\00"
define double @bisect(double %0, double %1, double %2, double (double)* nocapture %3) {
%5 = tail call double %3(double %0)
%6 = tail call double %3(double %1)
%7 = fmul double %5, %6
%8 = fcmp ogt double %7, 0.000000e+00
br i1 %8, label %13, label %9
9: ; preds = %4
%10 = fsub double %1, %0
%11 = tail call double @llvm.fabs.f64(double %10)
%12 = fcmp ogt double %11, %2
br i1 %12, label %15, label %37
13: ; preds = %4
%14 = tail call i32 (i8*, double, double, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), double %0, double %1)
br label %42
15: ; preds = %9, %30
%16 = phi double [ %27, %30 ], [ %0, %9 ]
%17 = phi double [ %24, %30 ], [ %1, %9 ]
%18 = fadd double %17, %16
%19 = fmul double %18, 5.000000e-01
%20 = tail call double %3(double %19)
%21 = fcmp oeq double %20, 0.000000e+00
%22 = fmul double %5, %20
%23 = fcmp olt double %22, 0.000000e+00
%24 = select i1 %23, double %19, double %17
%25 = select i1 %21, double %17, double %24
%26 = select i1 %21, i1 true, i1 %23
%27 = select i1 %26, double %16, double %19
br i1 %21, label %28, label %30
28: ; preds = %15
%29 = tail call i32 (i8*, double, double, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), double %19, double %27, double %25)
br label %37
30: ; preds = %15
%31 = xor i1 %21, true
%32 = tail call i32 (i8*, double, double, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), double %27, double %25)
%33 = fsub double %25, %27
%34 = tail call double @llvm.fabs.f64(double %33)
%35 = fcmp ogt double %34, %2
%36 = select i1 %35, i1 %31, i1 false
br i1 %36, label %15, label %37
37: ; preds = %30, %28, %9
%38 = phi double [ %1, %9 ], [ %17, %28 ], [ %24, %30 ]
%39 = phi double [ %0, %9 ], [ %27, %28 ], [ %27, %30 ]
%40 = fadd double %38, %39
%41 = fmul double %40, 5.000000e-01
br label %42
42: ; preds = %37, %13
%43 = phi double [ -9.999900e+04, %13 ], [ %41, %37 ]
ret double %43
}