#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 */
typedef struct TYPE_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  scalar_t__ mantissa1;
  scalar_t__ mantissa0;
};
struct TYPE_3__ {
  int exponent;
};
union ieee754_double {
  TYPE_2__ ieee;
  TYPE_1__ ieee_nan;
};

/* Variables and functions */
int isnan(double d) {
  union ieee754_double *u = (union ieee754_double *)&d;
  return u->ieee_nan.exponent == 2047 &&
         (u->ieee.mantissa0 || u->ieee.mantissa1);
}


x86 assembly (clang, -O0):
<isnan>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x8(%rbp)
lea    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rcx
xor    %eax,%eax
cmpl   $0x7ff,(%rcx)
mov    %al,-0x11(%rbp)
jne    114e <isnan+0x4e>
mov    -0x10(%rbp),%rcx
mov    $0x1,%al
cmpq   $0x0,0x8(%rcx)
mov    %al,-0x12(%rbp)
jne    1148 <isnan+0x48>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
setne  %al
mov    %al,-0x12(%rbp)
mov    -0x12(%rbp),%al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<isnan>:
movq   %xmm0,%rax
cmp    $0x7ff,%eax
sete   %cl
test   %rax,%rax
setne  %al
and    %cl,%al
movzbl %al,%eax
ret

LLVM IR (-O0):
%union.ieee754_double = type { %struct.TYPE_4__ }
%struct.TYPE_4__ = type { i64, i64 }
%struct.TYPE_3__ = type { i32 }
define i32 @isnan(double %0) {
%2 = alloca double
%3 = alloca %union.ieee754_double*
store double %0, double* %2
%4 = bitcast double* %2 to %union.ieee754_double*
store %union.ieee754_double* %4, %union.ieee754_double** %3
%5 = load %union.ieee754_double*, %union.ieee754_double** %3
%6 = bitcast %union.ieee754_double* %5 to %struct.TYPE_3__*
%7 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %6, i32 0, i32 0
%8 = load i32, i32* %7
%9 = icmp eq i32 %8, 2047
br i1 %9, label %10, label %24
10: ; preds = %1
%11 = load %union.ieee754_double*, %union.ieee754_double** %3
%12 = bitcast %union.ieee754_double* %11 to %struct.TYPE_4__*
%13 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %12, i32 0, i32 1
%14 = load i64, i64* %13
%15 = icmp ne i64 %14, 0
br i1 %15, label %22, label %16
16: ; preds = %10
%17 = load %union.ieee754_double*, %union.ieee754_double** %3
%18 = bitcast %union.ieee754_double* %17 to %struct.TYPE_4__*
%19 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %18, i32 0, i32 0
%20 = load i64, i64* %19
%21 = icmp ne i64 %20, 0
br label %22
22: ; preds = %16, %10
%23 = phi i1 [ true, %10 ], [ %21, %16 ]
br label %24
24: ; preds = %22, %1
%25 = phi i1 [ false, %1 ], [ %23, %22 ]
%26 = zext i1 %25 to i32
ret i32 %26
}

LLVM IR (-O2):
%union.ieee754_double = type { %struct.TYPE_4__ }
%struct.TYPE_4__ = type { i64, i64 }
define i32 @isnan(double %0) {
%2 = bitcast double %0 to i64
%3 = trunc i64 %2 to i32
%4 = icmp eq i32 %3, 2047
%5 = icmp ne i64 %2, 0
%6 = and i1 %5, %4
%7 = zext i1 %6 to i32
ret i32 %7
}