#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 frexp(double, int *);
int flt2ieee_nan(float x, unsigned char *ieee) {
  int sign, exp;
  unsigned int umant;
  double mant;
  if (x == 0.0) {
    ieee[0] = ieee[1] = ieee[2] = ieee[3] = 0;
    return 0;
  }
  if (((x) >= 9.9989e20 && (x) <= 9.9991e20)) {
    ieee[0] = ieee[1] = ieee[2] = ieee[3] = 255;
    return 0;
  }
  if (x < 0.0) {
    sign = 128;
    x = -x;
  } else
    sign = 0;
  mant = frexp((double)x, &exp);
  umant = mant * 16777216 + 0.5;
  if (umant >= 16777216) {
    umant = umant / 2;
    exp++;
  }
  exp = exp - 1 + 127;
  if (exp < 0) {
    ieee[0] = sign;
    ieee[1] = ieee[2] = ieee[3] = 0;
    return 0;
  }
  if (exp > 255) {
    ieee[0] = sign + 127;
    ieee[1] = 128;
    ieee[2] = ieee[3] = 0;
    return 0;
  }
  ieee[0] = sign + (exp >> 1);
  ieee[3] = umant & 255;
  ieee[2] = (umant >> 8) & 255;
  ieee[1] = ((exp & 1) << 7) + ((umant >> 16) & 127);
  return 0;
}


