#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(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(diff) <= min_tol)
          flag = 1;
      } else {
      }
    }
  }
  return (x);
}


x86 assembly (clang, -O0):
<sqrtfcn>:
push   %rbp
mov    %rsp,%rbp
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
movss  0xefa(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x8(%rbp)
movsd  0xed9(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x28(%rbp)
movss  -0x4(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    1157 <sqrtfcn+0x57>
jp     1157 <sqrtfcn+0x57>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x8(%rbp)
jmp    1240 <sqrtfcn+0x140>
movl   $0x1,-0x24(%rbp)
cmpl   $0x14,-0x24(%rbp)
jge    123b <sqrtfcn+0x13b>
cmpl   $0x0,-0x28(%rbp)
jne    1223 <sqrtfcn+0x123>
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  0xe5d(%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),%xmm1
movaps 0xe1c(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     121e <sqrtfcn+0x11e>
movl   $0x1,-0x28(%rbp)
jmp    1228 <sqrtfcn+0x128>
jmp    1228 <sqrtfcn+0x128>
jmp    122d <sqrtfcn+0x12d>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    115e <sqrtfcn+0x5e>
jmp    1240 <sqrtfcn+0x140>
movss  -0x8(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqrtfcn>:
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    110e <sqrtfcn+0xe>
jp     110e <sqrtfcn+0xe>
movaps %xmm1,%xmm0
ret
movaps %xmm0,%xmm4
divss  0xee7(%rip),%xmm4
xor    %ecx,%ecx
mov    $0x13,%eax
movaps 0xee9(%rip),%xmm2
movsd  0xef1(%rip),%xmm3
jmp    114b <sqrtfcn+0x4b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movaps %xmm4,%xmm1
movaps %xmm1,%xmm4
add    $0xffffffff,%eax
je     110a <sqrtfcn+0xa>
mov    %ecx,%edx
mov    $0x1,%ecx
test   %edx,%edx
jne    1140 <sqrtfcn+0x40>
movaps %xmm4,%xmm1
mulss  %xmm4,%xmm1
movaps %xmm0,%xmm5
subss  %xmm1,%xmm5
xorps  %xmm1,%xmm1
cvtss2sd %xmm5,%xmm1
xorps  %xmm5,%xmm5
cvtss2sd %xmm4,%xmm5
addsd  %xmm5,%xmm5
divsd  %xmm5,%xmm1
cvtsd2ss %xmm1,%xmm1
addss  %xmm4,%xmm1
movaps %xmm1,%xmm4
mulss  %xmm1,%xmm4
movaps %xmm0,%xmm5
subss  %xmm4,%xmm5
andps  %xmm2,%xmm5
xorps  %xmm4,%xmm4
cvtss2sd %xmm5,%xmm4
ucomisd %xmm4,%xmm3
jae    1143 <sqrtfcn+0x43>
xor    %ecx,%ecx
jmp    1143 <sqrtfcn+0x43>

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 @llvm.fabs.f64(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 = tail call float @llvm.fabs.f32(float %20)
%22 = fpext float %21 to double
%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
}