#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(int);
int /*<<< orphan*/ ldexp(float, int);
int 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));
  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>
mov    %eax,-0x1c(%rbp)
movss  0xe6c(%rip),%xmm0
call   1050 <log@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,%edi
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    $0x18,%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,(%rsp)
movaps %xmm3,%xmm0
call   1050 <log@plt>
mov    %eax,%ebx
movss  0xe80(%rip),%xmm0
call   1050 <log@plt>
mov    %eax,%ecx
mov    %ebx,%eax
cltd
idiv   %ecx
mov    %eax,%edi
call   1060 <floor@plt>
mov    %rax,%rbx
mov    $0x14,%edi
sub    %ebx,%edi
movaps (%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    $0x18,%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 i32 @log(float %12)
%14 = call i32 @log(float 2.000000e+00)
%15 = sdiv i32 %13, %14
%16 = call i64 @floor(i32 %15)
store i64 %16, i64* %4
%17 = load float, float* %2
%18 = load i64, i64* %4
%19 = sub nsw i64 20, %18
%20 = trunc i64 %19 to i32
%21 = call i32 @ldexp(float %17, i32 %20)
%22 = call i64 @rint(i32 %21)
store i64 %22, i64* %5
%23 = load i64, i64* %4
%24 = add nsw i64 %23, 768
%25 = shl i64 %24, 21
store i64 %25, i64* %4
%26 = load i32, i32* %3
%27 = sext i32 %26 to i64
%28 = load i64, i64* %4
%29 = or i64 %27, %28
%30 = load i64, i64* %5
%31 = or i64 %29, %30
ret i64 %31
}

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 i32 @log(float %5)
%7 = tail call i32 @log(float 2.000000e+00)
%8 = sdiv i32 %6, %7
%9 = tail call i64 @floor(i32 %8)
%10 = trunc i64 %9 to i32
%11 = sub i32 20, %10
%12 = tail call i32 @ldexp(float %5, i32 %11)
%13 = tail call i64 @rint(i32 %12)
%14 = shl i64 %9, 21
%15 = add i64 %14, 1610612736
%16 = or i64 %15, %4
%17 = or i64 %16, %13
ret i64 %17
}