#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_setzero_si128();
int /*<<< orphan*/ _mm_unpackhi_epi16(int /*<<< orphan*/ const,
                                      int /*<<< orphan*/ const);
int /*<<< orphan*/ _mm_unpackhi_epi32(int /*<<< orphan*/ const,
                                      int /*<<< orphan*/ const);
int /*<<< orphan*/ _mm_unpackhi_epi64(int /*<<< orphan*/ const,
                                      int /*<<< orphan*/ const);
int /*<<< orphan*/ _mm_unpacklo_epi16(int /*<<< orphan*/ const,
                                      int /*<<< orphan*/ const);
int /*<<< orphan*/ _mm_unpacklo_epi32(int /*<<< orphan*/ const,
                                      int /*<<< orphan*/ const);
int /*<<< orphan*/ _mm_unpacklo_epi64(int /*<<< orphan*/ const,
                                      int /*<<< orphan*/ const);
void transpose_16bit_8x4(const __m128i *const in, __m128i *const out) {
  const __m128i a0 = _mm_unpacklo_epi16(in[0], in[1]);
  const __m128i a1 = _mm_unpacklo_epi16(in[2], in[3]);
  const __m128i a4 = _mm_unpackhi_epi16(in[0], in[1]);
  const __m128i a5 = _mm_unpackhi_epi16(in[2], in[3]);
  const __m128i b0 = _mm_unpacklo_epi32(a0, a1);
  const __m128i b2 = _mm_unpacklo_epi32(a4, a5);
  const __m128i b4 = _mm_unpackhi_epi32(a0, a1);
  const __m128i b6 = _mm_unpackhi_epi32(a4, a5);
  const __m128i zeros = _mm_setzero_si128();
  out[0] = _mm_unpacklo_epi64(b0, zeros);
  out[1] = _mm_unpackhi_epi64(b0, zeros);
  out[2] = _mm_unpacklo_epi64(b4, zeros);
  out[3] = _mm_unpackhi_epi64(b4, zeros);
  out[4] = _mm_unpacklo_epi64(b2, zeros);
  out[5] = _mm_unpackhi_epi64(b2, zeros);
  out[6] = _mm_unpacklo_epi64(b6, zeros);
  out[7] = _mm_unpackhi_epi64(b6, zeros);
}


