#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 roundf(float);
float binearest_interp(float tl, float tr, float bl, float br, float x_amount,
                       float y_amount) {
  x_amount = roundf(x_amount);
  y_amount = roundf(y_amount);
  if (x_amount && !y_amount) {
    return br;
  }
  if (!x_amount && y_amount) {
    return tl;
  }
  if (!x_amount && !y_amount) {
    return bl;
  }
  if (x_amount && y_amount) {
    return tr;
  }
  return 0.0f;
}


x86 assembly (clang, -O0):
<binearest_interp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x8(%rbp)
movss  %xmm1,-0xc(%rbp)
movss  %xmm2,-0x10(%rbp)
movss  %xmm3,-0x14(%rbp)
movss  %xmm4,-0x18(%rbp)
movss  %xmm5,-0x1c(%rbp)
movss  -0x18(%rbp),%xmm0
call   1030 <roundf@plt>
movss  %xmm0,-0x18(%rbp)
movss  -0x1c(%rbp),%xmm0
call   1030 <roundf@plt>
movss  %xmm0,-0x1c(%rbp)
movss  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    1170 <binearest_interp+0x60>
jp     1170 <binearest_interp+0x60>
jmp    1196 <binearest_interp+0x86>
movss  -0x1c(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    1196 <binearest_interp+0x86>
jp     1196 <binearest_interp+0x86>
movss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1264 <binearest_interp+0x154>
movss  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    11d8 <binearest_interp+0xc8>
jp     11d8 <binearest_interp+0xc8>
movss  -0x1c(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    11c9 <binearest_interp+0xb9>
jp     11c9 <binearest_interp+0xb9>
jmp    11d8 <binearest_interp+0xc8>
movss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1264 <binearest_interp+0x154>
movss  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    1215 <binearest_interp+0x105>
jp     1215 <binearest_interp+0x105>
movss  -0x1c(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    1215 <binearest_interp+0x105>
jp     1215 <binearest_interp+0x105>
movss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1264 <binearest_interp+0x154>
movss  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    1231 <binearest_interp+0x121>
jp     1231 <binearest_interp+0x121>
jmp    125c <binearest_interp+0x14c>
movss  -0x1c(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    124d <binearest_interp+0x13d>
jp     124d <binearest_interp+0x13d>
jmp    125c <binearest_interp+0x14c>
movss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1264 <binearest_interp+0x154>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<binearest_interp>:
sub    $0x38,%rsp
movss  %xmm5,0xc(%rsp)
movss  %xmm3,0x8(%rsp)
movss  %xmm2,(%rsp)
movaps %xmm1,0x10(%rsp)
movss  %xmm0,0x4(%rsp)
movaps %xmm4,%xmm0
call   1030 <roundf@plt>
movaps %xmm0,0x20(%rsp)
movss  0xc(%rsp),%xmm0
call   1030 <roundf@plt>
movss  0x8(%rsp),%xmm3
movaps 0x20(%rsp),%xmm2
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm2
jne    115d <binearest_interp+0x4d>
jnp    1164 <binearest_interp+0x54>
ucomiss %xmm1,%xmm0
jne    1164 <binearest_interp+0x54>
jnp    11a6 <binearest_interp+0x96>
ucomiss %xmm1,%xmm2
jne    117b <binearest_interp+0x6b>
jp     117b <binearest_interp+0x6b>
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
movss  0x4(%rsp),%xmm3
jne    11a6 <binearest_interp+0x96>
jp     11a6 <binearest_interp+0x96>
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm2
jne    1191 <binearest_interp+0x81>
jp     1191 <binearest_interp+0x81>
ucomiss %xmm1,%xmm0
movss  (%rsp),%xmm3
jne    1191 <binearest_interp+0x81>
jnp    11a6 <binearest_interp+0x96>
cmpneqss %xmm1,%xmm2
cmpneqss %xmm1,%xmm0
andps  0x10(%rsp),%xmm0
andps  %xmm2,%xmm0
movaps %xmm0,%xmm3
movaps %xmm3,%xmm0
add    $0x38,%rsp
ret

LLVM IR (-O0):
define float @binearest_interp(float %0, float %1, float %2, float %3, float %4, float %5) {
%7 = alloca float
%8 = alloca float
%9 = alloca float
%10 = alloca float
%11 = alloca float
%12 = alloca float
%13 = alloca float
store float %0, float* %8
store float %1, float* %9
store float %2, float* %10
store float %3, float* %11
store float %4, float* %12
store float %5, float* %13
%14 = load float, float* %12
%15 = call float @llvm.round.f32(float %14)
store float %15, float* %12
%16 = load float, float* %13
%17 = call float @llvm.round.f32(float %16)
store float %17, float* %13
%18 = load float, float* %12
%19 = fcmp une float %18, 0.000000e+00
br i1 %19, label %20, label %25
20: ; preds = %6
%21 = load float, float* %13
%22 = fcmp une float %21, 0.000000e+00
br i1 %22, label %25, label %23
23: ; preds = %20
%24 = load float, float* %11
store float %24, float* %7
br label %50
25: ; preds = %20, %6
%26 = load float, float* %12
%27 = fcmp une float %26, 0.000000e+00
br i1 %27, label %33, label %28
28: ; preds = %25
%29 = load float, float* %13
%30 = fcmp une float %29, 0.000000e+00
br i1 %30, label %31, label %33
31: ; preds = %28
%32 = load float, float* %8
store float %32, float* %7
br label %50
33: ; preds = %28, %25
%34 = load float, float* %12
%35 = fcmp une float %34, 0.000000e+00
br i1 %35, label %41, label %36
36: ; preds = %33
%37 = load float, float* %13
%38 = fcmp une float %37, 0.000000e+00
br i1 %38, label %41, label %39
39: ; preds = %36
%40 = load float, float* %10
store float %40, float* %7
br label %50
41: ; preds = %36, %33
%42 = load float, float* %12
%43 = fcmp une float %42, 0.000000e+00
br i1 %43, label %44, label %49
44: ; preds = %41
%45 = load float, float* %13
%46 = fcmp une float %45, 0.000000e+00
br i1 %46, label %47, label %49
47: ; preds = %44
%48 = load float, float* %9
store float %48, float* %7
br label %50
49: ; preds = %44, %41
store float 0.000000e+00, float* %7
br label %50
50: ; preds = %49, %47, %39, %31, %23
%51 = load float, float* %7
ret float %51
}

LLVM IR (-O2):
define float @binearest_interp(float %0, float %1, float %2, float %3, float %4, float %5) {
%7 = tail call float @llvm.round.f32(float %4)
%8 = tail call float @llvm.round.f32(float %5)
%9 = fcmp oeq float %7, 0.000000e+00
%10 = fcmp une float %8, 0.000000e+00
%11 = select i1 %9, i1 true, i1 %10
br i1 %11, label %12, label %20
12: ; preds = %6
%13 = select i1 %9, i1 %10, i1 false
br i1 %13, label %20, label %14
14: ; preds = %12
%15 = fcmp une float %7, 0.000000e+00
%16 = select i1 %15, i1 true, i1 %10
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = select i1 %15, i1 %10, i1 false
%19 = select i1 %18, float %1, float 0.000000e+00
br label %20
20: ; preds = %17, %14, %12, %6
%21 = phi float [ %3, %6 ], [ %0, %12 ], [ %2, %14 ], [ %19, %17 ]
ret float %21
}