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


x86 assembly (clang, -O0):
<logbf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
call   1040 <isnan@plt>
cmp    $0x0,%rax
je     1160 <logbf+0x30>
movss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    11c8 <logbf+0x98>
movss  -0x8(%rbp),%xmm0
call   1050 <isinf@plt>
cmp    $0x0,%rax
je     1183 <logbf+0x53>
movss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    11c8 <logbf+0x98>
movss  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    11b9 <logbf+0x89>
jp     11b9 <logbf+0x89>
mov    0x2e47(%rip),%rax
mov    (%rax),%ecx
mov    0x2e2e(%rip),%rax
mov    %ecx,(%rax)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    11c8 <logbf+0x98>
movss  -0x8(%rbp),%xmm0
call   1030 <__approx_log2f@plt>
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<logbf>:
push   %rax
movss  %xmm0,0x4(%rsp)
call   1040 <isnan@plt>
test   %rax,%rax
jne    1151 <logbf+0x21>
movss  0x4(%rsp),%xmm0
call   1050 <isinf@plt>
test   %rax,%rax
je     1159 <logbf+0x29>
movss  0x4(%rsp),%xmm0
pop    %rax
ret
xorps  %xmm0,%xmm0
movss  0x4(%rsp),%xmm1
ucomiss %xmm0,%xmm1
jne    1169 <logbf+0x39>
jnp    1175 <logbf+0x45>
movss  0x4(%rsp),%xmm0
pop    %rax
jmp    1030 <__approx_log2f@plt>
mov    0x2e6c(%rip),%rax
mov    (%rax),%eax
mov    0x2e53(%rip),%rcx
mov    %eax,(%rcx)
pop    %rax
ret

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

LLVM IR (-O2):
@ERANGE = global i32 0
@errno = global i32 0
define float @logbf(float %0) {
%2 = tail call i64 @isnan(float %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %13
4: ; preds = %1
%5 = tail call i64 @isinf(float %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %13
7: ; preds = %4
%8 = fcmp une float %0, 0.000000e+00
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 float @__approx_log2f(float %0)
br label %13
13: ; preds = %4, %1, %11, %9
%14 = phi float [ %12, %11 ], [ 0.000000e+00, %9 ], [ %0, %1 ], [ %0, %4 ]
ret float %14
}