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

/* Variables and functions */
int UINT16_MAX;
__attribute__((__const__)) uint16_t dim_ramps16(float encoding) {
  double i_encoding = (double)(encoding / 2.f);
  double f_output = (double)UINT16_MAX * i_encoding;
  uint16_t output = (uint16_t)f_output;
  if (i_encoding < (double)0.25f && output > UINT16_MAX / 2)
    output = 0;
  if (i_encoding > (double)0.75f && output < UINT16_MAX / 2)
    output = UINT16_MAX;
  return output;
}


x86 assembly (clang, -O0):
<dim_ramps16>:
push   %rbp
mov    %rsp,%rbp
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
movss  0xefa(%rip),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    0x2eb6(%rip),%rax
cvtsi2sdl (%rax),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
cvttsd2si -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
movsd  0xeb8(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    117e <dim_ramps16+0x7e>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e80(%rip),%rax
mov    (%rax),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jle    117e <dim_ramps16+0x7e>
movl   $0x0,-0x1c(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xe7d(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11c5 <dim_ramps16+0xc5>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    0x2e3e(%rip),%rax
mov    (%rax),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jge    11c5 <dim_ramps16+0xc5>
mov    0x2e20(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<dim_ramps16>:
mulss  0xef8(%rip),%xmm0
mov    0x2ed1(%rip),%rax
mov    (%rax),%ecx
cvtsi2sd %ecx,%xmm1
cvtss2sd %xmm0,%xmm2
mulsd  %xmm2,%xmm1
cvttsd2si %xmm1,%eax
movss  0xedb(%rip),%xmm1
ucomiss %xmm0,%xmm1
ja     1138 <dim_ramps16+0x38>
ucomiss 0xed3(%rip),%xmm0
ja     1151 <dim_ramps16+0x51>
ret
mov    %ecx,%edx
shr    $0x1f,%edx
add    %ecx,%edx
sar    %edx
xor    %esi,%esi
cmp    %eax,%edx
cmovl  %esi,%eax
ucomiss 0xeb9(%rip),%xmm0
jbe    1137 <dim_ramps16+0x37>
mov    %ecx,%edx
shr    $0x1f,%edx
add    %ecx,%edx
sar    %edx
cmp    %edx,%eax
cmovl  %ecx,%eax
ret

LLVM IR (-O0):
@UINT16_MAX = global i32 0
define i32 @dim_ramps16(float %0) {
%2 = alloca float
%3 = alloca double
%4 = alloca double
%5 = alloca i32
store float %0, float* %2
%6 = load float, float* %2
%7 = fdiv float %6, 2.000000e+00
%8 = fpext float %7 to double
store double %8, double* %3
%9 = load i32, i32* @UINT16_MAX
%10 = sitofp i32 %9 to double
%11 = load double, double* %3
%12 = fmul double %10, %11
store double %12, double* %4
%13 = load double, double* %4
%14 = fptosi double %13 to i32
store i32 %14, i32* %5
%15 = load double, double* %3
%16 = fcmp olt double %15, 2.500000e-01
br i1 %16, label %17, label %23
17: ; preds = %1
%18 = load i32, i32* %5
%19 = load i32, i32* @UINT16_MAX
%20 = sdiv i32 %19, 2
%21 = icmp sgt i32 %18, %20
br i1 %21, label %22, label %23
22: ; preds = %17
store i32 0, i32* %5
br label %23
23: ; preds = %22, %17, %1
%24 = load double, double* %3
%25 = fcmp ogt double %24, 7.500000e-01
br i1 %25, label %26, label %33
26: ; preds = %23
%27 = load i32, i32* %5
%28 = load i32, i32* @UINT16_MAX
%29 = sdiv i32 %28, 2
%30 = icmp slt i32 %27, %29
br i1 %30, label %31, label %33
31: ; preds = %26
%32 = load i32, i32* @UINT16_MAX
store i32 %32, i32* %5
br label %33
33: ; preds = %31, %26, %23
%34 = load i32, i32* %5
ret i32 %34
}

LLVM IR (-O2):
@UINT16_MAX = global i32 0
define i32 @dim_ramps16(float %0) {
%2 = fmul float %0, 5.000000e-01
%3 = fpext float %2 to double
%4 = load i32, i32* @UINT16_MAX
%5 = sitofp i32 %4 to double
%6 = fmul double %3, %5
%7 = fptosi double %6 to i32
%8 = fcmp olt float %2, 2.500000e-01
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = sdiv i32 %4, 2
%11 = icmp slt i32 %10, %7
%12 = select i1 %11, i32 0, i32 %7
br label %13
13: ; preds = %9, %1
%14 = phi i32 [ %12, %9 ], [ %7, %1 ]
%15 = fcmp ogt float %2, 7.500000e-01
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = sdiv i32 %4, 2
%18 = icmp slt i32 %14, %17
%19 = select i1 %18, i32 %4, i32 %14
br label %20
20: ; preds = %16, %13
%21 = phi i32 [ %14, %13 ], [ %19, %16 ]
ret i32 %21
}