double mybsearch(double num) {
  double start = 1.0;
  double end = num;
  double mid = 0.0;
  while (1) {
    mid = (start + end) / 2;
    if (((mid * mid - num) <= 0.000001) && ((mid * mid - num) >= -0.000001)) {
      return mid;
    }
    if ((mid * mid - num) > 0.000001) {
      end = mid;
    } else {
      start = mid;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<mybsearch>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x8(%rbp)
movsd  0xeef(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  0xed6(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm2
movsd  -0x8(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe8f(%rip),%xmm0
ucomisd %xmm1,%xmm0
jb     11ca <mybsearch+0xca>
movsd  -0x20(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
movsd  -0x8(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe5f(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11ca <mybsearch+0xca>
movsd  -0x20(%rbp),%xmm0
pop    %rbp
ret
movsd  -0x20(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
movsd  -0x8(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe08(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1219 <mybsearch+0x119>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1223 <mybsearch+0x123>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    1128 <mybsearch+0x28>

x86 assembly (clang, -O2):
<mybsearch>:
movapd %xmm0,%xmm7
movsd  0xf04(%rip),%xmm0
addsd  %xmm7,%xmm0
mulsd  0xf00(%rip),%xmm0
movapd %xmm0,%xmm4
mulsd  %xmm0,%xmm4
subsd  %xmm7,%xmm4
movsd  0xef4(%rip),%xmm2
ucomisd %xmm4,%xmm2
jb     1140 <mybsearch+0x40>
ucomisd 0xeee(%rip),%xmm4
jae    11c0 <mybsearch+0xc0>
movapd 0xeb8(%rip),%xmm3
xorpd  %xmm7,%xmm3
movsd  0xebc(%rip),%xmm5
movsd  0xebc(%rip),%xmm6
movsd  0xec3(%rip),%xmm8
cs nopw 0x0(%rax,%rax,1)
nop
ucomisd %xmm2,%xmm4
movapd %xmm0,%xmm1
ja     117e <mybsearch+0x7e>
movapd %xmm7,%xmm1
movapd %xmm2,%xmm7
cmpltsd %xmm4,%xmm7
andpd  %xmm7,%xmm5
andnpd %xmm0,%xmm7
orpd   %xmm7,%xmm5
movapd %xmm5,%xmm0
addsd  %xmm1,%xmm0
mulsd  %xmm6,%xmm0
movapd %xmm0,%xmm4
mulsd  %xmm0,%xmm4
addsd  %xmm3,%xmm4
ucomisd %xmm4,%xmm2
movapd %xmm1,%xmm7
jb     1170 <mybsearch+0x70>
ucomisd %xmm8,%xmm4
movapd %xmm1,%xmm7
jb     1170 <mybsearch+0x70>
ret

LLVM IR (-O0):
define double @mybsearch(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
store double %0, double* %2
store double 1.000000e+00, double* %3
%6 = load double, double* %2
store double %6, double* %4
store double 0.000000e+00, double* %5
br label %7
7: ; preds = %1, %38
%8 = load double, double* %3
%9 = load double, double* %4
%10 = fadd double %8, %9
%11 = fdiv double %10, 2.000000e+00
store double %11, double* %5
%12 = load double, double* %5
%13 = load double, double* %5
%14 = load double, double* %2
%15 = fneg double %14
%16 = call double @llvm.fmuladd.f64(double %12, double %13, double %15)
%17 = fcmp ole double %16, 0x3EB0C6F7A0B5ED8D
br i1 %17, label %18, label %27
18: ; preds = %7
%19 = load double, double* %5
%20 = load double, double* %5
%21 = load double, double* %2
%22 = fneg double %21
%23 = call double @llvm.fmuladd.f64(double %19, double %20, double %22)
%24 = fcmp oge double %23, 0xBEB0C6F7A0B5ED8D
br i1 %24, label %25, label %27
25: ; preds = %18
%26 = load double, double* %5
ret double %26
27: ; preds = %18, %7
%28 = load double, double* %5
%29 = load double, double* %5
%30 = load double, double* %2
%31 = fneg double %30
%32 = call double @llvm.fmuladd.f64(double %28, double %29, double %31)
%33 = fcmp ogt double %32, 0x3EB0C6F7A0B5ED8D
br i1 %33, label %34, label %36
34: ; preds = %27
%35 = load double, double* %5
store double %35, double* %4
br label %38
36: ; preds = %27
%37 = load double, double* %5
store double %37, double* %3
br label %38
38: ; preds = %36, %34
br label %7
}

LLVM IR (-O2):
define double @mybsearch(double %0) {
%2 = fneg double %0
%3 = fadd double %0, 1.000000e+00
%4 = fmul double %3, 5.000000e-01
%5 = tail call double @llvm.fmuladd.f64(double %4, double %4, double %2)
%6 = fcmp ugt double %5, 0x3EB0C6F7A0B5ED8D
%7 = fcmp ult double %5, 0xBEB0C6F7A0B5ED8D
%8 = or i1 %6, %7
br i1 %8, label %11, label %9
9: ; preds = %11, %1
%10 = phi double [ %4, %1 ], [ %20, %11 ]
ret double %10
11: ; preds = %1, %11
%12 = phi double [ %21, %11 ], [ %5, %1 ]
%13 = phi double [ %20, %11 ], [ %4, %1 ]
%14 = phi double [ %18, %11 ], [ %0, %1 ]
%15 = phi double [ %17, %11 ], [ 1.000000e+00, %1 ]
%16 = fcmp ogt double %12, 0x3EB0C6F7A0B5ED8D
%17 = select i1 %16, double %15, double %13
%18 = select i1 %16, double %13, double %14
%19 = fadd double %17, %18
%20 = fmul double %19, 5.000000e-01
%21 = tail call double @llvm.fmuladd.f64(double %20, double %20, double %2)
%22 = fcmp ugt double %21, 0x3EB0C6F7A0B5ED8D
%23 = fcmp ult double %21, 0xBEB0C6F7A0B5ED8D
%24 = or i1 %22, %23
br i1 %24, label %11, label %9
}