double invSchwarzschildPotential(const double b, const double M) {
  const double err = 1e-6;
  double lhs, a1, a2;
  assert(b >= sqrt(27) * M);
  lhs = 1 / ((b) * (b));
  a1 = 3.0 * M;
  a2 = 3.0 * M;
  while (schwarzschildPotential(a1, M) <= lhs)
    a1 = a1 / 2;
  while (schwarzschildPotential(a2, M) >= lhs)
    a2 = a2 * 2;
  while (a2 - a1 >= err) {
    double a;
    a = (a1 + a2) / 2.0;
    if (schwarzschildPotential(a, M) > lhs)
      a1 = a;
    else
      a2 = a;
  }
  return ((a1 + a2) / 2.0);
}


x86 assembly (clang, -O0):
<invSchwarzschildPotential>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  0xece(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xeaf(%rip),%xmm0
call   1050 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm1
ucomisd %xmm1,%xmm0
setae  %al
and    $0x1,%al
movzbl %al,%edi
mov    $0x0,%al
call   1040 <assert@plt>
movsd  -0x8(%rbp),%xmm1
mulsd  -0x8(%rbp),%xmm1
movsd  0xe70(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe57(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe45(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
mov    $0x2,%al
call   1030 <schwarzschildPotential@plt>
cvtsi2sd %eax,%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     1204 <invSchwarzschildPotential+0xd4>
movsd  -0x28(%rbp),%xmm0
movsd  0xe2a(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    11c5 <invSchwarzschildPotential+0x95>
jmp    1209 <invSchwarzschildPotential+0xd9>
movsd  -0x30(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
mov    $0x2,%al
call   1030 <schwarzschildPotential@plt>
cvtsi2sd %eax,%xmm0
ucomisd -0x20(%rbp),%xmm0
jb     1240 <invSchwarzschildPotential+0x110>
movsd  0xdef(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    1209 <invSchwarzschildPotential+0xd9>
jmp    1245 <invSchwarzschildPotential+0x115>
movsd  -0x30(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
movsd  0xdc1(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     12ba <invSchwarzschildPotential+0x18a>
movsd  -0x28(%rbp),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  0xdad(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
mov    $0x2,%al
call   1030 <schwarzschildPotential@plt>
cvtsi2sd %eax,%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    12ab <invSchwarzschildPotential+0x17b>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    12b5 <invSchwarzschildPotential+0x185>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    1245 <invSchwarzschildPotential+0x115>
movsd  -0x28(%rbp),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  0xd54(%rip),%xmm1
divsd  %xmm1,%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<invSchwarzschildPotential>:
sub    $0x48,%rsp
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,0x10(%rsp)
movsd  0xec8(%rip),%xmm2
mulsd  %xmm1,%xmm2
xor    %edi,%edi
ucomisd %xmm2,%xmm0
setae  %dil
xor    %eax,%eax
call   1040 <assert@plt>
movsd  0x10(%rsp),%xmm0
mulsd  %xmm0,%xmm0
movsd  0xea9(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x20(%rsp)
movsd  0xe9f(%rip),%xmm0
movsd  0x8(%rsp),%xmm1
mulsd  %xmm1,%xmm0
movapd %xmm0,0x10(%rsp)
mov    $0x2,%al
call   1030 <schwarzschildPotential@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0x20(%rsp),%xmm1
ucomisd %xmm0,%xmm1
movapd 0x10(%rsp),%xmm0
jb     11e4 <invSchwarzschildPotential+0xc4>
movapd 0x10(%rsp),%xmm0
nopw   0x0(%rax,%rax,1)
mulsd  0xe60(%rip),%xmm0
movsd  %xmm0,0x28(%rsp)
movsd  0x8(%rsp),%xmm1
mov    $0x2,%al
call   1030 <schwarzschildPotential@plt>
movsd  0x28(%rsp),%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
movsd  0x20(%rsp),%xmm2
ucomisd %xmm1,%xmm2
jae    11b0 <invSchwarzschildPotential+0x90>
movsd  %xmm0,0x28(%rsp)
movaps 0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
mov    $0x2,%al
call   1030 <schwarzschildPotential@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
ucomisd 0x20(%rsp),%xmm0
jae    1213 <invSchwarzschildPotential+0xf3>
movapd 0x10(%rsp),%xmm2
jmp    1250 <invSchwarzschildPotential+0x130>
movapd 0x10(%rsp),%xmm2
nopl   0x0(%rax)
addsd  %xmm2,%xmm2
movapd %xmm2,0x10(%rsp)
movapd %xmm2,%xmm0
movsd  0x8(%rsp),%xmm1
mov    $0x2,%al
call   1030 <schwarzschildPotential@plt>
movapd 0x10(%rsp),%xmm2
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
ucomisd 0x20(%rsp),%xmm0
jae    1220 <invSchwarzschildPotential+0x100>
movapd %xmm2,%xmm0
movsd  0x28(%rsp),%xmm4
subsd  %xmm4,%xmm0
ucomisd 0xdba(%rip),%xmm0
movsd  0x8(%rsp),%xmm1
jae    12c7 <invSchwarzschildPotential+0x1a7>
movapd %xmm2,%xmm0
movapd %xmm4,%xmm3
addsd  %xmm3,%xmm0
mulsd  0xd96(%rip),%xmm0
add    $0x48,%rsp
ret
nopw   0x0(%rax,%rax,1)
cmpltsd %xmm2,%xmm0
movapd %xmm0,%xmm2
andnpd %xmm1,%xmm2
andpd  0x10(%rsp),%xmm0
orpd   %xmm2,%xmm0
movapd %xmm0,%xmm2
subsd  %xmm3,%xmm2
ucomisd 0xd69(%rip),%xmm2
movapd %xmm3,%xmm4
movapd %xmm0,%xmm2
movsd  0x8(%rsp),%xmm1
jb     1276 <invSchwarzschildPotential+0x156>
movsd  %xmm4,0x28(%rsp)
movapd %xmm2,0x10(%rsp)
movapd %xmm2,%xmm0
addsd  %xmm4,%xmm0
mulsd  0xd35(%rip),%xmm0
movapd %xmm0,0x30(%rsp)
mov    $0x2,%al
call   1030 <schwarzschildPotential@plt>
movapd 0x30(%rsp),%xmm1
movsd  0x20(%rsp),%xmm0
xorps  %xmm2,%xmm2
cvtsi2sd %eax,%xmm2
ucomisd %xmm0,%xmm2
movapd %xmm1,%xmm3
ja     1290 <invSchwarzschildPotential+0x170>
movsd  0x28(%rsp),%xmm3
jmp    1290 <invSchwarzschildPotential+0x170>

LLVM IR (-O0):
define double @invSchwarzschildPotential(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
store double %0, double* %3
store double %1, double* %4
store double 0x3EB0C6F7A0B5ED8D, double* %5
%10 = load double, double* %3
%11 = call double @sqrt(double 2.700000e+01)
%12 = load double, double* %4
%13 = fmul double %11, %12
%14 = fcmp oge double %10, %13
%15 = zext i1 %14 to i32
%16 = call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %15)
%17 = load double, double* %3
%18 = load double, double* %3
%19 = fmul double %17, %18
%20 = fdiv double 1.000000e+00, %19
store double %20, double* %6
%21 = load double, double* %4
%22 = fmul double 3.000000e+00, %21
store double %22, double* %7
%23 = load double, double* %4
%24 = fmul double 3.000000e+00, %23
store double %24, double* %8
br label %25
25: ; preds = %32, %2
%26 = load double, double* %7
%27 = load double, double* %4
%28 = call i32 (double, double, ...) bitcast (i32 (...)* @schwarzschildPotential to i32 (double, double, ...)*)(double %26, double %27)
%29 = sitofp i32 %28 to double
%30 = load double, double* %6
%31 = fcmp ole double %29, %30
br i1 %31, label %32, label %35
32: ; preds = %25
%33 = load double, double* %7
%34 = fdiv double %33, 2.000000e+00
store double %34, double* %7
br label %25
35: ; preds = %25
br label %36
36: ; preds = %43, %35
%37 = load double, double* %8
%38 = load double, double* %4
%39 = call i32 (double, double, ...) bitcast (i32 (...)* @schwarzschildPotential to i32 (double, double, ...)*)(double %37, double %38)
%40 = sitofp i32 %39 to double
%41 = load double, double* %6
%42 = fcmp oge double %40, %41
br i1 %42, label %43, label %46
43: ; preds = %36
%44 = load double, double* %8
%45 = fmul double %44, 2.000000e+00
store double %45, double* %8
br label %36
46: ; preds = %36
br label %47
47: ; preds = %67, %46
%48 = load double, double* %8
%49 = load double, double* %7
%50 = fsub double %48, %49
%51 = fcmp oge double %50, 0x3EB0C6F7A0B5ED8D
br i1 %51, label %52, label %68
52: ; preds = %47
%53 = load double, double* %7
%54 = load double, double* %8
%55 = fadd double %53, %54
%56 = fdiv double %55, 2.000000e+00
store double %56, double* %9
%57 = load double, double* %9
%58 = load double, double* %4
%59 = call i32 (double, double, ...) bitcast (i32 (...)* @schwarzschildPotential to i32 (double, double, ...)*)(double %57, double %58)
%60 = sitofp i32 %59 to double
%61 = load double, double* %6
%62 = fcmp ogt double %60, %61
br i1 %62, label %63, label %65
63: ; preds = %52
%64 = load double, double* %9
store double %64, double* %7
br label %67
65: ; preds = %52
%66 = load double, double* %9
store double %66, double* %8
br label %67
67: ; preds = %65, %63
br label %47
68: ; preds = %47
%69 = load double, double* %7
%70 = load double, double* %8
%71 = fadd double %69, %70
%72 = fdiv double %71, 2.000000e+00
ret double %72
}

LLVM IR (-O2):
define double @invSchwarzschildPotential(double %0, double %1) {
%3 = fmul double %1, 0x4014C8DC2E423980
%4 = fcmp ole double %3, %0
%5 = zext i1 %4 to i32
%6 = tail call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %5)
%7 = fmul double %0, %0
%8 = fdiv double 1.000000e+00, %7
%9 = fmul double %1, 3.000000e+00
%10 = tail call i32 (double, double, ...) bitcast (i32 (...)* @schwarzschildPotential to i32 (double, double, ...)*)(double %9, double %1)
%11 = sitofp i32 %10 to double
%12 = fcmp ult double %8, %11
br i1 %12, label %13, label %18
13: ; preds = %18, %2
%14 = phi double [ %9, %2 ], [ %20, %18 ]
%15 = tail call i32 (double, double, ...) bitcast (i32 (...)* @schwarzschildPotential to i32 (double, double, ...)*)(double %9, double %1)
%16 = sitofp i32 %15 to double
%17 = fcmp ugt double %8, %16
br i1 %17, label %24, label %28
18: ; preds = %2, %18
%19 = phi double [ %20, %18 ], [ %9, %2 ]
%20 = fmul double %19, 5.000000e-01
%21 = tail call i32 (double, double, ...) bitcast (i32 (...)* @schwarzschildPotential to i32 (double, double, ...)*)(double %20, double %1)
%22 = sitofp i32 %21 to double
%23 = fcmp ult double %8, %22
br i1 %23, label %13, label %18
24: ; preds = %28, %13
%25 = phi double [ %9, %13 ], [ %30, %28 ]
%26 = fsub double %25, %14
%27 = fcmp ult double %26, 0x3EB0C6F7A0B5ED8D
br i1 %27, label %46, label %34
28: ; preds = %13, %28
%29 = phi double [ %30, %28 ], [ %9, %13 ]
%30 = fmul double %29, 2.000000e+00
%31 = tail call i32 (double, double, ...) bitcast (i32 (...)* @schwarzschildPotential to i32 (double, double, ...)*)(double %30, double %1)
%32 = sitofp i32 %31 to double
%33 = fcmp ugt double %8, %32
br i1 %33, label %24, label %28
34: ; preds = %24, %34
%35 = phi double [ %43, %34 ], [ %14, %24 ]
%36 = phi double [ %42, %34 ], [ %25, %24 ]
%37 = fadd double %36, %35
%38 = fmul double %37, 5.000000e-01
%39 = tail call i32 (double, double, ...) bitcast (i32 (...)* @schwarzschildPotential to i32 (double, double, ...)*)(double %38, double %1)
%40 = sitofp i32 %39 to double
%41 = fcmp olt double %8, %40
%42 = select i1 %41, double %36, double %38
%43 = select i1 %41, double %38, double %35
%44 = fsub double %42, %43
%45 = fcmp ult double %44, 0x3EB0C6F7A0B5ED8D
br i1 %45, label %46, label %34
46: ; preds = %34, %24
%47 = phi double [ %25, %24 ], [ %42, %34 ]
%48 = phi double [ %14, %24 ], [ %43, %34 ]
%49 = fadd double %47, %48
%50 = fmul double %49, 5.000000e-01
ret double %50
}