float GetBinaryFraction(int x) {
  float res = 0;
  int i;
  for (i = 22; i >= 0; i--) {
    int b = x >> i;
    b &= 0x01;
    res += (float)(b)*powf(2.0f, (float)(i)-23.0f);
  }
  return res;
}


x86 assembly (clang, -O0):
<GetBinaryFraction>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x8(%rbp)
movl   $0x16,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     1198 <GetBinaryFraction+0x88>
mov    -0x4(%rbp),%eax
mov    -0xc(%rbp),%ecx
sar    %cl,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
and    $0x1,%eax
mov    %eax,-0x10(%rbp)
cvtsi2ssl -0x10(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
cvtsi2ssl -0xc(%rbp),%xmm1
movss  0xea5(%rip),%xmm0
subss  %xmm0,%xmm1
movss  0xe95(%rip),%xmm0
call   1030 <powf@plt>
movaps %xmm0,%xmm2
movss  -0x14(%rbp),%xmm0
movss  -0x8(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    112a <GetBinaryFraction+0x1a>
movss  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetBinaryFraction>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    $0x16,%ebx
xorps  %xmm0,%xmm0
movss  %xmm0,(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebp,%eax
mov    %ebx,%ecx
shr    %cl,%eax
and    $0x1,%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
movss  %xmm0,0x4(%rsp)
xorps  %xmm0,%xmm0
cvtsi2ss %ebx,%xmm0
addss  0xeab(%rip),%xmm0
call   1030 <exp2f@plt>
mulss  0x4(%rsp),%xmm0
addss  (%rsp),%xmm0
test   %ebx,%ebx
je     11ae <GetBinaryFraction+0x9e>
lea    -0x1(%rbx),%ecx
mov    %ebp,%eax
shr    %cl,%eax
and    $0x1,%eax
xorps  %xmm1,%xmm1
cvtsi2ss %eax,%xmm1
movss  %xmm1,0x4(%rsp)
movss  %xmm0,(%rsp)
xorps  %xmm0,%xmm0
cvtsi2ss %ecx,%xmm0
addss  0xe6c(%rip),%xmm0
call   1030 <exp2f@plt>
mulss  0x4(%rsp),%xmm0
addss  (%rsp),%xmm0
movss  %xmm0,(%rsp)
add    $0xfffffffe,%ebx
jmp    1130 <GetBinaryFraction+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define float @GetBinaryFraction(i32 %0) {
%2 = alloca i32
%3 = alloca float
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
store float 0.000000e+00, float* %3
store i32 22, i32* %4
br label %6
6: ; preds = %23, %1
%7 = load i32, i32* %4
%8 = icmp sge i32 %7, 0
br i1 %8, label %9, label %26
9: ; preds = %6
%10 = load i32, i32* %2
%11 = load i32, i32* %4
%12 = ashr i32 %10, %11
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = and i32 %13, 1
store i32 %14, i32* %5
%15 = load i32, i32* %5
%16 = sitofp i32 %15 to float
%17 = load i32, i32* %4
%18 = sitofp i32 %17 to float
%19 = fsub float %18, 2.300000e+01
%20 = call float @powf(float 2.000000e+00, float %19)
%21 = load float, float* %3
%22 = call float @llvm.fmuladd.f32(float %16, float %20, float %21)
store float %22, float* %3
br label %23
23: ; preds = %9
%24 = load i32, i32* %4
%25 = add nsw i32 %24, -1
store i32 %25, i32* %4
br label %6
26: ; preds = %6
%27 = load float, float* %3
ret float %27
}

LLVM IR (-O2):
define float @GetBinaryFraction(i32 %0) {
br label %2
2: ; preds = %14, %1
%3 = phi float [ 0.000000e+00, %1 ], [ %21, %14 ]
%4 = phi i32 [ 22, %1 ], [ %22, %14 ]
%5 = lshr i32 %0, %4
%6 = and i32 %5, 1
%7 = sitofp i32 %6 to float
%8 = sitofp i32 %4 to float
%9 = fadd float %8, -2.300000e+01
%10 = tail call float @exp2f(float %9)
%11 = tail call float @llvm.fmuladd.f32(float %7, float %10, float %3)
%12 = add nsw i32 %4, -1
%13 = icmp eq i32 %4, 0
br i1 %13, label %23, label %14
14: ; preds = %2
%15 = lshr i32 %0, %12
%16 = and i32 %15, 1
%17 = sitofp i32 %16 to float
%18 = sitofp i32 %12 to float
%19 = fadd float %18, -2.300000e+01
%20 = tail call float @exp2f(float %19)
%21 = tail call float @llvm.fmuladd.f32(float %17, float %20, float %11)
%22 = add nsw i32 %4, -2
br label %2
23: ; preds = %2
ret float %11
}