#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(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 < 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>:
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+0x58>
jp     1168 <flt2ieee+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    12e3 <flt2ieee+0x1d3>
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    11a1 <flt2ieee+0x91>
movl   $0x80,-0x14(%rbp)
movss  -0x8(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0x8(%rbp)
jmp    11a8 <flt2ieee+0x98>
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  0xe34(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe30(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %eax,-0x1c(%rbp)
cmpl   $0x1000000,-0x1c(%rbp)
jb     1203 <flt2ieee+0xf3>
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    1248 <flt2ieee+0x138>
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    12e3 <flt2ieee+0x1d3>
cmpl   $0xff,-0x18(%rbp)
jle    1287 <flt2ieee+0x177>
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    12e3 <flt2ieee+0x1d3>
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>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    112b <flt2ieee+0x1b>
jp     112b <flt2ieee+0x1b>
movl   $0x0,(%rbx)
jmp    11cd <flt2ieee+0xbd>
xor    %ebp,%ebp
ucomiss %xmm0,%xmm1
seta   %al
jbe    113c <flt2ieee+0x2c>
xorps  0xec4(%rip),%xmm0
mov    %al,%bpl
cvtss2sd %xmm0,%xmm0
lea    0x4(%rsp),%rdi
call   1030 <frexp@plt>
mulsd  0xebb(%rip),%xmm0
addsd  0xebb(%rip),%xmm0
cvttsd2si %xmm0,%rax
cmp    $0x1000000,%eax
jb     1178 <flt2ieee+0x68>
shr    %eax
mov    0x4(%rsp),%ecx
add    $0x1,%ecx
mov    %ecx,0x4(%rsp)
jmp    117c <flt2ieee+0x6c>
mov    0x4(%rsp),%ecx
shl    $0x7,%ebp
cmp    $0xffffff81,%ecx
jg     1193 <flt2ieee+0x83>
mov    %bpl,(%rbx)
movb   $0x0,0x3(%rbx)
movw   $0x0,0x1(%rbx)
jmp    11cd <flt2ieee+0xbd>
cmp    $0x82,%ecx
jl     11ae <flt2ieee+0x9e>
or     $0x7f,%bpl
mov    %bpl,(%rbx)
movw   $0x80,0x1(%rbx)
movb   $0x0,0x3(%rbx)
jmp    11cd <flt2ieee+0xbd>
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(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 %105
22: ; preds = %2
%23 = load float, float* %4
%24 = fpext float %23 to double
%25 = fcmp olt double %24, 0.000000e+00
br i1 %25, label %26, label %29
26: ; preds = %22
store i32 128, i32* %6
%27 = load float, float* %4
%28 = fneg float %27
store float %28, float* %4
br label %30
29: ; preds = %22
store i32 0, i32* %6
br label %30
30: ; preds = %29, %26
%31 = load float, float* %4
%32 = fpext float %31 to double
%33 = call double @frexp(double %32, i32* %7)
store double %33, double* %9
%34 = load double, double* %9
%35 = call double @llvm.fmuladd.f64(double %34, double 0x4170000000000000, double 5.000000e-01)
%36 = fptoui double %35 to i32
store i32 %36, i32* %8
%37 = load i32, i32* %8
%38 = icmp uge i32 %37, 16777216
br i1 %38, label %39, label %44
39: ; preds = %30
%40 = load i32, i32* %8
%41 = udiv i32 %40, 2
store i32 %41, i32* %8
%42 = load i32, i32* %7
%43 = add nsw i32 %42, 1
store i32 %43, i32* %7
br label %44
44: ; preds = %39, %30
%45 = load i32, i32* %7
%46 = sub nsw i32 %45, 1
%47 = add nsw i32 %46, 127
store i32 %47, i32* %7
%48 = load i32, i32* %7
%49 = icmp slt i32 %48, 0
br i1 %49, label %50, label %61
50: ; preds = %44
%51 = load i32, i32* %6
%52 = trunc i32 %51 to i8
%53 = load i8*, i8** %5
%54 = getelementptr inbounds i8, i8* %53, i64 0
store i8 %52, i8* %54
%55 = load i8*, i8** %5
%56 = getelementptr inbounds i8, i8* %55, i64 3
store i8 0, i8* %56
%57 = load i8*, i8** %5
%58 = getelementptr inbounds i8, i8* %57, i64 2
store i8 0, i8* %58
%59 = load i8*, i8** %5
%60 = getelementptr inbounds i8, i8* %59, i64 1
store i8 0, i8* %60
store i32 0, i32* %3
br label %105
61: ; preds = %44
%62 = load i32, i32* %7
%63 = icmp sgt i32 %62, 255
br i1 %63, label %64, label %76
64: ; preds = %61
%65 = load i32, i32* %6
%66 = add nsw i32 %65, 127
%67 = trunc i32 %66 to i8
%68 = load i8*, i8** %5
%69 = getelementptr inbounds i8, i8* %68, i64 0
store i8 %67, i8* %69
%70 = load i8*, i8** %5
%71 = getelementptr inbounds i8, i8* %70, i64 1
store i8 -128, 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
store i32 0, i32* %3
br label %105
76: ; preds = %61
%77 = load i32, i32* %6
%78 = load i32, i32* %7
%79 = ashr i32 %78, 1
%80 = add nsw i32 %77, %79
%81 = trunc i32 %80 to i8
%82 = load i8*, i8** %5
%83 = getelementptr inbounds i8, i8* %82, i64 0
store i8 %81, i8* %83
%84 = load i32, i32* %8
%85 = and i32 %84, 255
%86 = trunc i32 %85 to i8
%87 = load i8*, i8** %5
%88 = getelementptr inbounds i8, i8* %87, i64 3
store i8 %86, i8* %88
%89 = load i32, i32* %8
%90 = lshr i32 %89, 8
%91 = and i32 %90, 255
%92 = trunc i32 %91 to i8
%93 = load i8*, i8** %5
%94 = getelementptr inbounds i8, i8* %93, i64 2
store i8 %92, i8* %94
%95 = load i32, i32* %7
%96 = and i32 %95, 1
%97 = shl i32 %96, 7
%98 = load i32, i32* %8
%99 = lshr i32 %98, 16
%100 = and i32 %99, 127
%101 = add i32 %97, %100
%102 = trunc i32 %101 to i8
%103 = load i8*, i8** %5
%104 = getelementptr inbounds i8, i8* %103, i64 1
store i8 %102, i8* %104
store i32 0, i32* %3
br label %105
105: ; preds = %76, %64, %50, %13
%106 = load i32, i32* %3
ret i32 %106
}

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