#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 FDLIBM_fabs(double);
double FDLIBM_logb(double x) {
  int lx, ix;
  ix = (*(1 + (int *)&x)) & 0x7fffffff;
  lx = *(int *)&x;
  if ((ix | lx) == 0)
    return -1.0 / FDLIBM_fabs(x);
  if (ix >= 0x7ff00000)
    return x * x;
  if ((ix >>= 20) == 0)
    return -1022.0;
  else
    return (double)(ix - 1023);
}


x86 assembly (clang, -O0):
<FDLIBM_logb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    -0xc(%rbp),%eax
and    $0x7fffffff,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
or     -0x14(%rbp),%eax
cmp    $0x0,%eax
jne    1160 <FDLIBM_logb+0x50>
movsd  -0x10(%rbp),%xmm0
call   1030 <FDLIBM_fabs@plt>
movaps %xmm0,%xmm1
movsd  0xeb6(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11b6 <FDLIBM_logb+0xa6>
cmpl   $0x7ff00000,-0x18(%rbp)
jl     1181 <FDLIBM_logb+0x71>
movsd  -0x10(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11b6 <FDLIBM_logb+0xa6>
mov    -0x18(%rbp),%eax
sar    $0x14,%eax
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jne    11a5 <FDLIBM_logb+0x95>
movsd  0xe65(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11b6 <FDLIBM_logb+0xa6>
mov    -0x18(%rbp),%eax
sub    $0x3ff,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FDLIBM_logb>:
push   %rax
movq   %xmm0,%rcx
mov    %rcx,%rax
shr    $0x20,%rax
and    $0x7fffffff,%eax
or     %eax,%ecx
je     1133 <FDLIBM_logb+0x23>
cmp    $0x7ff00000,%eax
jb     114a <FDLIBM_logb+0x3a>
mulsd  %xmm0,%xmm0
pop    %rax
ret
call   1030 <FDLIBM_fabs@plt>
movapd %xmm0,%xmm1
movsd  0xec4(%rip),%xmm0
divsd  %xmm1,%xmm0
pop    %rax
ret
cmp    $0x100000,%eax
jae    115b <FDLIBM_logb+0x4b>
movsd  0xea7(%rip),%xmm0
pop    %rax
ret
shr    $0x14,%eax
add    $0xfffffc01,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
pop    %rax
ret

LLVM IR (-O0):
define double @FDLIBM_logb(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca i32
%5 = alloca i32
store double %0, double* %3
%6 = bitcast double* %3 to i32*
%7 = getelementptr inbounds i32, i32* %6, i64 1
%8 = load i32, i32* %7
%9 = and i32 %8, 2147483647
store i32 %9, i32* %5
%10 = bitcast double* %3 to i32*
%11 = load i32, i32* %10
store i32 %11, i32* %4
%12 = load i32, i32* %5
%13 = load i32, i32* %4
%14 = or i32 %12, %13
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %1
%17 = load double, double* %3
%18 = call double @FDLIBM_fabs(double %17)
%19 = fdiv double -1.000000e+00, %18
store double %19, double* %2
br label %36
20: ; preds = %1
%21 = load i32, i32* %5
%22 = icmp sge i32 %21, 2146435072
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = load double, double* %3
%25 = load double, double* %3
%26 = fmul double %24, %25
store double %26, double* %2
br label %36
27: ; preds = %20
%28 = load i32, i32* %5
%29 = ashr i32 %28, 20
store i32 %29, i32* %5
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %27
store double -1.022000e+03, double* %2
br label %36
32: ; preds = %27
%33 = load i32, i32* %5
%34 = sub nsw i32 %33, 1023
%35 = sitofp i32 %34 to double
store double %35, double* %2
br label %36
36: ; preds = %32, %31, %23, %16
%37 = load double, double* %2
ret double %37
}

LLVM IR (-O2):
define double @FDLIBM_logb(double %0) {
%2 = bitcast double %0 to i64
%3 = lshr i64 %2, 32
%4 = trunc i64 %3 to i32
%5 = and i32 %4, 2147483647
%6 = trunc i64 %2 to i32
%7 = or i32 %5, %6
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = tail call double @FDLIBM_fabs(double %0)
%11 = fdiv double -1.000000e+00, %10
br label %22
12: ; preds = %1
%13 = icmp ugt i32 %5, 2146435071
br i1 %13, label %14, label %16
14: ; preds = %12
%15 = fmul double %0, %0
br label %22
16: ; preds = %12
%17 = icmp ult i32 %5, 1048576
br i1 %17, label %22, label %18
18: ; preds = %16
%19 = lshr i32 %5, 20
%20 = add nsw i32 %19, -1023
%21 = sitofp i32 %20 to double
br label %22
22: ; preds = %16, %18, %14, %9
%23 = phi double [ %11, %9 ], [ %15, %14 ], [ %21, %18 ], [ -1.022000e+03, %16 ]
ret double %23
}