#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*/ uint8_t;
typedef int ptrdiff_t;
typedef int /*<<< orphan*/ __m64;

/* Variables and functions */
int /*<<< orphan*/ _mm_cvtsi32_si64(unsigned int);
unsigned int _mm_cvtsi64_si32(int /*<<< orphan*/);
int /*<<< orphan*/ _mm_unpackhi_pi16(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_unpackhi_pi32(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_unpacklo_pi16(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_unpacklo_pi8(int /*<<< orphan*/, int /*<<< orphan*/);
void transpose4x4(uint8_t *dst, uint8_t *src, ptrdiff_t dst_stride,
                  ptrdiff_t src_stride) {
  __m64 row0 = _mm_cvtsi32_si64(*(unsigned *)(src + (0 * src_stride)));
  __m64 row1 = _mm_cvtsi32_si64(*(unsigned *)(src + (1 * src_stride)));
  __m64 row2 = _mm_cvtsi32_si64(*(unsigned *)(src + (2 * src_stride)));
  __m64 row3 = _mm_cvtsi32_si64(*(unsigned *)(src + (3 * src_stride)));
  __m64 tmp0 = _mm_unpacklo_pi8(row0, row1);
  __m64 tmp1 = _mm_unpacklo_pi8(row2, row3);
  __m64 row01 = _mm_unpacklo_pi16(tmp0, tmp1);
  __m64 row23 = _mm_unpackhi_pi16(tmp0, tmp1);
  *((unsigned *)(dst + (0 * dst_stride))) = _mm_cvtsi64_si32(row01);
  *((unsigned *)(dst + (1 * dst_stride))) =
      _mm_cvtsi64_si32(_mm_unpackhi_pi32(row01, row01));
  *((unsigned *)(dst + (2 * dst_stride))) = _mm_cvtsi64_si32(row23);
  *((unsigned *)(dst + (3 * dst_stride))) =
      _mm_cvtsi64_si32(_mm_unpackhi_pi32(row23, row23));
}


x86 assembly (clang, -O0):
<transpose4x4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
imul   $0x0,-0x18(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edi
call   1040 <_mm_cvtsi32_si64@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
shl    $0x0,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edi
call   1040 <_mm_cvtsi32_si64@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edi
call   1040 <_mm_cvtsi32_si64@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
imul   $0x3,-0x18(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edi
call   1040 <_mm_cvtsi32_si64@plt>
mov    %eax,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1060 <_mm_unpacklo_pi8@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x28(%rbp),%esi
call   1060 <_mm_unpacklo_pi8@plt>
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x30(%rbp),%esi
call   1080 <_mm_unpacklo_pi16@plt>
mov    %eax,-0x34(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x30(%rbp),%esi
call   1050 <_mm_unpackhi_pi16@plt>
mov    %eax,-0x38(%rbp)
mov    -0x34(%rbp),%edi
call   1030 <_mm_cvtsi64_si32@plt>
mov    %eax,%edx
mov    -0x8(%rbp),%rax
imul   $0x0,-0x14(%rbp),%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x34(%rbp),%edi
mov    -0x34(%rbp),%esi
call   1070 <_mm_unpackhi_pi32@plt>
mov    %eax,%edi
call   1030 <_mm_cvtsi64_si32@plt>
mov    %eax,%edx
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
shl    $0x0,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x38(%rbp),%edi
call   1030 <_mm_cvtsi64_si32@plt>
mov    %eax,%edx
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x38(%rbp),%edi
mov    -0x38(%rbp),%esi
call   1070 <_mm_unpackhi_pi32@plt>
mov    %eax,%edi
call   1030 <_mm_cvtsi64_si32@plt>
mov    %eax,%edx
mov    -0x8(%rbp),%rax
imul   $0x3,-0x14(%rbp),%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<transpose4x4>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%ebp
mov    %edx,0x4(%rsp)
mov    %rsi,%rbx
mov    %rdi,%r15
mov    (%rsi),%edi
call   1040 <_mm_cvtsi32_si64@plt>
mov    %eax,%r12d
movslq %ebp,%rbp
mov    (%rbx,%rbp,4),%edi
call   1040 <_mm_cvtsi32_si64@plt>
mov    %eax,%r13d
lea    0x0(%rbp,%rbp,1),%eax
cltq
mov    (%rbx,%rax,4),%edi
call   1040 <_mm_cvtsi32_si64@plt>
mov    %eax,%r14d
lea    0x0(%rbp,%rbp,2),%eax
cltq
mov    (%rbx,%rax,4),%edi
call   1040 <_mm_cvtsi32_si64@plt>
mov    %eax,%ebx
mov    %r12d,%edi
mov    %r13d,%esi
call   1060 <_mm_unpacklo_pi8@plt>
mov    %eax,%r12d
mov    %r14d,%edi
mov    %ebx,%esi
call   1060 <_mm_unpacklo_pi8@plt>
mov    %eax,%ebx
mov    %r12d,%edi
mov    %eax,%esi
call   1080 <_mm_unpacklo_pi16@plt>
mov    %eax,%ebp
mov    %r12d,%edi
mov    %ebx,%esi
call   1050 <_mm_unpackhi_pi16@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1030 <_mm_cvtsi64_si32@plt>
mov    %eax,(%r15)
mov    %ebp,%edi
mov    %ebp,%esi
call   1070 <_mm_unpackhi_pi32@plt>
mov    %eax,%edi
call   1030 <_mm_cvtsi64_si32@plt>
movslq 0x4(%rsp),%rbp
mov    %eax,(%r15,%rbp,4)
mov    %ebx,%edi
call   1030 <_mm_cvtsi64_si32@plt>
lea    0x0(%rbp,%rbp,1),%ecx
movslq %ecx,%rcx
mov    %eax,(%r15,%rcx,4)
mov    %ebx,%edi
mov    %ebx,%esi
call   1070 <_mm_unpackhi_pi32@plt>
mov    %eax,%edi
call   1030 <_mm_cvtsi64_si32@plt>
lea    0x0(%rbp,%rbp,2),%ecx
movslq %ecx,%rcx
mov    %eax,(%r15,%rcx,4)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @transpose4x4(i32* nocapture writeonly %0, i32* nocapture %1, i32 %2, i32 %3) {
%5 = load i32, i32* %1
%6 = tail call i32 @_mm_cvtsi32_si64(i32 %5)
%7 = sext i32 %3 to i64
%8 = getelementptr inbounds i32, i32* %1, i64 %7
%9 = load i32, i32* %8
%10 = tail call i32 @_mm_cvtsi32_si64(i32 %9)
%11 = shl nsw i32 %3, 1
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i32, i32* %1, i64 %12
%14 = load i32, i32* %13
%15 = tail call i32 @_mm_cvtsi32_si64(i32 %14)
%16 = mul nsw i32 %3, 3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %1, i64 %17
%19 = load i32, i32* %18
%20 = tail call i32 @_mm_cvtsi32_si64(i32 %19)
%21 = tail call i32 @_mm_unpacklo_pi8(i32 %6, i32 %10)
%22 = tail call i32 @_mm_unpacklo_pi8(i32 %15, i32 %20)
%23 = tail call i32 @_mm_unpacklo_pi16(i32 %21, i32 %22)
%24 = tail call i32 @_mm_unpackhi_pi16(i32 %21, i32 %22)
%25 = tail call i32 @_mm_cvtsi64_si32(i32 %23)
store i32 %25, i32* %0
%26 = tail call i32 @_mm_unpackhi_pi32(i32 %23, i32 %23)
%27 = tail call i32 @_mm_cvtsi64_si32(i32 %26)
%28 = sext i32 %2 to i64
%29 = getelementptr inbounds i32, i32* %0, i64 %28
store i32 %27, i32* %29
%30 = tail call i32 @_mm_cvtsi64_si32(i32 %24)
%31 = shl nsw i32 %2, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %0, i64 %32
store i32 %30, i32* %33
%34 = tail call i32 @_mm_unpackhi_pi32(i32 %24, i32 %24)
%35 = tail call i32 @_mm_cvtsi64_si32(i32 %34)
%36 = mul nsw i32 %2, 3
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %0, i64 %37
store i32 %35, i32* %38
ret void
}