int rot3d_mat_transpose(double A[3][3]) {
  int j, k;
  double tmp;
  for (j = 0; j < 3; j++)
    for (k = 0; k < j; k++) {
      tmp = A[j][k];
      A[j][k] = A[k][j];
      A[k][j] = tmp;
    }
  return (0);
}


x86 assembly (clang, -O0):
<rot3d_mat_transpose>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x3,-0xc(%rbp)
jge    11b7 <rot3d_mat_transpose+0xb7>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a4 <rot3d_mat_transpose+0xa4>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movslq -0x10(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movslq -0xc(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movslq -0x10(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movslq -0xc(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1120 <rot3d_mat_transpose+0x20>
jmp    11a9 <rot3d_mat_transpose+0xa9>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    110f <rot3d_mat_transpose+0xf>
xor    %eax,%eax
pop    %rbp
ret

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

LLVM IR (-O0):
define i32 @rot3d_mat_transpose([3 x double]* %0) {
%2 = alloca [3 x double]*
%3 = alloca i32
%4 = alloca i32
%5 = alloca double
store [3 x double]* %0, [3 x double]** %2
store i32 0, i32* %3
br label %6
6: ; preds = %50, %1
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 3
br i1 %8, label %9, label %53
9: ; preds = %6
store i32 0, i32* %4
br label %10
10: ; preds = %46, %9
%11 = load i32, i32* %4
%12 = load i32, i32* %3
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %49
14: ; preds = %10
%15 = load [3 x double]*, [3 x double]** %2
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [3 x double], [3 x double]* %15, i64 %17
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [3 x double], [3 x double]* %18, i64 0, i64 %20
%22 = load double, double* %21
store double %22, double* %5
%23 = load [3 x double]*, [3 x double]** %2
%24 = load i32, i32* %4
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [3 x double], [3 x double]* %23, i64 %25
%27 = load i32, i32* %3
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [3 x double], [3 x double]* %26, i64 0, i64 %28
%30 = load double, double* %29
%31 = load [3 x double]*, [3 x double]** %2
%32 = load i32, i32* %3
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [3 x double], [3 x double]* %31, i64 %33
%35 = load i32, i32* %4
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [3 x double], [3 x double]* %34, i64 0, i64 %36
store double %30, double* %37
%38 = load double, double* %5
%39 = load [3 x double]*, [3 x double]** %2
%40 = load i32, i32* %4
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [3 x double], [3 x double]* %39, i64 %41
%43 = load i32, i32* %3
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [3 x double], [3 x double]* %42, i64 0, i64 %44
store double %38, double* %45
br label %46
46: ; preds = %14
%47 = load i32, i32* %4
%48 = add nsw i32 %47, 1
store i32 %48, i32* %4
br label %10
49: ; preds = %10
br label %50
50: ; preds = %49
%51 = load i32, i32* %3
%52 = add nsw i32 %51, 1
store i32 %52, i32* %3
br label %6
53: ; preds = %6
ret i32 0
}

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