#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 myabs(double);
double my_sqrt(double x) {
  double starey = 1.0;
  double novey;
  double eps1 = 1.0e-11;
  if (x == 0)
    return 0;
  if (x < 0)
    return 0.0 / 0.0;
  if (x > 0) {
    novey = (((x / starey) + starey) / 2);
    while (myabs(novey - starey) >= (eps1 * novey)) {
      starey = novey;
      novey = (((x / starey) + starey) / 2);
    }
    return novey;
  }
  return -1;
}


x86 assembly (clang, -O0):
<my_sqrt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  0xee3(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xece(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    115c <my_sqrt+0x4c>
jp     115c <my_sqrt+0x4c>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    121c <my_sqrt+0x10c>
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    117c <my_sqrt+0x6c>
movsd  0xeae(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    121c <my_sqrt+0x10c>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    120f <my_sqrt+0xff>
movsd  -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  0xe73(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
call   1030 <myabs@plt>
movsd  -0x28(%rbp),%xmm1
mulsd  -0x20(%rbp),%xmm1
ucomisd %xmm1,%xmm0
jb     1200 <my_sqrt+0xf0>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  0xe26(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    11ae <my_sqrt+0x9e>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    121c <my_sqrt+0x10c>
movsd  0xdf9(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_sqrt>:
sub    $0x18,%rsp
xorpd  %xmm3,%xmm3
ucomisd %xmm3,%xmm0
jne    1124 <my_sqrt+0x14>
jnp    11f1 <my_sqrt+0xe1>
movapd %xmm0,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    113f <my_sqrt+0x2f>
movsd  0xec6(%rip),%xmm3
jmp    11f1 <my_sqrt+0xe1>
ucomisd %xmm0,%xmm1
jbe    1194 <my_sqrt+0x84>
movsd  0xec3(%rip),%xmm2
addsd  %xmm1,%xmm2
mulsd  0xebf(%rip),%xmm2
movsd  %xmm2,0x8(%rsp)
movsd  0xea1(%rip),%xmm0
addsd  %xmm2,%xmm0
movsd  %xmm1,0x10(%rsp)
call   1030 <myabs@plt>
movsd  0x8(%rsp),%xmm2
movsd  0xe9c(%rip),%xmm1
mulsd  %xmm2,%xmm1
ucomisd %xmm1,%xmm0
jae    119e <my_sqrt+0x8e>
movapd %xmm2,%xmm3
jmp    11f1 <my_sqrt+0xe1>
movsd  0xe6c(%rip),%xmm3
jmp    11f1 <my_sqrt+0xe1>
movsd  0x10(%rsp),%xmm0
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
divsd  %xmm2,%xmm0
addsd  %xmm2,%xmm0
mulsd  0xe58(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
subsd  %xmm2,%xmm0
call   1030 <myabs@plt>
movsd  0x8(%rsp),%xmm3
movapd %xmm3,%xmm1
mulsd  0xe3f(%rip),%xmm1
ucomisd %xmm1,%xmm0
movsd  0x10(%rsp),%xmm0
movapd %xmm3,%xmm2
jae    11b0 <my_sqrt+0xa0>
movapd %xmm3,%xmm0
add    $0x18,%rsp
ret

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

LLVM IR (-O2):
define double @my_sqrt(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 %23, label %5
5: ; preds = %3
%6 = fcmp ogt double %0, 0.000000e+00
br i1 %6, label %7, label %23
7: ; preds = %5
%8 = fadd double %0, 1.000000e+00
%9 = fmul double %8, 5.000000e-01
%10 = fadd double %9, -1.000000e+00
%11 = tail call double @myabs(double %10)
%12 = fmul double %9, 0x3DA5FD7FE1796495
%13 = fcmp ult double %11, %12
br i1 %13, label %23, label %14
14: ; preds = %7, %14
%15 = phi double [ %18, %14 ], [ %9, %7 ]
%16 = fdiv double %0, %15
%17 = fadd double %15, %16
%18 = fmul double %17, 5.000000e-01
%19 = fsub double %18, %15
%20 = tail call double @myabs(double %19)
%21 = fmul double %18, 0x3DA5FD7FE1796495
%22 = fcmp ult double %20, %21
br i1 %22, label %23, label %14
23: ; preds = %14, %7, %5, %3, %1
%24 = phi double [ 0.000000e+00, %1 ], [ 0x7FF8000000000000, %3 ], [ -1.000000e+00, %5 ], [ %9, %7 ], [ %18, %14 ]
ret double %24
}