#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_srli_si128(int /*<<< orphan*/, int);
int /*<<< orphan*/ _mm_unpackhi_epi32(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);
void transpose_16bit_4x4(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]);
  out[0] = _mm_unpacklo_epi32(a0, a1);
  out[1] = _mm_srli_si128(out[0], 8);
  out[2] = _mm_unpackhi_epi32(a0, a1);
  out[3] = _mm_srli_si128(out[2], 8);
}


x86 assembly (clang, -O0):
<transpose_16bit_4x4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%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   1050 <_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   1050 <_mm_unpacklo_epi16@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1030 <_mm_unpacklo_epi32@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    $0x8,%esi
call   1040 <_mm_srli_si128@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1060 <_mm_unpackhi_epi32@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%edi
mov    $0x8,%esi
call   1040 <_mm_srli_si128@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0xc(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<transpose_16bit_4x4>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    (%rdi),%edi
mov    0x4(%rbx),%esi
call   1050 <_mm_unpacklo_epi16@plt>
mov    %eax,%ebp
mov    0x8(%rbx),%edi
mov    0xc(%rbx),%esi
call   1050 <_mm_unpacklo_epi16@plt>
mov    %eax,%ebx
mov    %ebp,%edi
mov    %eax,%esi
call   1030 <_mm_unpacklo_epi32@plt>
mov    %eax,(%r14)
mov    %eax,%edi
mov    $0x8,%esi
call   1040 <_mm_srli_si128@plt>
mov    %eax,0x4(%r14)
mov    %ebp,%edi
mov    %ebx,%esi
call   1060 <_mm_unpackhi_epi32@plt>
mov    %eax,0x8(%r14)
mov    %eax,%edi
mov    $0x8,%esi
call   1040 <_mm_srli_si128@plt>
mov    %eax,0xc(%r14)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @transpose_16bit_4x4(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %3
store i32* %1, i32** %4
%7 = load i32*, i32** %3
%8 = getelementptr inbounds i32, i32* %7, i64 0
%9 = load i32, i32* %8
%10 = load i32*, i32** %3
%11 = getelementptr inbounds i32, i32* %10, i64 1
%12 = load i32, i32* %11
%13 = call i32 @_mm_unpacklo_epi16(i32 %9, i32 %12)
store i32 %13, i32* %5
%14 = load i32*, i32** %3
%15 = getelementptr inbounds i32, i32* %14, i64 2
%16 = load i32, i32* %15
%17 = load i32*, i32** %3
%18 = getelementptr inbounds i32, i32* %17, i64 3
%19 = load i32, i32* %18
%20 = call i32 @_mm_unpacklo_epi16(i32 %16, i32 %19)
store i32 %20, i32* %6
%21 = load i32, i32* %5
%22 = load i32, i32* %6
%23 = call i32 @_mm_unpacklo_epi32(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** %4
%27 = getelementptr inbounds i32, i32* %26, i64 0
%28 = load i32, i32* %27
%29 = call i32 @_mm_srli_si128(i32 %28, i32 8)
%30 = load i32*, i32** %4
%31 = getelementptr inbounds i32, i32* %30, i64 1
store i32 %29, i32* %31
%32 = load i32, i32* %5
%33 = load i32, i32* %6
%34 = call i32 @_mm_unpackhi_epi32(i32 %32, i32 %33)
%35 = load i32*, i32** %4
%36 = getelementptr inbounds i32, i32* %35, i64 2
store i32 %34, i32* %36
%37 = load i32*, i32** %4
%38 = getelementptr inbounds i32, i32* %37, i64 2
%39 = load i32, i32* %38
%40 = call i32 @_mm_srli_si128(i32 %39, i32 8)
%41 = load i32*, i32** %4
%42 = getelementptr inbounds i32, i32* %41, i64 3
store i32 %40, i32* %42
ret void
}

LLVM IR (-O2):
define void @transpose_16bit_4x4(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 = tail call i32 @_mm_unpacklo_epi32(i32 %6, i32 %11)
store i32 %12, i32* %1
%13 = tail call i32 @_mm_srli_si128(i32 %12, i32 8)
%14 = getelementptr inbounds i32, i32* %1, i64 1
store i32 %13, i32* %14
%15 = tail call i32 @_mm_unpackhi_epi32(i32 %6, i32 %11)
%16 = getelementptr inbounds i32, i32* %1, i64 2
store i32 %15, i32* %16
%17 = tail call i32 @_mm_srli_si128(i32 %15, i32 8)
%18 = getelementptr inbounds i32, i32* %1, i64 3
store i32 %17, i32* %18
ret void
}