#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 */
scalar_t__ SignOfDouble(double);
double TheFunction(double);
double Bisection(double a, double b) {
  int maxIterationNumber = 100, n = 1;
  double c;
  while (n <= maxIterationNumber) {
    c = (a + b) / 2.0;
    if (TheFunction(c) == 0.0 || (b - a) / 2.0 < 0.0001) {
      return c;
    }
    if (SignOfDouble(TheFunction(c)) == SignOfDouble(TheFunction(a))) {
      a = c;
    } else {
      b = c;
    }
    n++;
  }
}


x86 assembly (clang, -O0):
<Bisection>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movl   $0x64,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jg     1219 <Bisection+0xf9>
movsd  -0x10(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  0xea2(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1030 <TheFunction@plt>
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1189 <Bisection+0x69>
jp     1189 <Bisection+0x69>
jmp    11b1 <Bisection+0x91>
movsd  -0x18(%rbp),%xmm1
subsd  -0x10(%rbp),%xmm1
movsd  0xe65(%rip),%xmm0
divsd  %xmm0,%xmm1
movsd  0xe61(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11c0 <Bisection+0xa0>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1219 <Bisection+0xf9>
movsd  -0x28(%rbp),%xmm0
call   1030 <TheFunction@plt>
call   1040 <SignOfDouble@plt>
mov    %rax,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <TheFunction@plt>
call   1040 <SignOfDouble@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
cmp    %rcx,%rax
jne    1201 <Bisection+0xe1>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    120b <Bisection+0xeb>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1140 <Bisection+0x20>
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Bisection>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
movsd  %xmm0,(%rsp)
mov    $0x64,%ebp
movsd  0xec8(%rip),%xmm0
jmp    1156 <Bisection+0x36>
nopw   0x0(%rax,%rax,1)
movsd  %xmm0,(%rsp)
add    $0xffffffff,%ebp
movsd  0xeb0(%rip),%xmm0
je     11f0 <Bisection+0xd0>
movsd  %xmm1,0x10(%rsp)
addsd  (%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movapd %xmm1,%xmm0
call   1030 <TheFunction@plt>
movsd  0xe84(%rip),%xmm2
movsd  0x10(%rsp),%xmm1
ucomisd 0xe86(%rip),%xmm0
jne    118e <Bisection+0x6e>
jnp    11f0 <Bisection+0xd0>
movapd %xmm1,%xmm0
subsd  (%rsp),%xmm0
mulsd  %xmm2,%xmm0
movsd  0xe65(%rip),%xmm1
ucomisd %xmm0,%xmm1
ja     11f0 <Bisection+0xd0>
movsd  0x8(%rsp),%xmm0
call   1030 <TheFunction@plt>
call   1040 <SignOfDouble@plt>
mov    %rax,%rbx
movsd  (%rsp),%xmm0
call   1030 <TheFunction@plt>
call   1040 <SignOfDouble@plt>
movsd  0x10(%rsp),%xmm1
movsd  0x8(%rsp),%xmm0
cmp    %rax,%rbx
je     1140 <Bisection+0x20>
movsd  0x8(%rsp),%xmm1
movsd  (%rsp),%xmm0
jmp    1140 <Bisection+0x20>
movsd  0x8(%rsp),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define double @Bisection(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
store double %0, double* %4
store double %1, double* %5
store i32 100, i32* %6
store i32 1, i32* %7
br label %9
9: ; preds = %41, %2
%10 = load i32, i32* %7
%11 = load i32, i32* %6
%12 = icmp sle i32 %10, %11
br i1 %12, label %13, label %44
13: ; preds = %9
%14 = load double, double* %4
%15 = load double, double* %5
%16 = fadd double %14, %15
%17 = fdiv double %16, 2.000000e+00
store double %17, double* %8
%18 = load double, double* %8
%19 = call double @TheFunction(double %18)
%20 = fcmp oeq double %19, 0.000000e+00
br i1 %20, label %27, label %21
21: ; preds = %13
%22 = load double, double* %5
%23 = load double, double* %4
%24 = fsub double %22, %23
%25 = fdiv double %24, 2.000000e+00
%26 = fcmp olt double %25, 1.000000e-04
br i1 %26, label %27, label %29
27: ; preds = %21, %13
%28 = load double, double* %8
store double %28, double* %3
br label %44
29: ; preds = %21
%30 = load double, double* %8
%31 = call double @TheFunction(double %30)
%32 = call i64 @SignOfDouble(double %31)
%33 = load double, double* %4
%34 = call double @TheFunction(double %33)
%35 = call i64 @SignOfDouble(double %34)
%36 = icmp eq i64 %32, %35
br i1 %36, label %37, label %39
37: ; preds = %29
%38 = load double, double* %8
store double %38, double* %4
br label %41
39: ; preds = %29
%40 = load double, double* %8
store double %40, double* %5
br label %41
41: ; preds = %39, %37
%42 = load i32, i32* %7
%43 = add nsw i32 %42, 1
store i32 %43, i32* %7
br label %9
44: ; preds = %27, %9
%45 = load double, double* %3
ret double %45
}

LLVM IR (-O2):
define double @Bisection(double %0, double %1) {
br label %3
3: ; preds = %2, %15
%4 = phi i32 [ 1, %2 ], [ %23, %15 ]
%5 = phi double [ %0, %2 ], [ %22, %15 ]
%6 = phi double [ %1, %2 ], [ %21, %15 ]
%7 = fadd double %6, %5
%8 = fmul double %7, 5.000000e-01
%9 = tail call double @TheFunction(double %8)
%10 = fcmp oeq double %9, 0.000000e+00
br i1 %10, label %25, label %11
11: ; preds = %3
%12 = fsub double %6, %5
%13 = fmul double %12, 5.000000e-01
%14 = fcmp olt double %13, 1.000000e-04
br i1 %14, label %25, label %15
15: ; preds = %11
%16 = tail call double @TheFunction(double %8)
%17 = tail call i64 @SignOfDouble(double %16)
%18 = tail call double @TheFunction(double %5)
%19 = tail call i64 @SignOfDouble(double %18)
%20 = icmp eq i64 %17, %19
%21 = select i1 %20, double %6, double %8
%22 = select i1 %20, double %8, double %5
%23 = add nuw nsw i32 %4, 1
%24 = icmp eq i32 %23, 101
br i1 %24, label %25, label %3
25: ; preds = %15, %3, %11
ret double %8
}