#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 */
float fmod(float, float);
float limat_quantize(float value, float resolution) {
  float tmp;
  if (resolution <= 1E-20f)
    return value;
  tmp = fmod(value, resolution);
  if (tmp >= 0.5f * resolution)
    return value - tmp + resolution;
  else if (tmp <= -0.5f * resolution)
    return value - tmp - resolution;
  else
    return value - tmp;
}


x86 assembly (clang, -O0):
<limat_quantize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movss  %xmm0,-0x8(%rbp)
movss  %xmm1,-0xc(%rbp)
movss  0xed6(%rip),%xmm0
ucomiss -0xc(%rbp),%xmm0
jb     1143 <limat_quantize+0x33>
movss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    11ce <limat_quantize+0xbe>
movss  -0x8(%rbp),%xmm0
movss  -0xc(%rbp),%xmm1
call   1030 <fmod@plt>
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
movss  0xea0(%rip),%xmm1
mulss  -0xc(%rbp),%xmm1
ucomiss %xmm1,%xmm0
jb     118b <limat_quantize+0x7b>
movss  -0x8(%rbp),%xmm0
subss  -0x10(%rbp),%xmm0
addss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    11ce <limat_quantize+0xbe>
movss  -0x10(%rbp),%xmm1
movss  0xe70(%rip),%xmm0
mulss  -0xc(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jb     11bf <limat_quantize+0xaf>
movss  -0x8(%rbp),%xmm0
subss  -0x10(%rbp),%xmm0
subss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    11ce <limat_quantize+0xbe>
movss  -0x8(%rbp),%xmm0
subss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<limat_quantize>:
push   %rax
movss  0xee7(%rip),%xmm2
ucomiss %xmm1,%xmm2
jae    1166 <limat_quantize+0x56>
movss  %xmm0,(%rsp)
movss  %xmm1,0x4(%rsp)
call   1030 <fmod@plt>
movss  0x4(%rsp),%xmm2
movss  0xec8(%rip),%xmm1
mulss  %xmm2,%xmm1
ucomiss %xmm1,%xmm0
jae    1168 <limat_quantize+0x58>
movss  0xebb(%rip),%xmm1
mulss  %xmm2,%xmm1
ucomiss %xmm0,%xmm1
movss  (%rsp),%xmm1
subss  %xmm0,%xmm1
movaps %xmm1,%xmm0
jb     1166 <limat_quantize+0x56>
subss  %xmm2,%xmm0
pop    %rax
ret
movss  (%rsp),%xmm1
subss  %xmm0,%xmm1
addss  %xmm2,%xmm1
movaps %xmm1,%xmm0
pop    %rax
ret

LLVM IR (-O0):
define float @limat_quantize(float %0, float %1) {
%3 = alloca float
%4 = alloca float
%5 = alloca float
%6 = alloca float
store float %0, float* %4
store float %1, float* %5
%7 = load float, float* %5
%8 = fcmp ole float %7, 0x3BC79CA100000000
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = load float, float* %4
store float %10, float* %3
br label %40
11: ; preds = %2
%12 = load float, float* %4
%13 = load float, float* %5
%14 = call float @fmod(float %12, float %13)
store float %14, float* %6
%15 = load float, float* %6
%16 = load float, float* %5
%17 = fmul float 5.000000e-01, %16
%18 = fcmp oge float %15, %17
br i1 %18, label %19, label %25
19: ; preds = %11
%20 = load float, float* %4
%21 = load float, float* %6
%22 = fsub float %20, %21
%23 = load float, float* %5
%24 = fadd float %22, %23
store float %24, float* %3
br label %40
25: ; preds = %11
%26 = load float, float* %6
%27 = load float, float* %5
%28 = fmul float -5.000000e-01, %27
%29 = fcmp ole float %26, %28
br i1 %29, label %30, label %36
30: ; preds = %25
%31 = load float, float* %4
%32 = load float, float* %6
%33 = fsub float %31, %32
%34 = load float, float* %5
%35 = fsub float %33, %34
store float %35, float* %3
br label %40
36: ; preds = %25
%37 = load float, float* %4
%38 = load float, float* %6
%39 = fsub float %37, %38
store float %39, float* %3
br label %40
40: ; preds = %36, %30, %19, %9
%41 = load float, float* %3
ret float %41
}

LLVM IR (-O2):
define float @limat_quantize(float %0, float %1) {
%3 = fcmp ugt float %1, 0x3BC79CA100000000
br i1 %3, label %4, label %17
4: ; preds = %2
%5 = tail call float @fmod(float %0, float %1)
%6 = fmul float %1, 5.000000e-01
%7 = fcmp ult float %5, %6
br i1 %7, label %11, label %8
8: ; preds = %4
%9 = fsub float %0, %5
%10 = fadd float %9, %1
br label %17
11: ; preds = %4
%12 = fmul float %1, -5.000000e-01
%13 = fcmp ugt float %5, %12
%14 = fsub float %0, %5
br i1 %13, label %17, label %15
15: ; preds = %11
%16 = fsub float %14, %1
br label %17
17: ; preds = %11, %2, %15, %8
%18 = phi float [ %10, %8 ], [ %16, %15 ], [ %0, %2 ], [ %14, %11 ]
ret float %18
}