#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 fabs_float(double);
float sqrtfcn(float val) {
  float x = val / 10;
  float 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 (fabs_float(diff) <= min_tol)
          flag = 1;
      } else {
      }
    }
  }
  return (x);
}


x86 assembly (clang, -O0):
<sqrtfcn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
movss  0xee6(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x8(%rbp)
movsd  0xec5(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x28(%rbp)
movss  -0x4(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    116b <sqrtfcn+0x5b>
jp     116b <sqrtfcn+0x5b>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x8(%rbp)
jmp    1251 <sqrtfcn+0x141>
movl   $0x1,-0x24(%rbp)
cmpl   $0x14,-0x24(%rbp)
jge    124c <sqrtfcn+0x13c>
cmpl   $0x0,-0x28(%rbp)
jne    1234 <sqrtfcn+0x124>
movss  -0x4(%rbp),%xmm1
movss  -0x8(%rbp),%xmm0
movss  -0x8(%rbp),%xmm2
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0x8(%rbp),%xmm1
cvtss2sd %xmm1,%xmm2
movsd  0xe49(%rip),%xmm1
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0x8(%rbp),%xmm0
addss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0x4(%rbp),%xmm1
movss  -0x8(%rbp),%xmm0
movss  -0x8(%rbp),%xmm2
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1030 <fabs_float@plt>
movaps %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     122f <sqrtfcn+0x11f>
movl   $0x1,-0x28(%rbp)
jmp    1239 <sqrtfcn+0x129>
jmp    1239 <sqrtfcn+0x129>
jmp    123e <sqrtfcn+0x12e>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1172 <sqrtfcn+0x62>
jmp    1251 <sqrtfcn+0x141>
movss  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqrtfcn>:
push   %rbp
push   %rbx
push   %rax
xorps  %xmm1,%xmm1
movss  %xmm0,(%rsp)
ucomiss %xmm1,%xmm0
jne    112c <sqrtfcn+0x1c>
jp     112c <sqrtfcn+0x1c>
movaps %xmm1,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
movss  (%rsp),%xmm0
divss  0xec7(%rip),%xmm0
xor    %ebp,%ebp
mov    $0x13,%ebx
jmp    115e <sqrtfcn+0x4e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movss  0x4(%rsp),%xmm1
movaps %xmm1,%xmm0
add    $0xffffffff,%ebx
je     1122 <sqrtfcn+0x12>
mov    %ebp,%eax
mov    $0x1,%ebp
test   %eax,%eax
je     1170 <sqrtfcn+0x60>
movaps %xmm0,%xmm1
jmp    1156 <sqrtfcn+0x46>
xchg   %ax,%ax
movaps %xmm0,%xmm1
mulss  %xmm0,%xmm1
movss  (%rsp),%xmm3
movaps %xmm3,%xmm2
subss  %xmm1,%xmm2
xorps  %xmm1,%xmm1
cvtss2sd %xmm2,%xmm1
xorps  %xmm2,%xmm2
cvtss2sd %xmm0,%xmm2
addsd  %xmm2,%xmm2
divsd  %xmm2,%xmm1
cvtsd2ss %xmm1,%xmm1
addss  %xmm0,%xmm1
movss  %xmm1,0x4(%rsp)
movaps %xmm1,%xmm0
mulss  %xmm1,%xmm0
movaps %xmm3,%xmm1
subss  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
call   1030 <fabs_float@plt>
movsd  0xe3f(%rip),%xmm1
ucomisd %xmm0,%xmm1
jae    1150 <sqrtfcn+0x40>
xor    %ebp,%ebp
jmp    1150 <sqrtfcn+0x40>

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

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