#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 */
double __builtin_inf();
int ilogbp1(int /*<<< orphan*/);
int /*<<< orphan*/ xfabs(double);
int xilogb(double d) {
  int e = ilogbp1(xfabs(d)) - 1;
  e = d == 0 ? -2147483648 : e;
  e = d == __builtin_inf() || d == -__builtin_inf() ? 2147483647 : 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   1040 <xfabs@plt>
mov    %eax,%edi
call   1030 <ilogbp1@plt>
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    116c <xilogb+0x4c>
jp     116c <xilogb+0x4c>
mov    $0xffffffff80000000,%rax
mov    %rax,-0x18(%rbp)
jmp    1174 <xilogb+0x54>
movslq -0xc(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %eax,-0xc(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xe78(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    119d <xilogb+0x7d>
jp     119d <xilogb+0x7d>
jmp    11ba <xilogb+0x9a>
movsd  -0x8(%rbp),%xmm0
movsd  0xe5e(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    11c7 <xilogb+0xa7>
jp     11c7 <xilogb+0xa7>
mov    $0x7fffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    11cd <xilogb+0xad>
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xilogb>:
push   %rax
movsd  %xmm0,(%rsp)
call   1040 <xfabs@plt>
mov    %eax,%edi
call   1030 <ilogbp1@plt>
add    $0xffffffff,%eax
xorpd  %xmm0,%xmm0
movsd  (%rsp),%xmm1
ucomisd %xmm0,%xmm1
mov    $0x80000000,%ecx
cmovne %eax,%ecx
cmovnp %ecx,%eax
movsd  0xeab(%rip),%xmm0
ucomisd %xmm1,%xmm0
mov    $0x7fffffff,%ecx
cmovae %ecx,%eax
ucomisd 0xe9f(%rip),%xmm1
cmovae %ecx,%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @xilogb(double %0) {
%2 = alloca double
%3 = alloca i32
store double %0, double* %2
%4 = load double, double* %2
%5 = call i32 @xfabs(double %4)
%6 = call i32 @ilogbp1(i32 %5)
%7 = sub nsw i32 %6, 1
store i32 %7, i32* %3
%8 = load double, double* %2
%9 = fcmp oeq double %8, 0.000000e+00
br i1 %9, label %10, label %11
10: ; preds = %1
br label %14
11: ; preds = %1
%12 = load i32, i32* %3
%13 = sext i32 %12 to i64
br label %14
14: ; preds = %11, %10
%15 = phi i64 [ -2147483648, %10 ], [ %13, %11 ]
%16 = trunc i64 %15 to i32
store i32 %16, i32* %3
%17 = load double, double* %2
%18 = fcmp oeq double %17, 0x7FF0000000000000
br i1 %18, label %22, label %19
19: ; preds = %14
%20 = load double, double* %2
%21 = fcmp oeq double %20, 0xFFF0000000000000
br i1 %21, label %22, label %23
22: ; preds = %19, %14
br label %25
23: ; preds = %19
%24 = load i32, i32* %3
br label %25
25: ; preds = %23, %22
%26 = phi i32 [ 2147483647, %22 ], [ %24, %23 ]
store i32 %26, i32* %3
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
define i32 @xilogb(double %0) {
%2 = tail call i32 @xfabs(double %0)
%3 = tail call i32 @ilogbp1(i32 %2)
%4 = add nsw i32 %3, -1
%5 = fcmp oeq double %0, 0.000000e+00
%6 = select i1 %5, i32 -2147483648, i32 %4
%7 = fcmp oeq double %0, 0x7FF0000000000000
%8 = fcmp oeq double %0, 0xFFF0000000000000
%9 = or i1 %7, %8
%10 = select i1 %9, i32 2147483647, i32 %6
ret i32 %10
}