#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_add_epi16(int /*<<< orphan*/, int /*<<< orphan*/ const);
int /*<<< orphan*/ _mm_maddubs_epi16(int /*<<< orphan*/,
                                     int /*<<< orphan*/ const);
int /*<<< orphan*/ _mm_packus_epi16(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_set1_epi16(int);
int /*<<< orphan*/ _mm_srai_epi16(int /*<<< orphan*/, int);
int /*<<< orphan*/ _mm_unpackhi_epi8(int /*<<< orphan*/ const,
                                     int /*<<< orphan*/ const);
int /*<<< orphan*/ _mm_unpacklo_epi8(int /*<<< orphan*/ const,
                                     int /*<<< orphan*/ const);
__m128i apply_filter(const __m128i v_a_b, const __m128i v_b_b,
                     const __m128i v_filter_b) {
  const __m128i v_rounding_w = _mm_set1_epi16(1 << (7 - 1));
  __m128i v_input_lo_b = _mm_unpacklo_epi8(v_a_b, v_b_b);
  __m128i v_input_hi_b = _mm_unpackhi_epi8(v_a_b, v_b_b);
  __m128i v_temp0_w = _mm_maddubs_epi16(v_input_lo_b, v_filter_b);
  __m128i v_temp1_w = _mm_maddubs_epi16(v_input_hi_b, v_filter_b);
  __m128i v_res_lo_w =
      _mm_srai_epi16(_mm_add_epi16(v_temp0_w, v_rounding_w), 7);
  __m128i v_res_hi_w =
      _mm_srai_epi16(_mm_add_epi16(v_temp1_w, v_rounding_w), 7);
  return _mm_packus_epi16(v_res_lo_w, v_res_hi_w);
}


x86 assembly (clang, -O0):
<apply_filter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    $0x40,%edi
call   1080 <_mm_set1_epi16@plt>
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1040 <_mm_unpacklo_epi8@plt>
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1050 <_mm_unpackhi_epi8@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1070 <_mm_maddubs_epi16@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1070 <_mm_maddubs_epi16@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1030 <_mm_add_epi16@plt>
mov    %eax,%edi
mov    $0x7,%esi
call   1090 <_mm_srai_epi16@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1030 <_mm_add_epi16@plt>
mov    %eax,%edi
mov    $0x7,%esi
call   1090 <_mm_srai_epi16@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x28(%rbp),%esi
call   1060 <_mm_packus_epi16@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<apply_filter>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r15d
mov    %esi,%ebx
mov    %edi,%ebp
mov    $0x40,%edi
call   1080 <_mm_set1_epi16@plt>
mov    %eax,%r14d
mov    %ebp,%edi
mov    %ebx,%esi
call   1040 <_mm_unpacklo_epi8@plt>
mov    %eax,%r12d
mov    %ebp,%edi
mov    %ebx,%esi
call   1050 <_mm_unpackhi_epi8@plt>
mov    %eax,%ebx
mov    %r12d,%edi
mov    %r15d,%esi
call   1070 <_mm_maddubs_epi16@plt>
mov    %eax,%ebp
mov    %ebx,%edi
mov    %r15d,%esi
call   1070 <_mm_maddubs_epi16@plt>
mov    %eax,%ebx
mov    %ebp,%edi
mov    %r14d,%esi
call   1030 <_mm_add_epi16@plt>
mov    %eax,%edi
mov    $0x7,%esi
call   1090 <_mm_srai_epi16@plt>
mov    %eax,%ebp
mov    %ebx,%edi
mov    %r14d,%esi
call   1030 <_mm_add_epi16@plt>
mov    %eax,%edi
mov    $0x7,%esi
call   1090 <_mm_srai_epi16@plt>
mov    %ebp,%edi
mov    %eax,%esi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <_mm_packus_epi16@plt>

LLVM IR (-O0):
define i32 @apply_filter(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%14 = call i32 @_mm_set1_epi16(i32 64)
store i32 %14, i32* %7
%15 = load i32, i32* %4
%16 = load i32, i32* %5
%17 = call i32 @_mm_unpacklo_epi8(i32 %15, i32 %16)
store i32 %17, i32* %8
%18 = load i32, i32* %4
%19 = load i32, i32* %5
%20 = call i32 @_mm_unpackhi_epi8(i32 %18, i32 %19)
store i32 %20, i32* %9
%21 = load i32, i32* %8
%22 = load i32, i32* %6
%23 = call i32 @_mm_maddubs_epi16(i32 %21, i32 %22)
store i32 %23, i32* %10
%24 = load i32, i32* %9
%25 = load i32, i32* %6
%26 = call i32 @_mm_maddubs_epi16(i32 %24, i32 %25)
store i32 %26, i32* %11
%27 = load i32, i32* %10
%28 = load i32, i32* %7
%29 = call i32 @_mm_add_epi16(i32 %27, i32 %28)
%30 = call i32 @_mm_srai_epi16(i32 %29, i32 7)
store i32 %30, i32* %12
%31 = load i32, i32* %11
%32 = load i32, i32* %7
%33 = call i32 @_mm_add_epi16(i32 %31, i32 %32)
%34 = call i32 @_mm_srai_epi16(i32 %33, i32 7)
store i32 %34, i32* %13
%35 = load i32, i32* %12
%36 = load i32, i32* %13
%37 = call i32 @_mm_packus_epi16(i32 %35, i32 %36)
ret i32 %37
}

LLVM IR (-O2):
define i32 @apply_filter(i32 %0, i32 %1, i32 %2) {
%4 = tail call i32 @_mm_set1_epi16(i32 64)
%5 = tail call i32 @_mm_unpacklo_epi8(i32 %0, i32 %1)
%6 = tail call i32 @_mm_unpackhi_epi8(i32 %0, i32 %1)
%7 = tail call i32 @_mm_maddubs_epi16(i32 %5, i32 %2)
%8 = tail call i32 @_mm_maddubs_epi16(i32 %6, i32 %2)
%9 = tail call i32 @_mm_add_epi16(i32 %7, i32 %4)
%10 = tail call i32 @_mm_srai_epi16(i32 %9, i32 7)
%11 = tail call i32 @_mm_add_epi16(i32 %8, i32 %4)
%12 = tail call i32 @_mm_srai_epi16(i32 %11, i32 7)
%13 = tail call i32 @_mm_packus_epi16(i32 %10, i32 %12)
ret i32 %13
}