#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 */
int /*<<< orphan*/ assert(int);
float maxFixed(int, int);
float minFixed(int, int);
double powInt(int, int);
float roundInt(float);
float floatToFixed(float number, int k, int l) {
  float quant = 1.0 / powInt(2, l);
  float div = roundInt(number / quant);
  float ret = quant * div;
  assert(ret <= maxFixed(k, l) && ret >= minFixed(k, l));
  return ret;
}


x86 assembly (clang, -O0):
<floatToFixed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movss  %xmm0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%esi
mov    $0x2,%edi
call   1030 <powInt@plt>
movaps %xmm0,%xmm1
movsd  0xe85(%rip),%xmm0
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x4(%rbp),%xmm0
divss  -0x10(%rbp),%xmm0
call   1070 <roundInt@plt>
movss  %xmm0,-0x14(%rbp)
movss  -0x10(%rbp),%xmm0
mulss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1060 <maxFixed@plt>
movss  -0x20(%rbp),%xmm1
xor    %eax,%eax
ucomiss %xmm1,%xmm0
mov    %al,-0x19(%rbp)
jb     11f9 <floatToFixed+0xa9>
movss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1050 <minFixed@plt>
movaps %xmm0,%xmm1
movss  -0x24(%rbp),%xmm0
ucomiss %xmm1,%xmm0
setae  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movss  -0x18(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<floatToFixed>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
movss  %xmm0,(%rsp)
mov    $0x2,%edi
call   1030 <powInt@plt>
movsd  0xe92(%rip),%xmm1
divsd  %xmm0,%xmm1
cvtsd2ss %xmm1,%xmm1
movss  %xmm1,0x4(%rsp)
movss  (%rsp),%xmm0
divss  %xmm1,%xmm0
call   1070 <roundInt@plt>
mulss  0x4(%rsp),%xmm0
movss  %xmm0,(%rsp)
mov    %ebp,%edi
mov    %ebx,%esi
call   1060 <maxFixed@plt>
xor    %edi,%edi
ucomiss (%rsp),%xmm0
jb     11bd <floatToFixed+0x6d>
mov    %ebp,%edi
mov    %ebx,%esi
call   1050 <minFixed@plt>
xor    %edi,%edi
movss  (%rsp),%xmm1
ucomiss %xmm0,%xmm1
setae  %dil
call   1040 <assert@plt>
movss  (%rsp),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define float @floatToFixed(float %0, i32 %1, i32 %2) {
%4 = alloca float
%5 = alloca i32
%6 = alloca i32
%7 = alloca float
%8 = alloca float
%9 = alloca float
store float %0, float* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%10 = load i32, i32* %6
%11 = call double @powInt(i32 2, i32 %10)
%12 = fdiv double 1.000000e+00, %11
%13 = fptrunc double %12 to float
store float %13, float* %7
%14 = load float, float* %4
%15 = load float, float* %7
%16 = fdiv float %14, %15
%17 = call float @roundInt(float %16)
store float %17, float* %8
%18 = load float, float* %7
%19 = load float, float* %8
%20 = fmul float %18, %19
store float %20, float* %9
%21 = load float, float* %9
%22 = load i32, i32* %5
%23 = load i32, i32* %6
%24 = call float @maxFixed(i32 %22, i32 %23)
%25 = fcmp ole float %21, %24
br i1 %25, label %26, label %32
26: ; preds = %3
%27 = load float, float* %9
%28 = load i32, i32* %5
%29 = load i32, i32* %6
%30 = call float @minFixed(i32 %28, i32 %29)
%31 = fcmp oge float %27, %30
br label %32
32: ; preds = %26, %3
%33 = phi i1 [ false, %3 ], [ %31, %26 ]
%34 = zext i1 %33 to i32
%35 = call i32 @assert(i32 %34)
%36 = load float, float* %9
ret float %36
}

LLVM IR (-O2):
define float @floatToFixed(float %0, i32 %1, i32 %2) {
%4 = tail call double @powInt(i32 2, i32 %2)
%5 = fdiv double 1.000000e+00, %4
%6 = fptrunc double %5 to float
%7 = fdiv float %0, %6
%8 = tail call float @roundInt(float %7)
%9 = fmul float %8, %6
%10 = tail call float @maxFixed(i32 %1, i32 %2)
%11 = fcmp ugt float %9, %10
br i1 %11, label %16, label %12
12: ; preds = %3
%13 = tail call float @minFixed(i32 %1, i32 %2)
%14 = fcmp oge float %9, %13
%15 = zext i1 %14 to i32
br label %16
16: ; preds = %12, %3
%17 = phi i32 [ 0, %3 ], [ %15, %12 ]
%18 = tail call i32 @assert(i32 %17)
ret float %9
}