double _XcmsSquareRoot(a)
double a;
{
  register double cur_guess, delta;
  if (a == 0.)
    return 0.;
  if (a < 0.) {
    return 0.;
  }
  if (a > 1.)
    cur_guess = a / 4.;
  else
    cur_guess = a * 4.;
  do {
    delta = (cur_guess - a / cur_guess) / 2.;
    cur_guess -= delta;
    if (delta < 0.)
      delta = -delta;
  } while (delta >= cur_guess * 1e-6);
  return cur_guess;
}


x86 assembly (clang, -O0):
<_XcmsSquareRoot>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    112e <_XcmsSquareRoot+0x2e>
jp     112e <_XcmsSquareRoot+0x2e>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1223 <_XcmsSquareRoot+0x123>
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1149 <_XcmsSquareRoot+0x49>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1223 <_XcmsSquareRoot+0x123>
movsd  -0x10(%rbp),%xmm0
movsd  0xeaa(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    117b <_XcmsSquareRoot+0x7b>
movsd  -0x10(%rbp),%xmm0
movsd  0xe9b(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    118d <_XcmsSquareRoot+0x8d>
movsd  0xe85(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1192 <_XcmsSquareRoot+0x92>
movsd  -0x18(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
divsd  -0x18(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  0xe63(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    11f8 <_XcmsSquareRoot+0xf8>
movsd  -0x20(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    11fd <_XcmsSquareRoot+0xfd>
movsd  -0x20(%rbp),%xmm0
movsd  0xe0e(%rip),%xmm1
mulsd  -0x18(%rbp),%xmm1
ucomisd %xmm1,%xmm0
jae    1192 <_XcmsSquareRoot+0x92>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<_XcmsSquareRoot>:
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jae    1194 <_XcmsSquareRoot+0x94>
xor    %eax,%eax
ucomisd 0xee8(%rip),%xmm0
seta   %al
lea    0xefe(%rip),%rcx
movsd  (%rcx,%rax,8),%xmm1
mulsd  %xmm0,%xmm1
movsd  0xed4(%rip),%xmm8
movapd 0xef4(%rip),%xmm3
xorpd  %xmm4,%xmm4
movsd  0xec8(%rip),%xmm5
nopl   0x0(%rax,%rax,1)
movapd %xmm0,%xmm7
divsd  %xmm1,%xmm7
movapd %xmm1,%xmm6
subsd  %xmm7,%xmm6
mulsd  %xmm8,%xmm6
subsd  %xmm6,%xmm1
movapd %xmm6,%xmm2
xorpd  %xmm3,%xmm2
movapd %xmm6,%xmm7
cmpltsd %xmm4,%xmm7
andpd  %xmm7,%xmm2
andnpd %xmm6,%xmm7
orpd   %xmm2,%xmm7
movapd %xmm1,%xmm2
mulsd  %xmm5,%xmm2
ucomisd %xmm2,%xmm7
jae    1150 <_XcmsSquareRoot+0x50>
movapd %xmm1,%xmm0
ret

LLVM IR (-O0):
define double @_XcmsSquareRoot(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
store double %0, double* %3
%6 = load double, double* %3
%7 = fcmp oeq double %6, 0.000000e+00
br i1 %7, label %8, label %9
8: ; preds = %1
store double 0.000000e+00, double* %2
br label %46
9: ; preds = %1
%10 = load double, double* %3
%11 = fcmp olt double %10, 0.000000e+00
br i1 %11, label %12, label %13
12: ; preds = %9
store double 0.000000e+00, double* %2
br label %46
13: ; preds = %9
%14 = load double, double* %3
%15 = fcmp ogt double %14, 1.000000e+00
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = load double, double* %3
%18 = fdiv double %17, 4.000000e+00
store double %18, double* %4
br label %22
19: ; preds = %13
%20 = load double, double* %3
%21 = fmul double %20, 4.000000e+00
store double %21, double* %4
br label %22
22: ; preds = %19, %16
br label %23
23: ; preds = %39, %22
%24 = load double, double* %4
%25 = load double, double* %3
%26 = load double, double* %4
%27 = fdiv double %25, %26
%28 = fsub double %24, %27
%29 = fdiv double %28, 2.000000e+00
store double %29, double* %5
%30 = load double, double* %5
%31 = load double, double* %4
%32 = fsub double %31, %30
store double %32, double* %4
%33 = load double, double* %5
%34 = fcmp olt double %33, 0.000000e+00
br i1 %34, label %35, label %38
35: ; preds = %23
%36 = load double, double* %5
%37 = fneg double %36
store double %37, double* %5
br label %38
38: ; preds = %35, %23
br label %39
39: ; preds = %38
%40 = load double, double* %5
%41 = load double, double* %4
%42 = fmul double %41, 0x3EB0C6F7A0B5ED8D
%43 = fcmp oge double %40, %42
br i1 %43, label %23, label %44
44: ; preds = %39
%45 = load double, double* %4
store double %45, double* %2
br label %46
46: ; preds = %44, %12, %8
%47 = load double, double* %2
ret double %47
}

LLVM IR (-O2):
define double @_XcmsSquareRoot(double %0) {
%2 = fcmp ugt double %0, 0.000000e+00
br i1 %2, label %3, label %18
3: ; preds = %1
%4 = fcmp ogt double %0, 1.000000e+00
%5 = select i1 %4, double 2.500000e-01, double 4.000000e+00
%6 = fmul double %5, %0
br label %7
7: ; preds = %7, %3
%8 = phi double [ %6, %3 ], [ %12, %7 ]
%9 = fdiv double %0, %8
%10 = fsub double %8, %9
%11 = fmul double %10, 5.000000e-01
%12 = fsub double %8, %11
%13 = fcmp olt double %11, 0.000000e+00
%14 = fneg double %11
%15 = select i1 %13, double %14, double %11
%16 = fmul double %12, 0x3EB0C6F7A0B5ED8D
%17 = fcmp ult double %15, %16
br i1 %17, label %18, label %7
18: ; preds = %7, %1
%19 = phi double [ 0.000000e+00, %1 ], [ %12, %7 ]
ret double %19
}