#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 unsigned int int64_t;
typedef scalar_t__ int32_t;

/* Variables and functions */
unsigned int exp_radix(int);
int32_t float_to_fixed(int exponent, int32_t mantissa,
                       unsigned int fractional_bits) {
  int64_t fixed = (int64_t)mantissa << fractional_bits;
  if (exponent < 0) {
    int64_t divisor = exp_radix(-exponent) / 2;
    fixed /= divisor;
    fixed = (fixed + ((mantissa) < 0 ? -(1) : (1))) / 2;
  } else {
    fixed *= exp_radix(exponent);
  }
  return fixed;
}


x86 assembly (clang, -O0):
<float_to_fixed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
shl    %cl,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    117a <float_to_fixed+0x6a>
xor    %edi,%edi
sub    -0x4(%rbp),%edi
call   1030 <exp_radix@plt>
shr    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%eax
xor    %edx,%edx
div    %ecx
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x10(%rbp),%rsi
mov    $0x1,%ecx
mov    $0xffffffff,%edx
cmp    $0x0,%rsi
cmovl  %edx,%ecx
add    %ecx,%eax
shr    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1189 <float_to_fixed+0x79>
mov    -0x4(%rbp),%edi
call   1030 <exp_radix@plt>
imul   -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<float_to_fixed>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ecx
mov    %rsi,%rbx
mov    %ebx,%ebp
shl    %cl,%ebp
test   %edi,%edi
js     112a <float_to_fixed+0x1a>
call   1030 <exp_radix@plt>
imul   %ebp,%eax
jmp    114b <float_to_fixed+0x3b>
neg    %edi
call   1030 <exp_radix@plt>
mov    %eax,%ecx
shr    %ecx
mov    %ebp,%eax
xor    %edx,%edx
div    %ecx
xor    %ecx,%ecx
test   %rbx,%rbx
setns  %cl
lea    (%rax,%rcx,2),%eax
add    $0xffffffff,%eax
shr    %eax
mov    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i64 @float_to_fixed(i32 %0, i64 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i64 %1, i64* %5
store i32 %2, i32* %6
%9 = load i64, i64* %5
%10 = trunc i64 %9 to i32
%11 = load i32, i32* %6
%12 = shl i32 %10, %11
store i32 %12, i32* %7
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %30
15: ; preds = %3
%16 = load i32, i32* %4
%17 = sub nsw i32 0, %16
%18 = call i32 @exp_radix(i32 %17)
%19 = udiv i32 %18, 2
store i32 %19, i32* %8
%20 = load i32, i32* %8
%21 = load i32, i32* %7
%22 = udiv i32 %21, %20
store i32 %22, i32* %7
%23 = load i32, i32* %7
%24 = load i64, i64* %5
%25 = icmp slt i64 %24, 0
%26 = zext i1 %25 to i64
%27 = select i1 %25, i32 -1, i32 1
%28 = add i32 %23, %27
%29 = udiv i32 %28, 2
store i32 %29, i32* %7
br label %35
30: ; preds = %3
%31 = load i32, i32* %4
%32 = call i32 @exp_radix(i32 %31)
%33 = load i32, i32* %7
%34 = mul i32 %33, %32
store i32 %34, i32* %7
br label %35
35: ; preds = %30, %15
%36 = load i32, i32* %7
%37 = zext i32 %36 to i64
ret i64 %37
}

LLVM IR (-O2):
define i64 @float_to_fixed(i32 %0, i64 %1, i32 %2) {
%4 = trunc i64 %1 to i32
%5 = shl i32 %4, %2
%6 = icmp slt i32 %0, 0
br i1 %6, label %7, label %16
7: ; preds = %3
%8 = sub nsw i32 0, %0
%9 = tail call i32 @exp_radix(i32 %8)
%10 = lshr i32 %9, 1
%11 = udiv i32 %5, %10
%12 = icmp slt i64 %1, 0
%13 = select i1 %12, i32 -1, i32 1
%14 = add i32 %11, %13
%15 = lshr i32 %14, 1
br label %19
16: ; preds = %3
%17 = tail call i32 @exp_radix(i32 %0)
%18 = mul i32 %17, %5
br label %19
19: ; preds = %16, %7
%20 = phi i32 [ %15, %7 ], [ %18, %16 ]
%21 = zext i32 %20 to i64
ret i64 %21
}