#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
double NAN;
double fabs(double);
double fsqrt(double x) {
  double epilson = 1e-15;
  double sr = x;
  if (x == 0.0)
    return 0.0;
  if (x < 0.0)
    return NAN;
  while (fabs(sr - x / sr) > epilson * sr)
    sr = (x / sr + sr) / 2.0;
  return sr;
}


x86 assembly (clang, -O0):
<fsqrt>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x10(%rbp)
movsd  0xeef(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1145 <fsqrt+0x45>
jp     1145 <fsqrt+0x45>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11ce <fsqrt+0xce>
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1168 <fsqrt+0x68>
mov    0x2e9e(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11ce <fsqrt+0xce>
jmp    116d <fsqrt+0x6d>
movsd  -0x20(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
divsd  -0x20(%rbp),%xmm1
subsd  %xmm1,%xmm0
movaps 0xe89(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  -0x18(%rbp),%xmm1
mulsd  -0x20(%rbp),%xmm1
ucomisd %xmm1,%xmm0
jbe    11c4 <fsqrt+0xc4>
movsd  -0x10(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  0xe52(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    116d <fsqrt+0x6d>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<fsqrt>:
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1111 <fsqrt+0x11>
jp     1111 <fsqrt+0x11>
movapd %xmm1,%xmm0
ret
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jbe    1127 <fsqrt+0x27>
mov    0x2ed6(%rip),%rax
movsd  (%rax),%xmm0
ret
movapd %xmm0,%xmm2
divsd  %xmm0,%xmm2
movapd %xmm0,%xmm1
subsd  %xmm2,%xmm1
andpd  0xec1(%rip),%xmm1
movsd  0xec9(%rip),%xmm3
mulsd  %xmm0,%xmm3
ucomisd %xmm3,%xmm1
jbe    119f <fsqrt+0x9f>
movsd  0xebf(%rip),%xmm3
movapd 0xe9f(%rip),%xmm4
movsd  0xea7(%rip),%xmm5
movapd %xmm0,%xmm1
nopl   (%rax)
addsd  %xmm2,%xmm1
mulsd  %xmm3,%xmm1
movapd %xmm0,%xmm2
divsd  %xmm1,%xmm2
movapd %xmm1,%xmm6
subsd  %xmm2,%xmm6
andpd  %xmm4,%xmm6
movapd %xmm1,%xmm7
mulsd  %xmm5,%xmm7
ucomisd %xmm7,%xmm6
ja     1170 <fsqrt+0x70>
jmp    110c <fsqrt+0xc>
ret

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

LLVM IR (-O2):
@NAN = global double 0.000000e+00
define double @fsqrt(double %0) {
%2 = fcmp oeq double %0, 0.000000e+00
br i1 %2, label %23, label %3
3: ; preds = %1
%4 = fcmp olt double %0, 0.000000e+00
br i1 %4, label %11, label %5
5: ; preds = %3
%6 = fdiv double %0, %0
%7 = fsub double %0, %6
%8 = tail call double @llvm.fabs.f64(double %7)
%9 = fmul double %0, 1.000000e-15
%10 = fcmp ogt double %8, %9
br i1 %10, label %13, label %23
11: ; preds = %3
%12 = load double, double* @NAN
br label %23
13: ; preds = %5, %13
%14 = phi double [ %18, %13 ], [ %6, %5 ]
%15 = phi double [ %17, %13 ], [ %0, %5 ]
%16 = fadd double %15, %14
%17 = fmul double %16, 5.000000e-01
%18 = fdiv double %0, %17
%19 = fsub double %17, %18
%20 = tail call double @llvm.fabs.f64(double %19)
%21 = fmul double %17, 1.000000e-15
%22 = fcmp ogt double %20, %21
br i1 %22, label %13, label %23
23: ; preds = %13, %5, %1, %11
%24 = phi double [ %12, %11 ], [ 0.000000e+00, %1 ], [ %0, %5 ], [ %17, %13 ]
ret double %24
}