x86 assembly (clang, -O0):
<flt2ieee_nan>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movss  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1168 <flt2ieee_nan+0x58>
jp     1168 <flt2ieee_nan+0x58>
mov    -0x10(%rbp),%rax
movb   $0x0,0x3(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,0x2(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1344 <flt2ieee_nan+0x234>
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe87(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11c9 <flt2ieee_nan+0xb9>
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe74(%rip),%xmm0
ucomisd %xmm1,%xmm0
jb     11c9 <flt2ieee_nan+0xb9>
mov    -0x10(%rbp),%rax
movb   $0xff,0x3(%rax)
mov    -0x10(%rbp),%rax
movb   $0xff,0x2(%rax)
mov    -0x10(%rbp),%rax
movb   $0xff,0x1(%rax)
mov    -0x10(%rbp),%rax
movb   $0xff,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1344 <flt2ieee_nan+0x234>
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    1202 <flt2ieee_nan+0xf2>
movl   $0x80,-0x14(%rbp)
movss  -0x8(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0x8(%rbp)
jmp    1209 <flt2ieee_nan+0xf9>
movl   $0x0,-0x14(%rbp)
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    -0x18(%rbp),%rdi
call   1030 <frexp@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  0xde3(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xddf(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %eax,-0x1c(%rbp)
cmpl   $0x1000000,-0x1c(%rbp)
jb     1264 <flt2ieee_nan+0x154>
mov    -0x1c(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
add    $0x7f,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    12a9 <flt2ieee_nan+0x199>
mov    -0x14(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,0x3(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,0x2(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,0x1(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1344 <flt2ieee_nan+0x234>
cmpl   $0xff,-0x18(%rbp)
jle    12e8 <flt2ieee_nan+0x1d8>
mov    -0x14(%rbp),%eax
add    $0x7f,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
movb   $0x80,0x1(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,0x3(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,0x2(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1344 <flt2ieee_nan+0x234>
mov    -0x14(%rbp),%eax
mov    -0x18(%rbp),%ecx
sar    $0x1,%ecx
add    %ecx,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x3(%rax)
mov    -0x1c(%rbp),%eax
shr    $0x8,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x18(%rbp),%eax
and    $0x1,%eax
shl    $0x7,%eax
mov    -0x1c(%rbp),%ecx
shr    $0x10,%ecx
and    $0x7f,%ecx
add    %ecx,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x1(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<flt2ieee_nan>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    112b <flt2ieee_nan+0x1b>
jp     112b <flt2ieee_nan+0x1b>
movl   $0x0,(%rbx)
jmp    11fa <flt2ieee_nan+0xea>
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
ucomisd 0xec6(%rip),%xmm1
jb     1155 <flt2ieee_nan+0x45>
movsd  0xec4(%rip),%xmm2
ucomisd %xmm1,%xmm2
jb     1155 <flt2ieee_nan+0x45>
movl   $0xffffffff,(%rbx)
jmp    11fa <flt2ieee_nan+0xea>
xorps  %xmm1,%xmm1
xor    %ebp,%ebp
ucomiss %xmm0,%xmm1
seta   %al
jbe    1169 <flt2ieee_nan+0x59>
xorps  0xeb7(%rip),%xmm0
mov    %al,%bpl
cvtss2sd %xmm0,%xmm0
lea    0x4(%rsp),%rdi
call   1030 <frexp@plt>
mulsd  0xe8e(%rip),%xmm0
addsd  0xe8e(%rip),%xmm0
cvttsd2si %xmm0,%rax
cmp    $0x1000000,%eax
jb     11a5 <flt2ieee_nan+0x95>
shr    %eax
mov    0x4(%rsp),%ecx
add    $0x1,%ecx
mov    %ecx,0x4(%rsp)
jmp    11a9 <flt2ieee_nan+0x99>
mov    0x4(%rsp),%ecx
shl    $0x7,%ebp
cmp    $0xffffff81,%ecx
jg     11c0 <flt2ieee_nan+0xb0>
mov    %bpl,(%rbx)
movb   $0x0,0x3(%rbx)
movw   $0x0,0x1(%rbx)
jmp    11fa <flt2ieee_nan+0xea>
cmp    $0x82,%ecx
jl     11db <flt2ieee_nan+0xcb>
or     $0x7f,%bpl
mov    %bpl,(%rbx)
movw   $0x80,0x1(%rbx)
movb   $0x0,0x3(%rbx)
jmp    11fa <flt2ieee_nan+0xea>
add    $0x7e,%ecx
mov    %ecx,%edx
shr    %edx
add    %ebp,%edx
mov    %dl,(%rbx)
mov    %al,0x3(%rbx)
mov    %ah,0x2(%rbx)
shl    $0x7,%ecx
shr    $0x10,%eax
and    $0x7f,%eax
or     %ecx,%eax
mov    %al,0x1(%rbx)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @flt2ieee_nan(float %0, i8* %1) {
%3 = alloca i32
%4 = alloca float
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
store float %0, float* %4
store i8* %1, i8** %5
%10 = load float, float* %4
%11 = fpext float %10 to double
%12 = fcmp oeq double %11, 0.000000e+00
br i1 %12, label %13, label %22
13: ; preds = %2
%14 = load i8*, i8** %5
%15 = getelementptr inbounds i8, i8* %14, i64 3
store i8 0, i8* %15
%16 = load i8*, i8** %5
%17 = getelementptr inbounds i8, i8* %16, i64 2
store i8 0, i8* %17
%18 = load i8*, i8** %5
%19 = getelementptr inbounds i8, i8* %18, i64 1
store i8 0, i8* %19
%20 = load i8*, i8** %5
%21 = getelementptr inbounds i8, i8* %20, i64 0
store i8 0, i8* %21
store i32 0, i32* %3
br label %122
22: ; preds = %2
%23 = load float, float* %4
%24 = fpext float %23 to double
%25 = fcmp oge double %24, 0x444B1A2170AD88AA
br i1 %25, label %26, label %39
26: ; preds = %22
%27 = load float, float* %4
%28 = fpext float %27 to double
%29 = fcmp ole double %28, 9.999100e+20
br i1 %29, label %30, label %39
30: ; preds = %26
%31 = load i8*, i8** %5
%32 = getelementptr inbounds i8, i8* %31, i64 3
store i8 -1, i8* %32
%33 = load i8*, i8** %5
%34 = getelementptr inbounds i8, i8* %33, i64 2
store i8 -1, i8* %34
%35 = load i8*, i8** %5
%36 = getelementptr inbounds i8, i8* %35, i64 1
store i8 -1, i8* %36
%37 = load i8*, i8** %5
%38 = getelementptr inbounds i8, i8* %37, i64 0
store i8 -1, i8* %38
store i32 0, i32* %3
br label %122
39: ; preds = %26, %22
%40 = load float, float* %4
%41 = fpext float %40 to double
%42 = fcmp olt double %41, 0.000000e+00
br i1 %42, label %43, label %46
43: ; preds = %39
store i32 128, i32* %6
%44 = load float, float* %4
%45 = fneg float %44
store float %45, float* %4
br label %47
46: ; preds = %39
store i32 0, i32* %6
br label %47
47: ; preds = %46, %43
%48 = load float, float* %4
%49 = fpext float %48 to double
%50 = call double @frexp(double %49, i32* %7)
store double %50, double* %9
%51 = load double, double* %9
%52 = call double @llvm.fmuladd.f64(double %51, double 0x4170000000000000, double 5.000000e-01)
%53 = fptoui double %52 to i32
store i32 %53, i32* %8
%54 = load i32, i32* %8
%55 = icmp uge i32 %54, 16777216
br i1 %55, label %56, label %61
56: ; preds = %47
%57 = load i32, i32* %8
%58 = udiv i32 %57, 2
store i32 %58, i32* %8
%59 = load i32, i32* %7
%60 = add nsw i32 %59, 1
store i32 %60, i32* %7
br label %61
61: ; preds = %56, %47
%62 = load i32, i32* %7
%63 = sub nsw i32 %62, 1
%64 = add nsw i32 %63, 127
store i32 %64, i32* %7
%65 = load i32, i32* %7
%66 = icmp slt i32 %65, 0
br i1 %66, label %67, label %78
67: ; preds = %61
%68 = load i32, i32* %6
%69 = trunc i32 %68 to i8
%70 = load i8*, i8** %5
%71 = getelementptr inbounds i8, i8* %70, i64 0
store i8 %69, i8* %71
%72 = load i8*, i8** %5
%73 = getelementptr inbounds i8, i8* %72, i64 3
store i8 0, i8* %73
%74 = load i8*, i8** %5
%75 = getelementptr inbounds i8, i8* %74, i64 2
store i8 0, i8* %75
%76 = load i8*, i8** %5
%77 = getelementptr inbounds i8, i8* %76, i64 1
store i8 0, i8* %77
store i32 0, i32* %3
br label %122
78: ; preds = %61
%79 = load i32, i32* %7
%80 = icmp sgt i32 %79, 255
br i1 %80, label %81, label %93
81: ; preds = %78
%82 = load i32, i32* %6
%83 = add nsw i32 %82, 127
%84 = trunc i32 %83 to i8
%85 = load i8*, i8** %5
%86 = getelementptr inbounds i8, i8* %85, i64 0
store i8 %84, i8* %86
%87 = load i8*, i8** %5
%88 = getelementptr inbounds i8, i8* %87, i64 1
store i8 -128, i8* %88
%89 = load i8*, i8** %5
%90 = getelementptr inbounds i8, i8* %89, i64 3
store i8 0, i8* %90
%91 = load i8*, i8** %5
%92 = getelementptr inbounds i8, i8* %91, i64 2
store i8 0, i8* %92
store i32 0, i32* %3
br label %122
93: ; preds = %78
%94 = load i32, i32* %6
%95 = load i32, i32* %7
%96 = ashr i32 %95, 1
%97 = add nsw i32 %94, %96
%98 = trunc i32 %97 to i8
%99 = load i8*, i8** %5
%100 = getelementptr inbounds i8, i8* %99, i64 0
store i8 %98, i8* %100
%101 = load i32, i32* %8
%102 = and i32 %101, 255
%103 = trunc i32 %102 to i8
%104 = load i8*, i8** %5
%105 = getelementptr inbounds i8, i8* %104, i64 3
store i8 %103, i8* %105
%106 = load i32, i32* %8
%107 = lshr i32 %106, 8
%108 = and i32 %107, 255
%109 = trunc i32 %108 to i8
%110 = load i8*, i8** %5
%111 = getelementptr inbounds i8, i8* %110, i64 2
store i8 %109, i8* %111
%112 = load i32, i32* %7
%113 = and i32 %112, 1
%114 = shl i32 %113, 7
%115 = load i32, i32* %8
%116 = lshr i32 %115, 16
%117 = and i32 %116, 127
%118 = add i32 %114, %117
%119 = trunc i32 %118 to i8
%120 = load i8*, i8** %5
%121 = getelementptr inbounds i8, i8* %120, i64 1
store i8 %119, i8* %121
store i32 0, i32* %3
br label %122
122: ; preds = %93, %81, %67, %30, %13
%123 = load i32, i32* %3
ret i32 %123
}

LLVM IR (-O2):
define i32 @flt2ieee_nan(float %0, i8* nocapture writeonly %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = fpext float %0 to double
%6 = fcmp oeq float %0, 0.000000e+00
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = bitcast i8* %1 to i32*
store i32 0, i32* %8
br label %64
9: ; preds = %2
%10 = fcmp ult double %5, 0x444B1A2170AD88AA
%11 = fcmp ugt double %5, 9.999100e+20
%12 = or i1 %10, %11
br i1 %12, label %15, label %13
13: ; preds = %9
%14 = bitcast i8* %1 to i32*
store i32 -1, i32* %14
br label %64
15: ; preds = %9
%16 = fcmp olt float %0, 0.000000e+00
%17 = fneg float %0
%18 = select i1 %16, float %17, float %0
%19 = select i1 %16, i32 128, i32 0
%20 = fpext float %18 to double
%21 = call double @frexp(double %20, i32* %3)
%22 = tail call double @llvm.fmuladd.f64(double %21, double 0x4170000000000000, double 5.000000e-01)
%23 = fptoui double %22 to i32
%24 = icmp ugt i32 %23, 16777215
br i1 %24, label %25, label %29
25: ; preds = %15
%26 = lshr i32 %23, 1
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 1
store i32 %28, i32* %3
br label %31
29: ; preds = %15
%30 = load i32, i32* %3
br label %31
31: ; preds = %29, %25
%32 = phi i32 [ %30, %29 ], [ %28, %25 ]
%33 = phi i32 [ %23, %29 ], [ %26, %25 ]
%34 = add nsw i32 %32, 126
%35 = icmp slt i32 %32, -126
br i1 %35, label %36, label %41
36: ; preds = %31
%37 = trunc i32 %19 to i8
store i8 %37, i8* %1
%38 = getelementptr inbounds i8, i8* %1, i64 3
store i8 0, i8* %38
%39 = getelementptr inbounds i8, i8* %1, i64 2
store i8 0, i8* %39
%40 = getelementptr inbounds i8, i8* %1, i64 1
store i8 0, i8* %40
br label %64
41: ; preds = %31
%42 = icmp sgt i32 %32, 129
br i1 %42, label %43, label %49
43: ; preds = %41
%44 = trunc i32 %19 to i8
%45 = or i8 %44, 127
store i8 %45, i8* %1
%46 = getelementptr inbounds i8, i8* %1, i64 1
store i8 -128, i8* %46
%47 = getelementptr inbounds i8, i8* %1, i64 3
store i8 0, i8* %47
%48 = getelementptr inbounds i8, i8* %1, i64 2
store i8 0, i8* %48
br label %64
49: ; preds = %41
%50 = lshr i32 %34, 1
%51 = add nuw nsw i32 %50, %19
%52 = trunc i32 %51 to i8
store i8 %52, i8* %1
%53 = trunc i32 %33 to i8
%54 = getelementptr inbounds i8, i8* %1, i64 3
store i8 %53, i8* %54
%55 = lshr i32 %33, 8
%56 = trunc i32 %55 to i8
%57 = getelementptr inbounds i8, i8* %1, i64 2
store i8 %56, i8* %57
%58 = shl nuw nsw i32 %34, 7
%59 = lshr i32 %33, 16
%60 = and i32 %59, 127
%61 = or i32 %60, %58
%62 = trunc i32 %61 to i8
%63 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %62, i8* %63
br label %64
64: ; preds = %49, %43, %36, %13, %7
ret i32 0
}