int fits_nan_32(unsigned char *v) {
  register unsigned long k;
  k = (v[0] << 24) | (v[1] << 16) | (v[2] << 8) | v[3];
  k &= 0x7fffffff;
  return (((k >= 0x7f7fffff) && (k <= 0x7fffffff)) ||
          ((k >= 0x00000001) && (k <= 0x00800000)));
}


x86 assembly (clang, -O0):
<fits_nan_32>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
shl    $0x18,%eax
mov    -0x8(%rbp),%rcx
movzbl 0x1(%rcx),%ecx
shl    $0x10,%ecx
or     %ecx,%eax
mov    -0x8(%rbp),%rcx
movzbl 0x2(%rcx),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    -0x8(%rbp),%rcx
movzbl 0x3(%rcx),%ecx
or     %ecx,%eax
cltq
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
and    $0x7fffffff,%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x7f7fffff,-0x10(%rbp)
7f
jb     116b <fits_nan_32+0x6b>
mov    $0x1,%al
cmpq   $0x7fffffff,-0x10(%rbp)
7f
mov    %al,-0x11(%rbp)
jbe    118f <fits_nan_32+0x8f>
xor    %eax,%eax
cmpq   $0x1,-0x10(%rbp)
mov    %al,-0x12(%rbp)
jb     1189 <fits_nan_32+0x89>
cmpq   $0x800000,-0x10(%rbp)
setbe  %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):
<fits_nan_32>:
movzbl (%rdi),%eax
movzbl 0x1(%rdi),%ecx
shl    $0x10,%rcx
movzbl 0x2(%rdi),%edx
shl    $0x8,%rdx
movzbl 0x3(%rdi),%esi
and    $0x7f,%eax
shl    $0x18,%rax
or     %rcx,%rax
or     %rdx,%rax
lea    (%rax,%rsi,1),%rcx
cmp    $0x7f7fffff,%rcx
setae  %cl
add    %rsi,%rax
add    $0xffffffffffffffff,%rax
cmp    $0x800000,%rax
setb   %al
or     %cl,%al
movzbl %al,%eax
ret

LLVM IR (-O0):
define i32 @fits_nan_32(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = getelementptr inbounds i8, i8* %4, i64 0
%6 = load i8, i8* %5
%7 = zext i8 %6 to i32
%8 = shl i32 %7, 24
%9 = load i8*, i8** %2
%10 = getelementptr inbounds i8, i8* %9, i64 1
%11 = load i8, i8* %10
%12 = zext i8 %11 to i32
%13 = shl i32 %12, 16
%14 = or i32 %8, %13
%15 = load i8*, i8** %2
%16 = getelementptr inbounds i8, i8* %15, i64 2
%17 = load i8, i8* %16
%18 = zext i8 %17 to i32
%19 = shl i32 %18, 8
%20 = or i32 %14, %19
%21 = load i8*, i8** %2
%22 = getelementptr inbounds i8, i8* %21, i64 3
%23 = load i8, i8* %22
%24 = zext i8 %23 to i32
%25 = or i32 %20, %24
%26 = sext i32 %25 to i64
store i64 %26, i64* %3
%27 = load i64, i64* %3
%28 = and i64 %27, 2147483647
store i64 %28, i64* %3
%29 = load i64, i64* %3
%30 = icmp uge i64 %29, 2139095039
br i1 %30, label %31, label %34
31: ; preds = %1
%32 = load i64, i64* %3
%33 = icmp ule i64 %32, 2147483647
br i1 %33, label %42, label %34
34: ; preds = %31, %1
%35 = load i64, i64* %3
%36 = icmp uge i64 %35, 1
br i1 %36, label %37, label %40
37: ; preds = %34
%38 = load i64, i64* %3
%39 = icmp ule i64 %38, 8388608
br label %40
40: ; preds = %37, %34
%41 = phi i1 [ false, %34 ], [ %39, %37 ]
br label %42
42: ; preds = %40, %31
%43 = phi i1 [ true, %31 ], [ %41, %40 ]
%44 = zext i1 %43 to i32
ret i32 %44
}

LLVM IR (-O2):
define i32 @fits_nan_32(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = zext i8 %2 to i64
%4 = shl nuw nsw i64 %3, 24
%5 = getelementptr inbounds i8, i8* %0, i64 1
%6 = load i8, i8* %5
%7 = zext i8 %6 to i64
%8 = shl nuw nsw i64 %7, 16
%9 = getelementptr inbounds i8, i8* %0, i64 2
%10 = load i8, i8* %9
%11 = zext i8 %10 to i64
%12 = shl nuw nsw i64 %11, 8
%13 = getelementptr inbounds i8, i8* %0, i64 3
%14 = load i8, i8* %13
%15 = zext i8 %14 to i64
%16 = and i64 %4, 2130706432
%17 = or i64 %16, %8
%18 = or i64 %17, %12
%19 = or i64 %18, %15
%20 = icmp ugt i64 %19, 2139095038
%21 = add nsw i64 %19, -1
%22 = icmp ult i64 %21, 8388608
%23 = select i1 %20, i1 true, i1 %22
%24 = zext i1 %23 to i32
ret i32 %24
}