#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);
double func(double);
int /*<<< orphan*/ printf(char *);
double rtbis(double x1, double x2, double xacc) {
  int JMAX = 100;
  int j;
  double dx, f, fmid, xmid;
  double myval;
  fmid = func(x2);
  f = func(x1);
  if (f * fmid >= 0.) {
    printf("root must be bracketed in rtbis\n");
    exit(1);
  }
  if (f < 0.) {
    myval = x1;
    dx = x2 - x1;
  } else {
    myval = x2;
    dx = x1 - x2;
  }
  for (j = 0; j < JMAX; j++) {
    dx = dx * 5.e-1;
    xmid = myval + dx;
    fmid = func(xmid);
    if (fmid <= 0.)
      myval = xmid;
    if (fabs(dx) < xacc || fmid == 0.)
      return (myval);
  }
  printf("** Error: Too many bisection in rtbis\n");
}


x86 assembly (clang, -O0):
<rtbis>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movl   $0x64,-0x24(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1040 <func@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <func@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
mulsd  -0x40(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1199 <rtbis+0x69>
lea    0xe96(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
xorps  %xmm0,%xmm0
ucomisd -0x38(%rbp),%xmm0
jbe    11c5 <rtbis+0x95>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    11de <rtbis+0xae>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1292 <rtbis+0x162>
movsd  0xe07(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x50(%rbp),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
call   1040 <func@plt>
movsd  %xmm0,-0x40(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x40(%rbp),%xmm0
jb     1239 <rtbis+0x109>
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x30(%rbp),%xmm1
movaps 0xdcb(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
ja     1270 <rtbis+0x140>
movsd  -0x40(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    127f <rtbis+0x14f>
jp     127f <rtbis+0x14f>
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    129e <rtbis+0x16e>
jmp    1284 <rtbis+0x154>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11e5 <rtbis+0xb5>
lea    0xda8(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rtbis>:
push   %rbx
sub    $0x40,%rsp
movsd  %xmm2,0x38(%rsp)
movaps %xmm0,(%rsp)
movaps %xmm1,0x10(%rsp)
movaps %xmm1,%xmm0
call   1040 <func@plt>
movsd  %xmm0,0x20(%rsp)
movapd (%rsp),%xmm0
call   1040 <func@plt>
movapd %xmm0,%xmm3
movsd  0x20(%rsp),%xmm1
mulsd  %xmm0,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jae    1251 <rtbis+0x121>
ucomisd %xmm3,%xmm0
ja     1193 <rtbis+0x63>
movapd (%rsp),%xmm1
movapd %xmm1,%xmm4
movapd 0x10(%rsp),%xmm2
subsd  %xmm2,%xmm4
jmp    11a6 <rtbis+0x76>
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    $0x64,%ebx
nopl   0x0(%rax)
movapd %xmm3,(%rsp)
mulsd  0xe33(%rip),%xmm4
movapd %xmm4,0x20(%rsp)
movapd %xmm4,%xmm0
addsd  %xmm3,%xmm0
movapd %xmm0,0x10(%rsp)
call   1040 <func@plt>
xorpd  %xmm5,%xmm5
movapd 0x20(%rsp),%xmm4
movapd %xmm0,%xmm3
cmpnlesd %xmm5,%xmm3
movapd %xmm3,%xmm2
andnpd 0x10(%rsp),%xmm2
andpd  (%rsp),%xmm3
orpd   %xmm2,%xmm3
movapd %xmm4,%xmm1
andpd  0xdf8(%rip),%xmm1
movsd  0x38(%rsp),%xmm2
ucomisd %xmm1,%xmm2
ja     1247 <rtbis+0x117>
ucomisd %xmm5,%xmm0
jne    122c <rtbis+0xfc>
jnp    1247 <rtbis+0x117>
add    $0xffffffff,%ebx
jne    11c0 <rtbis+0x90>
lea    0xde8(%rip),%rdi
movapd %xmm3,(%rsp)
call   1030 <puts@plt>
movapd (%rsp),%xmm3
movapd %xmm3,%xmm0
add    $0x40,%rsp
pop    %rbx
ret
lea    0xdee(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

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

LLVM IR (-O2):
@str = [38 x i8] c"** Error: Too many bisection in rtbis\00"
@str.2 = [32 x i8] c"root must be bracketed in rtbis\00"
define double @rtbis(double %0, double %1, double %2) {
%4 = tail call double @func(double %1)
%5 = tail call double @func(double %0)
%6 = fmul double %4, %5
%7 = fcmp ult double %6, 0.000000e+00
br i1 %7, label %11, label %8
8: ; preds = %3
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.2, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %3
%12 = fcmp olt double %5, 0.000000e+00
%13 = fsub double %1, %0
%14 = fsub double %0, %1
%15 = select i1 %12, double %13, double %14
%16 = select i1 %12, double %0, double %1
br label %20
17: ; preds = %20
%18 = add nuw nsw i32 %22, 1
%19 = icmp eq i32 %18, 100
br i1 %19, label %33, label %20
20: ; preds = %11, %17
%21 = phi double [ %16, %11 ], [ %28, %17 ]
%22 = phi i32 [ 0, %11 ], [ %18, %17 ]
%23 = phi double [ %15, %11 ], [ %24, %17 ]
%24 = fmul double %23, 5.000000e-01
%25 = fadd double %24, %21
%26 = tail call double @func(double %25)
%27 = fcmp ugt double %26, 0.000000e+00
%28 = select i1 %27, double %21, double %25
%29 = tail call double @llvm.fabs.f64(double %24)
%30 = fcmp olt double %29, %2
%31 = fcmp oeq double %26, 0.000000e+00
%32 = select i1 %30, i1 true, i1 %31
br i1 %32, label %35, label %17
33: ; preds = %17
%34 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
br label %35
35: ; preds = %20, %33
ret double %28
}