#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 uint32_t;

/* Variables and functions */
uint32_t etna_cfloat_to_uintN(float f, int bits) {
  if (f <= 0.0f)
    return 0;
  if (f >= (1.0f - 1.0f / (1 << bits)))
    return (1 << bits) - 1;
  return f * (1 << bits);
}


x86 assembly (clang, -O0):
<etna_cfloat_to_uintN>:
push   %rbp
mov    %rsp,%rbp
movss  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
xorps  %xmm0,%xmm0
ucomiss -0x8(%rbp),%xmm0
jb     1125 <etna_cfloat_to_uintN+0x25>
movl   $0x0,-0x4(%rbp)
jmp    118c <etna_cfloat_to_uintN+0x8c>
movss  -0x8(%rbp),%xmm0
mov    -0xc(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
cvtsi2ss %eax,%xmm1
movss  0xec0(%rip),%xmm2
divss  %xmm1,%xmm2
movss  0xeb4(%rip),%xmm1
subss  %xmm2,%xmm1
ucomiss %xmm1,%xmm0
jb     116e <etna_cfloat_to_uintN+0x6e>
mov    -0xc(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
sub    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    118c <etna_cfloat_to_uintN+0x8c>
movss  -0x8(%rbp),%xmm0
mov    -0xc(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
cvtsi2ss %eax,%xmm1
mulss  %xmm1,%xmm0
cvttss2si %xmm0,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<etna_cfloat_to_uintN>:
xor    %eax,%eax
xorps  %xmm1,%xmm1
ucomiss %xmm0,%xmm1
jae    113a <etna_cfloat_to_uintN+0x3a>
mov    $0x1,%eax
mov    %edi,%ecx
shl    %cl,%eax
xorps  %xmm1,%xmm1
cvtsi2ss %eax,%xmm1
movss  0xede(%rip),%xmm2
movaps %xmm2,%xmm3
divss  %xmm1,%xmm3
subss  %xmm3,%xmm2
ucomiss %xmm2,%xmm0
jae    113b <etna_cfloat_to_uintN+0x3b>
mulss  %xmm0,%xmm1
cvttss2si %xmm1,%eax
ret
add    $0xffffffff,%eax
ret

LLVM IR (-O0):
define i32 @etna_cfloat_to_uintN(float %0, i32 %1) {
%3 = alloca i32
%4 = alloca float
%5 = alloca i32
store float %0, float* %4
store i32 %1, i32* %5
%6 = load float, float* %4
%7 = fcmp ole float %6, 0.000000e+00
br i1 %7, label %8, label %9
8: ; preds = %2
store i32 0, i32* %3
br label %28
9: ; preds = %2
%10 = load float, float* %4
%11 = load i32, i32* %5
%12 = shl i32 1, %11
%13 = sitofp i32 %12 to float
%14 = fdiv float 1.000000e+00, %13
%15 = fsub float 1.000000e+00, %14
%16 = fcmp oge float %10, %15
br i1 %16, label %17, label %21
17: ; preds = %9
%18 = load i32, i32* %5
%19 = shl i32 1, %18
%20 = sub nsw i32 %19, 1
store i32 %20, i32* %3
br label %28
21: ; preds = %9
%22 = load float, float* %4
%23 = load i32, i32* %5
%24 = shl i32 1, %23
%25 = sitofp i32 %24 to float
%26 = fmul float %22, %25
%27 = fptosi float %26 to i32
store i32 %27, i32* %3
br label %28
28: ; preds = %21, %17, %8
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
define i32 @etna_cfloat_to_uintN(float %0, i32 %1) {
%3 = fcmp ugt float %0, 0.000000e+00
br i1 %3, label %4, label %15
4: ; preds = %2
%5 = shl nuw i32 1, %1
%6 = sitofp i32 %5 to float
%7 = fdiv float 1.000000e+00, %6
%8 = fsub float 1.000000e+00, %7
%9 = fcmp ugt float %8, %0
br i1 %9, label %12, label %10
10: ; preds = %4
%11 = add nsw i32 %5, -1
br label %15
12: ; preds = %4
%13 = fmul float %6, %0
%14 = fptosi float %13 to i32
br label %15
15: ; preds = %2, %12, %10
%16 = phi i32 [ %11, %10 ], [ %14, %12 ], [ 0, %2 ]
ret i32 %16
}