#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);
float roundInt(float);
float wrapF(float, float, float);
float floatToFix(float number, float delta, int k, int l, int catchOverflow) {
  float div = roundInt(number / delta);
  float ret = delta * div;
  if (catchOverflow) {
    assert(ret <= maxFixed(k, l) && ret >= minFixed(k, l));
  } else if (ret > maxFixed(k, l) || ret < minFixed(k, l)) {
    ret = wrapF(ret, minFixed(k, l), maxFixed(k, l));
  }
  return ret;
}


x86 assembly (clang, -O0):
<floatToFix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movss  -0x4(%rbp),%xmm0
divss  -0x8(%rbp),%xmm0
call   1070 <roundInt@plt>
movss  %xmm0,-0x18(%rbp)
movss  -0x8(%rbp),%xmm0
mulss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11f8 <floatToFix+0xa8>
movss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1060 <maxFixed@plt>
movss  -0x24(%rbp),%xmm1
xor    %eax,%eax
ucomiss %xmm1,%xmm0
mov    %al,-0x1d(%rbp)
jb     11e6 <floatToFix+0x96>
movss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x28(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1050 <minFixed@plt>
movaps %xmm0,%xmm1
movss  -0x28(%rbp),%xmm0
ucomiss %xmm1,%xmm0
setae  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
jmp    1282 <floatToFix+0x132>
movss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x2c(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1060 <maxFixed@plt>
movaps %xmm0,%xmm1
movss  -0x2c(%rbp),%xmm0
ucomiss %xmm1,%xmm0
ja     1241 <floatToFix+0xf1>
movss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x30(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1050 <minFixed@plt>
movss  -0x30(%rbp),%xmm1
ucomiss %xmm1,%xmm0
jbe    127d <floatToFix+0x12d>
movss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x34(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1050 <minFixed@plt>
movss  %xmm0,-0x38(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1060 <maxFixed@plt>
movss  -0x38(%rbp),%xmm1
movaps %xmm0,%xmm2
movss  -0x34(%rbp),%xmm0
call   1030 <wrapF@plt>
movss  %xmm0,-0x1c(%rbp)
jmp    1282 <floatToFix+0x132>
movss  -0x1c(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<floatToFix>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%ebx
mov    %esi,%r14d
mov    %edi,%ebp
movss  %xmm1,0x8(%rsp)
divss  %xmm1,%xmm0
call   1070 <roundInt@plt>
mulss  0x8(%rsp),%xmm0
movss  %xmm0,0x8(%rsp)
mov    %ebp,%edi
mov    %r14d,%esi
call   1060 <maxFixed@plt>
test   %ebx,%ebx
je     11be <floatToFix+0x6e>
xor    %edi,%edi
ucomiss 0x8(%rsp),%xmm0
jb     11aa <floatToFix+0x5a>
mov    %ebp,%edi
mov    %r14d,%esi
call   1050 <minFixed@plt>
xor    %edi,%edi
movss  0x8(%rsp),%xmm1
ucomiss %xmm0,%xmm1
setae  %dil
call   1040 <assert@plt>
movss  0x8(%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
movss  0x8(%rsp),%xmm1
ucomiss %xmm0,%xmm1
ja     11e0 <floatToFix+0x90>
mov    %ebp,%edi
mov    %r14d,%esi
call   1050 <minFixed@plt>
ucomiss 0x8(%rsp),%xmm0
movss  0x8(%rsp),%xmm0
jbe    11b5 <floatToFix+0x65>
mov    %ebp,%edi
mov    %r14d,%esi
call   1050 <minFixed@plt>
movss  %xmm0,0xc(%rsp)
mov    %ebp,%edi
mov    %r14d,%esi
call   1060 <maxFixed@plt>
movaps %xmm0,%xmm2
movss  0x8(%rsp),%xmm0
movss  0xc(%rsp),%xmm1
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <wrapF@plt>

LLVM IR (-O0):
define float @floatToFix(float %0, float %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca float
%7 = alloca float
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca float
%12 = alloca float
store float %0, float* %6
store float %1, float* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%13 = load float, float* %6
%14 = load float, float* %7
%15 = fdiv float %13, %14
%16 = call float @roundInt(float %15)
store float %16, float* %11
%17 = load float, float* %7
%18 = load float, float* %11
%19 = fmul float %17, %18
store float %19, float* %12
%20 = load i32, i32* %10
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %38
22: ; preds = %5
%23 = load float, float* %12
%24 = load i32, i32* %8
%25 = load i32, i32* %9
%26 = call float @maxFixed(i32 %24, i32 %25)
%27 = fcmp ole float %23, %26
br i1 %27, label %28, label %34
28: ; preds = %22
%29 = load float, float* %12
%30 = load i32, i32* %8
%31 = load i32, i32* %9
%32 = call float @minFixed(i32 %30, i32 %31)
%33 = fcmp oge float %29, %32
br label %34
34: ; preds = %28, %22
%35 = phi i1 [ false, %22 ], [ %33, %28 ]
%36 = zext i1 %35 to i32
%37 = call i32 @assert(i32 %36)
br label %60
38: ; preds = %5
%39 = load float, float* %12
%40 = load i32, i32* %8
%41 = load i32, i32* %9
%42 = call float @maxFixed(i32 %40, i32 %41)
%43 = fcmp ogt float %39, %42
br i1 %43, label %50, label %44
44: ; preds = %38
%45 = load float, float* %12
%46 = load i32, i32* %8
%47 = load i32, i32* %9
%48 = call float @minFixed(i32 %46, i32 %47)
%49 = fcmp olt float %45, %48
br i1 %49, label %50, label %59
50: ; preds = %44, %38
%51 = load float, float* %12
%52 = load i32, i32* %8
%53 = load i32, i32* %9
%54 = call float @minFixed(i32 %52, i32 %53)
%55 = load i32, i32* %8
%56 = load i32, i32* %9
%57 = call float @maxFixed(i32 %55, i32 %56)
%58 = call float @wrapF(float %51, float %54, float %57)
store float %58, float* %12
br label %59
59: ; preds = %50, %44
br label %60
60: ; preds = %59, %34
%61 = load float, float* %12
ret float %61
}

LLVM IR (-O2):
define float @floatToFix(float %0, float %1, i32 %2, i32 %3, i32 %4) {
%6 = fdiv float %0, %1
%7 = tail call float @roundInt(float %6)
%8 = fmul float %7, %1
%9 = icmp eq i32 %4, 0
%10 = tail call float @maxFixed(i32 %2, i32 %3)
br i1 %9, label %20, label %11
11: ; preds = %5
%12 = fcmp ugt float %8, %10
br i1 %12, label %17, label %13
13: ; preds = %11
%14 = tail call float @minFixed(i32 %2, i32 %3)
%15 = fcmp oge float %8, %14
%16 = zext i1 %15 to i32
br label %17
17: ; preds = %13, %11
%18 = phi i32 [ 0, %11 ], [ %16, %13 ]
%19 = tail call i32 @assert(i32 %18)
br label %29
20: ; preds = %5
%21 = fcmp ogt float %8, %10
br i1 %21, label %25, label %22
22: ; preds = %20
%23 = tail call float @minFixed(i32 %2, i32 %3)
%24 = fcmp olt float %8, %23
br i1 %24, label %25, label %29
25: ; preds = %22, %20
%26 = tail call float @minFixed(i32 %2, i32 %3)
%27 = tail call float @maxFixed(i32 %2, i32 %3)
%28 = tail call float @wrapF(float %8, float %26, float %27)
br label %29
29: ; preds = %22, %25, %17
%30 = phi float [ %8, %17 ], [ %28, %25 ], [ %8, %22 ]
ret float %30
}