#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 /*<<< orphan*/ __m128i;

/* Variables and functions */
int /*<<< orphan*/ _mm_adds_epu8(int /*<<< orphan*/ const,
                                 int /*<<< orphan*/ const);
int /*<<< orphan*/ _mm_and_si128(int /*<<< orphan*/ const,
                                 int /*<<< orphan*/ const);
int /*<<< orphan*/ _mm_cmpeq_epi8(int /*<<< orphan*/ const, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_or_si128(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_set1_epi8(int);
int /*<<< orphan*/ _mm_setzero_si128();
int /*<<< orphan*/ _mm_srli_epi16(int /*<<< orphan*/ const, int);
int /*<<< orphan*/ _mm_subs_epu8(int /*<<< orphan*/ const,
                                 int /*<<< orphan*/ const);
void NeedsFilter(const __m128i *const p1, const __m128i *const p0,
                 const __m128i *const q0, const __m128i *const q1, int thresh,
                 __m128i *const mask) {
  const __m128i m_thresh = _mm_set1_epi8(thresh);
  const __m128i t1 =
      _mm_or_si128(_mm_subs_epu8((*q1), (*p1)), _mm_subs_epu8((*p1), (*q1)));
  const __m128i kFE = _mm_set1_epi8(0xFE);
  const __m128i t2 = _mm_and_si128(t1, kFE);
  const __m128i t3 = _mm_srli_epi16(t2, 1);
  const __m128i t4 =
      _mm_or_si128(_mm_subs_epu8((*q0), (*p0)), _mm_subs_epu8((*p0), (*q0)));
  const __m128i t5 = _mm_adds_epu8(t4, t4);
  const __m128i t6 = _mm_adds_epu8(t5, t3);
  const __m128i t7 = _mm_subs_epu8(t6, m_thresh);
  *mask = _mm_cmpeq_epi8(t7, _mm_setzero_si128());
}


x86 assembly (clang, -O0):
<NeedsFilter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x24(%rbp),%edi
call   1050 <_mm_set1_epi8@plt>
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
call   1060 <_mm_subs_epu8@plt>
mov    %eax,-0x60(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
call   1060 <_mm_subs_epu8@plt>
mov    -0x60(%rbp),%edi
mov    %eax,%esi
call   1070 <_mm_or_si128@plt>
mov    %eax,-0x38(%rbp)
mov    $0xfe,%edi
call   1050 <_mm_set1_epi8@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%edi
mov    -0x3c(%rbp),%esi
call   1090 <_mm_and_si128@plt>
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%edi
mov    $0x1,%esi
call   1040 <_mm_srli_epi16@plt>
mov    %eax,-0x44(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
call   1060 <_mm_subs_epu8@plt>
mov    %eax,-0x5c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
call   1060 <_mm_subs_epu8@plt>
mov    -0x5c(%rbp),%edi
mov    %eax,%esi
call   1070 <_mm_or_si128@plt>
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%edi
mov    -0x48(%rbp),%esi
call   1080 <_mm_adds_epu8@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%edi
mov    -0x44(%rbp),%esi
call   1080 <_mm_adds_epu8@plt>
mov    %eax,-0x50(%rbp)
mov    -0x50(%rbp),%edi
mov    -0x34(%rbp),%esi
call   1060 <_mm_subs_epu8@plt>
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    $0x0,%al
call   1030 <_mm_setzero_si128@plt>
mov    -0x58(%rbp),%edi
mov    %eax,%esi
call   10a0 <_mm_cmpeq_epi8@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<NeedsFilter>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,(%rsp)
mov    %rcx,%rbx
mov    %rdx,%r13
mov    %rsi,%r14
mov    %rdi,%rbp
mov    %r8d,%edi
call   1050 <_mm_set1_epi8@plt>
mov    %eax,%r15d
mov    (%rbx),%edi
mov    0x0(%rbp),%esi
call   1060 <_mm_subs_epu8@plt>
mov    %eax,%r12d
mov    0x0(%rbp),%edi
mov    (%rbx),%esi
call   1060 <_mm_subs_epu8@plt>
mov    %r12d,%edi
mov    %eax,%esi
call   1070 <_mm_or_si128@plt>
mov    %eax,%ebx
mov    $0xfe,%edi
call   1050 <_mm_set1_epi8@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1090 <_mm_and_si128@plt>
mov    %eax,%edi
mov    $0x1,%esi
call   1040 <_mm_srli_epi16@plt>
mov    %eax,%r12d
mov    0x0(%r13),%edi
mov    (%r14),%esi
call   1060 <_mm_subs_epu8@plt>
mov    %eax,%ebx
mov    (%r14),%edi
mov    0x0(%r13),%esi
call   1060 <_mm_subs_epu8@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1070 <_mm_or_si128@plt>
mov    %eax,%edi
mov    %eax,%esi
call   1080 <_mm_adds_epu8@plt>
mov    %eax,%edi
mov    %r12d,%esi
call   1080 <_mm_adds_epu8@plt>
mov    %eax,%edi
mov    %r15d,%esi
call   1060 <_mm_subs_epu8@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1030 <_mm_setzero_si128@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   10a0 <_mm_cmpeq_epi8@plt>
mov    (%rsp),%rcx
mov    %eax,(%rcx)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @NeedsFilter(i32* %0, i32* %1, i32* %2, i32* %3, i32 %4, i32* %5) {
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
store i32* %0, i32** %7
store i32* %1, i32** %8
store i32* %2, i32** %9
store i32* %3, i32** %10
store i32 %4, i32* %11
store i32* %5, i32** %12
%22 = load i32, i32* %11
%23 = call i32 @_mm_set1_epi8(i32 %22)
store i32 %23, i32* %13
%24 = load i32*, i32** %10
%25 = load i32, i32* %24
%26 = load i32*, i32** %7
%27 = load i32, i32* %26
%28 = call i32 @_mm_subs_epu8(i32 %25, i32 %27)
%29 = load i32*, i32** %7
%30 = load i32, i32* %29
%31 = load i32*, i32** %10
%32 = load i32, i32* %31
%33 = call i32 @_mm_subs_epu8(i32 %30, i32 %32)
%34 = call i32 @_mm_or_si128(i32 %28, i32 %33)
store i32 %34, i32* %14
%35 = call i32 @_mm_set1_epi8(i32 254)
store i32 %35, i32* %15
%36 = load i32, i32* %14
%37 = load i32, i32* %15
%38 = call i32 @_mm_and_si128(i32 %36, i32 %37)
store i32 %38, i32* %16
%39 = load i32, i32* %16
%40 = call i32 @_mm_srli_epi16(i32 %39, i32 1)
store i32 %40, i32* %17
%41 = load i32*, i32** %9
%42 = load i32, i32* %41
%43 = load i32*, i32** %8
%44 = load i32, i32* %43
%45 = call i32 @_mm_subs_epu8(i32 %42, i32 %44)
%46 = load i32*, i32** %8
%47 = load i32, i32* %46
%48 = load i32*, i32** %9
%49 = load i32, i32* %48
%50 = call i32 @_mm_subs_epu8(i32 %47, i32 %49)
%51 = call i32 @_mm_or_si128(i32 %45, i32 %50)
store i32 %51, i32* %18
%52 = load i32, i32* %18
%53 = load i32, i32* %18
%54 = call i32 @_mm_adds_epu8(i32 %52, i32 %53)
store i32 %54, i32* %19
%55 = load i32, i32* %19
%56 = load i32, i32* %17
%57 = call i32 @_mm_adds_epu8(i32 %55, i32 %56)
store i32 %57, i32* %20
%58 = load i32, i32* %20
%59 = load i32, i32* %13
%60 = call i32 @_mm_subs_epu8(i32 %58, i32 %59)
store i32 %60, i32* %21
%61 = load i32, i32* %21
%62 = call i32 (...) @_mm_setzero_si128()
%63 = call i32 @_mm_cmpeq_epi8(i32 %61, i32 %62)
%64 = load i32*, i32** %12
store i32 %63, i32* %64
ret void
}

LLVM IR (-O2):
define void @NeedsFilter(i32* nocapture %0, i32* nocapture %1, i32* nocapture %2, i32* nocapture %3, i32 %4, i32* nocapture writeonly %5) {
%7 = tail call i32 @_mm_set1_epi8(i32 %4)
%8 = load i32, i32* %3
%9 = load i32, i32* %0
%10 = tail call i32 @_mm_subs_epu8(i32 %8, i32 %9)
%11 = load i32, i32* %0
%12 = load i32, i32* %3
%13 = tail call i32 @_mm_subs_epu8(i32 %11, i32 %12)
%14 = tail call i32 @_mm_or_si128(i32 %10, i32 %13)
%15 = tail call i32 @_mm_set1_epi8(i32 254)
%16 = tail call i32 @_mm_and_si128(i32 %14, i32 %15)
%17 = tail call i32 @_mm_srli_epi16(i32 %16, i32 1)
%18 = load i32, i32* %2
%19 = load i32, i32* %1
%20 = tail call i32 @_mm_subs_epu8(i32 %18, i32 %19)
%21 = load i32, i32* %1
%22 = load i32, i32* %2
%23 = tail call i32 @_mm_subs_epu8(i32 %21, i32 %22)
%24 = tail call i32 @_mm_or_si128(i32 %20, i32 %23)
%25 = tail call i32 @_mm_adds_epu8(i32 %24, i32 %24)
%26 = tail call i32 @_mm_adds_epu8(i32 %25, i32 %17)
%27 = tail call i32 @_mm_subs_epu8(i32 %26, i32 %7)
%28 = tail call i32 (...) @_mm_setzero_si128()
%29 = tail call i32 @_mm_cmpeq_epi8(i32 %27, i32 %28)
store i32 %29, i32* %5
ret void
}