#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*/ assert(int);
double f(double);
double fabs(double);
double bisection(double a, double b, double epsilon, int iterations) {
  int i;
  double m, fm;
  assert(f(a) < 0.0 && f(b) > 0.0);
  assert(epsilon > 0.0);
  for (i = 0; i < iterations; i++) {
    m = (a + b) / 2.0;
    fm = f(m);
    if (fabs(fm) <= epsilon)
      return m;
    if (fm > 0.0)
      b = m;
    else
      a = m;
  }
  return m;
}


x86 assembly (clang, -O0):
<bisection>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
mov    %edi,-0x24(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <f@plt>
movaps %xmm0,%xmm1
xor    %eax,%eax
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
mov    %al,-0x39(%rbp)
jbe    1170 <bisection+0x50>
movsd  -0x18(%rbp),%xmm0
call   1030 <f@plt>
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
seta   %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
seta   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    123f <bisection+0x11f>
movsd  -0x10(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  0xe55(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1030 <f@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm1
movaps 0xe21(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     1201 <bisection+0xe1>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1249 <bisection+0x129>
movsd  -0x38(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1222 <bisection+0x102>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    122c <bisection+0x10c>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    1231 <bisection+0x111>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    119d <bisection+0x7d>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bisection>:
push   %rbx
sub    $0x30,%rsp
mov    %edi,%ebx
movsd  %xmm2,(%rsp)
movapd %xmm1,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
call   1030 <f@plt>
xor    %edi,%edi
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jbe    1162 <bisection+0x42>
movapd 0x10(%rsp),%xmm0
call   1030 <f@plt>
xor    %edi,%edi
ucomisd 0xeaa(%rip),%xmm0
seta   %dil
call   1040 <assert@plt>
xor    %edi,%edi
movsd  (%rsp),%xmm0
ucomisd 0xe92(%rip),%xmm0
seta   %dil
call   1040 <assert@plt>
test   %ebx,%ebx
jle    1202 <bisection+0xe2>
movapd 0x10(%rsp),%xmm1
jmp    11b0 <bisection+0x90>
nopl   0x0(%rax,%rax,1)
xorpd  %xmm1,%xmm1
cmpltsd %xmm0,%xmm1
movapd %xmm1,%xmm0
andpd  %xmm2,%xmm0
andnpd 0x10(%rsp),%xmm1
orpd   %xmm0,%xmm1
add    $0xffffffff,%ebx
je     1209 <bisection+0xe9>
movapd %xmm1,0x10(%rsp)
movapd %xmm1,%xmm0
addsd  0x8(%rsp),%xmm0
mulsd  0xe38(%rip),%xmm0
movapd %xmm0,0x20(%rsp)
call   1030 <f@plt>
movapd %xmm0,%xmm1
andpd  0xe31(%rip),%xmm1
movsd  (%rsp),%xmm2
ucomisd %xmm1,%xmm2
jae    1204 <bisection+0xe4>
ucomisd 0xe16(%rip),%xmm0
movapd 0x20(%rsp),%xmm2
ja     1190 <bisection+0x70>
movsd  %xmm2,0x8(%rsp)
jmp    1190 <bisection+0x70>
jmp    1209 <bisection+0xe9>
movaps 0x20(%rsp),%xmm2
movapd %xmm2,%xmm0
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @bisection(double %0, double %1, double %2, i32 %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca i32
%10 = alloca i32
%11 = alloca double
%12 = alloca double
store double %0, double* %6
store double %1, double* %7
store double %2, double* %8
store i32 %3, i32* %9
%13 = load double, double* %6
%14 = call double @f(double %13)
%15 = fcmp olt double %14, 0.000000e+00
br i1 %15, label %16, label %20
16: ; preds = %4
%17 = load double, double* %7
%18 = call double @f(double %17)
%19 = fcmp ogt double %18, 0.000000e+00
br label %20
20: ; preds = %16, %4
%21 = phi i1 [ false, %4 ], [ %19, %16 ]
%22 = zext i1 %21 to i32
%23 = call i32 @assert(i32 %22)
%24 = load double, double* %8
%25 = fcmp ogt double %24, 0.000000e+00
%26 = zext i1 %25 to i32
%27 = call i32 @assert(i32 %26)
store i32 0, i32* %10
br label %28
28: ; preds = %53, %20
%29 = load i32, i32* %10
%30 = load i32, i32* %9
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %56
32: ; preds = %28
%33 = load double, double* %6
%34 = load double, double* %7
%35 = fadd double %33, %34
%36 = fdiv double %35, 2.000000e+00
store double %36, double* %11
%37 = load double, double* %11
%38 = call double @f(double %37)
store double %38, double* %12
%39 = load double, double* %12
%40 = call double @llvm.fabs.f64(double %39)
%41 = load double, double* %8
%42 = fcmp ole double %40, %41
br i1 %42, label %43, label %45
43: ; preds = %32
%44 = load double, double* %11
store double %44, double* %5
br label %58
45: ; preds = %32
%46 = load double, double* %12
%47 = fcmp ogt double %46, 0.000000e+00
br i1 %47, label %48, label %50
48: ; preds = %45
%49 = load double, double* %11
store double %49, double* %7
br label %52
50: ; preds = %45
%51 = load double, double* %11
store double %51, double* %6
br label %52
52: ; preds = %50, %48
br label %53
53: ; preds = %52
%54 = load i32, i32* %10
%55 = add nsw i32 %54, 1
store i32 %55, i32* %10
br label %28
56: ; preds = %28
%57 = load double, double* %11
store double %57, double* %5
br label %58
58: ; preds = %56, %43
%59 = load double, double* %5
ret double %59
}

LLVM IR (-O2):
define double @bisection(double %0, double %1, double %2, i32 %3) {
%5 = tail call double @f(double %0)
%6 = fcmp olt double %5, 0.000000e+00
br i1 %6, label %7, label %11
7: ; preds = %4
%8 = tail call double @f(double %1)
%9 = fcmp ogt double %8, 0.000000e+00
%10 = zext i1 %9 to i32
br label %11
11: ; preds = %7, %4
%12 = phi i32 [ 0, %4 ], [ %10, %7 ]
%13 = tail call i32 @assert(i32 %12)
%14 = fcmp ogt double %2, 0.000000e+00
%15 = zext i1 %14 to i32
%16 = tail call i32 @assert(i32 %15)
%17 = icmp sgt i32 %3, 0
br i1 %17, label %18, label %33
18: ; preds = %11, %27
%19 = phi i32 [ %31, %27 ], [ 0, %11 ]
%20 = phi double [ %30, %27 ], [ %0, %11 ]
%21 = phi double [ %29, %27 ], [ %1, %11 ]
%22 = fadd double %21, %20
%23 = fmul double %22, 5.000000e-01
%24 = tail call double @f(double %23)
%25 = tail call double @llvm.fabs.f64(double %24)
%26 = fcmp ugt double %25, %2
br i1 %26, label %27, label %33
27: ; preds = %18
%28 = fcmp ogt double %24, 0.000000e+00
%29 = select i1 %28, double %23, double %21
%30 = select i1 %28, double %20, double %23
%31 = add nuw nsw i32 %19, 1
%32 = icmp eq i32 %31, %3
br i1 %32, label %33, label %18
33: ; preds = %18, %27, %11
%34 = phi double [ undef, %11 ], [ %23, %27 ], [ %23, %18 ]
ret double %34
}