#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*/ ERANGE;
long double __approx_log2l(long double);
int /*<<< orphan*/ errno;
scalar_t__ isinf(long double);
scalar_t__ isnan(long double);
long double logbl(long double x) {
  if (isnan(x))
    return x;
  if (isinf(x))
    return x;
  if (!x) {
    errno = ERANGE;
    return 0;
  }
  return __approx_log2l(x);
}


x86 assembly (clang, -O0):
<logbl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
fldt   0x10(%rbp)
fstpt  -0x20(%rbp)
fldt   -0x20(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
call   1030 <isnan@plt>
cmp    $0x0,%rax
je     1160 <logbl+0x30>
fldt   -0x20(%rbp)
fstpt  -0x10(%rbp)
jmp    11ca <logbl+0x9a>
fldt   -0x20(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
call   1050 <isinf@plt>
cmp    $0x0,%rax
je     1182 <logbl+0x52>
fldt   -0x20(%rbp)
fstpt  -0x10(%rbp)
jmp    11ca <logbl+0x9a>
fldt   -0x20(%rbp)
fldz
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jne    11ba <logbl+0x8a>
jp     11ba <logbl+0x8a>
jmp    119e <logbl+0x6e>
mov    0x2e43(%rip),%rax
mov    (%rax),%ecx
mov    0x2e2a(%rip),%rax
mov    %ecx,(%rax)
fldz
fstpt  -0x10(%rbp)
jmp    11ca <logbl+0x9a>
fldt   -0x20(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
call   1040 <__approx_log2l@plt>
fstpt  -0x10(%rbp)
fldt   -0x10(%rbp)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<logbl>:
sub    $0x28,%rsp
fldt   0x30(%rsp)
fld    %st(0)
fstpt  0x1c(%rsp)
fstpt  (%rsp)
call   1030 <isnan@plt>
test   %rax,%rax
jne    115c <logbl+0x2c>
fldt   0x1c(%rsp)
fstpt  (%rsp)
call   1050 <isinf@plt>
test   %rax,%rax
je     1165 <logbl+0x35>
fldt   0x1c(%rsp)
add    $0x28,%rsp
ret
fldz
fldt   0x1c(%rsp)
fucomip %st(1),%st
jne    1171 <logbl+0x41>
jnp    1184 <logbl+0x54>
fstp   %st(0)
fldt   0x1c(%rsp)
fstpt  (%rsp)
call   1040 <__approx_log2l@plt>
add    $0x28,%rsp
ret
mov    0x2e5d(%rip),%rax
mov    (%rax),%eax
mov    0x2e44(%rip),%rcx
mov    %eax,(%rcx)
add    $0x28,%rsp
ret

LLVM IR (-O0):
@ERANGE = global i32 0
@errno = global i32 0
define x86_fp80 @logbl(x86_fp80 %0) {
%2 = alloca x86_fp80
%3 = alloca x86_fp80
store x86_fp80 %0, x86_fp80* %3
%4 = load x86_fp80, x86_fp80* %3
%5 = call i64 @isnan(x86_fp80 %4)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = load x86_fp80, x86_fp80* %3
store x86_fp80 %8, x86_fp80* %2
br label %23
9: ; preds = %1
%10 = load x86_fp80, x86_fp80* %3
%11 = call i64 @isinf(x86_fp80 %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = load x86_fp80, x86_fp80* %3
store x86_fp80 %14, x86_fp80* %2
br label %23
15: ; preds = %9
%16 = load x86_fp80, x86_fp80* %3
%17 = fcmp une x86_fp80 %16, 0xK00000000000000000000
br i1 %17, label %20, label %18
18: ; preds = %15
%19 = load i32, i32* @ERANGE
store i32 %19, i32* @errno
store x86_fp80 0xK00000000000000000000, x86_fp80* %2
br label %23
20: ; preds = %15
%21 = load x86_fp80, x86_fp80* %3
%22 = call x86_fp80 @__approx_log2l(x86_fp80 %21)
store x86_fp80 %22, x86_fp80* %2
br label %23
23: ; preds = %20, %18, %13, %7
%24 = load x86_fp80, x86_fp80* %2
ret x86_fp80 %24
}

LLVM IR (-O2):
@ERANGE = global i32 0
@errno = global i32 0
define x86_fp80 @logbl(x86_fp80 %0) {
%2 = tail call i64 @isnan(x86_fp80 %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %13
4: ; preds = %1
%5 = tail call i64 @isinf(x86_fp80 %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %13
7: ; preds = %4
%8 = fcmp une x86_fp80 %0, 0xK00000000000000000000
br i1 %8, label %11, label %9
9: ; preds = %7
%10 = load i32, i32* @ERANGE
store i32 %10, i32* @errno
br label %13
11: ; preds = %7
%12 = tail call x86_fp80 @__approx_log2l(x86_fp80 %0)
br label %13
13: ; preds = %4, %1, %11, %9
%14 = phi x86_fp80 [ %12, %11 ], [ 0xK00000000000000000000, %9 ], [ %0, %1 ], [ %0, %4 ]
ret x86_fp80 %14
}