#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_unpackhi_epi32(int /*<<< orphan*/ const,
                                      int /*<<< orphan*/ const);
int /*<<< orphan*/ _mm_unpackhi_epi64(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_32bit_4x4(const __m128i *const in, __m128i *const out) {
  const __m128i a0 = _mm_unpacklo_epi32(in[0], in[1]);
  const __m128i a1 = _mm_unpacklo_epi32(in[2], in[3]);
  const __m128i a2 = _mm_unpackhi_epi32(in[0], in[1]);
  const __m128i a3 = _mm_unpackhi_epi32(in[2], in[3]);
  out[0] = _mm_unpacklo_epi64(a0, a1);
  out[1] = _mm_unpackhi_epi64(a0, a1);
  out[2] = _mm_unpacklo_epi64(a2, a3);
  out[3] = _mm_unpackhi_epi64(a2, a3);
}


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

x86 assembly (clang, -O2):
<transpose_32bit_4x4>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r12
mov    %rdi,%rbp
mov    (%rdi),%edi
mov    0x4(%rbp),%esi
call   1030 <_mm_unpacklo_epi32@plt>
mov    %eax,%r14d
mov    0x8(%rbp),%edi
mov    0xc(%rbp),%esi
call   1030 <_mm_unpacklo_epi32@plt>
mov    %eax,%ebx
mov    0x0(%rbp),%edi
mov    0x4(%rbp),%esi
call   1060 <_mm_unpackhi_epi32@plt>
mov    %eax,%r15d
mov    0x8(%rbp),%edi
mov    0xc(%rbp),%esi
call   1060 <_mm_unpackhi_epi32@plt>
mov    %eax,%ebp
mov    %r14d,%edi
mov    %ebx,%esi
call   1050 <_mm_unpacklo_epi64@plt>
mov    %eax,(%r12)
mov    %r14d,%edi
mov    %ebx,%esi
call   1040 <_mm_unpackhi_epi64@plt>
mov    %eax,0x4(%r12)
mov    %r15d,%edi
mov    %ebp,%esi
call   1050 <_mm_unpacklo_epi64@plt>
mov    %eax,0x8(%r12)
mov    %r15d,%edi
mov    %ebp,%esi
call   1040 <_mm_unpackhi_epi64@plt>
mov    %eax,0xc(%r12)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @transpose_32bit_4x4(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %3
store i32* %1, i32** %4
%9 = load i32*, i32** %3
%10 = getelementptr inbounds i32, i32* %9, i64 0
%11 = load i32, i32* %10
%12 = load i32*, i32** %3
%13 = getelementptr inbounds i32, i32* %12, i64 1
%14 = load i32, i32* %13
%15 = call i32 @_mm_unpacklo_epi32(i32 %11, i32 %14)
store i32 %15, i32* %5
%16 = load i32*, i32** %3
%17 = getelementptr inbounds i32, i32* %16, i64 2
%18 = load i32, i32* %17
%19 = load i32*, i32** %3
%20 = getelementptr inbounds i32, i32* %19, i64 3
%21 = load i32, i32* %20
%22 = call i32 @_mm_unpacklo_epi32(i32 %18, i32 %21)
store i32 %22, i32* %6
%23 = load i32*, i32** %3
%24 = getelementptr inbounds i32, i32* %23, i64 0
%25 = load i32, i32* %24
%26 = load i32*, i32** %3
%27 = getelementptr inbounds i32, i32* %26, i64 1
%28 = load i32, i32* %27
%29 = call i32 @_mm_unpackhi_epi32(i32 %25, i32 %28)
store i32 %29, i32* %7
%30 = load i32*, i32** %3
%31 = getelementptr inbounds i32, i32* %30, i64 2
%32 = load i32, i32* %31
%33 = load i32*, i32** %3
%34 = getelementptr inbounds i32, i32* %33, i64 3
%35 = load i32, i32* %34
%36 = call i32 @_mm_unpackhi_epi32(i32 %32, i32 %35)
store i32 %36, i32* %8
%37 = load i32, i32* %5
%38 = load i32, i32* %6
%39 = call i32 @_mm_unpacklo_epi64(i32 %37, i32 %38)
%40 = load i32*, i32** %4
%41 = getelementptr inbounds i32, i32* %40, i64 0
store i32 %39, i32* %41
%42 = load i32, i32* %5
%43 = load i32, i32* %6
%44 = call i32 @_mm_unpackhi_epi64(i32 %42, i32 %43)
%45 = load i32*, i32** %4
%46 = getelementptr inbounds i32, i32* %45, i64 1
store i32 %44, i32* %46
%47 = load i32, i32* %7
%48 = load i32, i32* %8
%49 = call i32 @_mm_unpacklo_epi64(i32 %47, i32 %48)
%50 = load i32*, i32** %4
%51 = getelementptr inbounds i32, i32* %50, i64 2
store i32 %49, i32* %51
%52 = load i32, i32* %7
%53 = load i32, i32* %8
%54 = call i32 @_mm_unpackhi_epi64(i32 %52, i32 %53)
%55 = load i32*, i32** %4
%56 = getelementptr inbounds i32, i32* %55, i64 3
store i32 %54, i32* %56
ret void
}

LLVM IR (-O2):
define void @transpose_32bit_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_epi32(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_epi32(i32 %8, i32 %10)
%12 = load i32, i32* %0
%13 = load i32, i32* %4
%14 = tail call i32 @_mm_unpackhi_epi32(i32 %12, i32 %13)
%15 = load i32, i32* %7
%16 = load i32, i32* %9
%17 = tail call i32 @_mm_unpackhi_epi32(i32 %15, i32 %16)
%18 = tail call i32 @_mm_unpacklo_epi64(i32 %6, i32 %11)
store i32 %18, i32* %1
%19 = tail call i32 @_mm_unpackhi_epi64(i32 %6, i32 %11)
%20 = getelementptr inbounds i32, i32* %1, i64 1
store i32 %19, i32* %20
%21 = tail call i32 @_mm_unpacklo_epi64(i32 %14, i32 %17)
%22 = getelementptr inbounds i32, i32* %1, i64 2
store i32 %21, i32* %22
%23 = tail call i32 @_mm_unpackhi_epi64(i32 %14, i32 %17)
%24 = getelementptr inbounds i32, i32* %1, i64 3
store i32 %23, i32* %24
ret void
}