#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_be_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[0] |= 0x80;
  if (exponent & 0x01)
    out[1] |= 0x80;
  out[3] = mantissa & 0xFF;
  out[2] = (mantissa >> 8) & 0xFF;
  out[1] |= (mantissa >> 16) & 0x7F;
  out[0] |= (exponent >> 1) & 0x7F;
  return;
}


x86 assembly (clang, -O0):
<float32_be_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_be_write+0x49>
jp     1169 <float32_be_write+0x49>
jmp    1267 <float32_be_write+0x147>
movss  -0x4(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    11a4 <float32_be_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     11f8 <float32_be_write+0xd8>
mov    -0x10(%rbp),%rax
movzbl (%rax),%ecx
or     $0x80,%ecx
mov    %cl,(%rax)
mov    -0x14(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1218 <float32_be_write+0xf8>
mov    -0x10(%rbp),%rax
movzbl 0x1(%rax),%ecx
or     $0x80,%ecx
mov    %cl,0x1(%rax)
mov    -0x18(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x3(%rax)
mov    -0x18(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x18(%rbp),%edx
sar    $0x10,%edx
and    $0x7f,%edx
mov    -0x10(%rbp),%rax
movzbl 0x1(%rax),%ecx
or     %edx,%ecx
mov    %cl,0x1(%rax)
mov    -0x14(%rbp),%edx
sar    $0x1,%edx
and    $0x7f,%edx
mov    -0x10(%rbp),%rax
movzbl (%rax),%ecx
or     %edx,%ecx
mov    %cl,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<float32_be_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_be_write+0x28>
jnp    11b0 <float32_be_write+0x90>
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    118d <float32_be_write+0x6d>
orb    $0x80,(%rbx)
mov    %eax,%edx
shl    $0x7,%dl
or     0x1(%rbx),%dl
mov    %ecx,%esi
rol    $0x8,%si
mov    %si,0x2(%rbx)
shr    $0x10,%ecx
and    $0x7f,%cl
or     %dl,%cl
mov    %cl,0x1(%rbx)
add    $0x7e,%al
shr    %al
or     %al,(%rbx)
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define void @float32_be_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 0
%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 1
%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 3
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 2
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 1
%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 0
%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_be_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 %39, 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 %18
15: ; preds = %7
%16 = load i8, i8* %1
%17 = or i8 %16, -128
store i8 %17, i8* %1
br label %18
18: ; preds = %15, %7
%19 = getelementptr inbounds i8, i8* %1, i64 1
%20 = load i8, i8* %19
%21 = trunc i32 %12 to i8
%22 = shl i8 %21, 7
%23 = or i8 %22, %20
%24 = trunc i32 %14 to i8
%25 = getelementptr inbounds i8, i8* %1, i64 3
store i8 %24, i8* %25
%26 = lshr i32 %14, 8
%27 = trunc i32 %26 to i8
%28 = getelementptr inbounds i8, i8* %1, i64 2
store i8 %27, i8* %28
%29 = lshr i32 %14, 16
%30 = getelementptr inbounds i8, i8* %1, i64 1
%31 = trunc i32 %29 to i8
%32 = and i8 %31, 127
%33 = or i8 %23, %32
store i8 %33, i8* %30
%34 = load i8, i8* %1
%35 = trunc i32 %12 to i8
%36 = add i8 %35, 126
%37 = lshr i8 %36, 1
%38 = or i8 %34, %37
store i8 %38, i8* %1
br label %39
39: ; preds = %2, %18
ret void
}