double _sqrt(double number) {
  double start = 0, end = number, middle = 0;
  double guess_result = start;
  while ((end - start) > 0.0000001) {
    middle = (start + end) / 2.0;
    guess_result = middle * middle;
    if (guess_result == number) {
      return middle;
    } else if (guess_result < number) {
      start = middle;
    } else {
      end = middle;
    }
  }
  return middle;
}


x86 assembly (clang, -O0):
<_sqrt>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  0xec1(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11cf <_sqrt+0xcf>
movsd  -0x18(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  0xead(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jne    1198 <_sqrt+0x98>
jp     1198 <_sqrt+0x98>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11d9 <_sqrt+0xd9>
movsd  -0x30(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11bb <_sqrt+0xbb>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11c5 <_sqrt+0xc5>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    11ca <_sqrt+0xca>
jmp    112d <_sqrt+0x2d>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<_sqrt>:
xorpd  %xmm1,%xmm1
ucomisd 0xef4(%rip),%xmm0
jbe    117f <_sqrt+0x7f>
xorpd  %xmm5,%xmm5
movsd  0xeee(%rip),%xmm2
movsd  0xede(%rip),%xmm3
movapd %xmm0,%xmm4
jmp    1157 <_sqrt+0x57>
nopl   0x0(%rax,%rax,1)
cmpltsd %xmm0,%xmm6
movapd %xmm6,%xmm7
andpd  %xmm1,%xmm7
andnpd %xmm5,%xmm6
orpd   %xmm7,%xmm6
movapd %xmm4,%xmm5
subsd  %xmm6,%xmm5
ucomisd %xmm3,%xmm5
movapd %xmm6,%xmm5
jbe    117f <_sqrt+0x7f>
movapd %xmm5,%xmm1
addsd  %xmm4,%xmm1
mulsd  %xmm2,%xmm1
movapd %xmm1,%xmm6
mulsd  %xmm1,%xmm6
ucomisd %xmm0,%xmm6
jne    1173 <_sqrt+0x73>
jnp    117f <_sqrt+0x7f>
ucomisd %xmm6,%xmm0
ja     1130 <_sqrt+0x30>
movapd %xmm1,%xmm4
jmp    1130 <_sqrt+0x30>
movapd %xmm1,%xmm0
ret

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

LLVM IR (-O2):
define double @_sqrt(double %0) {
%2 = fcmp ogt double %0, 0x3E7AD7F29ABCAF48
br i1 %2, label %3, label %16
3: ; preds = %1, %10
%4 = phi double [ %13, %10 ], [ %0, %1 ]
%5 = phi double [ %12, %10 ], [ 0.000000e+00, %1 ]
%6 = fadd double %5, %4
%7 = fmul double %6, 5.000000e-01
%8 = fmul double %7, %7
%9 = fcmp oeq double %8, %0
br i1 %9, label %16, label %10
10: ; preds = %3
%11 = fcmp olt double %8, %0
%12 = select i1 %11, double %7, double %5
%13 = select i1 %11, double %4, double %7
%14 = fsub double %13, %12
%15 = fcmp ogt double %14, 0x3E7AD7F29ABCAF48
br i1 %15, label %3, label %16
16: ; preds = %3, %10, %1
%17 = phi double [ 0.000000e+00, %1 ], [ %7, %10 ], [ %7, %3 ]
ret double %17
}