#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_castsi128_si256(int /*<<< orphan*/ const);
int /*<<< orphan*/ _mm256_insertf128_si256(int /*<<< orphan*/,
                                           int /*<<< orphan*/ const, int);
int /*<<< orphan*/ _mm256_set1_epi32(int);
int /*<<< orphan*/ _mm256_shuffle_epi8(int /*<<< orphan*/ const,
                                       int /*<<< orphan*/ const);
int /*<<< orphan*/ _mm_loadu_si128(int /*<<< orphan*/ const *);
void pack_filters(const int16_t *filter, __m256i *f) {
  const __m128i h = _mm_loadu_si128((const __m128i *)filter);
  const __m256i hh = _mm256_insertf128_si256(_mm256_castsi128_si256(h), h, 1);
  const __m256i p0 = _mm256_set1_epi32(0x03020100);
  const __m256i p1 = _mm256_set1_epi32(0x07060504);
  const __m256i p2 = _mm256_set1_epi32(0x0b0a0908);
  const __m256i p3 = _mm256_set1_epi32(0x0f0e0d0c);
  f[0] = _mm256_shuffle_epi8(hh, p0);
  f[1] = _mm256_shuffle_epi8(hh, p1);
  f[2] = _mm256_shuffle_epi8(hh, p2);
  f[3] = _mm256_shuffle_epi8(hh, p3);
}


x86 assembly (clang, -O0):
<pack_filters>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <_mm_loadu_si128@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <_mm256_castsi128_si256@plt>
mov    %eax,%edi
mov    -0x14(%rbp),%esi
mov    $0x1,%edx
call   1060 <_mm256_insertf128_si256@plt>
mov    %eax,-0x18(%rbp)
mov    $0x3020100,%edi
call   1040 <_mm256_set1_epi32@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x7060504,%edi
call   1040 <_mm256_set1_epi32@plt>
mov    %eax,-0x20(%rbp)
mov    $0xb0a0908,%edi
call   1040 <_mm256_set1_epi32@plt>
mov    %eax,-0x24(%rbp)
mov    $0xf0e0d0c,%edi
call   1040 <_mm256_set1_epi32@plt>
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1070 <_mm256_shuffle_epi8@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1070 <_mm256_shuffle_epi8@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x18(%rbp),%edi
mov    -0x24(%rbp),%esi
call   1070 <_mm256_shuffle_epi8@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x18(%rbp),%edi
mov    -0x28(%rbp),%esi
call   1070 <_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):
<pack_filters>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
call   1050 <_mm_loadu_si128@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1030 <_mm256_castsi128_si256@plt>
mov    %eax,%edi
mov    %ebp,%esi
mov    $0x1,%edx
call   1060 <_mm256_insertf128_si256@plt>
mov    %eax,%ebp
mov    $0x3020100,%edi
call   1040 <_mm256_set1_epi32@plt>
mov    %eax,%r14d
mov    $0x7060504,%edi
call   1040 <_mm256_set1_epi32@plt>
mov    %eax,%r15d
mov    $0xb0a0908,%edi
call   1040 <_mm256_set1_epi32@plt>
mov    %eax,%r12d
mov    $0xf0e0d0c,%edi
call   1040 <_mm256_set1_epi32@plt>
mov    %eax,%r13d
mov    %ebp,%edi
mov    %r14d,%esi
call   1070 <_mm256_shuffle_epi8@plt>
mov    %eax,(%rbx)
mov    %ebp,%edi
mov    %r15d,%esi
call   1070 <_mm256_shuffle_epi8@plt>
mov    %eax,0x4(%rbx)
mov    %ebp,%edi
mov    %r12d,%esi
call   1070 <_mm256_shuffle_epi8@plt>
mov    %eax,0x8(%rbx)
mov    %ebp,%edi
mov    %r13d,%esi
call   1070 <_mm256_shuffle_epi8@plt>
mov    %eax,0xc(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @pack_filters(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32* %0, i32** %3
store i32* %1, i32** %4
%11 = load i32*, i32** %3
%12 = call i32 @_mm_loadu_si128(i32* %11)
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = call i32 @_mm256_castsi128_si256(i32 %13)
%15 = load i32, i32* %5
%16 = call i32 @_mm256_insertf128_si256(i32 %14, i32 %15, i32 1)
store i32 %16, i32* %6
%17 = call i32 @_mm256_set1_epi32(i32 50462976)
store i32 %17, i32* %7
%18 = call i32 @_mm256_set1_epi32(i32 117835012)
store i32 %18, i32* %8
%19 = call i32 @_mm256_set1_epi32(i32 185207048)
store i32 %19, i32* %9
%20 = call i32 @_mm256_set1_epi32(i32 252579084)
store i32 %20, i32* %10
%21 = load i32, i32* %6
%22 = load i32, i32* %7
%23 = call i32 @_mm256_shuffle_epi8(i32 %21, i32 %22)
%24 = load i32*, i32** %4
%25 = getelementptr inbounds i32, i32* %24, i64 0
store i32 %23, i32* %25
%26 = load i32, i32* %6
%27 = load i32, i32* %8
%28 = call i32 @_mm256_shuffle_epi8(i32 %26, i32 %27)
%29 = load i32*, i32** %4
%30 = getelementptr inbounds i32, i32* %29, i64 1
store i32 %28, i32* %30
%31 = load i32, i32* %6
%32 = load i32, i32* %9
%33 = call i32 @_mm256_shuffle_epi8(i32 %31, i32 %32)
%34 = load i32*, i32** %4
%35 = getelementptr inbounds i32, i32* %34, i64 2
store i32 %33, i32* %35
%36 = load i32, i32* %6
%37 = load i32, i32* %10
%38 = call i32 @_mm256_shuffle_epi8(i32 %36, i32 %37)
%39 = load i32*, i32** %4
%40 = getelementptr inbounds i32, i32* %39, i64 3
store i32 %38, i32* %40
ret void
}

LLVM IR (-O2):
define void @pack_filters(i32* %0, i32* nocapture writeonly %1) {
%3 = tail call i32 @_mm_loadu_si128(i32* %0)
%4 = tail call i32 @_mm256_castsi128_si256(i32 %3)
%5 = tail call i32 @_mm256_insertf128_si256(i32 %4, i32 %3, i32 1)
%6 = tail call i32 @_mm256_set1_epi32(i32 50462976)
%7 = tail call i32 @_mm256_set1_epi32(i32 117835012)
%8 = tail call i32 @_mm256_set1_epi32(i32 185207048)
%9 = tail call i32 @_mm256_set1_epi32(i32 252579084)
%10 = tail call i32 @_mm256_shuffle_epi8(i32 %5, i32 %6)
store i32 %10, i32* %1
%11 = tail call i32 @_mm256_shuffle_epi8(i32 %5, i32 %7)
%12 = getelementptr inbounds i32, i32* %1, i64 1
store i32 %11, i32* %12
%13 = tail call i32 @_mm256_shuffle_epi8(i32 %5, i32 %8)
%14 = getelementptr inbounds i32, i32* %1, i64 2
store i32 %13, i32* %14
%15 = tail call i32 @_mm256_shuffle_epi8(i32 %5, i32 %9)
%16 = getelementptr inbounds i32, i32* %1, i64 3
store i32 %15, i32* %16
ret void
}