#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 */
double exp(float);
short int FuzzyCost(short int v, float mean, float var, float topval) {
  float x;
  x = (((float)v) - mean);
  x = x * x;
  x = topval * (1.0 - exp(-x / (2 * var)));
  return ((short int)x);
}


x86 assembly (clang, -O0):
<FuzzyCost>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
movss  %xmm0,-0x8(%rbp)
movss  %xmm1,-0xc(%rbp)
movss  %xmm2,-0x10(%rbp)
movswl -0x2(%rbp),%eax
cvtsi2ss %eax,%xmm0
movss  -0x8(%rbp),%xmm1
subss  %xmm1,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
mulss  %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movaps 0xe99(%rip),%xmm1
movss  -0x14(%rbp),%xmm0
pxor   %xmm1,%xmm0
movss  -0xc(%rbp),%xmm1
addss  %xmm1,%xmm1
divss  %xmm1,%xmm0
call   1030 <exp@plt>
movaps %xmm0,%xmm2
movsd  -0x20(%rbp),%xmm0
movsd  0xe7e(%rip),%xmm1
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
cvttss2si %xmm0,%eax
cwtl
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FuzzyCost>:
push   %rax
cvtsi2ss %edi,%xmm3
subss  %xmm0,%xmm3
xorps  %xmm0,%xmm0
cvtss2sd %xmm2,%xmm0
movsd  %xmm0,(%rsp)
movaps 0xed4(%rip),%xmm0
xorps  %xmm3,%xmm0
mulss  %xmm3,%xmm0
addss  %xmm1,%xmm1
divss  %xmm1,%xmm0
call   1030 <exp@plt>
movsd  0xec8(%rip),%xmm1
subsd  %xmm0,%xmm1
mulsd  (%rsp),%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
cvttss2si %xmm0,%eax
pop    %rcx
ret

LLVM IR (-O0):
define signext i16 @FuzzyCost(i16 signext %0, float %1, float %2, float %3) {
%5 = alloca i16
%6 = alloca float
%7 = alloca float
%8 = alloca float
%9 = alloca float
store i16 %0, i16* %5
store float %1, float* %6
store float %2, float* %7
store float %3, float* %8
%10 = load i16, i16* %5
%11 = sitofp i16 %10 to float
%12 = load float, float* %6
%13 = fsub float %11, %12
store float %13, float* %9
%14 = load float, float* %9
%15 = load float, float* %9
%16 = fmul float %14, %15
store float %16, float* %9
%17 = load float, float* %8
%18 = fpext float %17 to double
%19 = load float, float* %9
%20 = fneg float %19
%21 = load float, float* %7
%22 = fmul float 2.000000e+00, %21
%23 = fdiv float %20, %22
%24 = call double @exp(float %23)
%25 = fsub double 1.000000e+00, %24
%26 = fmul double %18, %25
%27 = fptrunc double %26 to float
store float %27, float* %9
%28 = load float, float* %9
%29 = fptosi float %28 to i16
ret i16 %29
}

LLVM IR (-O2):
define signext i16 @FuzzyCost(i16 signext %0, float %1, float %2, float %3) {
%5 = sitofp i16 %0 to float
%6 = fsub float %5, %1
%7 = fpext float %3 to double
%8 = fneg float %6
%9 = fmul float %6, %8
%10 = fmul float %2, 2.000000e+00
%11 = fdiv float %9, %10
%12 = tail call double @exp(float %11)
%13 = fsub double 1.000000e+00, %12
%14 = fmul double %13, %7
%15 = fptrunc double %14 to float
%16 = fptosi float %15 to i16
ret i16 %16
}