#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*/ int16_t;
typedef int /*<<< orphan*/ __m256i;
typedef int /*<<< orphan*/ __m128i;

/* Variables and functions */
int /*<<< orphan*/ _mm256_broadcastsi128_si256(int /*<<< orphan*/);
int /*<<< orphan*/ _mm256_set1_epi16(int);
int /*<<< orphan*/ _mm256_shuffle_epi8(int /*<<< orphan*/ const,
                                       int /*<<< orphan*/);
int /*<<< orphan*/ _mm_load_si128(int /*<<< orphan*/ const *);
void shuffle_filter_avx2(const int16_t *const filter, __m256i *const f) {
  const __m256i f_values =
      _mm256_broadcastsi128_si256(_mm_load_si128((const __m128i *)filter));
  f[0] = _mm256_shuffle_epi8(f_values, _mm256_set1_epi16(0x0200u));
  f[1] = _mm256_shuffle_epi8(f_values, _mm256_set1_epi16(0x0604u));
  f[2] = _mm256_shuffle_epi8(f_values, _mm256_set1_epi16(0x0a08u));
  f[3] = _mm256_shuffle_epi8(f_values, _mm256_set1_epi16(0x0e0cu));
}


x86 assembly (clang, -O0):
<shuffle_filter_avx2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <_mm_load_si128@plt>
mov    %eax,%edi
call   1040 <_mm256_broadcastsi128_si256@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    $0x200,%edi
call   1050 <_mm256_set1_epi16@plt>
mov    -0x24(%rbp),%edi
mov    %eax,%esi
call   1060 <_mm256_shuffle_epi8@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    $0x604,%edi
call   1050 <_mm256_set1_epi16@plt>
mov    -0x20(%rbp),%edi
mov    %eax,%esi
call   1060 <_mm256_shuffle_epi8@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    $0xa08,%edi
call   1050 <_mm256_set1_epi16@plt>
mov    -0x1c(%rbp),%edi
mov    %eax,%esi
call   1060 <_mm256_shuffle_epi8@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    $0xe0c,%edi
call   1050 <_mm256_set1_epi16@plt>
mov    -0x18(%rbp),%edi
mov    %eax,%esi
call   1060 <_mm256_shuffle_epi8@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0xc(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shuffle_filter_avx2>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
call   1030 <_mm_load_si128@plt>
mov    %eax,%edi
call   1040 <_mm256_broadcastsi128_si256@plt>
mov    %eax,%ebp
mov    $0x200,%edi
call   1050 <_mm256_set1_epi16@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1060 <_mm256_shuffle_epi8@plt>
mov    %eax,(%rbx)
mov    $0x604,%edi
call   1050 <_mm256_set1_epi16@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1060 <_mm256_shuffle_epi8@plt>
mov    %eax,0x4(%rbx)
mov    $0xa08,%edi
call   1050 <_mm256_set1_epi16@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1060 <_mm256_shuffle_epi8@plt>
mov    %eax,0x8(%rbx)
mov    $0xe0c,%edi
call   1050 <_mm256_set1_epi16@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1060 <_mm256_shuffle_epi8@plt>
mov    %eax,0xc(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @shuffle_filter_avx2(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
store i32* %0, i32** %3
store i32* %1, i32** %4
%6 = load i32*, i32** %3
%7 = call i32 @_mm_load_si128(i32* %6)
%8 = call i32 @_mm256_broadcastsi128_si256(i32 %7)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = call i32 @_mm256_set1_epi16(i32 512)
%11 = call i32 @_mm256_shuffle_epi8(i32 %9, i32 %10)
%12 = load i32*, i32** %4
%13 = getelementptr inbounds i32, i32* %12, i64 0
store i32 %11, i32* %13
%14 = load i32, i32* %5
%15 = call i32 @_mm256_set1_epi16(i32 1540)
%16 = call i32 @_mm256_shuffle_epi8(i32 %14, i32 %15)
%17 = load i32*, i32** %4
%18 = getelementptr inbounds i32, i32* %17, i64 1
store i32 %16, i32* %18
%19 = load i32, i32* %5
%20 = call i32 @_mm256_set1_epi16(i32 2568)
%21 = call i32 @_mm256_shuffle_epi8(i32 %19, i32 %20)
%22 = load i32*, i32** %4
%23 = getelementptr inbounds i32, i32* %22, i64 2
store i32 %21, i32* %23
%24 = load i32, i32* %5
%25 = call i32 @_mm256_set1_epi16(i32 3596)
%26 = call i32 @_mm256_shuffle_epi8(i32 %24, i32 %25)
%27 = load i32*, i32** %4
%28 = getelementptr inbounds i32, i32* %27, i64 3
store i32 %26, i32* %28
ret void
}

LLVM IR (-O2):
define void @shuffle_filter_avx2(i32* %0, i32* nocapture writeonly %1) {
%3 = tail call i32 @_mm_load_si128(i32* %0)
%4 = tail call i32 @_mm256_broadcastsi128_si256(i32 %3)
%5 = tail call i32 @_mm256_set1_epi16(i32 512)
%6 = tail call i32 @_mm256_shuffle_epi8(i32 %4, i32 %5)
store i32 %6, i32* %1
%7 = tail call i32 @_mm256_set1_epi16(i32 1540)
%8 = tail call i32 @_mm256_shuffle_epi8(i32 %4, i32 %7)
%9 = getelementptr inbounds i32, i32* %1, i64 1
store i32 %8, i32* %9
%10 = tail call i32 @_mm256_set1_epi16(i32 2568)
%11 = tail call i32 @_mm256_shuffle_epi8(i32 %4, i32 %10)
%12 = getelementptr inbounds i32, i32* %1, i64 2
store i32 %11, i32* %12
%13 = tail call i32 @_mm256_set1_epi16(i32 3596)
%14 = tail call i32 @_mm256_shuffle_epi8(i32 %4, i32 %13)
%15 = getelementptr inbounds i32, i32* %1, i64 3
store i32 %14, i32* %15
ret void
}