#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__ abs_double(double);
scalar_t__ pow(int, int);
int /*<<< orphan*/ printf(char *, int, ...);
double stub1(double);
double stub2(double);
double stub3(double);
double stub4(double);
double stub5(double);
double bisectionMethod(double a, double b, int e, double (*fp)(double),
                       int verbose) {
  double mid = (a + b) / 2.0;
  double premid = 0.0;
  int no = 0;
  while (abs_double((mid - premid)) >= pow(10, -(e + 1))) {
    if (verbose)
      printf("xn = %lf and xn+1=%lf and |xn+1-xn|=%lf\n", premid, mid,
             abs_double(mid - premid));
    premid = mid;
    if ((*fp)(mid) == 0)
      return mid;
    if ((*fp)(a) * (*fp)(mid) < 0)
      b = mid;
    else if ((*fp)(mid) * (*fp)(b) < 0)
      a = mid;
    no++;
    mid = (a + b) / 2;
  }
  if (verbose)
    printf("No Of Iterations: %d\n", no);
  return mid;
}


x86 assembly (clang, -O0):
<bisectionMethod>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %edi,-0x1c(%rbp)
mov    %rsi,-0x28(%rbp)
mov    %edx,-0x2c(%rbp)
movsd  -0x10(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  0xea2(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
movsd  -0x38(%rbp),%xmm0
subsd  -0x40(%rbp),%xmm0
call   1040 <abs_double@plt>
mov    %rax,-0x50(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
xor    %esi,%esi
sub    %eax,%esi
mov    $0xa,%edi
call   1050 <pow@plt>
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
cmp    %rcx,%rax
jl     12d1 <bisectionMethod+0x1a1>
cmpl   $0x0,-0x2c(%rbp)
je     11f1 <bisectionMethod+0xc1>
cvttsd2si -0x40(%rbp),%eax
mov    %eax,-0x5c(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x38(%rbp),%xmm0
subsd  -0x40(%rbp),%xmm0
call   1040 <abs_double@plt>
mov    -0x5c(%rbp),%esi
movsd  -0x58(%rbp),%xmm0
mov    %rax,%rdx
lea    0xe1e(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x28(%rbp),%rax
movsd  -0x38(%rbp),%xmm0
call   *%rax
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1228 <bisectionMethod+0xf8>
jp     1228 <bisectionMethod+0xf8>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12f6 <bisectionMethod+0x1c6>
mov    -0x28(%rbp),%rax
movsd  -0x10(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x68(%rbp)
mov    -0x28(%rbp),%rax
movsd  -0x38(%rbp),%xmm0
call   *%rax
movsd  -0x68(%rbp),%xmm1
mulsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    1268 <bisectionMethod+0x138>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    12a8 <bisectionMethod+0x178>
mov    -0x28(%rbp),%rax
movsd  -0x38(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x70(%rbp)
mov    -0x28(%rbp),%rax
movsd  -0x18(%rbp),%xmm0
call   *%rax
movsd  -0x70(%rbp),%xmm1
mulsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    12a3 <bisectionMethod+0x173>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    12a8 <bisectionMethod+0x178>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
movsd  -0x10(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  0xd3d(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    1176 <bisectionMethod+0x46>
cmpl   $0x0,-0x2c(%rbp)
je     12ec <bisectionMethod+0x1bc>
mov    -0x44(%rbp),%esi
lea    0xd4c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bisectionMethod>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edx,%r14d
mov    %rsi,%r13
mov    %edi,%r15d
movsd  %xmm0,0x20(%rsp)
movsd  %xmm1,0x18(%rsp)
addsd  %xmm1,%xmm0
mulsd  0xea1(%rip),%xmm0
movsd  %xmm0,0x10(%rsp)
call   1040 <abs_double@plt>
mov    %rax,%r12
not    %r15d
mov    $0xa,%edi
mov    %r15d,%esi
call   1050 <pow@plt>
xor    %ebp,%ebp
cmp    %rax,%r12
jge    11b4 <bisectionMethod+0x84>
movsd  0x10(%rsp),%xmm1
test   %r14d,%r14d
je     12fb <bisectionMethod+0x1cb>
lea    0xe9f(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
movsd  %xmm1,0x8(%rsp)
call   1030 <printf@plt>
movsd  0x8(%rsp),%xmm1
jmp    12fb <bisectionMethod+0x1cb>
xor    %ebp,%ebp
lea    0xe53(%rip),%r12
movsd  0x10(%rsp),%xmm1
xorpd  %xmm0,%xmm0
jmp    1233 <bisectionMethod+0x103>
nopl   0x0(%rax)
movsd  (%rsp),%xmm2
movapd %xmm2,%xmm0
movsd  0x20(%rsp),%xmm1
add    $0x1,%ebp
movsd  %xmm0,0x18(%rsp)
movsd  %xmm1,0x20(%rsp)
addsd  %xmm1,%xmm0
mulsd  0xe06(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
subsd  %xmm2,%xmm0
movsd  %xmm0,0x10(%rsp)
call   1040 <abs_double@plt>
mov    %rax,%rbx
mov    $0xa,%edi
mov    %r15d,%esi
call   1050 <pow@plt>
movsd  0x8(%rsp),%xmm1
movsd  (%rsp),%xmm0
cmp    %rax,%rbx
jl     118a <bisectionMethod+0x5a>
test   %r14d,%r14d
movsd  %xmm1,(%rsp)
je     1265 <bisectionMethod+0x135>
cvttsd2si %xmm0,%ebx
movsd  0x10(%rsp),%xmm0
call   1040 <abs_double@plt>
mov    %r12,%rdi
mov    %ebx,%esi
movsd  (%rsp),%xmm0
mov    %rax,%rdx
mov    $0x1,%al
call   1030 <printf@plt>
movsd  (%rsp),%xmm1
movapd %xmm1,%xmm0
call   *%r13
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1278 <bisectionMethod+0x148>
jnp    12f6 <bisectionMethod+0x1c6>
movsd  0x20(%rsp),%xmm0
call   *%r13
movsd  %xmm0,0x8(%rsp)
movsd  (%rsp),%xmm0
call   *%r13
mulsd  0x8(%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
ja     11d0 <bisectionMethod+0xa0>
movsd  (%rsp),%xmm0
call   *%r13
movsd  %xmm0,0x8(%rsp)
movsd  0x18(%rsp),%xmm0
call   *%r13
mulsd  0x8(%rsp),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jbe    12e0 <bisectionMethod+0x1b0>
movsd  (%rsp),%xmm2
movapd %xmm2,%xmm1
movsd  0x18(%rsp),%xmm0
jmp    11df <bisectionMethod+0xaf>
xchg   %ax,%ax
movsd  0x18(%rsp),%xmm0
movsd  0x20(%rsp),%xmm1
movsd  (%rsp),%xmm2
jmp    11df <bisectionMethod+0xaf>
movsd  (%rsp),%xmm1
movapd %xmm1,%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [41 x i8] c"xn = %lf and xn+1=%lf and |xn+1-xn|=%lf\0A\00"
@.str.1 = [22 x i8] c"No Of Iterations: %d\0A\00"
define double @bisectionMethod(double %0, double %1, i32 %2, double (double)* %3, i32 %4) {
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca i32
%10 = alloca double (double)*
%11 = alloca i32
%12 = alloca double
%13 = alloca double
%14 = alloca i32
store double %0, double* %7
store double %1, double* %8
store i32 %2, i32* %9
store double (double)* %3, double (double)** %10
store i32 %4, i32* %11
%15 = load double, double* %7
%16 = load double, double* %8
%17 = fadd double %15, %16
%18 = fdiv double %17, 2.000000e+00
store double %18, double* %12
store double 0.000000e+00, double* %13
store i32 0, i32* %14
br label %19
19: ; preds = %72, %5
%20 = load double, double* %12
%21 = load double, double* %13
%22 = fsub double %20, %21
%23 = call i64 @abs_double(double %22)
%24 = load i32, i32* %9
%25 = add nsw i32 %24, 1
%26 = sub nsw i32 0, %25
%27 = call i64 @pow(i32 10, i32 %26)
%28 = icmp sge i64 %23, %27
br i1 %28, label %29, label %79
29: ; preds = %19
%30 = load i32, i32* %11
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %41
32: ; preds = %29
%33 = load double, double* %13
%34 = fptosi double %33 to i32
%35 = load double, double* %12
%36 = load double, double* %12
%37 = load double, double* %13
%38 = fsub double %36, %37
%39 = call i64 @abs_double(double %38)
%40 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %34, double %35, i64 %39)
br label %41
41: ; preds = %32, %29
%42 = load double, double* %12
store double %42, double* %13
%43 = load double (double)*, double (double)** %10
%44 = load double, double* %12
%45 = call double %43(double %44)
%46 = fcmp oeq double %45, 0.000000e+00
br i1 %46, label %47, label %49
47: ; preds = %41
%48 = load double, double* %12
store double %48, double* %6
br label %87
49: ; preds = %41
%50 = load double (double)*, double (double)** %10
%51 = load double, double* %7
%52 = call double %50(double %51)
%53 = load double (double)*, double (double)** %10
%54 = load double, double* %12
%55 = call double %53(double %54)
%56 = fmul double %52, %55
%57 = fcmp olt double %56, 0.000000e+00
br i1 %57, label %58, label %60
58: ; preds = %49
%59 = load double, double* %12
store double %59, double* %8
br label %72
60: ; preds = %49
%61 = load double (double)*, double (double)** %10
%62 = load double, double* %12
%63 = call double %61(double %62)
%64 = load double (double)*, double (double)** %10
%65 = load double, double* %8
%66 = call double %64(double %65)
%67 = fmul double %63, %66
%68 = fcmp olt double %67, 0.000000e+00
br i1 %68, label %69, label %71
69: ; preds = %60
%70 = load double, double* %12
store double %70, double* %7
br label %71
71: ; preds = %69, %60
br label %72
72: ; preds = %71, %58
%73 = load i32, i32* %14
%74 = add nsw i32 %73, 1
store i32 %74, i32* %14
%75 = load double, double* %7
%76 = load double, double* %8
%77 = fadd double %75, %76
%78 = fdiv double %77, 2.000000e+00
store double %78, double* %12
br label %19
79: ; preds = %19
%80 = load i32, i32* %11
%81 = icmp ne i32 %80, 0
br i1 %81, label %82, label %85
82: ; preds = %79
%83 = load i32, i32* %14
%84 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %83)
br label %85
85: ; preds = %82, %79
%86 = load double, double* %12
store double %86, double* %6
br label %87
87: ; preds = %85, %47
%88 = load double, double* %6
ret double %88
}

LLVM IR (-O2):
@.str = [41 x i8] c"xn = %lf and xn+1=%lf and |xn+1-xn|=%lf\0A\00"
@.str.1 = [22 x i8] c"No Of Iterations: %d\0A\00"
define double @bisectionMethod(double %0, double %1, i32 %2, double (double)* nocapture %3, i32 %4) {
%6 = fadd double %0, %1
%7 = fmul double %6, 5.000000e-01
%8 = tail call i64 @abs_double(double %7)
%9 = xor i32 %2, -1
%10 = tail call i64 @pow(i32 10, i32 %9)
%11 = icmp slt i64 %8, %10
br i1 %11, label %49, label %12
12: ; preds = %5
%13 = icmp eq i32 %4, 0
br label %14
14: ; preds = %12, %39
%15 = phi double [ %7, %12 ], [ %45, %39 ]
%16 = phi double [ %7, %12 ], [ %44, %39 ]
%17 = phi i32 [ 0, %12 ], [ %42, %39 ]
%18 = phi double [ 0.000000e+00, %12 ], [ %16, %39 ]
%19 = phi double [ %0, %12 ], [ %41, %39 ]
%20 = phi double [ %1, %12 ], [ %40, %39 ]
br i1 %13, label %25, label %21
21: ; preds = %14
%22 = fptosi double %18 to i32
%23 = tail call i64 @abs_double(double %15)
%24 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %22, double %16, i64 %23)
br label %25
25: ; preds = %21, %14
%26 = tail call double %3(double %16)
%27 = fcmp oeq double %26, 0.000000e+00
br i1 %27, label %55, label %28
28: ; preds = %25
%29 = tail call double %3(double %19)
%30 = tail call double %3(double %16)
%31 = fmul double %29, %30
%32 = fcmp olt double %31, 0.000000e+00
br i1 %32, label %39, label %33
33: ; preds = %28
%34 = tail call double %3(double %16)
%35 = tail call double %3(double %20)
%36 = fmul double %34, %35
%37 = fcmp olt double %36, 0.000000e+00
br i1 %37, label %38, label %39
38: ; preds = %33
br label %39
39: ; preds = %28, %33, %38
%40 = phi double [ %20, %38 ], [ %20, %33 ], [ %16, %28 ]
%41 = phi double [ %16, %38 ], [ %19, %33 ], [ %19, %28 ]
%42 = add nuw nsw i32 %17, 1
%43 = fadd double %40, %41
%44 = fmul double %43, 5.000000e-01
%45 = fsub double %44, %16
%46 = tail call i64 @abs_double(double %45)
%47 = tail call i64 @pow(i32 10, i32 %9)
%48 = icmp slt i64 %46, %47
br i1 %48, label %49, label %14
49: ; preds = %39, %5
%50 = phi i32 [ 0, %5 ], [ %42, %39 ]
%51 = phi double [ %7, %5 ], [ %44, %39 ]
%52 = icmp eq i32 %4, 0
br i1 %52, label %55, label %53
53: ; preds = %49
%54 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %50)
br label %55
55: ; preds = %25, %49, %53
%56 = phi double [ %51, %49 ], [ %51, %53 ], [ %16, %25 ]
ret double %56
}