#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);
scalar_t__ fabs(float);
float stbir__filter_trapezoid(float x, float scale) {
  float halfscale = scale / 2;
  float t = 0.5f + halfscale;
  assert(scale <= 1);
  x = (float)fabs(x);
  if (x >= t)
    return 0;
  else {
    float r = 0.5f - halfscale;
    if (x <= r)
      return 1;
    else
      return (t - x) / scale;
  }
}


x86 assembly (clang, -O0):
<stbir__filter_trapezoid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x8(%rbp)
movss  %xmm1,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
movss  0xec9(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  0xeb4(%rip),%xmm0
addss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  0xe9e(%rip),%xmm0
ucomiss -0xc(%rbp),%xmm0
setae  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movss  -0x8(%rbp),%xmm0
call   1030 <fabs@plt>
cvtsi2ss %rax,%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
ucomiss -0x14(%rbp),%xmm0
jb     11a3 <stbir__filter_trapezoid+0x83>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    11ee <stbir__filter_trapezoid+0xce>
movss  0xe59(%rip),%xmm0
subss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x8(%rbp),%xmm1
movss  -0x18(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jb     11da <stbir__filter_trapezoid+0xba>
movss  0xe30(%rip),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    11ee <stbir__filter_trapezoid+0xce>
movss  -0x14(%rbp),%xmm0
subss  -0x8(%rbp),%xmm0
divss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stbir__filter_trapezoid>:
sub    $0x18,%rsp
movss  %xmm0,0x14(%rsp)
movss  0xece(%rip),%xmm0
movaps %xmm1,%xmm2
mulss  %xmm0,%xmm2
movss  %xmm2,0xc(%rsp)
addss  %xmm0,%xmm2
movss  %xmm2,0x10(%rsp)
movss  0xeb3(%rip),%xmm0
xor    %edi,%edi
movss  %xmm1,0x8(%rsp)
ucomiss %xmm1,%xmm0
setae  %dil
call   1040 <assert@plt>
movss  0x14(%rsp),%xmm0
call   1030 <fabs@plt>
movss  0x10(%rsp),%xmm2
xorps  %xmm1,%xmm1
cvtsi2ss %rax,%xmm1
xorps  %xmm0,%xmm0
ucomiss %xmm2,%xmm1
jae    11ae <stbir__filter_trapezoid+0x8e>
movss  0xe72(%rip),%xmm0
subss  0xc(%rsp),%xmm0
ucomiss %xmm1,%xmm0
movss  0xe65(%rip),%xmm0
jae    11ae <stbir__filter_trapezoid+0x8e>
subss  %xmm1,%xmm2
divss  0x8(%rsp),%xmm2
movaps %xmm2,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define float @stbir__filter_trapezoid(float %0, float %1) {
%3 = alloca float
%4 = alloca float
%5 = alloca float
%6 = alloca float
%7 = alloca float
%8 = alloca float
store float %0, float* %4
store float %1, float* %5
%9 = load float, float* %5
%10 = fdiv float %9, 2.000000e+00
store float %10, float* %6
%11 = load float, float* %6
%12 = fadd float 5.000000e-01, %11
store float %12, float* %7
%13 = load float, float* %5
%14 = fcmp ole float %13, 1.000000e+00
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = load float, float* %4
%18 = call i64 @fabs(float %17)
%19 = sitofp i64 %18 to float
store float %19, float* %4
%20 = load float, float* %4
%21 = load float, float* %7
%22 = fcmp oge float %20, %21
br i1 %22, label %23, label %24
23: ; preds = %2
store float 0.000000e+00, float* %3
br label %37
24: ; preds = %2
%25 = load float, float* %6
%26 = fsub float 5.000000e-01, %25
store float %26, float* %8
%27 = load float, float* %4
%28 = load float, float* %8
%29 = fcmp ole float %27, %28
br i1 %29, label %30, label %31
30: ; preds = %24
store float 1.000000e+00, float* %3
br label %37
31: ; preds = %24
%32 = load float, float* %7
%33 = load float, float* %4
%34 = fsub float %32, %33
%35 = load float, float* %5
%36 = fdiv float %34, %35
store float %36, float* %3
br label %37
37: ; preds = %31, %30, %23
%38 = load float, float* %3
ret float %38
}

LLVM IR (-O2):
define float @stbir__filter_trapezoid(float %0, float %1) {
%3 = fmul float %1, 5.000000e-01
%4 = fadd float %3, 5.000000e-01
%5 = fcmp ole float %1, 1.000000e+00
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = tail call i64 @fabs(float %0)
%9 = sitofp i64 %8 to float
%10 = fcmp ugt float %4, %9
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = fsub float 5.000000e-01, %3
%13 = fcmp ult float %12, %9
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = fsub float %4, %9
%16 = fdiv float %15, %1
br label %17
17: ; preds = %14, %11, %2
%18 = phi float [ 0.000000e+00, %2 ], [ %16, %14 ], [ 1.000000e+00, %11 ]
ret float %18
}