x86 assembly (clang, -O0):
<transpose_16bit_8x4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%esi
call   1070 <_mm_unpacklo_epi16@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%edi
mov    -0x8(%rbp),%rax
mov    0xc(%rax),%esi
call   1070 <_mm_unpacklo_epi16@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%esi
call   1050 <_mm_unpackhi_epi16@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%edi
mov    -0x8(%rbp),%rax
mov    0xc(%rax),%esi
call   1050 <_mm_unpackhi_epi16@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1040 <_mm_unpacklo_epi32@plt>
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1040 <_mm_unpacklo_epi32@plt>
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1090 <_mm_unpackhi_epi32@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1090 <_mm_unpackhi_epi32@plt>
mov    %eax,-0x30(%rbp)
mov    $0x0,%al
call   1030 <_mm_setzero_si128@plt>
mov    %eax,-0x34(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x34(%rbp),%esi
call   1080 <_mm_unpacklo_epi64@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x24(%rbp),%edi
mov    -0x34(%rbp),%esi
call   1060 <_mm_unpackhi_epi64@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x2c(%rbp),%edi
mov    -0x34(%rbp),%esi
call   1080 <_mm_unpacklo_epi64@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x2c(%rbp),%edi
mov    -0x34(%rbp),%esi
call   1060 <_mm_unpackhi_epi64@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0xc(%rax)
mov    -0x28(%rbp),%edi
mov    -0x34(%rbp),%esi
call   1080 <_mm_unpacklo_epi64@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x10(%rax)
mov    -0x28(%rbp),%edi
mov    -0x34(%rbp),%esi
call   1060 <_mm_unpackhi_epi64@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x14(%rax)
mov    -0x30(%rbp),%edi
mov    -0x34(%rbp),%esi
call   1080 <_mm_unpacklo_epi64@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x18(%rax)
mov    -0x30(%rbp),%edi
mov    -0x34(%rbp),%esi
call   1060 <_mm_unpackhi_epi64@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x1c(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<transpose_16bit_8x4>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbp
mov    (%rdi),%edi
mov    0x4(%rbp),%esi
call   1070 <_mm_unpacklo_epi16@plt>
mov    %eax,%ebx
mov    0x8(%rbp),%edi
mov    0xc(%rbp),%esi
call   1070 <_mm_unpacklo_epi16@plt>
mov    %eax,%r12d
mov    0x0(%rbp),%edi
mov    0x4(%rbp),%esi
call   1050 <_mm_unpackhi_epi16@plt>
mov    %eax,%r15d
mov    0x8(%rbp),%edi
mov    0xc(%rbp),%esi
call   1050 <_mm_unpackhi_epi16@plt>
mov    %eax,%ebp
mov    %ebx,%edi
mov    %r12d,%esi
call   1040 <_mm_unpacklo_epi32@plt>
mov    %eax,%r13d
mov    %r15d,%edi
mov    %ebp,%esi
call   1040 <_mm_unpacklo_epi32@plt>
mov    %eax,0x4(%rsp)
mov    %ebx,%edi
mov    %r12d,%esi
call   1090 <_mm_unpackhi_epi32@plt>
mov    %eax,%r12d
mov    %r15d,%edi
mov    %ebp,%esi
call   1090 <_mm_unpackhi_epi32@plt>
mov    %eax,%r15d
xor    %eax,%eax
call   1030 <_mm_setzero_si128@plt>
mov    %eax,%ebp
mov    %r13d,%edi
mov    %eax,%esi
call   1080 <_mm_unpacklo_epi64@plt>
mov    %eax,(%r14)
mov    %r13d,%edi
mov    %ebp,%esi
call   1060 <_mm_unpackhi_epi64@plt>
mov    %eax,0x4(%r14)
mov    %r12d,%edi
mov    %ebp,%esi
call   1080 <_mm_unpacklo_epi64@plt>
mov    %eax,0x8(%r14)
mov    %r12d,%edi
mov    %ebp,%esi
call   1060 <_mm_unpackhi_epi64@plt>
mov    %eax,0xc(%r14)
mov    0x4(%rsp),%ebx
mov    %ebx,%edi
mov    %ebp,%esi
call   1080 <_mm_unpacklo_epi64@plt>
mov    %eax,0x10(%r14)
mov    %ebx,%edi
mov    %ebp,%esi
call   1060 <_mm_unpackhi_epi64@plt>
mov    %eax,0x14(%r14)
mov    %r15d,%edi
mov    %ebp,%esi
call   1080 <_mm_unpacklo_epi64@plt>
mov    %eax,0x18(%r14)
mov    %r15d,%edi
mov    %ebp,%esi
call   1060 <_mm_unpackhi_epi64@plt>
mov    %eax,0x1c(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @transpose_16bit_8x4(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
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32* %0, i32** %3
store i32* %1, i32** %4
%14 = load i32*, i32** %3
%15 = getelementptr inbounds i32, i32* %14, i64 0
%16 = load i32, i32* %15
%17 = load i32*, i32** %3
%18 = getelementptr inbounds i32, i32* %17, i64 1
%19 = load i32, i32* %18
%20 = call i32 @_mm_unpacklo_epi16(i32 %16, i32 %19)
store i32 %20, i32* %5
%21 = load i32*, i32** %3
%22 = getelementptr inbounds i32, i32* %21, i64 2
%23 = load i32, i32* %22
%24 = load i32*, i32** %3
%25 = getelementptr inbounds i32, i32* %24, i64 3
%26 = load i32, i32* %25
%27 = call i32 @_mm_unpacklo_epi16(i32 %23, i32 %26)
store i32 %27, i32* %6
%28 = load i32*, i32** %3
%29 = getelementptr inbounds i32, i32* %28, i64 0
%30 = load i32, i32* %29
%31 = load i32*, i32** %3
%32 = getelementptr inbounds i32, i32* %31, i64 1
%33 = load i32, i32* %32
%34 = call i32 @_mm_unpackhi_epi16(i32 %30, i32 %33)
store i32 %34, i32* %7
%35 = load i32*, i32** %3
%36 = getelementptr inbounds i32, i32* %35, i64 2
%37 = load i32, i32* %36
%38 = load i32*, i32** %3
%39 = getelementptr inbounds i32, i32* %38, i64 3
%40 = load i32, i32* %39
%41 = call i32 @_mm_unpackhi_epi16(i32 %37, i32 %40)
store i32 %41, i32* %8
%42 = load i32, i32* %5
%43 = load i32, i32* %6
%44 = call i32 @_mm_unpacklo_epi32(i32 %42, i32 %43)
store i32 %44, i32* %9
%45 = load i32, i32* %7
%46 = load i32, i32* %8
%47 = call i32 @_mm_unpacklo_epi32(i32 %45, i32 %46)
store i32 %47, i32* %10
%48 = load i32, i32* %5
%49 = load i32, i32* %6
%50 = call i32 @_mm_unpackhi_epi32(i32 %48, i32 %49)
store i32 %50, i32* %11
%51 = load i32, i32* %7
%52 = load i32, i32* %8
%53 = call i32 @_mm_unpackhi_epi32(i32 %51, i32 %52)
store i32 %53, i32* %12
%54 = call i32 (...) @_mm_setzero_si128()
store i32 %54, i32* %13
%55 = load i32, i32* %9
%56 = load i32, i32* %13
%57 = call i32 @_mm_unpacklo_epi64(i32 %55, i32 %56)
%58 = load i32*, i32** %4
%59 = getelementptr inbounds i32, i32* %58, i64 0
store i32 %57, i32* %59
%60 = load i32, i32* %9
%61 = load i32, i32* %13
%62 = call i32 @_mm_unpackhi_epi64(i32 %60, i32 %61)
%63 = load i32*, i32** %4
%64 = getelementptr inbounds i32, i32* %63, i64 1
store i32 %62, i32* %64
%65 = load i32, i32* %11
%66 = load i32, i32* %13
%67 = call i32 @_mm_unpacklo_epi64(i32 %65, i32 %66)
%68 = load i32*, i32** %4
%69 = getelementptr inbounds i32, i32* %68, i64 2
store i32 %67, i32* %69
%70 = load i32, i32* %11
%71 = load i32, i32* %13
%72 = call i32 @_mm_unpackhi_epi64(i32 %70, i32 %71)
%73 = load i32*, i32** %4
%74 = getelementptr inbounds i32, i32* %73, i64 3
store i32 %72, i32* %74
%75 = load i32, i32* %10
%76 = load i32, i32* %13
%77 = call i32 @_mm_unpacklo_epi64(i32 %75, i32 %76)
%78 = load i32*, i32** %4
%79 = getelementptr inbounds i32, i32* %78, i64 4
store i32 %77, i32* %79
%80 = load i32, i32* %10
%81 = load i32, i32* %13
%82 = call i32 @_mm_unpackhi_epi64(i32 %80, i32 %81)
%83 = load i32*, i32** %4
%84 = getelementptr inbounds i32, i32* %83, i64 5
store i32 %82, i32* %84
%85 = load i32, i32* %12
%86 = load i32, i32* %13
%87 = call i32 @_mm_unpacklo_epi64(i32 %85, i32 %86)
%88 = load i32*, i32** %4
%89 = getelementptr inbounds i32, i32* %88, i64 6
store i32 %87, i32* %89
%90 = load i32, i32* %12
%91 = load i32, i32* %13
%92 = call i32 @_mm_unpackhi_epi64(i32 %90, i32 %91)
%93 = load i32*, i32** %4
%94 = getelementptr inbounds i32, i32* %93, i64 7
store i32 %92, i32* %94
ret void
}

LLVM IR (-O2):
define void @transpose_16bit_8x4(i32* nocapture %0, i32* nocapture writeonly %1) {
%3 = load i32, i32* %0
%4 = getelementptr inbounds i32, i32* %0, i64 1
%5 = load i32, i32* %4
%6 = tail call i32 @_mm_unpacklo_epi16(i32 %3, i32 %5)
%7 = getelementptr inbounds i32, i32* %0, i64 2
%8 = load i32, i32* %7
%9 = getelementptr inbounds i32, i32* %0, i64 3
%10 = load i32, i32* %9
%11 = tail call i32 @_mm_unpacklo_epi16(i32 %8, i32 %10)
%12 = load i32, i32* %0
%13 = load i32, i32* %4
%14 = tail call i32 @_mm_unpackhi_epi16(i32 %12, i32 %13)
%15 = load i32, i32* %7
%16 = load i32, i32* %9
%17 = tail call i32 @_mm_unpackhi_epi16(i32 %15, i32 %16)
%18 = tail call i32 @_mm_unpacklo_epi32(i32 %6, i32 %11)
%19 = tail call i32 @_mm_unpacklo_epi32(i32 %14, i32 %17)
%20 = tail call i32 @_mm_unpackhi_epi32(i32 %6, i32 %11)
%21 = tail call i32 @_mm_unpackhi_epi32(i32 %14, i32 %17)
%22 = tail call i32 (...) @_mm_setzero_si128()
%23 = tail call i32 @_mm_unpacklo_epi64(i32 %18, i32 %22)
store i32 %23, i32* %1
%24 = tail call i32 @_mm_unpackhi_epi64(i32 %18, i32 %22)
%25 = getelementptr inbounds i32, i32* %1, i64 1
store i32 %24, i32* %25
%26 = tail call i32 @_mm_unpacklo_epi64(i32 %20, i32 %22)
%27 = getelementptr inbounds i32, i32* %1, i64 2
store i32 %26, i32* %27
%28 = tail call i32 @_mm_unpackhi_epi64(i32 %20, i32 %22)
%29 = getelementptr inbounds i32, i32* %1, i64 3
store i32 %28, i32* %29
%30 = tail call i32 @_mm_unpacklo_epi64(i32 %19, i32 %22)
%31 = getelementptr inbounds i32, i32* %1, i64 4
store i32 %30, i32* %31
%32 = tail call i32 @_mm_unpackhi_epi64(i32 %19, i32 %22)
%33 = getelementptr inbounds i32, i32* %1, i64 5
store i32 %32, i32* %33
%34 = tail call i32 @_mm_unpacklo_epi64(i32 %21, i32 %22)
%35 = getelementptr inbounds i32, i32* %1, i64 6
store i32 %34, i32* %35
%36 = tail call i32 @_mm_unpackhi_epi64(i32 %21, i32 %22)
%37 = getelementptr inbounds i32, i32* %1, i64 7
store i32 %36, i32* %37
ret void
}