#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 */
int /*<<< orphan*/ EDOM;
float INFINITY;
float NAN;
float __sqrt_approx(float);
int /*<<< orphan*/ errno;
scalar_t__ isinf(float);
scalar_t__ isnan(float);
float sqrtf(float x) {
  float y;
  if (x < 0.0) {
    errno = EDOM;
    return NAN;
  }
  if (isnan(x))
    return NAN;
  if (isinf(x))
    return INFINITY;
  if (x == 0.0)
    return 0.0;
  y = __sqrt_approx(x);
  y = 0.5 * (y + x / y);
  y = 0.5 * (y + x / y);
  y = 0.5 * (y + x / y);
  return y;
}


x86 assembly (clang, -O0):
<sqrtf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    117a <sqrtf+0x4a>
mov    0x2e7e(%rip),%rax
mov    (%rax),%ecx
mov    0x2e65(%rip),%rax
mov    %ecx,(%rax)
mov    0x2e8c(%rip),%rax
movss  (%rax),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1292 <sqrtf+0x162>
movss  -0x8(%rbp),%xmm0
call   1040 <isnan@plt>
cmp    $0x0,%rax
je     11a3 <sqrtf+0x73>
mov    0x2e63(%rip),%rax
movss  (%rax),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1292 <sqrtf+0x162>
movss  -0x8(%rbp),%xmm0
call   1050 <isinf@plt>
cmp    $0x0,%rax
je     11cc <sqrtf+0x9c>
mov    0x2e22(%rip),%rax
movss  (%rax),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1292 <sqrtf+0x162>
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11f5 <sqrtf+0xc5>
jp     11f5 <sqrtf+0xc5>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1292 <sqrtf+0x162>
movss  -0x8(%rbp),%xmm0
call   1030 <__sqrt_approx@plt>
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
movss  -0x8(%rbp),%xmm1
divss  -0xc(%rbp),%xmm1
addss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xddd(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
movss  -0x8(%rbp),%xmm1
divss  -0xc(%rbp),%xmm1
addss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xdb1(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
movss  -0x8(%rbp),%xmm1
divss  -0xc(%rbp),%xmm1
addss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xd85(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqrtf>:
push   %rax
xorps  %xmm1,%xmm1
ucomiss %xmm0,%xmm1
jbe    114d <sqrtf+0x1d>
mov    0x2e98(%rip),%rax
mov    (%rax),%eax
mov    0x2e7f(%rip),%rcx
mov    %eax,(%rcx)
jmp    115d <sqrtf+0x2d>
movss  %xmm0,0x4(%rsp)
call   1040 <isnan@plt>
test   %rax,%rax
je     116a <sqrtf+0x3a>
mov    0x2e94(%rip),%rax
movss  (%rax),%xmm0
pop    %rax
ret
movss  0x4(%rsp),%xmm0
call   1050 <isinf@plt>
test   %rax,%rax
je     1183 <sqrtf+0x53>
mov    0x2e5f(%rip),%rax
jmp    1164 <sqrtf+0x34>
xorps  %xmm0,%xmm0
movss  0x4(%rsp),%xmm1
ucomiss %xmm0,%xmm1
jne    1193 <sqrtf+0x63>
jnp    11d9 <sqrtf+0xa9>
movaps %xmm1,%xmm0
call   1030 <__sqrt_approx@plt>
movss  0x4(%rsp),%xmm3
movaps %xmm3,%xmm1
divss  %xmm0,%xmm1
addss  %xmm0,%xmm1
movss  0xe4c(%rip),%xmm0
mulss  %xmm0,%xmm1
movaps %xmm3,%xmm2
divss  %xmm1,%xmm2
addss  %xmm1,%xmm2
mulss  %xmm0,%xmm2
movaps %xmm3,%xmm1
divss  %xmm2,%xmm1
addss  %xmm2,%xmm1
mulss  %xmm0,%xmm1
movaps %xmm1,%xmm0
pop    %rax
ret

LLVM IR (-O0):
@EDOM = global i32 0
@errno = global i32 0
@NAN = global float 0.000000e+00
@INFINITY = global float 0.000000e+00
define float @sqrtf(float %0) {
%2 = alloca float
%3 = alloca float
%4 = alloca float
store float %0, float* %3
%5 = load float, float* %3
%6 = fpext float %5 to double
%7 = fcmp olt double %6, 0.000000e+00
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i32, i32* @EDOM
store i32 %9, i32* @errno
%10 = load float, float* @NAN
store float %10, float* %2
br label %56
11: ; preds = %1
%12 = load float, float* %3
%13 = call i64 @isnan(float %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = load float, float* @NAN
store float %16, float* %2
br label %56
17: ; preds = %11
%18 = load float, float* %3
%19 = call i64 @isinf(float %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = load float, float* @INFINITY
store float %22, float* %2
br label %56
23: ; preds = %17
%24 = load float, float* %3
%25 = fpext float %24 to double
%26 = fcmp oeq double %25, 0.000000e+00
br i1 %26, label %27, label %28
27: ; preds = %23
store float 0.000000e+00, float* %2
br label %56
28: ; preds = %23
%29 = load float, float* %3
%30 = call float @__sqrt_approx(float %29)
store float %30, float* %4
%31 = load float, float* %4
%32 = load float, float* %3
%33 = load float, float* %4
%34 = fdiv float %32, %33
%35 = fadd float %31, %34
%36 = fpext float %35 to double
%37 = fmul double 5.000000e-01, %36
%38 = fptrunc double %37 to float
store float %38, float* %4
%39 = load float, float* %4
%40 = load float, float* %3
%41 = load float, float* %4
%42 = fdiv float %40, %41
%43 = fadd float %39, %42
%44 = fpext float %43 to double
%45 = fmul double 5.000000e-01, %44
%46 = fptrunc double %45 to float
store float %46, float* %4
%47 = load float, float* %4
%48 = load float, float* %3
%49 = load float, float* %4
%50 = fdiv float %48, %49
%51 = fadd float %47, %50
%52 = fpext float %51 to double
%53 = fmul double 5.000000e-01, %52
%54 = fptrunc double %53 to float
store float %54, float* %4
%55 = load float, float* %4
store float %55, float* %2
br label %56
56: ; preds = %28, %27, %21, %15, %8
%57 = load float, float* %2
ret float %57
}

LLVM IR (-O2):
@EDOM = global i32 0
@errno = global i32 0
@NAN = global float 0.000000e+00
@INFINITY = global float 0.000000e+00
define float @sqrtf(float %0) {
%2 = fcmp olt float %0, 0.000000e+00
br i1 %2, label %3, label %6
3: ; preds = %1
%4 = load i32, i32* @EDOM
store i32 %4, i32* @errno
%5 = load float, float* @NAN
br label %29
6: ; preds = %1
%7 = tail call i64 @isnan(float %0)
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %6
%10 = load float, float* @NAN
br label %29
11: ; preds = %6
%12 = tail call i64 @isinf(float %0)
%13 = icmp eq i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %11
%15 = load float, float* @INFINITY
br label %29
16: ; preds = %11
%17 = fcmp oeq float %0, 0.000000e+00
br i1 %17, label %29, label %18
18: ; preds = %16
%19 = tail call float @__sqrt_approx(float %0)
%20 = fdiv float %0, %19
%21 = fadd float %19, %20
%22 = fmul float %21, 5.000000e-01
%23 = fdiv float %0, %22
%24 = fadd float %22, %23
%25 = fmul float %24, 5.000000e-01
%26 = fdiv float %0, %25
%27 = fadd float %25, %26
%28 = fmul float %27, 5.000000e-01
br label %29
29: ; preds = %16, %18, %14, %9, %3
%30 = phi float [ %5, %3 ], [ %10, %9 ], [ %15, %14 ], [ %28, %18 ], [ 0.000000e+00, %16 ]
ret float %30
}