#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 FP_ILOGB0;
int FP_ILOGBNAN;
int INT_MAX;
int __approx_log2l(long double);
scalar_t__ isinf(long double);
scalar_t__ isnan(long double);
int ilogbl(long double x) {
  if (isnan(x))
    return FP_ILOGBNAN;
  if (isinf(x))
    return INT_MAX;
  if (!x)
    return FP_ILOGB0;
  return __approx_log2l(x);
}


x86 assembly (clang, -O0):
<ilogbl>:
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     1166 <ilogbl+0x36>
mov    0x2e74(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11cb <ilogbl+0x9b>
fldt   -0x20(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
call   1050 <isinf@plt>
cmp    $0x0,%rax
je     118e <ilogbl+0x5e>
mov    0x2e64(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11cb <ilogbl+0x9b>
fldt   -0x20(%rbp)
fldz
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jne    11bb <ilogbl+0x8b>
jp     11bb <ilogbl+0x8b>
jmp    11aa <ilogbl+0x7a>
mov    0x2e27(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11cb <ilogbl+0x9b>
fldt   -0x20(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
call   1040 <__approx_log2l@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ilogbl>:
sub    $0x28,%rsp
fldt   0x30(%rsp)
fld    %st(0)
fstpt  0x1c(%rsp)
fstpt  (%rsp)
call   1030 <isnan@plt>
test   %rax,%rax
je     1154 <ilogbl+0x24>
mov    0x2e7e(%rip),%rax
jmp    116c <ilogbl+0x3c>
fldt   0x1c(%rsp)
fstpt  (%rsp)
call   1050 <isinf@plt>
test   %rax,%rax
je     1173 <ilogbl+0x43>
mov    0x2e7c(%rip),%rax
mov    (%rax),%eax
add    $0x28,%rsp
ret
fldz
fldt   0x1c(%rsp)
fucomip %st(1),%st
fstp   %st(0)
jne    1181 <ilogbl+0x51>
jnp    1192 <ilogbl+0x62>
fldt   0x1c(%rsp)
fstpt  (%rsp)
call   1040 <__approx_log2l@plt>
add    $0x28,%rsp
ret
mov    0x2e3f(%rip),%rax
jmp    116c <ilogbl+0x3c>

LLVM IR (-O0):
@FP_ILOGBNAN = global i32 0
@INT_MAX = global i32 0
@FP_ILOGB0 = global i32 0
define i32 @ilogbl(x86_fp80 %0) {
%2 = alloca i32
%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 i32, i32* @FP_ILOGBNAN
store i32 %8, i32* %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 i32, i32* @INT_MAX
store i32 %14, i32* %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* @FP_ILOGB0
store i32 %19, i32* %2
br label %23
20: ; preds = %15
%21 = load x86_fp80, x86_fp80* %3
%22 = call i32 @__approx_log2l(x86_fp80 %21)
store i32 %22, i32* %2
br label %23
23: ; preds = %20, %18, %13, %7
%24 = load i32, i32* %2
ret i32 %24
}

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