void transpose_3x3(double *mat) {
  double a;
  a = mat[1];
  mat[1] = mat[3];
  mat[3] = a;
  a = mat[2];
  mat[2] = mat[6];
  mat[6] = a;
  a = mat[5];
  mat[5] = mat[7];
  mat[7] = a;
}


x86 assembly (clang, -O0):
<transpose_3x3>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x18(%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x8(%rax)
movsd  -0x10(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x18(%rax)
mov    -0x8(%rbp),%rax
movsd  0x10(%rax),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x30(%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x10(%rax)
movsd  -0x10(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x30(%rax)
mov    -0x8(%rbp),%rax
movsd  0x28(%rax),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x38(%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x28(%rax)
movsd  -0x10(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x38(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<transpose_3x3>:
movsd  0x18(%rdi),%xmm0
movsd  0x8(%rdi),%xmm1
movsd  0x10(%rdi),%xmm2
movsd  %xmm0,0x8(%rdi)
movsd  %xmm1,0x18(%rdi)
movsd  0x30(%rdi),%xmm0
movsd  %xmm0,0x10(%rdi)
movsd  %xmm2,0x30(%rdi)
movsd  0x28(%rdi),%xmm0
movsd  0x38(%rdi),%xmm1
movsd  %xmm1,0x28(%rdi)
movsd  %xmm0,0x38(%rdi)
ret

LLVM IR (-O0):
define void @transpose_3x3(double* %0) {
%2 = alloca double*
%3 = alloca double
store double* %0, double** %2
%4 = load double*, double** %2
%5 = getelementptr inbounds double, double* %4, i64 1
%6 = load double, double* %5
store double %6, double* %3
%7 = load double*, double** %2
%8 = getelementptr inbounds double, double* %7, i64 3
%9 = load double, double* %8
%10 = load double*, double** %2
%11 = getelementptr inbounds double, double* %10, i64 1
store double %9, double* %11
%12 = load double, double* %3
%13 = load double*, double** %2
%14 = getelementptr inbounds double, double* %13, i64 3
store double %12, double* %14
%15 = load double*, double** %2
%16 = getelementptr inbounds double, double* %15, i64 2
%17 = load double, double* %16
store double %17, double* %3
%18 = load double*, double** %2
%19 = getelementptr inbounds double, double* %18, i64 6
%20 = load double, double* %19
%21 = load double*, double** %2
%22 = getelementptr inbounds double, double* %21, i64 2
store double %20, double* %22
%23 = load double, double* %3
%24 = load double*, double** %2
%25 = getelementptr inbounds double, double* %24, i64 6
store double %23, double* %25
%26 = load double*, double** %2
%27 = getelementptr inbounds double, double* %26, i64 5
%28 = load double, double* %27
store double %28, double* %3
%29 = load double*, double** %2
%30 = getelementptr inbounds double, double* %29, i64 7
%31 = load double, double* %30
%32 = load double*, double** %2
%33 = getelementptr inbounds double, double* %32, i64 5
store double %31, double* %33
%34 = load double, double* %3
%35 = load double*, double** %2
%36 = getelementptr inbounds double, double* %35, i64 7
store double %34, double* %36
ret void
}

LLVM IR (-O2):
define void @transpose_3x3(double* nocapture %0) {
%2 = getelementptr inbounds double, double* %0, i64 1
%3 = load double, double* %2
%4 = getelementptr inbounds double, double* %0, i64 3
%5 = load double, double* %4
store double %5, double* %2
store double %3, double* %4
%6 = getelementptr inbounds double, double* %0, i64 2
%7 = load double, double* %6
%8 = getelementptr inbounds double, double* %0, i64 6
%9 = load double, double* %8
store double %9, double* %6
store double %7, double* %8
%10 = getelementptr inbounds double, double* %0, i64 5
%11 = load double, double* %10
%12 = getelementptr inbounds double, double* %0, i64 7
%13 = load double, double* %12
store double %13, double* %10
store double %11, double* %12
ret void
}