#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 INT_MAX;
int /*<<< orphan*/ fabsk(double);
int ilogbk(int /*<<< orphan*/);
scalar_t__ xisinf(double);
scalar_t__ xisnan(double);
__attribute__((visibility("default"))) const int xilogb(double d) {
  int e = ilogbk(fabsk(d));
  e = d == 0.0 ? ((int)-2147483648) : e;
  e = xisnan(d) ? ((int)2147483647) : e;
  e = xisinf(d) ? INT_MAX : e;
  return e;
}


x86 assembly (clang, -O0):
<xilogb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1050 <fabsk@plt>
mov    %eax,%edi
call   1060 <ilogbk@plt>
mov    %eax,-0xc(%rbp)
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1186 <xilogb+0x46>
jp     1186 <xilogb+0x46>
mov    $0x80000000,%eax
mov    %eax,-0x10(%rbp)
jmp    118c <xilogb+0x4c>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1030 <xisnan@plt>
cmp    $0x0,%rax
je     11b3 <xilogb+0x73>
mov    $0x7fffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    11b9 <xilogb+0x79>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0xc(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1040 <xisinf@plt>
cmp    $0x0,%rax
je     11e4 <xilogb+0xa4>
mov    0x2e0e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    11ea <xilogb+0xaa>
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xilogb>:
push   %rbp
push   %rbx
push   %rax
movsd  %xmm0,(%rsp)
call   1050 <fabsk@plt>
mov    %eax,%edi
call   1060 <ilogbk@plt>
xorpd  %xmm1,%xmm1
movsd  (%rsp),%xmm0
ucomisd %xmm1,%xmm0
mov    $0x80000000,%ebp
cmovne %eax,%ebp
cmovp  %eax,%ebp
call   1030 <xisnan@plt>
test   %rax,%rax
mov    $0x7fffffff,%ebx
cmove  %ebp,%ebx
movsd  (%rsp),%xmm0
call   1040 <xisinf@plt>
test   %rax,%rax
je     1194 <xilogb+0x54>
mov    0x2e56(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@INT_MAX = global i32 0
define i32 @xilogb(double %0) {
%2 = alloca double
%3 = alloca i32
store double %0, double* %2
%4 = load double, double* %2
%5 = call i32 @fabsk(double %4)
%6 = call i32 @ilogbk(i32 %5)
store i32 %6, i32* %3
%7 = load double, double* %2
%8 = fcmp oeq double %7, 0.000000e+00
br i1 %8, label %9, label %10
9: ; preds = %1
br label %12
10: ; preds = %1
%11 = load i32, i32* %3
br label %12
12: ; preds = %10, %9
%13 = phi i32 [ -2147483648, %9 ], [ %11, %10 ]
store i32 %13, i32* %3
%14 = load double, double* %2
%15 = call i64 @xisnan(double %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %12
br label %20
18: ; preds = %12
%19 = load i32, i32* %3
br label %20
20: ; preds = %18, %17
%21 = phi i32 [ 2147483647, %17 ], [ %19, %18 ]
store i32 %21, i32* %3
%22 = load double, double* %2
%23 = call i64 @xisinf(double %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %20
%26 = load i32, i32* @INT_MAX
br label %29
27: ; preds = %20
%28 = load i32, i32* %3
br label %29
29: ; preds = %27, %25
%30 = phi i32 [ %26, %25 ], [ %28, %27 ]
store i32 %30, i32* %3
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@INT_MAX = global i32 0
define i32 @xilogb(double %0) {
%2 = tail call i32 @fabsk(double %0)
%3 = tail call i32 @ilogbk(i32 %2)
%4 = fcmp oeq double %0, 0.000000e+00
%5 = select i1 %4, i32 -2147483648, i32 %3
%6 = tail call i64 @xisnan(double %0)
%7 = icmp eq i64 %6, 0
%8 = select i1 %7, i32 %5, i32 2147483647
%9 = tail call i64 @xisinf(double %0)
%10 = icmp eq i64 %9, 0
%11 = load i32, i32* @INT_MAX
%12 = select i1 %10, i32 %8, i32 %11
ret i32 %12
}