#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 */
long floor(double);
int /*<<< orphan*/ ldexp(float, int);
double log(float);
long rint(int /*<<< orphan*/);
long _float32_pack(float val) {
  int sign = 0;
  long exp;
  long mant;
  if (val < 0) {
    sign = 0x80000000;
    val = -val;
  }
  exp = floor(log(val) / log(2.f) + .001);
  mant = rint(ldexp(val, (21 - 1) - exp));
  exp = (exp + 768) << 21;
  return (sign | exp | mant);
}


x86 assembly (clang, -O0):
<_float32_pack>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
xorps  %xmm0,%xmm0
ucomiss -0x4(%rbp),%xmm0
jbe    117f <_float32_pack+0x3f>
movl   $0x80000000,-0x8(%rbp)
movss  -0x4(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
call   1050 <log@plt>
movsd  %xmm0,-0x20(%rbp)
movss  0xe72(%rip),%xmm0
call   1050 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  0xe51(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1060 <floor@plt>
mov    %rax,-0x10(%rbp)
movss  -0x4(%rbp),%xmm0
mov    $0x14,%eax
sub    -0x10(%rbp),%rax
mov    %eax,%edi
call   1030 <ldexp@plt>
mov    %eax,%edi
call   1040 <rint@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
add    $0x300,%rax
shl    $0x15,%rax
mov    %rax,-0x10(%rbp)
movslq -0x8(%rbp),%rax
or     -0x10(%rbp),%rax
or     -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_float32_pack>:
push   %r14
push   %rbx
sub    $0x28,%rsp
xorps  %xmm1,%xmm1
xor    %r14d,%r14d
ucomiss %xmm0,%xmm1
setbe  %r14b
movaps 0xea5(%rip),%xmm2
xorps  %xmm0,%xmm2
shl    $0x1f,%r14
add    $0xffffffff80000000,%r14
movaps %xmm0,%xmm3
cmpltss %xmm1,%xmm3
andps  %xmm3,%xmm2
andnps %xmm0,%xmm3
orps   %xmm2,%xmm3
movaps %xmm3,0x10(%rsp)
movaps %xmm3,%xmm0
call   1050 <log@plt>
movsd  %xmm0,0x8(%rsp)
movss  0xe7b(%rip),%xmm0
call   1050 <log@plt>
movsd  0x8(%rsp),%xmm1
divsd  %xmm0,%xmm1
addsd  0xe6c(%rip),%xmm1
movapd %xmm1,%xmm0
call   1060 <floor@plt>
mov    %rax,%rbx
mov    $0x14,%edi
sub    %ebx,%edi
movaps 0x10(%rsp),%xmm0
call   1030 <ldexp@plt>
mov    %eax,%edi
call   1040 <rint@plt>
shl    $0x15,%rbx
add    $0x60000000,%rbx
or     %r14,%rbx
or     %rbx,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i64 @_float32_pack(float %0) {
%2 = alloca float
%3 = alloca i32
%4 = alloca i64
%5 = alloca i64
store float %0, float* %2
store i32 0, i32* %3
%6 = load float, float* %2
%7 = fcmp olt float %6, 0.000000e+00
br i1 %7, label %8, label %11
8: ; preds = %1
store i32 -2147483648, i32* %3
%9 = load float, float* %2
%10 = fneg float %9
store float %10, float* %2
br label %11
11: ; preds = %8, %1
%12 = load float, float* %2
%13 = call double @log(float %12)
%14 = call double @log(float 2.000000e+00)
%15 = fdiv double %13, %14
%16 = fadd double %15, 1.000000e-03
%17 = call i64 @floor(double %16)
store i64 %17, i64* %4
%18 = load float, float* %2
%19 = load i64, i64* %4
%20 = sub nsw i64 20, %19
%21 = trunc i64 %20 to i32
%22 = call i32 @ldexp(float %18, i32 %21)
%23 = call i64 @rint(i32 %22)
store i64 %23, i64* %5
%24 = load i64, i64* %4
%25 = add nsw i64 %24, 768
%26 = shl i64 %25, 21
store i64 %26, i64* %4
%27 = load i32, i32* %3
%28 = sext i32 %27 to i64
%29 = load i64, i64* %4
%30 = or i64 %28, %29
%31 = load i64, i64* %5
%32 = or i64 %30, %31
ret i64 %32
}

LLVM IR (-O2):
define i64 @_float32_pack(float %0) {
%2 = fcmp olt float %0, 0.000000e+00
%3 = fneg float %0
%4 = select i1 %2, i64 -2147483648, i64 0
%5 = select i1 %2, float %3, float %0
%6 = tail call double @log(float %5)
%7 = tail call double @log(float 2.000000e+00)
%8 = fdiv double %6, %7
%9 = fadd double %8, 1.000000e-03
%10 = tail call i64 @floor(double %9)
%11 = trunc i64 %10 to i32
%12 = sub i32 20, %11
%13 = tail call i32 @ldexp(float %5, i32 %12)
%14 = tail call i64 @rint(i32 %13)
%15 = shl i64 %10, 21
%16 = add i64 %15, 1610612736
%17 = or i64 %16, %4
%18 = or i64 %17, %14
ret i64 %18
}