#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*/ NeedsFilter(int /*<<< orphan*/ const *const,
                               int /*<<< orphan*/ const *const,
                               int /*<<< orphan*/ const *const,
                               int /*<<< orphan*/ const *const, int,
                               int /*<<< orphan*/ *);
int /*<<< orphan*/ _mm_and_si128(int /*<<< orphan*/ const, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_cmpeq_epi8(int /*<<< orphan*/ const, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_set1_epi8(int);
int /*<<< orphan*/ _mm_setzero_si128();
int /*<<< orphan*/ _mm_subs_epu8(int /*<<< orphan*/, int /*<<< orphan*/ const);
void ComplexMask(const __m128i *const p1, const __m128i *const p0,
                 const __m128i *const q0, const __m128i *const q1, int thresh,
                 int ithresh, __m128i *const mask) {
  const __m128i it = _mm_set1_epi8(ithresh);
  const __m128i diff = _mm_subs_epu8(*mask, it);
  const __m128i thresh_mask = _mm_cmpeq_epi8(diff, _mm_setzero_si128());
  __m128i filter_mask;
  NeedsFilter(p1, p0, q0, q1, thresh, &filter_mask);
  *mask = _mm_and_si128(thresh_mask, filter_mask);
}


x86 assembly (clang, -O0):
<ComplexMask>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9d,-0x28(%rbp)
mov    -0x28(%rbp),%edi
call   1040 <_mm_set1_epi8@plt>
mov    %eax,-0x2c(%rbp)
mov    0x10(%rbp),%rax
mov    (%rax),%edi
mov    -0x2c(%rbp),%esi
call   1060 <_mm_subs_epu8@plt>
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    $0x0,%al
call   1030 <_mm_setzero_si128@plt>
mov    -0x3c(%rbp),%edi
mov    %eax,%esi
call   1080 <_mm_cmpeq_epi8@plt>
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x24(%rbp),%r8d
lea    -0x38(%rbp),%r9
call   1050 <NeedsFilter@plt>
mov    -0x34(%rbp),%edi
mov    -0x38(%rbp),%esi
call   1070 <_mm_and_si128@plt>
mov    %eax,%ecx
mov    0x10(%rbp),%rax
mov    %ecx,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ComplexMask>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%r14d
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%r13
mov    %rdi,%rbp
mov    0x40(%rsp),%rbx
mov    %r9d,%edi
call   1040 <_mm_set1_epi8@plt>
mov    (%rbx),%edi
mov    %eax,%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   1080 <_mm_cmpeq_epi8@plt>
mov    %eax,%ebx
lea    0x4(%rsp),%r9
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
mov    %r15,%rcx
mov    %r14d,%r8d
call   1050 <NeedsFilter@plt>
mov    0x4(%rsp),%esi
mov    %ebx,%edi
call   1070 <_mm_and_si128@plt>
mov    0x40(%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 @ComplexMask(i32* %0, i32* %1, i32* %2, i32* %3, i32 %4, i32 %5, i32* %6) {
%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
store i32* %0, i32** %8
store i32* %1, i32** %9
store i32* %2, i32** %10
store i32* %3, i32** %11
store i32 %4, i32* %12
store i32 %5, i32* %13
store i32* %6, i32** %14
%19 = load i32, i32* %13
%20 = call i32 @_mm_set1_epi8(i32 %19)
store i32 %20, i32* %15
%21 = load i32*, i32** %14
%22 = load i32, i32* %21
%23 = load i32, i32* %15
%24 = call i32 @_mm_subs_epu8(i32 %22, i32 %23)
store i32 %24, i32* %16
%25 = load i32, i32* %16
%26 = call i32 (...) @_mm_setzero_si128()
%27 = call i32 @_mm_cmpeq_epi8(i32 %25, i32 %26)
store i32 %27, i32* %17
%28 = load i32*, i32** %8
%29 = load i32*, i32** %9
%30 = load i32*, i32** %10
%31 = load i32*, i32** %11
%32 = load i32, i32* %12
%33 = call i32 @NeedsFilter(i32* %28, i32* %29, i32* %30, i32* %31, i32 %32, i32* %18)
%34 = load i32, i32* %17
%35 = load i32, i32* %18
%36 = call i32 @_mm_and_si128(i32 %34, i32 %35)
%37 = load i32*, i32** %14
store i32 %36, i32* %37
ret void
}

LLVM IR (-O2):
define void @ComplexMask(i32* %0, i32* %1, i32* %2, i32* %3, i32 %4, i32 %5, i32* nocapture %6) {
%8 = alloca i32
%9 = tail call i32 @_mm_set1_epi8(i32 %5)
%10 = load i32, i32* %6
%11 = tail call i32 @_mm_subs_epu8(i32 %10, i32 %9)
%12 = tail call i32 (...) @_mm_setzero_si128()
%13 = tail call i32 @_mm_cmpeq_epi8(i32 %11, i32 %12)
%14 = bitcast i32* %8 to i8*
%15 = call i32 @NeedsFilter(i32* %0, i32* %1, i32* %2, i32* %3, i32 %4, i32* %8)
%16 = load i32, i32* %8
%17 = call i32 @_mm_and_si128(i32 %13, i32 %16)
store i32 %17, i32* %6
ret void
}