#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 */
float frexpf(float const, int *);
float ldexpf(float, int);
float sqrtf(const float x) {
  float f, y;
  int n;
  if (x == 0.0)
    return x;
  else if (x == 1.0)
    return 1.0;
  else if (x < 0.0) {
    return 0.0;
  }
  f = frexpf(x, &n);
  y = 0.41731 + 0.59016 * f;
  y += f / y;
  y = ldexpf(y, -2) + f / y;
  if (n & 1) {
    y *= 0.7071067812;
    ++n;
  }
  return ldexpf(y, n / 2);
}


x86 assembly (clang, -O0):
<sqrtf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1158 <sqrtf+0x38>
jp     1158 <sqrtf+0x38>
movss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    127d <sqrtf+0x15d>
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe97(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    118b <sqrtf+0x6b>
jp     118b <sqrtf+0x6b>
movss  0xe9f(%rip),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    127d <sqrtf+0x15d>
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    11ae <sqrtf+0x8e>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    127d <sqrtf+0x15d>
jmp    11b3 <sqrtf+0x93>
jmp    11b8 <sqrtf+0x98>
movss  -0x8(%rbp),%xmm0
lea    -0x14(%rbp),%rdi
call   1030 <frexpf@plt>
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe2c(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe28(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0xc(%rbp),%xmm0
divss  -0x10(%rbp),%xmm0
addss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
mov    $0xfffffffe,%edi
call   1040 <ldexpf@plt>
movss  -0xc(%rbp),%xmm1
divss  -0x10(%rbp),%xmm1
addss  %xmm1,%xmm0
movss  %xmm0,-0x10(%rbp)
mov    -0x14(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1261 <sqrtf+0x141>
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xdcd(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
movss  -0x10(%rbp),%xmm0
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   1040 <ldexpf@plt>
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqrtf>:
sub    $0x18,%rsp
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    1133 <sqrtf+0x13>
jp     1133 <sqrtf+0x13>
movaps %xmm0,%xmm1
jmp    114a <sqrtf+0x2a>
movss  0xec5(%rip),%xmm1
ucomiss %xmm1,%xmm0
jne    1142 <sqrtf+0x22>
jnp    114a <sqrtf+0x2a>
xorps  %xmm1,%xmm1
ucomiss %xmm0,%xmm1
jbe    1152 <sqrtf+0x32>
movaps %xmm1,%xmm0
add    $0x18,%rsp
ret
lea    0x14(%rsp),%rdi
call   1030 <frexpf@plt>
movss  %xmm0,0x10(%rsp)
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
mulsd  0xe97(%rip),%xmm1
addsd  0xe97(%rip),%xmm1
cvtsd2ss %xmm1,%xmm1
divss  %xmm1,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,0xc(%rsp)
mov    $0xfffffffe,%edi
call   1040 <ldexpf@plt>
movss  0x10(%rsp),%xmm1
divss  0xc(%rsp),%xmm1
addss  %xmm0,%xmm1
movaps %xmm1,%xmm0
mov    0x14(%rsp),%eax
mov    %eax,%ecx
and    $0x1,%ecx
add    %ecx,%eax
test   %ecx,%ecx
je     11c7 <sqrtf+0xa7>
cvtss2sd %xmm0,%xmm0
mulsd  0xe55(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
mov    %eax,%edi
shr    $0x1f,%edi
add    %eax,%edi
sar    %edi
add    $0x18,%rsp
jmp    1040 <ldexpf@plt>

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

LLVM IR (-O2):
define float @sqrtf(float %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = fcmp oeq float %0, 0.000000e+00
br i1 %4, label %31, label %5
5: ; preds = %1
%6 = fcmp oeq float %0, 1.000000e+00
br i1 %6, label %31, label %7
7: ; preds = %5
%8 = fcmp olt float %0, 0.000000e+00
br i1 %8, label %31, label %9
9: ; preds = %7
%10 = call float @frexpf(float %0, i32* %2)
%11 = fpext float %10 to double
%12 = tail call double @llvm.fmuladd.f64(double %11, double 5.901600e-01, double 4.173100e-01)
%13 = fptrunc double %12 to float
%14 = fdiv float %10, %13
%15 = fadd float %14, %13
%16 = tail call float @ldexpf(float %15, i32 -2)
%17 = fdiv float %10, %15
%18 = fadd float %16, %17
%19 = load i32, i32* %2
%20 = and i32 %19, 1
%21 = icmp eq i32 %20, 0
%22 = fpext float %18 to double
%23 = fmul double %22, 0x3FE6A09E6681151E
%24 = fptrunc double %23 to float
%25 = xor i1 %21, true
%26 = zext i1 %25 to i32
%27 = add nsw i32 %19, %26
%28 = select i1 %21, float %18, float %24
%29 = sdiv i32 %27, 2
%30 = tail call float @ldexpf(float %28, i32 %29)
br label %31
31: ; preds = %7, %5, %1, %9
%32 = phi float [ %30, %9 ], [ %0, %1 ], [ 1.000000e+00, %5 ], [ 0.000000e+00, %7 ]
ret float %32
}