float *mat3_transpose(float *result, float *m) {
  float transposed[16];
  transposed[0] = m[0];
  transposed[1] = m[3];
  transposed[2] = m[6];
  transposed[3] = m[1];
  transposed[4] = m[4];
  transposed[5] = m[7];
  transposed[6] = m[2];
  transposed[7] = m[5];
  transposed[8] = m[8];
  result[0] = transposed[0];
  result[1] = transposed[1];
  result[2] = transposed[2];
  result[3] = transposed[3];
  result[4] = transposed[4];
  result[5] = transposed[5];
  result[6] = transposed[6];
  result[7] = transposed[7];
  result[8] = transposed[8];
  return result;
}


x86 assembly (clang, -O0):
<mat3_transpose>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movss  (%rax),%xmm0
movss  %xmm0,-0x50(%rbp)
mov    -0x10(%rbp),%rax
movss  0xc(%rax),%xmm0
movss  %xmm0,-0x4c(%rbp)
mov    -0x10(%rbp),%rax
movss  0x18(%rax),%xmm0
movss  %xmm0,-0x48(%rbp)
mov    -0x10(%rbp),%rax
movss  0x4(%rax),%xmm0
movss  %xmm0,-0x44(%rbp)
mov    -0x10(%rbp),%rax
movss  0x10(%rax),%xmm0
movss  %xmm0,-0x40(%rbp)
mov    -0x10(%rbp),%rax
movss  0x1c(%rax),%xmm0
movss  %xmm0,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
movss  0x8(%rax),%xmm0
movss  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
movss  0x14(%rax),%xmm0
movss  %xmm0,-0x34(%rbp)
mov    -0x10(%rbp),%rax
movss  0x20(%rax),%xmm0
movss  %xmm0,-0x30(%rbp)
movss  -0x50(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,(%rax)
movss  -0x4c(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x4(%rax)
movss  -0x48(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x8(%rax)
movss  -0x44(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0xc(%rax)
movss  -0x40(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x10(%rax)
movss  -0x3c(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x14(%rax)
movss  -0x38(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x18(%rax)
movss  -0x34(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x1c(%rax)
movss  -0x30(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movss  %xmm0,0x20(%rax)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<mat3_transpose>:
mov    %rdi,%rax
movss  0xc(%rsi),%xmm8
movss  0x18(%rsi),%xmm1
movss  (%rsi),%xmm2
movss  0x4(%rsi),%xmm3
movss  0x10(%rsi),%xmm4
movss  0x1c(%rsi),%xmm5
movss  0x8(%rsi),%xmm6
movss  0x14(%rsi),%xmm7
movss  0x20(%rsi),%xmm0
movss  %xmm2,(%rdi)
movss  %xmm8,0x4(%rdi)
movss  %xmm1,0x8(%rdi)
movss  %xmm3,0xc(%rdi)
movss  %xmm4,0x10(%rdi)
movss  %xmm5,0x14(%rdi)
movss  %xmm6,0x18(%rdi)
movss  %xmm7,0x1c(%rdi)
movss  %xmm0,0x20(%rdi)
ret

LLVM IR (-O0):
define float* @mat3_transpose(float* %0, float* %1) {
%3 = alloca float*
%4 = alloca float*
%5 = alloca [16 x float]
store float* %0, float** %3
store float* %1, float** %4
%6 = load float*, float** %4
%7 = getelementptr inbounds float, float* %6, i64 0
%8 = load float, float* %7
%9 = getelementptr inbounds [16 x float], [16 x float]* %5, i64 0, i64 0
store float %8, float* %9
%10 = load float*, float** %4
%11 = getelementptr inbounds float, float* %10, i64 3
%12 = load float, float* %11
%13 = getelementptr inbounds [16 x float], [16 x float]* %5, i64 0, i64 1
store float %12, float* %13
%14 = load float*, float** %4
%15 = getelementptr inbounds float, float* %14, i64 6
%16 = load float, float* %15
%17 = getelementptr inbounds [16 x float], [16 x float]* %5, i64 0, i64 2
store float %16, float* %17
%18 = load float*, float** %4
%19 = getelementptr inbounds float, float* %18, i64 1
%20 = load float, float* %19
%21 = getelementptr inbounds [16 x float], [16 x float]* %5, i64 0, i64 3
store float %20, float* %21
%22 = load float*, float** %4
%23 = getelementptr inbounds float, float* %22, i64 4
%24 = load float, float* %23
%25 = getelementptr inbounds [16 x float], [16 x float]* %5, i64 0, i64 4
store float %24, float* %25
%26 = load float*, float** %4
%27 = getelementptr inbounds float, float* %26, i64 7
%28 = load float, float* %27
%29 = getelementptr inbounds [16 x float], [16 x float]* %5, i64 0, i64 5
store float %28, float* %29
%30 = load float*, float** %4
%31 = getelementptr inbounds float, float* %30, i64 2
%32 = load float, float* %31
%33 = getelementptr inbounds [16 x float], [16 x float]* %5, i64 0, i64 6
store float %32, float* %33
%34 = load float*, float** %4
%35 = getelementptr inbounds float, float* %34, i64 5
%36 = load float, float* %35
%37 = getelementptr inbounds [16 x float], [16 x float]* %5, i64 0, i64 7
store float %36, float* %37
%38 = load float*, float** %4
%39 = getelementptr inbounds float, float* %38, i64 8
%40 = load float, float* %39
%41 = getelementptr inbounds [16 x float], [16 x float]* %5, i64 0, i64 8
store float %40, float* %41
%42 = getelementptr inbounds [16 x float], [16 x float]* %5, i64 0, i64 0
%43 = load float, float* %42
%44 = load float*, float** %3
%45 = getelementptr inbounds float, float* %44, i64 0
store float %43, float* %45
%46 = getelementptr inbounds [16 x float], [16 x float]* %5, i64 0, i64 1
%47 = load float, float* %46
%48 = load float*, float** %3
%49 = getelementptr inbounds float, float* %48, i64 1
store float %47, float* %49
%50 = getelementptr inbounds [16 x float], [16 x float]* %5, i64 0, i64 2
%51 = load float, float* %50
%52 = load float*, float** %3
%53 = getelementptr inbounds float, float* %52, i64 2
store float %51, float* %53
%54 = getelementptr inbounds [16 x float], [16 x float]* %5, i64 0, i64 3
%55 = load float, float* %54
%56 = load float*, float** %3
%57 = getelementptr inbounds float, float* %56, i64 3
store float %55, float* %57
%58 = getelementptr inbounds [16 x float], [16 x float]* %5, i64 0, i64 4
%59 = load float, float* %58
%60 = load float*, float** %3
%61 = getelementptr inbounds float, float* %60, i64 4
store float %59, float* %61
%62 = getelementptr inbounds [16 x float], [16 x float]* %5, i64 0, i64 5
%63 = load float, float* %62
%64 = load float*, float** %3
%65 = getelementptr inbounds float, float* %64, i64 5
store float %63, float* %65
%66 = getelementptr inbounds [16 x float], [16 x float]* %5, i64 0, i64 6
%67 = load float, float* %66
%68 = load float*, float** %3
%69 = getelementptr inbounds float, float* %68, i64 6
store float %67, float* %69
%70 = getelementptr inbounds [16 x float], [16 x float]* %5, i64 0, i64 7
%71 = load float, float* %70
%72 = load float*, float** %3
%73 = getelementptr inbounds float, float* %72, i64 7
store float %71, float* %73
%74 = getelementptr inbounds [16 x float], [16 x float]* %5, i64 0, i64 8
%75 = load float, float* %74
%76 = load float*, float** %3
%77 = getelementptr inbounds float, float* %76, i64 8
store float %75, float* %77
%78 = load float*, float** %3
ret float* %78
}

LLVM IR (-O2):
define float* @mat3_transpose(float* returned writeonly %0, float* nocapture %1) {
%3 = load float, float* %1
%4 = getelementptr inbounds float, float* %1, i64 3
%5 = load float, float* %4
%6 = getelementptr inbounds float, float* %1, i64 6
%7 = load float, float* %6
%8 = getelementptr inbounds float, float* %1, i64 1
%9 = load float, float* %8
%10 = getelementptr inbounds float, float* %1, i64 4
%11 = load float, float* %10
%12 = getelementptr inbounds float, float* %1, i64 7
%13 = load float, float* %12
%14 = getelementptr inbounds float, float* %1, i64 2
%15 = load float, float* %14
%16 = getelementptr inbounds float, float* %1, i64 5
%17 = load float, float* %16
%18 = getelementptr inbounds float, float* %1, i64 8
%19 = load float, float* %18
store float %3, float* %0
%20 = getelementptr inbounds float, float* %0, i64 1
store float %5, float* %20
%21 = getelementptr inbounds float, float* %0, i64 2
store float %7, float* %21
%22 = getelementptr inbounds float, float* %0, i64 3
store float %9, float* %22
%23 = getelementptr inbounds float, float* %0, i64 4
store float %11, float* %23
%24 = getelementptr inbounds float, float* %0, i64 5
store float %13, float* %24
%25 = getelementptr inbounds float, float* %0, i64 6
store float %15, float* %25
%26 = getelementptr inbounds float, float* %0, i64 7
store float %17, float* %26
%27 = getelementptr inbounds float, float* %0, i64 8
store float %19, float* %27
ret float* %0
}