#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*/ frexpl(long double, int *);
long double ldexpl(long double, int);
scalar_t__ sqrt(int);
long double sqrtl(long double x) {
  long double delta, y;
  int exponent;
  if (x < 0.0L)
    return (long double)sqrt(-1);
  if (x + x == x || x != x)
    return x;
  frexpl(x, &exponent);
  y = ldexpl(x, -exponent / 2);
  do {
    delta = y;
    y = (y + x / y) * 0.5L;
    delta -= y;
  } while (delta != 0.0L);
  return y;
}


x86 assembly (clang, -O0):
<sqrtl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
fldt   0x10(%rbp)
fstpt  -0x20(%rbp)
fldt   -0x20(%rbp)
fldz
fucomip %st(1),%st
fstp   %st(0)
jbe    116b <sqrtl+0x3b>
jmp    1152 <sqrtl+0x22>
mov    $0xffffffff,%edi
call   1050 <sqrt@plt>
mov    %rax,-0x50(%rbp)
fildll -0x50(%rbp)
fstpt  -0x10(%rbp)
jmp    1219 <sqrtl+0xe9>
fldt   -0x20(%rbp)
fld    %st(0)
fadd   %st(1),%st
fucomip %st(1),%st
fstp   %st(0)
jne    1187 <sqrtl+0x57>
jp     1187 <sqrtl+0x57>
jmp    1197 <sqrtl+0x67>
fldt   -0x20(%rbp)
fucomip %st(0),%st
jnp    11a2 <sqrtl+0x72>
jmp    1197 <sqrtl+0x67>
fldt   -0x20(%rbp)
fstpt  -0x10(%rbp)
jmp    1219 <sqrtl+0xe9>
fldt   -0x20(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
lea    -0x44(%rbp),%rdi
call   1030 <frexpl@plt>
fldt   -0x20(%rbp)
mov    -0x44(%rbp),%eax
mov    %eax,%edi
neg    %edi
shr    $0x1f,%edi
sub    %eax,%edi
sar    %edi
mov    %rsp,%rax
fstpt  (%rax)
call   1040 <ldexpl@plt>
fstpt  -0x40(%rbp)
fldt   -0x40(%rbp)
fstpt  -0x30(%rbp)
fldt   -0x40(%rbp)
fldt   -0x20(%rbp)
fdiv   %st(1),%st
faddp  %st,%st(1)
flds   0xe19(%rip)
fmulp  %st,%st(1)
fstpt  -0x40(%rbp)
fldt   -0x40(%rbp)
fldt   -0x30(%rbp)
fsubp  %st,%st(1)
fstpt  -0x30(%rbp)
fldt   -0x30(%rbp)
fldz
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jne    11d1 <sqrtl+0xa1>
jp     11d1 <sqrtl+0xa1>
jmp    1213 <sqrtl+0xe3>
fldt   -0x40(%rbp)
fstpt  -0x10(%rbp)
fldt   -0x10(%rbp)
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqrtl>:
sub    $0x38,%rsp
fldt   0x40(%rsp)
fldz
fucomi %st(1),%st
jbe    1157 <sqrtl+0x27>
fstp   %st(1)
fstp   %st(0)
mov    $0xffffffff,%edi
call   1050 <sqrt@plt>
mov    %rax,0x20(%rsp)
fildll 0x20(%rsp)
jmp    11d4 <sqrtl+0xa4>
fld    %st(1)
fadd   %st(2),%st
fxch   %st(2)
fucomi %st(0),%st
jp     11d0 <sqrtl+0xa0>
fxch   %st(2)
fucomip %st(2),%st
jne    1169 <sqrtl+0x39>
jnp    11d2 <sqrtl+0xa2>
fld    %st(1)
fstpt  (%rsp)
lea    0x10(%rsp),%rdi
fxch   %st(1)
fstpt  0x14(%rsp)
fstpt  0x2c(%rsp)
call   1030 <frexpl@plt>
mov    0x10(%rsp),%eax
mov    %eax,%edi
shr    $0x1f,%edi
add    %eax,%edi
sar    %edi
neg    %edi
fldt   0x14(%rsp)
fstpt  (%rsp)
call   1040 <ldexpl@plt>
fldt   0x2c(%rsp)
fldt   0x14(%rsp)
fldz
fxch   %st(3)
fxch   %st(2)
nopl   0x0(%rax,%rax,1)
fstp   %st(3)
fld    %st(0)
fdiv   %st(2),%st
fadd   %st(2),%st
fmuls  0xe42(%rip)
fsubr  %st,%st(2)
fxch   %st(2)
fucomip %st(3),%st
fld    %st(1)
fxch   %st(2)
fxch   %st(3)
jne    11b0 <sqrtl+0x80>
jp     11b0 <sqrtl+0x80>
jmp    11da <sqrtl+0xaa>
fstp   %st(2)
fstp   %st(0)
fldz
fldz
fldz
fstp   %st(2)
fstp   %st(0)
fstp   %st(0)
add    $0x38,%rsp
ret

LLVM IR (-O0):
define x86_fp80 @sqrtl(x86_fp80 %0) {
%2 = alloca x86_fp80
%3 = alloca x86_fp80
%4 = alloca x86_fp80
%5 = alloca x86_fp80
%6 = alloca i32
store x86_fp80 %0, x86_fp80* %3
%7 = load x86_fp80, x86_fp80* %3
%8 = fcmp olt x86_fp80 %7, 0xK00000000000000000000
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = call i64 @sqrt(i32 -1)
%11 = sitofp i64 %10 to x86_fp80
store x86_fp80 %11, x86_fp80* %2
br label %48
12: ; preds = %1
%13 = load x86_fp80, x86_fp80* %3
%14 = load x86_fp80, x86_fp80* %3
%15 = fadd x86_fp80 %13, %14
%16 = load x86_fp80, x86_fp80* %3
%17 = fcmp oeq x86_fp80 %15, %16
br i1 %17, label %22, label %18
18: ; preds = %12
%19 = load x86_fp80, x86_fp80* %3
%20 = load x86_fp80, x86_fp80* %3
%21 = fcmp une x86_fp80 %19, %20
br i1 %21, label %22, label %24
22: ; preds = %18, %12
%23 = load x86_fp80, x86_fp80* %3
store x86_fp80 %23, x86_fp80* %2
br label %48
24: ; preds = %18
%25 = load x86_fp80, x86_fp80* %3
%26 = call i32 @frexpl(x86_fp80 %25, i32* %6)
%27 = load x86_fp80, x86_fp80* %3
%28 = load i32, i32* %6
%29 = sub nsw i32 0, %28
%30 = sdiv i32 %29, 2
%31 = call x86_fp80 @ldexpl(x86_fp80 %27, i32 %30)
store x86_fp80 %31, x86_fp80* %5
br label %32
32: ; preds = %43, %24
%33 = load x86_fp80, x86_fp80* %5
store x86_fp80 %33, x86_fp80* %4
%34 = load x86_fp80, x86_fp80* %5
%35 = load x86_fp80, x86_fp80* %3
%36 = load x86_fp80, x86_fp80* %5
%37 = fdiv x86_fp80 %35, %36
%38 = fadd x86_fp80 %34, %37
%39 = fmul x86_fp80 %38, 0xK3FFE8000000000000000
store x86_fp80 %39, x86_fp80* %5
%40 = load x86_fp80, x86_fp80* %5
%41 = load x86_fp80, x86_fp80* %4
%42 = fsub x86_fp80 %41, %40
store x86_fp80 %42, x86_fp80* %4
br label %43
43: ; preds = %32
%44 = load x86_fp80, x86_fp80* %4
%45 = fcmp une x86_fp80 %44, 0xK00000000000000000000
br i1 %45, label %32, label %46
46: ; preds = %43
%47 = load x86_fp80, x86_fp80* %5
store x86_fp80 %47, x86_fp80* %2
br label %48
48: ; preds = %46, %22, %9
%49 = load x86_fp80, x86_fp80* %2
ret x86_fp80 %49
}

LLVM IR (-O2):
define x86_fp80 @sqrtl(x86_fp80 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = fcmp olt x86_fp80 %0, 0xK00000000000000000000
br i1 %4, label %5, label %8
5: ; preds = %1
%6 = tail call i64 @sqrt(i32 -1)
%7 = sitofp i64 %6 to x86_fp80
br label %25
8: ; preds = %1
%9 = fadd x86_fp80 %0, %0
%10 = fcmp oeq x86_fp80 %9, %0
%11 = fcmp uno x86_fp80 %0, 0xK00000000000000000000
%12 = or i1 %11, %10
br i1 %12, label %25, label %13
13: ; preds = %8
%14 = call i32 @frexpl(x86_fp80 %0, i32* %2)
%15 = load i32, i32* %2
%16 = sdiv i32 %15, -2
%17 = tail call x86_fp80 @ldexpl(x86_fp80 %0, i32 %16)
br label %18
18: ; preds = %18, %13
%19 = phi x86_fp80 [ %17, %13 ], [ %22, %18 ]
%20 = fdiv x86_fp80 %0, %19
%21 = fadd x86_fp80 %19, %20
%22 = fmul x86_fp80 %21, 0xK3FFE8000000000000000
%23 = fsub x86_fp80 %19, %22
%24 = fcmp une x86_fp80 %23, 0xK00000000000000000000
br i1 %24, label %18, label %25
25: ; preds = %18, %8, %5
%26 = phi x86_fp80 [ %7, %5 ], [ %0, %8 ], [ %22, %18 ]
ret x86_fp80 %26
}