#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_and_si128(int /*<<< orphan*/ const,
                                 int /*<<< orphan*/ const);
int /*<<< orphan*/ _mm_andnot_si128(int /*<<< orphan*/ const,
                                    int /*<<< orphan*/ const);
int /*<<< orphan*/ _mm_or_si128(int /*<<< orphan*/, int /*<<< orphan*/ const);
int /*<<< orphan*/ _mm_packus_epi16(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_srli_epi16(int /*<<< orphan*/ const, int);
__m128i filter16_mask(const __m128i *const flat,
                      const __m128i *const other_filt,
                      const __m128i *const f_lo, const __m128i *const f_hi) {
  const __m128i f =
      _mm_packus_epi16(_mm_srli_epi16(*f_lo, 4), _mm_srli_epi16(*f_hi, 4));
  const __m128i result = _mm_and_si128(*flat, f);
  return _mm_or_si128(_mm_andnot_si128(*flat, *other_filt), result);
}


x86 assembly (clang, -O0):
<filter16_mask>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
mov    $0x4,%esi
call   1040 <_mm_srli_epi16@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
mov    $0x4,%esi
call   1040 <_mm_srli_epi16@plt>
mov    -0x2c(%rbp),%edi
mov    %eax,%esi
call   1030 <_mm_packus_epi16@plt>
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%esi
call   1070 <_mm_and_si128@plt>
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
call   1060 <_mm_andnot_si128@plt>
mov    %eax,%edi
mov    -0x28(%rbp),%esi
call   1050 <_mm_or_si128@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filter16_mask>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
mov    (%rdx),%edi
mov    $0x4,%esi
call   1040 <_mm_srli_epi16@plt>
mov    %eax,%ebp
mov    (%r15),%edi
mov    $0x4,%esi
call   1040 <_mm_srli_epi16@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1030 <_mm_packus_epi16@plt>
mov    (%rbx),%edi
mov    %eax,%esi
call   1070 <_mm_and_si128@plt>
mov    %eax,%ebp
mov    (%rbx),%edi
mov    (%r14),%esi
call   1060 <_mm_andnot_si128@plt>
mov    %eax,%edi
mov    %ebp,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <_mm_or_si128@plt>

LLVM IR (-O0):
define i32 @filter16_mask(i32* %0, i32* %1, i32* %2, i32* %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
store i32* %3, i32** %8
%11 = load i32*, i32** %7
%12 = load i32, i32* %11
%13 = call i32 @_mm_srli_epi16(i32 %12, i32 4)
%14 = load i32*, i32** %8
%15 = load i32, i32* %14
%16 = call i32 @_mm_srli_epi16(i32 %15, i32 4)
%17 = call i32 @_mm_packus_epi16(i32 %13, i32 %16)
store i32 %17, i32* %9
%18 = load i32*, i32** %5
%19 = load i32, i32* %18
%20 = load i32, i32* %9
%21 = call i32 @_mm_and_si128(i32 %19, i32 %20)
store i32 %21, i32* %10
%22 = load i32*, i32** %5
%23 = load i32, i32* %22
%24 = load i32*, i32** %6
%25 = load i32, i32* %24
%26 = call i32 @_mm_andnot_si128(i32 %23, i32 %25)
%27 = load i32, i32* %10
%28 = call i32 @_mm_or_si128(i32 %26, i32 %27)
ret i32 %28
}

LLVM IR (-O2):
define i32 @filter16_mask(i32* nocapture %0, i32* nocapture %1, i32* nocapture %2, i32* nocapture %3) {
%5 = load i32, i32* %2
%6 = tail call i32 @_mm_srli_epi16(i32 %5, i32 4)
%7 = load i32, i32* %3
%8 = tail call i32 @_mm_srli_epi16(i32 %7, i32 4)
%9 = tail call i32 @_mm_packus_epi16(i32 %6, i32 %8)
%10 = load i32, i32* %0
%11 = tail call i32 @_mm_and_si128(i32 %10, i32 %9)
%12 = load i32, i32* %0
%13 = load i32, i32* %1
%14 = tail call i32 @_mm_andnot_si128(i32 %12, i32 %13)
%15 = tail call i32 @_mm_or_si128(i32 %14, i32 %11)
ret i32 %15
}