#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 */
typedef int uint8_t;
typedef int uint32_t;

/* Variables and functions */
int frexp(float, int *);
scalar_t__ isinf(float);
scalar_t__ isnan(float);
void IEE754_binary32_encode(float x, char out[4]) {
  bool sign = x < 0;
  uint8_t exponent;
  uint32_t fraction;
  if (isinf(x)) {
    exponent = 0xFF;
    fraction = 0;
  } else if (isnan(x)) {
    exponent = 0xFF;
    fraction = 0x7FFFFF;
  } else {
    if (sign)
      x = -x;
    int e = 0;
    fraction = frexp(x, &e) * ((uint32_t)2 << 23);
    if (e <= 126) {
      fraction = 0;
      exponent = 0;
    } else {
      exponent = e + 126;
      if (e + 126 > 0xFF) {
        exponent = 0xFF;
        fraction = 0;
      }
    }
  }
  out[0] = ((sign << 7) & 0x80) | ((exponent >> 1) & 0x7F);
  out[1] = ((exponent << 7) & 0x80) | ((fraction >> 16) & 0x7F);
  out[2] = (fraction >> 8) & 0xFF;
  out[3] = fraction & 0xFF;
}


x86 assembly (clang, -O0):
<IEE754_binary32_encode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x4(%rbp)
mov    %rdi,-0x10(%rbp)
xorps  %xmm0,%xmm0
ucomiss -0x4(%rbp),%xmm0
seta   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x14(%rbp)
movss  -0x4(%rbp),%xmm0
call   1050 <isinf@plt>
cmp    $0x0,%rax
je     117a <IEE754_binary32_encode+0x4a>
movl   $0xff,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
jmp    1231 <IEE754_binary32_encode+0x101>
movss  -0x4(%rbp),%xmm0
call   1040 <isnan@plt>
cmp    $0x0,%rax
je     11a1 <IEE754_binary32_encode+0x71>
movl   $0xff,-0x18(%rbp)
movl   $0x7fffff,-0x1c(%rbp)
jmp    122c <IEE754_binary32_encode+0xfc>
cmpl   $0x0,-0x14(%rbp)
je     11c2 <IEE754_binary32_encode+0x92>
movss  -0x4(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0x4(%rbp)
movl   $0x0,-0x20(%rbp)
movss  -0x4(%rbp),%xmm0
lea    -0x20(%rbp),%rdi
call   1030 <frexp@plt>
shl    $0x18,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x7e,-0x20(%rbp)
jg     11fa <IEE754_binary32_encode+0xca>
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
jmp    1227 <IEE754_binary32_encode+0xf7>
mov    -0x20(%rbp),%eax
add    $0x7e,%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%eax
add    $0x7e,%eax
cmp    $0xff,%eax
jle    1222 <IEE754_binary32_encode+0xf2>
movl   $0xff,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
jmp    1227 <IEE754_binary32_encode+0xf7>
jmp    122c <IEE754_binary32_encode+0xfc>
jmp    1231 <IEE754_binary32_encode+0x101>
mov    -0x14(%rbp),%eax
shl    $0x7,%eax
and    $0x80,%eax
mov    -0x18(%rbp),%ecx
sar    $0x1,%ecx
and    $0x7f,%ecx
or     %ecx,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%eax
shl    $0x7,%eax
and    $0x80,%eax
mov    -0x1c(%rbp),%ecx
sar    $0x10,%ecx
and    $0x7f,%ecx
or     %ecx,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x1c(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x1c(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x3(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<IEE754_binary32_encode>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%rbx
movaps %xmm0,0x10(%rsp)
call   1050 <isinf@plt>
xor    %ecx,%ecx
mov    $0xff,%ebp
test   %rax,%rax
je     1156 <IEE754_binary32_encode+0x26>
movaps 0x10(%rsp),%xmm3
jmp    116f <IEE754_binary32_encode+0x3f>
movaps 0x10(%rsp),%xmm0
call   1040 <isnan@plt>
mov    $0x7fffff,%ecx
test   %rax,%rax
movaps 0x10(%rsp),%xmm3
je     11a2 <IEE754_binary32_encode+0x72>
xorps  %xmm0,%xmm0
xor    %eax,%eax
ucomiss %xmm3,%xmm0
seta   %al
shl    $0x7,%eax
mov    %ebp,%edx
shr    %edx
or     %eax,%edx
mov    %dl,(%rbx)
shl    $0x7,%ebp
mov    %ecx,%eax
shr    $0x10,%eax
and    $0x7f,%eax
or     %ebp,%eax
mov    %al,0x1(%rbx)
mov    %ch,0x2(%rbx)
mov    %cl,0x3(%rbx)
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret
movaps 0xe57(%rip),%xmm1
xorps  %xmm3,%xmm1
xorps  %xmm2,%xmm2
movaps %xmm3,%xmm0
cmpltss %xmm2,%xmm0
andps  %xmm0,%xmm1
andnps %xmm3,%xmm0
orps   %xmm1,%xmm0
movl   $0x0,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1030 <frexp@plt>
mov    0xc(%rsp),%edx
xor    %ebp,%ebp
mov    $0x0,%ecx
cmp    $0x7f,%edx
jl     114f <IEE754_binary32_encode+0x1f>
shl    $0x18,%eax
lea    0x7e(%rdx),%esi
xor    %ecx,%ecx
cmp    $0x82,%edx
mov    $0xff,%ebp
cmovb  %esi,%ebp
cmovb  %eax,%ecx
jmp    114f <IEE754_binary32_encode+0x1f>

LLVM IR (-O0):
define void @IEE754_binary32_encode(float %0, i8* %1) {
%3 = alloca float
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store float %0, float* %3
store i8* %1, i8** %4
%9 = load float, float* %3
%10 = fcmp olt float %9, 0.000000e+00
%11 = zext i1 %10 to i32
store i32 %11, i32* %5
%12 = load float, float* %3
%13 = call i64 @isinf(float %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %2
store i32 255, i32* %6
store i32 0, i32* %7
br label %44
16: ; preds = %2
%17 = load float, float* %3
%18 = call i64 @isnan(float %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %16
store i32 255, i32* %6
store i32 8388607, i32* %7
br label %43
21: ; preds = %16
%22 = load i32, i32* %5
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load float, float* %3
%26 = fneg float %25
store float %26, float* %3
br label %27
27: ; preds = %24, %21
store i32 0, i32* %8
%28 = load float, float* %3
%29 = call i32 @frexp(float %28, i32* %8)
%30 = mul nsw i32 %29, 16777216
store i32 %30, i32* %7
%31 = load i32, i32* %8
%32 = icmp sle i32 %31, 126
br i1 %32, label %33, label %34
33: ; preds = %27
store i32 0, i32* %7
store i32 0, i32* %6
br label %42
34: ; preds = %27
%35 = load i32, i32* %8
%36 = add nsw i32 %35, 126
store i32 %36, i32* %6
%37 = load i32, i32* %8
%38 = add nsw i32 %37, 126
%39 = icmp sgt i32 %38, 255
br i1 %39, label %40, label %41
40: ; preds = %34
store i32 255, i32* %6
store i32 0, i32* %7
br label %41
41: ; preds = %40, %34
br label %42
42: ; preds = %41, %33
br label %43
43: ; preds = %42, %20
br label %44
44: ; preds = %43, %15
%45 = load i32, i32* %5
%46 = shl i32 %45, 7
%47 = and i32 %46, 128
%48 = load i32, i32* %6
%49 = ashr i32 %48, 1
%50 = and i32 %49, 127
%51 = or i32 %47, %50
%52 = trunc i32 %51 to i8
%53 = load i8*, i8** %4
%54 = getelementptr inbounds i8, i8* %53, i64 0
store i8 %52, i8* %54
%55 = load i32, i32* %6
%56 = shl i32 %55, 7
%57 = and i32 %56, 128
%58 = load i32, i32* %7
%59 = ashr i32 %58, 16
%60 = and i32 %59, 127
%61 = or i32 %57, %60
%62 = trunc i32 %61 to i8
%63 = load i8*, i8** %4
%64 = getelementptr inbounds i8, i8* %63, i64 1
store i8 %62, i8* %64
%65 = load i32, i32* %7
%66 = ashr i32 %65, 8
%67 = and i32 %66, 255
%68 = trunc i32 %67 to i8
%69 = load i8*, i8** %4
%70 = getelementptr inbounds i8, i8* %69, i64 2
store i8 %68, i8* %70
%71 = load i32, i32* %7
%72 = and i32 %71, 255
%73 = trunc i32 %72 to i8
%74 = load i8*, i8** %4
%75 = getelementptr inbounds i8, i8* %74, i64 3
store i8 %73, i8* %75
ret void
}

LLVM IR (-O2):
define void @IEE754_binary32_encode(float %0, i8* nocapture writeonly %1) {
%3 = alloca i32
%4 = fcmp olt float %0, 0.000000e+00
%5 = tail call i64 @isinf(float %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %26
7: ; preds = %2
%8 = tail call i64 @isnan(float %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %26
10: ; preds = %7
%11 = fneg float %0
%12 = select i1 %4, float %11, float %0
%13 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%14 = call i32 @frexp(float %12, i32* %3)
%15 = load i32, i32* %3
%16 = icmp slt i32 %15, 127
br i1 %16, label %23, label %17
17: ; preds = %10
%18 = shl nsw i32 %14, 24
%19 = add nuw nsw i32 %15, 126
%20 = icmp ugt i32 %15, 129
%21 = select i1 %20, i32 255, i32 %19
%22 = select i1 %20, i32 0, i32 %18
br label %23
23: ; preds = %17, %10
%24 = phi i32 [ 0, %10 ], [ %21, %17 ]
%25 = phi i32 [ 0, %10 ], [ %22, %17 ]
br label %26
26: ; preds = %7, %2, %23
%27 = phi i32 [ %24, %23 ], [ 255, %2 ], [ 255, %7 ]
%28 = phi i32 [ %25, %23 ], [ 0, %2 ], [ 8388607, %7 ]
%29 = select i1 %4, i32 128, i32 0
%30 = lshr i32 %27, 1
%31 = or i32 %30, %29
%32 = trunc i32 %31 to i8
store i8 %32, i8* %1
%33 = shl nuw nsw i32 %27, 7
%34 = lshr i32 %28, 16
%35 = and i32 %34, 127
%36 = or i32 %35, %33
%37 = trunc i32 %36 to i8
%38 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %37, i8* %38
%39 = lshr i32 %28, 8
%40 = trunc i32 %39 to i8
%41 = getelementptr inbounds i8, i8* %1, i64 2
store i8 %40, i8* %41
%42 = trunc i32 %28 to i8
%43 = getelementptr inbounds i8, i8* %1, i64 3
store i8 %42, i8* %43
ret void
}