#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 uint64_t;
typedef int int32_t;
typedef int fractional_bits;

/* Variables and functions */
int exp_radix(int);
int fixed_to_float(unsigned int fractional_bits, int32_t fixed,
                   int *exponent_out) {
  int exponent = ((((uint64_t)fractional_bits * 1292913986) +
                   (((uint64_t)1) << (32)) - 1) >>
                  (32));
  int floating = (((fixed * exp_radix(exponent)) +
                   (((fixed * exp_radix(exponent))) < 0
                        ? -((1 << ((fractional_bits)-1)))
                        : ((1 << ((fractional_bits)-1))))) >>
                  (fractional_bits));
  while (floating % 10 == 0 && exponent > 0) {
    exponent--;
    floating /= 10;
  }
  *exponent_out = -exponent;
  return floating;
}


x86 assembly (clang, -O0):
<fixed_to_float>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
imul   $0x4d104d42,-0x4(%rbp),%eax
add    %ecx,%eax
sub    $0x1,%eax
mov    $0x20,%ecx
sar    %cl,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <exp_radix@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <exp_radix@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
imul   %ecx,%eax
cmp    $0x0,%eax
jge    118b <fixed_to_float+0x7b>
mov    -0x4(%rbp),%ecx
sub    $0x1,%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,%ecx
xor    %eax,%eax
sub    %ecx,%eax
mov    %eax,-0x28(%rbp)
jmp    119b <fixed_to_float+0x8b>
mov    -0x4(%rbp),%ecx
sub    $0x1,%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%eax
mov    -0x28(%rbp),%ecx
add    %ecx,%eax
mov    -0x4(%rbp),%ecx
sar    %cl,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
xor    %eax,%eax
cmp    $0x0,%edx
mov    %al,-0x29(%rbp)
jne    11ce <fixed_to_float+0xbe>
cmpl   $0x0,-0x14(%rbp)
setg   %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    11de <fixed_to_float+0xce>
jmp    11fa <fixed_to_float+0xea>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
jmp    11ab <fixed_to_float+0x9b>
xor    %ecx,%ecx
sub    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fixed_to_float>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebx
mov    %edi,%r14d
call   1030 <exp_radix@plt>
mov    %eax,%ebp
imul   %ebx,%ebp
call   1030 <exp_radix@plt>
imul   %ebx,%eax
sar    $0x1f,%eax
or     $0x1,%eax
lea    -0x1(%r14),%ecx
shl    %cl,%eax
add    %ebp,%eax
mov    %r14d,%ecx
sar    %cl,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @fixed_to_float(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%9 = load i32, i32* %4
%10 = mul nsw i32 %9, 1292913986
%11 = add nsw i32 %10, poison
%12 = sub nsw i32 %11, 1
%13 = ashr i32 %12, 32
store i32 %13, i32* %7
%14 = load i32, i32* %5
%15 = load i32, i32* %7
%16 = call i32 @exp_radix(i32 %15)
%17 = mul nsw i32 %14, %16
%18 = load i32, i32* %5
%19 = load i32, i32* %7
%20 = call i32 @exp_radix(i32 %19)
%21 = mul nsw i32 %18, %20
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %3
%24 = load i32, i32* %4
%25 = sub i32 %24, 1
%26 = shl i32 1, %25
%27 = sub nsw i32 0, %26
br label %32
28: ; preds = %3
%29 = load i32, i32* %4
%30 = sub i32 %29, 1
%31 = shl i32 1, %30
br label %32
32: ; preds = %28, %23
%33 = phi i32 [ %27, %23 ], [ %31, %28 ]
%34 = add nsw i32 %17, %33
%35 = load i32, i32* %4
%36 = ashr i32 %34, %35
store i32 %36, i32* %8
br label %37
37: ; preds = %46, %32
%38 = load i32, i32* %8
%39 = srem i32 %38, 10
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %37
%42 = load i32, i32* %7
%43 = icmp sgt i32 %42, 0
br label %44
44: ; preds = %41, %37
%45 = phi i1 [ false, %37 ], [ %43, %41 ]
br i1 %45, label %46, label %51
46: ; preds = %44
%47 = load i32, i32* %7
%48 = add nsw i32 %47, -1
store i32 %48, i32* %7
%49 = load i32, i32* %8
%50 = sdiv i32 %49, 10
store i32 %50, i32* %8
br label %37
51: ; preds = %44
%52 = load i32, i32* %7
%53 = sub nsw i32 0, %52
%54 = load i32*, i32** %6
store i32 %53, i32* %54
%55 = load i32, i32* %8
ret i32 %55
}

LLVM IR (-O2):
define i32 @fixed_to_float(i32 %0, i32 %1, i32* nocapture writeonly %2) {
%4 = tail call i32 @exp_radix(i32 poison)
%5 = mul nsw i32 %4, %1
%6 = tail call i32 @exp_radix(i32 poison)
%7 = mul nsw i32 %6, %1
%8 = add i32 %0, -1
%9 = icmp sgt i32 %7, -1
%10 = select i1 %9, i32 1, i32 -1
%11 = shl i32 %10, %8
%12 = add nsw i32 %11, %5
%13 = ashr i32 %12, %0
ret i32 %13
}