void transposem(double *dest, const double *src) {
  int i, j;
  for (i = 0; i < 4; i++) {
    for (j = 0; j < 4; j++) {
      dest[(i + (j << 2))] = src[(j + (i << 2))];
    }
  }
}


x86 assembly (clang, -O0):
<transposem>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jge    117d <transposem+0x7d>
movl   $0x0,-0x18(%rbp)
cmpl   $0x4,-0x18(%rbp)
jge    116a <transposem+0x6a>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    -0x14(%rbp),%edx
shl    $0x2,%edx
add    %edx,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%edx
shl    $0x2,%edx
add    %edx,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1124 <transposem+0x24>
jmp    116f <transposem+0x6f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1113 <transposem+0x13>
pop    %rbp
ret

x86 assembly (clang, -O2):
<transposem>:
movsd  (%rsi),%xmm0
movsd  %xmm0,(%rdi)
movsd  0x8(%rsi),%xmm0
movsd  %xmm0,0x20(%rdi)
movsd  0x10(%rsi),%xmm0
movsd  %xmm0,0x40(%rdi)
movsd  0x18(%rsi),%xmm0
movsd  %xmm0,0x60(%rdi)
movsd  0x20(%rsi),%xmm0
movsd  %xmm0,0x8(%rdi)
movsd  0x28(%rsi),%xmm0
movsd  %xmm0,0x28(%rdi)
movsd  0x30(%rsi),%xmm0
movsd  %xmm0,0x48(%rdi)
movsd  0x38(%rsi),%xmm0
movsd  %xmm0,0x68(%rdi)
movsd  0x40(%rsi),%xmm0
movsd  %xmm0,0x10(%rdi)
movsd  0x48(%rsi),%xmm0
movsd  %xmm0,0x30(%rdi)
movsd  0x50(%rsi),%xmm0
movsd  %xmm0,0x50(%rdi)
movsd  0x58(%rsi),%xmm0
movsd  %xmm0,0x70(%rdi)
movsd  0x60(%rsi),%xmm0
movsd  %xmm0,0x18(%rdi)
movsd  0x68(%rsi),%xmm0
movsd  %xmm0,0x38(%rdi)
movsd  0x70(%rsi),%xmm0
movsd  %xmm0,0x58(%rdi)
movsd  0x78(%rsi),%xmm0
movsd  %xmm0,0x78(%rdi)
ret

LLVM IR (-O0):
define void @transposem(double* %0, double* %1) {
%3 = alloca double*
%4 = alloca double*
%5 = alloca i32
%6 = alloca i32
store double* %0, double** %3
store double* %1, double** %4
store i32 0, i32* %5
br label %7
7: ; preds = %34, %2
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 4
br i1 %9, label %10, label %37
10: ; preds = %7
store i32 0, i32* %6
br label %11
11: ; preds = %30, %10
%12 = load i32, i32* %6
%13 = icmp slt i32 %12, 4
br i1 %13, label %14, label %33
14: ; preds = %11
%15 = load double*, double** %4
%16 = load i32, i32* %6
%17 = load i32, i32* %5
%18 = shl i32 %17, 2
%19 = add nsw i32 %16, %18
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds double, double* %15, i64 %20
%22 = load double, double* %21
%23 = load double*, double** %3
%24 = load i32, i32* %5
%25 = load i32, i32* %6
%26 = shl i32 %25, 2
%27 = add nsw i32 %24, %26
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double, double* %23, i64 %28
store double %22, double* %29
br label %30
30: ; preds = %14
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 1
store i32 %32, i32* %6
br label %11
33: ; preds = %11
br label %34
34: ; preds = %33
%35 = load i32, i32* %5
%36 = add nsw i32 %35, 1
store i32 %36, i32* %5
br label %7
37: ; preds = %7
ret void
}

LLVM IR (-O2):
define void @transposem(double* nocapture writeonly %0, double* nocapture %1) {
%3 = load double, double* %1
store double %3, double* %0
%4 = getelementptr inbounds double, double* %1, i64 1
%5 = load double, double* %4
%6 = getelementptr inbounds double, double* %0, i64 4
store double %5, double* %6
%7 = getelementptr inbounds double, double* %1, i64 2
%8 = load double, double* %7
%9 = getelementptr inbounds double, double* %0, i64 8
store double %8, double* %9
%10 = getelementptr inbounds double, double* %1, i64 3
%11 = load double, double* %10
%12 = getelementptr inbounds double, double* %0, i64 12
store double %11, double* %12
%13 = getelementptr inbounds double, double* %1, i64 4
%14 = load double, double* %13
%15 = getelementptr inbounds double, double* %0, i64 1
store double %14, double* %15
%16 = getelementptr inbounds double, double* %1, i64 5
%17 = load double, double* %16
%18 = getelementptr inbounds double, double* %0, i64 5
store double %17, double* %18
%19 = getelementptr inbounds double, double* %1, i64 6
%20 = load double, double* %19
%21 = getelementptr inbounds double, double* %0, i64 9
store double %20, double* %21
%22 = getelementptr inbounds double, double* %1, i64 7
%23 = load double, double* %22
%24 = getelementptr inbounds double, double* %0, i64 13
store double %23, double* %24
%25 = getelementptr inbounds double, double* %1, i64 8
%26 = load double, double* %25
%27 = getelementptr inbounds double, double* %0, i64 2
store double %26, double* %27
%28 = getelementptr inbounds double, double* %1, i64 9
%29 = load double, double* %28
%30 = getelementptr inbounds double, double* %0, i64 6
store double %29, double* %30
%31 = getelementptr inbounds double, double* %1, i64 10
%32 = load double, double* %31
%33 = getelementptr inbounds double, double* %0, i64 10
store double %32, double* %33
%34 = getelementptr inbounds double, double* %1, i64 11
%35 = load double, double* %34
%36 = getelementptr inbounds double, double* %0, i64 14
store double %35, double* %36
%37 = getelementptr inbounds double, double* %1, i64 12
%38 = load double, double* %37
%39 = getelementptr inbounds double, double* %0, i64 3
store double %38, double* %39
%40 = getelementptr inbounds double, double* %1, i64 13
%41 = load double, double* %40
%42 = getelementptr inbounds double, double* %0, i64 7
store double %41, double* %42
%43 = getelementptr inbounds double, double* %1, i64 14
%44 = load double, double* %43
%45 = getelementptr inbounds double, double* %0, i64 11
store double %44, double* %45
%46 = getelementptr inbounds double, double* %1, i64 15
%47 = load double, double* %46
%48 = getelementptr inbounds double, double* %0, i64 15
store double %47, double* %48
ret void
}