#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 uint32_t;

/* Variables and functions */
uint32_t htonf(float f) {
  uint32_t p;
  uint32_t sign;
  if (f < 0) {
    sign = 1;
    f = -f;
  } else {
    sign = 0;
  }
  p = ((((uint32_t)f) & 0x7fff) << 16) | (sign << 31);
  p |= (uint32_t)(((f - (int)f) * 65536.0f)) & 0xffff;
  return p;
}


x86 assembly (clang, -O0):
<htonf>:
push   %rbp
mov    %rsp,%rbp
movss  %xmm0,-0x4(%rbp)
xorps  %xmm0,%xmm0
ucomiss -0x4(%rbp),%xmm0
jbe    1139 <htonf+0x39>
movl   $0x1,-0xc(%rbp)
movss  -0x4(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1140 <htonf+0x40>
movl   $0x0,-0xc(%rbp)
cvttss2si -0x4(%rbp),%eax
and    $0x7fff,%eax
shl    $0x10,%eax
mov    -0xc(%rbp),%ecx
shl    $0x1f,%ecx
or     %ecx,%eax
mov    %eax,-0x8(%rbp)
movss  -0x4(%rbp),%xmm0
cvttss2si -0x4(%rbp),%eax
cvtsi2ss %eax,%xmm1
subss  %xmm1,%xmm0
movss  0xe8e(%rip),%xmm1
mulss  %xmm1,%xmm0
cvttss2si %xmm0,%eax
and    $0xffff,%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<htonf>:
xorps  %xmm1,%xmm1
xor    %eax,%eax
ucomiss %xmm0,%xmm1
seta   %cl
jbe    1114 <htonf+0x14>
xorps  0xeec(%rip),%xmm0
mov    %cl,%al
shl    $0x1f,%eax
cvttss2si %xmm0,%ecx
shl    $0x10,%ecx
and    $0x7fff0000,%ecx
or     %eax,%ecx
cvttps2dq %xmm0,%xmm1
cvtdq2ps %xmm1,%xmm1
subss  %xmm1,%xmm0
mulss  0xed5(%rip),%xmm0
cvttss2si %xmm0,%eax
movzwl %ax,%eax
or     %ecx,%eax
ret

LLVM IR (-O0):
define i32 @htonf(float %0) {
%2 = alloca float
%3 = alloca i32
%4 = alloca i32
store float %0, float* %2
%5 = load float, float* %2
%6 = fcmp olt float %5, 0.000000e+00
br i1 %6, label %7, label %10
7: ; preds = %1
store i32 1, i32* %4
%8 = load float, float* %2
%9 = fneg float %8
store float %9, float* %2
br label %11
10: ; preds = %1
store i32 0, i32* %4
br label %11
11: ; preds = %10, %7
%12 = load float, float* %2
%13 = fptosi float %12 to i32
%14 = and i32 %13, 32767
%15 = shl i32 %14, 16
%16 = load i32, i32* %4
%17 = shl i32 %16, 31
%18 = or i32 %15, %17
store i32 %18, i32* %3
%19 = load float, float* %2
%20 = load float, float* %2
%21 = fptosi float %20 to i32
%22 = sitofp i32 %21 to float
%23 = fsub float %19, %22
%24 = fmul float %23, 6.553600e+04
%25 = fptosi float %24 to i32
%26 = and i32 %25, 65535
%27 = load i32, i32* %3
%28 = or i32 %27, %26
store i32 %28, i32* %3
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
define i32 @htonf(float %0) {
%2 = fcmp olt float %0, 0.000000e+00
%3 = fneg float %0
%4 = select i1 %2, float %3, float %0
%5 = select i1 %2, i32 -2147483648, i32 0
%6 = fptosi float %4 to i32
%7 = shl i32 %6, 16
%8 = and i32 %7, 2147418112
%9 = or i32 %8, %5
%10 = sitofp i32 %6 to float
%11 = fsub float %4, %10
%12 = fmul float %11, 6.553600e+04
%13 = fptosi float %12 to i32
%14 = and i32 %13, 65535
%15 = or i32 %9, %14
ret i32 %15
}