#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*/ printf(char *);
double paw_bisection(double (*my_func)(double), double x1, double x2,
                     double eps) {
  int j;
  int root_found;
  double dx, f, fmid, xmid, root;
  root_found = 0;
  fmid = my_func(x2);
  f = my_func(x1);
  if (f * fmid >= 0.0) {
    printf(" paw_bisection.c : root must be bracketed");
    exit(99);
  }
  if (f < 0.0) {
    root = x1;
    dx = x2 - x1;
  } else {
    root = x2;
    dx = x1 - x2;
  }
  for (j = 0; j < 400; ++j) {
    dx = 0.5 * dx;
    xmid = root + dx;
    fmid = my_func(xmid);
    if (fmid <= 0.0)
      root = xmid;
    if (fabs(dx) < eps || fmid == 0.0) {
      root_found = 1;
      break;
    }
  }
  if (!(root_found)) {
    printf("unable to find root within alotted number of iterations");
    exit(1);
  }
  return root;
}


x86 assembly (clang, -O0):
<paw_bisection>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movsd  -0x18(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x40(%rbp)
mov    -0x8(%rbp),%rax
movsd  -0x10(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
mulsd  -0x40(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     118f <paw_bisection+0x6f>
lea    0xea0(%rip),%rdi
call   1030 <printf@plt>
mov    $0x63,%edi
call   1040 <exit@plt>
xorps  %xmm0,%xmm0
ucomisd -0x38(%rbp),%xmm0
jbe    11bb <paw_bisection+0x9b>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    11d4 <paw_bisection+0xb4>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x190,-0x24(%rbp)
jge    1287 <paw_bisection+0x167>
movsd  0xe10(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x50(%rbp),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x8(%rbp),%rax
movsd  -0x48(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x40(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x40(%rbp),%xmm0
jb     1231 <paw_bisection+0x111>
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x30(%rbp),%xmm1
movaps 0xdd3(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
ja     1268 <paw_bisection+0x148>
movsd  -0x40(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1274 <paw_bisection+0x154>
jp     1274 <paw_bisection+0x154>
movl   $0x1,-0x28(%rbp)
jmp    1287 <paw_bisection+0x167>
jmp    1279 <paw_bisection+0x159>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11db <paw_bisection+0xbb>
cmpl   $0x0,-0x28(%rbp)
jne    12a7 <paw_bisection+0x187>
lea    0xdb2(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
movsd  -0x50(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<paw_bisection>:
push   %rbp
push   %rbx
sub    $0x38,%rsp
movsd  %xmm2,0x30(%rsp)
movaps %xmm0,(%rsp)
mov    %rdi,%rbx
movaps %xmm1,0x10(%rsp)
movaps %xmm1,%xmm0
call   *%rdi
movsd  %xmm0,0x20(%rsp)
movapd (%rsp),%xmm0
call   *%rbx
movapd %xmm0,%xmm3
movsd  0x20(%rsp),%xmm1
mulsd  %xmm0,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jae    123f <paw_bisection+0x11f>
ucomisd %xmm3,%xmm0
ja     1181 <paw_bisection+0x61>
movapd (%rsp),%xmm1
movapd %xmm1,%xmm4
movapd 0x10(%rsp),%xmm2
subsd  %xmm2,%xmm4
jmp    1194 <paw_bisection+0x74>
movapd 0x10(%rsp),%xmm2
movapd %xmm2,%xmm4
movapd (%rsp),%xmm1
subsd  %xmm1,%xmm4
cmpltsd %xmm0,%xmm3
andpd  %xmm3,%xmm1
andnpd %xmm2,%xmm3
orpd   %xmm1,%xmm3
mov    $0x190,%ebp
nopw   0x0(%rax,%rax,1)
movapd %xmm3,0x20(%rsp)
mulsd  0xe42(%rip),%xmm4
movapd %xmm4,(%rsp)
movapd %xmm4,%xmm0
addsd  %xmm3,%xmm0
movapd %xmm0,0x10(%rsp)
call   *%rbx
movapd (%rsp),%xmm4
movapd %xmm0,%xmm3
xorpd  %xmm5,%xmm5
cmpnlesd %xmm5,%xmm3
movapd %xmm3,%xmm2
andnpd 0x10(%rsp),%xmm2
andpd  0x20(%rsp),%xmm3
orpd   %xmm2,%xmm3
movapd %xmm4,%xmm1
andpd  0xe0b(%rip),%xmm1
movsd  0x30(%rsp),%xmm2
ucomisd %xmm1,%xmm2
ja     1234 <paw_bisection+0x114>
ucomisd %xmm5,%xmm0
jne    1219 <paw_bisection+0xf9>
jnp    1234 <paw_bisection+0x114>
add    $0xffffffff,%ebp
jne    11b0 <paw_bisection+0x90>
lea    0xe25(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
movapd %xmm3,%xmm0
add    $0x38,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xdda(%rip),%rdi
call   1030 <printf@plt>
mov    $0x63,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@.str = [42 x i8] c" paw_bisection.c : root must be bracketed\00"
@.str.1 = [56 x i8] c"unable to find root within alotted number of iterations\00"
define double @paw_bisection(double (double)* %0, double %1, double %2, double %3) {
%5 = alloca double (double)*
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca i32
%10 = alloca i32
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double
store double (double)* %0, double (double)** %5
store double %1, double* %6
store double %2, double* %7
store double %3, double* %8
store i32 0, i32* %10
%16 = load double (double)*, double (double)** %5
%17 = load double, double* %7
%18 = call double %16(double %17)
store double %18, double* %13
%19 = load double (double)*, double (double)** %5
%20 = load double, double* %6
%21 = call double %19(double %20)
store double %21, double* %12
%22 = load double, double* %12
%23 = load double, double* %13
%24 = fmul double %22, %23
%25 = fcmp oge double %24, 0.000000e+00
br i1 %25, label %26, label %29
26: ; preds = %4
%27 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%28 = call i32 @exit(i32 99)
unreachable
29: ; preds = %4
%30 = load double, double* %12
%31 = fcmp olt double %30, 0.000000e+00
br i1 %31, label %32, label %37
32: ; preds = %29
%33 = load double, double* %6
store double %33, double* %15
%34 = load double, double* %7
%35 = load double, double* %6
%36 = fsub double %34, %35
store double %36, double* %11
br label %42
37: ; preds = %29
%38 = load double, double* %7
store double %38, double* %15
%39 = load double, double* %6
%40 = load double, double* %7
%41 = fsub double %39, %40
store double %41, double* %11
br label %42
42: ; preds = %37, %32
store i32 0, i32* %9
br label %43
43: ; preds = %69, %42
%44 = load i32, i32* %9
%45 = icmp slt i32 %44, 400
br i1 %45, label %46, label %72
46: ; preds = %43
%47 = load double, double* %11
%48 = fmul double 5.000000e-01, %47
store double %48, double* %11
%49 = load double, double* %15
%50 = load double, double* %11
%51 = fadd double %49, %50
store double %51, double* %14
%52 = load double (double)*, double (double)** %5
%53 = load double, double* %14
%54 = call double %52(double %53)
store double %54, double* %13
%55 = load double, double* %13
%56 = fcmp ole double %55, 0.000000e+00
br i1 %56, label %57, label %59
57: ; preds = %46
%58 = load double, double* %14
store double %58, double* %15
br label %59
59: ; preds = %57, %46
%60 = load double, double* %11
%61 = call double @llvm.fabs.f64(double %60)
%62 = load double, double* %8
%63 = fcmp olt double %61, %62
br i1 %63, label %67, label %64
64: ; preds = %59
%65 = load double, double* %13
%66 = fcmp oeq double %65, 0.000000e+00
br i1 %66, label %67, label %68
67: ; preds = %64, %59
store i32 1, i32* %10
br label %72
68: ; preds = %64
br label %69
69: ; preds = %68
%70 = load i32, i32* %9
%71 = add nsw i32 %70, 1
store i32 %71, i32* %9
br label %43
72: ; preds = %67, %43
%73 = load i32, i32* %10
%74 = icmp ne i32 %73, 0
br i1 %74, label %78, label %75
75: ; preds = %72
%76 = call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0))
%77 = call i32 @exit(i32 1)
unreachable
78: ; preds = %72
%79 = load double, double* %15
ret double %79
}

LLVM IR (-O2):
@.str = [42 x i8] c" paw_bisection.c : root must be bracketed\00"
@.str.1 = [56 x i8] c"unable to find root within alotted number of iterations\00"
define double @paw_bisection(double (double)* nocapture %0, double %1, double %2, double %3) {
%5 = tail call double %0(double %2)
%6 = tail call double %0(double %1)
%7 = fmul double %5, %6
%8 = fcmp ult double %7, 0.000000e+00
br i1 %8, label %12, label %9
9: ; preds = %4
%10 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 99)
unreachable
12: ; preds = %4
%13 = fcmp olt double %6, 0.000000e+00
%14 = fsub double %2, %1
%15 = fsub double %1, %2
%16 = select i1 %13, double %14, double %15
%17 = select i1 %13, double %1, double %2
br label %21
18: ; preds = %21
%19 = add nuw nsw i32 %23, 1
%20 = icmp eq i32 %19, 400
br i1 %20, label %34, label %21
21: ; preds = %12, %18
%22 = phi double [ %17, %12 ], [ %29, %18 ]
%23 = phi i32 [ 0, %12 ], [ %19, %18 ]
%24 = phi double [ %16, %12 ], [ %25, %18 ]
%25 = fmul double %24, 5.000000e-01
%26 = fadd double %25, %22
%27 = tail call double %0(double %26)
%28 = fcmp ugt double %27, 0.000000e+00
%29 = select i1 %28, double %22, double %26
%30 = tail call double @llvm.fabs.f64(double %25)
%31 = fcmp olt double %30, %3
%32 = fcmp oeq double %27, 0.000000e+00
%33 = select i1 %31, i1 true, i1 %32
br i1 %33, label %37, label %18
34: ; preds = %18
%35 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0))
%36 = tail call i32 @exit(i32 1)
unreachable
37: ; preds = %21
ret double %29
}