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


x86 assembly (clang, -O0):
<ilogb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <isnan@plt>
cmp    $0x0,%rax
je     1162 <ilogb+0x32>
mov    0x2e78(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11bd <ilogb+0x8d>
movsd  -0x10(%rbp),%xmm0
call   1050 <isinf@plt>
cmp    $0x0,%rax
je     1187 <ilogb+0x57>
mov    0x2e6b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11bd <ilogb+0x8d>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11b0 <ilogb+0x80>
jp     11b0 <ilogb+0x80>
mov    0x2e32(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11bd <ilogb+0x8d>
movsd  -0x10(%rbp),%xmm0
call   1030 <__approx_log2@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ilogb>:
push   %rax
movsd  %xmm0,(%rsp)
call   1040 <isnan@plt>
test   %rax,%rax
je     1149 <ilogb+0x19>
mov    0x2e89(%rip),%rax
jmp    115f <ilogb+0x2f>
movsd  (%rsp),%xmm0
call   1050 <isinf@plt>
test   %rax,%rax
je     1163 <ilogb+0x33>
mov    0x2e89(%rip),%rax
mov    (%rax),%eax
pop    %rcx
ret
xorpd  %xmm0,%xmm0
movsd  (%rsp),%xmm1
ucomisd %xmm0,%xmm1
jne    1174 <ilogb+0x44>
jnp    117f <ilogb+0x4f>
movsd  (%rsp),%xmm0
pop    %rax
jmp    1030 <__approx_log2@plt>
mov    0x2e52(%rip),%rax
jmp    115f <ilogb+0x2f>

LLVM IR (-O0):
@FP_ILOGBNAN = global i32 0
@INT_MAX = global i32 0
@FP_ILOGB0 = global i32 0
define i32 @ilogb(double %0) {
%2 = alloca i32
%3 = alloca double
store double %0, double* %3
%4 = load double, double* %3
%5 = call i64 @isnan(double %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 double, double* %3
%11 = call i64 @isinf(double %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 double, double* %3
%17 = fcmp une double %16, 0.000000e+00
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 double, double* %3
%22 = call i32 @__approx_log2(double %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 @ilogb(double %0) {
%2 = tail call i64 @isnan(double %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(double %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 double %0, 0.000000e+00
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_log2(double %0)
br label %17
17: ; preds = %15, %13, %9, %4
%18 = phi i32 [ %5, %4 ], [ %10, %9 ], [ %16, %15 ], [ %14, %13 ]
ret i32 %18
}