#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 */
float frexp(float, int *);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
void float32_le_write(float in, unsigned char *out) {
  int exponent, mantissa, negative = 0;
  memset(out, 0, sizeof(int));
  if (in == 0.0)
    return;
  if (in < 0.0) {
    in *= -1.0;
    negative = 1;
  };
  in = frexp(in, &exponent);
  exponent += 126;
  in *= (float)0x1000000;
  mantissa = (((int)in) & 0x7FFFFF);
  if (negative)
    out[3] |= 0x80;
  if (exponent & 0x01)
    out[2] |= 0x80;
  out[0] = mantissa & 0xFF;
  out[1] = (mantissa >> 8) & 0xFF;
  out[2] |= (mantissa >> 16) & 0x7F;
  out[3] |= (exponent >> 1) & 0x7F;
  return;
}


x86 assembly (clang, -O0):
<float32_le_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x4(%rbp)
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
movss  -0x4(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1169 <float32_le_write+0x49>
jp     1169 <float32_le_write+0x49>
jmp    126a <float32_le_write+0x14a>
movss  -0x4(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    11a4 <float32_le_write+0x84>
movss  -0x4(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe70(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
movl   $0x1,-0x1c(%rbp)
movss  -0x4(%rbp),%xmm0
lea    -0x14(%rbp),%rdi
call   1040 <frexp@plt>
movss  %xmm0,-0x4(%rbp)
mov    -0x14(%rbp),%eax
add    $0x7e,%eax
mov    %eax,-0x14(%rbp)
movss  0xe40(%rip),%xmm0
mulss  -0x4(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
cvttss2si -0x4(%rbp),%eax
and    $0x7fffff,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11fa <float32_le_write+0xda>
mov    -0x10(%rbp),%rax
movzbl 0x3(%rax),%ecx
or     $0x80,%ecx
mov    %cl,0x3(%rax)
mov    -0x14(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     121a <float32_le_write+0xfa>
mov    -0x10(%rbp),%rax
movzbl 0x2(%rax),%ecx
or     $0x80,%ecx
mov    %cl,0x2(%rax)
mov    -0x18(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x18(%rbp),%edx
sar    $0x10,%edx
and    $0x7f,%edx
mov    -0x10(%rbp),%rax
movzbl 0x2(%rax),%ecx
or     %edx,%ecx
mov    %cl,0x2(%rax)
mov    -0x14(%rbp),%edx
sar    $0x1,%edx
and    $0x7f,%edx
mov    -0x10(%rbp),%rax
movzbl 0x3(%rax),%ecx
or     %edx,%ecx
mov    %cl,0x3(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<float32_le_write>:
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
movaps %xmm0,0x10(%rsp)
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
xorps  %xmm2,%xmm2
movaps 0x10(%rsp),%xmm1
ucomiss %xmm2,%xmm1
jne    1148 <float32_le_write+0x28>
jnp    11ad <float32_le_write+0x8d>
movaps %xmm1,%xmm0
movaps 0xeae(%rip),%xmm1
movaps %xmm0,%xmm3
xorps  %xmm0,%xmm1
cmpltss %xmm2,%xmm0
andps  %xmm0,%xmm1
andnps %xmm3,%xmm0
orps   %xmm1,%xmm0
lea    0xc(%rsp),%rdi
call   1040 <frexp@plt>
xorps  %xmm1,%xmm1
ucomiss 0x10(%rsp),%xmm1
mov    0xc(%rsp),%eax
mulss  0xe8c(%rip),%xmm0
cvttss2si %xmm0,%ecx
jbe    118e <float32_le_write+0x6e>
orb    $0x80,0x3(%rbx)
mov    %eax,%edx
shl    $0x7,%dl
or     0x2(%rbx),%dl
mov    %cl,(%rbx)
mov    %ch,0x1(%rbx)
shr    $0x10,%ecx
and    $0x7f,%cl
or     %dl,%cl
mov    %cl,0x2(%rbx)
add    $0x7e,%al
shr    %al
or     %al,0x3(%rbx)
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define void @float32_le_write(float %0, i8* %1) {
%3 = alloca float
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store float %0, float* %3
store i8* %1, i8** %4
store i32 0, i32* %7
%8 = load i8*, i8** %4
%9 = call i32 @memset(i8* %8, i32 0, i32 4)
%10 = load float, float* %3
%11 = fpext float %10 to double
%12 = fcmp oeq double %11, 0.000000e+00
br i1 %12, label %13, label %14
13: ; preds = %2
br label %83
14: ; preds = %2
%15 = load float, float* %3
%16 = fpext float %15 to double
%17 = fcmp olt double %16, 0.000000e+00
br i1 %17, label %18, label %23
18: ; preds = %14
%19 = load float, float* %3
%20 = fpext float %19 to double
%21 = fmul double %20, -1.000000e+00
%22 = fptrunc double %21 to float
store float %22, float* %3
store i32 1, i32* %7
br label %23
23: ; preds = %18, %14
%24 = load float, float* %3
%25 = call float @frexp(float %24, i32* %5)
store float %25, float* %3
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 126
store i32 %27, i32* %5
%28 = load float, float* %3
%29 = fmul float %28, 0x4170000000000000
store float %29, float* %3
%30 = load float, float* %3
%31 = fptosi float %30 to i32
%32 = and i32 %31, 8388607
store i32 %32, i32* %6
%33 = load i32, i32* %7
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %42
35: ; preds = %23
%36 = load i8*, i8** %4
%37 = getelementptr inbounds i8, i8* %36, i64 3
%38 = load i8, i8* %37
%39 = zext i8 %38 to i32
%40 = or i32 %39, 128
%41 = trunc i32 %40 to i8
store i8 %41, i8* %37
br label %42
42: ; preds = %35, %23
%43 = load i32, i32* %5
%44 = and i32 %43, 1
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %53
46: ; preds = %42
%47 = load i8*, i8** %4
%48 = getelementptr inbounds i8, i8* %47, i64 2
%49 = load i8, i8* %48
%50 = zext i8 %49 to i32
%51 = or i32 %50, 128
%52 = trunc i32 %51 to i8
store i8 %52, i8* %48
br label %53
53: ; preds = %46, %42
%54 = load i32, i32* %6
%55 = and i32 %54, 255
%56 = trunc i32 %55 to i8
%57 = load i8*, i8** %4
%58 = getelementptr inbounds i8, i8* %57, i64 0
store i8 %56, i8* %58
%59 = load i32, i32* %6
%60 = ashr i32 %59, 8
%61 = and i32 %60, 255
%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* %6
%66 = ashr i32 %65, 16
%67 = and i32 %66, 127
%68 = load i8*, i8** %4
%69 = getelementptr inbounds i8, i8* %68, i64 2
%70 = load i8, i8* %69
%71 = zext i8 %70 to i32
%72 = or i32 %71, %67
%73 = trunc i32 %72 to i8
store i8 %73, i8* %69
%74 = load i32, i32* %5
%75 = ashr i32 %74, 1
%76 = and i32 %75, 127
%77 = load i8*, i8** %4
%78 = getelementptr inbounds i8, i8* %77, i64 3
%79 = load i8, i8* %78
%80 = zext i8 %79 to i32
%81 = or i32 %80, %76
%82 = trunc i32 %81 to i8
store i8 %82, i8* %78
br label %83
83: ; preds = %53, %13
ret void
}

LLVM IR (-O2):
define void @float32_le_write(float %0, i8* %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32 @memset(i8* %1, i32 0, i32 4)
%6 = fcmp oeq float %0, 0.000000e+00
br i1 %6, label %40, label %7
7: ; preds = %2
%8 = fcmp olt float %0, 0.000000e+00
%9 = fneg float %0
%10 = select i1 %8, float %9, float %0
%11 = call float @frexp(float %10, i32* %3)
%12 = load i32, i32* %3
%13 = fmul float %11, 0x4170000000000000
%14 = fptosi float %13 to i32
br i1 %8, label %15, label %19
15: ; preds = %7
%16 = getelementptr inbounds i8, i8* %1, i64 3
%17 = load i8, i8* %16
%18 = or i8 %17, -128
store i8 %18, i8* %16
br label %19
19: ; preds = %15, %7
%20 = getelementptr inbounds i8, i8* %1, i64 2
%21 = load i8, i8* %20
%22 = trunc i32 %12 to i8
%23 = shl i8 %22, 7
%24 = or i8 %23, %21
%25 = trunc i32 %14 to i8
store i8 %25, i8* %1
%26 = lshr i32 %14, 8
%27 = trunc i32 %26 to i8
%28 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %27, i8* %28
%29 = lshr i32 %14, 16
%30 = getelementptr inbounds i8, i8* %1, i64 2
%31 = trunc i32 %29 to i8
%32 = and i8 %31, 127
%33 = or i8 %24, %32
store i8 %33, i8* %30
%34 = getelementptr inbounds i8, i8* %1, i64 3
%35 = load i8, i8* %34
%36 = trunc i32 %12 to i8
%37 = add i8 %36, 126
%38 = lshr i8 %37, 1
%39 = or i8 %35, %38
store i8 %39, i8* %34
br label %40
40: ; preds = %2, %19
ret void
}