#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 */
#define FP_INFINITE 130
#define FP_NAN 129
#define FP_SUBNORMAL 128
int fpclassify(double);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *,
                           char const *, int);
int /*<<< orphan*/ stderr;
bool is_valid_fp(double val, const char *file, int line) {
  const char *ty = "";
  switch (fpclassify(val)) {
  case FP_NAN:
    ty = "NaN";
    break;
  case FP_INFINITE:
    ty = "Inf";
    break;
  case FP_SUBNORMAL:
    ty = "Sub";
    break;
  default:
    return true;
  }
  fprintf(stderr, "warning: %s floating-point at %s:%d\n", ty, file, line);
  return false;
}


x86 assembly (clang, -O0):
<is_valid_fp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
mov    %esi,-0x1c(%rbp)
lea    0xef5(%rip),%rax
mov    %rax,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <fpclassify@plt>
mov    %eax,%ecx
mov    %ecx,-0x2c(%rbp)
sub    $0x80,%eax
je     11a4 <is_valid_fp+0x84>
jmp    115e <is_valid_fp+0x3e>
mov    -0x2c(%rbp),%eax
sub    $0x81,%eax
je     1184 <is_valid_fp+0x64>
jmp    1171 <is_valid_fp+0x51>
mov    -0x2c(%rbp),%eax
sub    $0x82,%eax
je     1194 <is_valid_fp+0x74>
jmp    11b4 <is_valid_fp+0x94>
lea    0xe75(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    11c0 <is_valid_fp+0xa0>
lea    0xe69(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    11c0 <is_valid_fp+0xa0>
lea    0xe5d(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    11c0 <is_valid_fp+0xa0>
movl   $0x1,-0x4(%rbp)
jmp    11e8 <is_valid_fp+0xc8>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x1c(%rbp),%r8d
lea    0xe30(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_valid_fp>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1040 <fpclassify@plt>
add    $0xffffff80,%eax
mov    $0x1,%ecx
cmp    $0x2,%eax
ja     1167 <is_valid_fp+0x47>
cltq
lea    0xef1(%rip),%rcx
movslq (%rcx,%rax,4),%rdx
add    %rcx,%rdx
mov    0x2e8f(%rip),%rax
mov    (%rax),%edi
lea    0xeb2(%rip),%rsi
mov    %rbx,%rcx
mov    %ebp,%r8d
call   1030 <fprintf@plt>
xor    %ecx,%ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [4 x i8] c"NaN\00"
@.str.2 = [4 x i8] c"Inf\00"
@.str.3 = [4 x i8] c"Sub\00"
@stderr = global i32 0
@.str.4 = [37 x i8] c"warning: %s floating-point at %s:%d\0A\00"
define i32 @is_valid_fp(double %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca double
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
store double %0, double* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %8
%9 = load double, double* %5
%10 = call i32 @fpclassify(double %9)
switch i32 %10, label %14 [
i32 129, label %11
i32 130, label %12
i32 128, label %13
]
11: ; preds = %3
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %8
br label %15
12: ; preds = %3
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8** %8
br label %15
13: ; preds = %3
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8** %8
br label %15
14: ; preds = %3
store i32 1, i32* %4
br label %21
15: ; preds = %13, %12, %11
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %8
%18 = load i8*, i8** %6
%19 = load i32, i32* %7
%20 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), i8* %17, i8* %18, i32 %19)
store i32 0, i32* %4
br label %21
21: ; preds = %15, %14
%22 = load i32, i32* %4
ret i32 %22
}

LLVM IR (-O2):
@.str.1 = [4 x i8] c"NaN\00"
@.str.2 = [4 x i8] c"Inf\00"
@.str.3 = [4 x i8] c"Sub\00"
@stderr = global i32 0
@.str.4 = [37 x i8] c"warning: %s floating-point at %s:%d\0A\00"
@reltable.is_valid_fp = [3 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.3 to i64), i64 ptrtoint ([3 x i32]* @reltable.is_valid_fp to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.1 to i64), i64 ptrtoint ([3 x i32]* @reltable.is_valid_fp to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.2 to i64), i64 ptrtoint ([3 x i32]* @reltable.is_valid_fp to i64)) to i32)]
define i32 @is_valid_fp(double %0, i8* %1, i32 %2) {
%4 = tail call i32 @fpclassify(double %0)
%5 = add i32 %4, -128
%6 = icmp ult i32 %5, 3
br i1 %6, label %7, label %13
7: ; preds = %3
%8 = sext i32 %5 to i64
%9 = shl i64 %8, 2
%10 = call i8* @llvm.load.relative.i64(i8* bitcast ([3 x i32]* @reltable.is_valid_fp to i8*), i64 %9)
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), i8* %10, i8* %1, i32 %2)
br label %13
13: ; preds = %3, %7
%14 = phi i32 [ 0, %7 ], [ 1, %3 ]
ret i32 %14
}