double Calc_getSquareRoot(double const inNum) {
  static unsigned int const maxSteps = 40;
  static double const maxErr = 0.001;
  double retVal = -1.0, result = inNum;
  unsigned int step = 0;
  for (; step < maxSteps; ++step) {
    result = 0.5 * (result + (inNum / result));
    if ((result * result - inNum) <= maxErr) {
      retVal = result;
      break;
    }
  }
  return retVal;
}


x86 assembly (clang, -O0):
<Calc_getSquareRoot>:
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)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x28,-0x1c(%rbp)
jae    11b7 <Calc_getSquareRoot+0xb7>
movsd  -0x18(%rbp),%xmm1
movsd  -0x8(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
addsd  %xmm0,%xmm1
movsd  0xec4(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm1
movsd  -0x18(%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  0xe7d(%rip),%xmm0
ucomisd %xmm1,%xmm0
jb     11a4 <Calc_getSquareRoot+0xa4>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    11b7 <Calc_getSquareRoot+0xb7>
jmp    11a9 <Calc_getSquareRoot+0xa9>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1127 <Calc_getSquareRoot+0x27>
movsd  -0x10(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<Calc_getSquareRoot>:
movapd 0xef8(%rip),%xmm2
xorpd  %xmm0,%xmm2
mov    $0x28,%eax
movsd  0xef7(%rip),%xmm3
movsd  0xef7(%rip),%xmm5
movsd  0xef7(%rip),%xmm4
movapd %xmm0,%xmm6
nopl   (%rax)
movapd %xmm0,%xmm1
divsd  %xmm6,%xmm1
addsd  %xmm6,%xmm1
mulsd  %xmm3,%xmm1
movapd %xmm1,%xmm6
mulsd  %xmm1,%xmm6
addsd  %xmm2,%xmm6
ucomisd %xmm6,%xmm5
jae    117d <Calc_getSquareRoot+0x7d>
movapd %xmm0,%xmm6
divsd  %xmm1,%xmm6
addsd  %xmm1,%xmm6
mulsd  %xmm3,%xmm6
movapd %xmm6,%xmm1
mulsd  %xmm6,%xmm1
addsd  %xmm2,%xmm1
ucomisd %xmm1,%xmm5
jae    1182 <Calc_getSquareRoot+0x82>
add    $0xfffffffe,%eax
jne    1130 <Calc_getSquareRoot+0x30>
movapd %xmm4,%xmm1
movapd %xmm1,%xmm0
ret
movapd %xmm6,%xmm0
ret

LLVM IR (-O0):
@Calc_getSquareRoot.maxSteps = internal constant i32 40
@Calc_getSquareRoot.maxErr = internal constant double 1.000000e-03
define double @Calc_getSquareRoot(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca i32
store double %0, double* %2
store double -1.000000e+00, double* %3
%6 = load double, double* %2
store double %6, double* %4
store i32 0, i32* %5
br label %7
7: ; preds = %26, %1
%8 = load i32, i32* %5
%9 = icmp ult i32 %8, 40
br i1 %9, label %10, label %29
10: ; preds = %7
%11 = load double, double* %4
%12 = load double, double* %2
%13 = load double, double* %4
%14 = fdiv double %12, %13
%15 = fadd double %11, %14
%16 = fmul double 5.000000e-01, %15
store double %16, double* %4
%17 = load double, double* %4
%18 = load double, double* %4
%19 = load double, double* %2
%20 = fneg double %19
%21 = call double @llvm.fmuladd.f64(double %17, double %18, double %20)
%22 = fcmp ole double %21, 1.000000e-03
br i1 %22, label %23, label %25
23: ; preds = %10
%24 = load double, double* %4
store double %24, double* %3
br label %29
25: ; preds = %10
br label %26
26: ; preds = %25
%27 = load i32, i32* %5
%28 = add i32 %27, 1
store i32 %28, i32* %5
br label %7
29: ; preds = %23, %7
%30 = load double, double* %3
ret double %30
}

LLVM IR (-O2):
define double @Calc_getSquareRoot(double %0) {
%2 = fneg double %0
br label %12
3: ; preds = %12
%4 = fdiv double %0, %17
%5 = fadd double %17, %4
%6 = fmul double %5, 5.000000e-01
%7 = tail call double @llvm.fmuladd.f64(double %6, double %6, double %2)
%8 = fcmp ugt double %7, 1.000000e-03
br i1 %8, label %9, label %20
9: ; preds = %3
%10 = add nuw nsw i32 %13, 2
%11 = icmp eq i32 %10, 40
br i1 %11, label %20, label %12
12: ; preds = %9, %1
%13 = phi i32 [ 0, %1 ], [ %10, %9 ]
%14 = phi double [ %0, %1 ], [ %6, %9 ]
%15 = fdiv double %0, %14
%16 = fadd double %14, %15
%17 = fmul double %16, 5.000000e-01
%18 = tail call double @llvm.fmuladd.f64(double %17, double %17, double %2)
%19 = fcmp ugt double %18, 1.000000e-03
br i1 %19, label %3, label %20
20: ; preds = %9, %3, %12
%21 = phi double [ %17, %12 ], [ %6, %3 ], [ -1.000000e+00, %9 ]
ret double %21
}