double qurt_sqrt(val)
double val;
{
  double x = val / 10;
  double dx;
  double diff;
  double min_tol = 0.00001;
  int i, flag;
  flag = 0;
  if (val == 0)
    x = 0;
  else {
    for (i = 1; i < 20; i++) {
      if (!flag) {
        dx = (val - (x * x)) / (2.0 * x);
        x = x + dx;
        diff = val - (x * x);
        if (qurt_fabs(diff) <= min_tol)
          flag = 1;
      } else {
      }
    }
  }
  return (x);
}


x86 assembly (clang, -O0):
<qurt_sqrt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xede(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xec5(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x30(%rbp)
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    116c <qurt_sqrt+0x5c>
jp     116c <qurt_sqrt+0x5c>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    1255 <qurt_sqrt+0x145>
movl   $0x1,-0x2c(%rbp)
cmpl   $0x14,-0x2c(%rbp)
jge    1250 <qurt_sqrt+0x140>
cmpl   $0x0,-0x30(%rbp)
jne    1238 <qurt_sqrt+0x128>
movsd  -0x8(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe53(%rip),%xmm1
mulsd  -0x10(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
mov    $0x1,%al
call   1030 <qurt_fabs@plt>
cvtsi2sd %eax,%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     1233 <qurt_sqrt+0x123>
movl   $0x1,-0x30(%rbp)
jmp    123d <qurt_sqrt+0x12d>
jmp    123d <qurt_sqrt+0x12d>
jmp    1242 <qurt_sqrt+0x132>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1173 <qurt_sqrt+0x63>
jmp    1255 <qurt_sqrt+0x145>
movsd  -0x10(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<qurt_sqrt>:
push   %rbx
sub    $0x10,%rsp
xorpd  %xmm3,%xmm3
movsd  %xmm0,(%rsp)
ucomisd %xmm3,%xmm0
jne    1130 <qurt_sqrt+0x20>
jp     1130 <qurt_sqrt+0x20>
movapd %xmm3,%xmm0
add    $0x10,%rsp
pop    %rbx
ret
movsd  (%rsp),%xmm3
divsd  0xec3(%rip),%xmm3
xor    %eax,%eax
mov    $0x13,%ebx
jmp    1157 <qurt_sqrt+0x47>
cs nopw 0x0(%rax,%rax,1)
mov    %ecx,%eax
add    $0xffffffff,%ebx
je     1126 <qurt_sqrt+0x16>
mov    $0x1,%ecx
test   %eax,%eax
jne    1150 <qurt_sqrt+0x40>
movapd %xmm3,%xmm0
mulsd  %xmm3,%xmm0
movsd  (%rsp),%xmm2
movapd %xmm2,%xmm1
subsd  %xmm0,%xmm1
movapd %xmm3,%xmm0
addsd  %xmm3,%xmm0
divsd  %xmm0,%xmm1
addsd  %xmm1,%xmm3
movsd  %xmm3,0x8(%rsp)
mulsd  %xmm3,%xmm3
movapd %xmm2,%xmm0
subsd  %xmm3,%xmm0
mov    $0x1,%al
call   1030 <qurt_fabs@plt>
movsd  0x8(%rsp),%xmm3
xor    %ecx,%ecx
test   %eax,%eax
setle  %cl
jmp    1150 <qurt_sqrt+0x40>

LLVM IR (-O0):
define double @qurt_sqrt(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca i32
%8 = alloca i32
store double %0, double* %2
%9 = load double, double* %2
%10 = fdiv double %9, 1.000000e+01
store double %10, double* %3
store double 1.000000e-05, double* %6
store i32 0, i32* %8
%11 = load double, double* %2
%12 = fcmp oeq double %11, 0.000000e+00
br i1 %12, label %13, label %14
13: ; preds = %1
store double 0.000000e+00, double* %3
br label %51
14: ; preds = %1
store i32 1, i32* %7
br label %15
15: ; preds = %47, %14
%16 = load i32, i32* %7
%17 = icmp slt i32 %16, 20
br i1 %17, label %18, label %50
18: ; preds = %15
%19 = load i32, i32* %8
%20 = icmp ne i32 %19, 0
br i1 %20, label %45, label %21
21: ; preds = %18
%22 = load double, double* %2
%23 = load double, double* %3
%24 = load double, double* %3
%25 = fneg double %23
%26 = call double @llvm.fmuladd.f64(double %25, double %24, double %22)
%27 = load double, double* %3
%28 = fmul double 2.000000e+00, %27
%29 = fdiv double %26, %28
store double %29, double* %4
%30 = load double, double* %3
%31 = load double, double* %4
%32 = fadd double %30, %31
store double %32, double* %3
%33 = load double, double* %2
%34 = load double, double* %3
%35 = load double, double* %3
%36 = fneg double %34
%37 = call double @llvm.fmuladd.f64(double %36, double %35, double %33)
store double %37, double* %5
%38 = load double, double* %5
%39 = call i32 (double, ...) bitcast (i32 (...)* @qurt_fabs to i32 (double, ...)*)(double %38)
%40 = sitofp i32 %39 to double
%41 = load double, double* %6
%42 = fcmp ole double %40, %41
br i1 %42, label %43, label %44
43: ; preds = %21
store i32 1, i32* %8
br label %44
44: ; preds = %43, %21
br label %46
45: ; preds = %18
br label %46
46: ; preds = %45, %44
br label %47
47: ; preds = %46
%48 = load i32, i32* %7
%49 = add nsw i32 %48, 1
store i32 %49, i32* %7
br label %15
50: ; preds = %15
br label %51
51: ; preds = %50, %13
%52 = load double, double* %3
ret double %52
}

LLVM IR (-O2):
define double @qurt_sqrt(double %0) {
%2 = fcmp oeq double %0, 0.000000e+00
br i1 %2, label %26, label %3
3: ; preds = %1
%4 = fdiv double %0, 1.000000e+01
br label %5
5: ; preds = %3, %21
%6 = phi i32 [ 0, %3 ], [ %23, %21 ]
%7 = phi i32 [ 1, %3 ], [ %24, %21 ]
%8 = phi double [ %4, %3 ], [ %22, %21 ]
%9 = icmp eq i32 %6, 0
br i1 %9, label %10, label %21
10: ; preds = %5
%11 = fneg double %8
%12 = tail call double @llvm.fmuladd.f64(double %11, double %8, double %0)
%13 = fmul double %8, 2.000000e+00
%14 = fdiv double %12, %13
%15 = fadd double %8, %14
%16 = fneg double %15
%17 = tail call double @llvm.fmuladd.f64(double %16, double %15, double %0)
%18 = tail call i32 (double, ...) bitcast (i32 (...)* @qurt_fabs to i32 (double, ...)*)(double %17)
%19 = icmp slt i32 %18, 1
%20 = zext i1 %19 to i32
br label %21
21: ; preds = %10, %5
%22 = phi double [ %8, %5 ], [ %15, %10 ]
%23 = phi i32 [ 1, %5 ], [ %20, %10 ]
%24 = add nuw nsw i32 %7, 1
%25 = icmp eq i32 %24, 20
br i1 %25, label %26, label %5
26: ; preds = %21, %1
%27 = phi double [ 0.000000e+00, %1 ], [ %22, %21 ]
ret double %27
}