void transpose(mat, trans_mat) double mat[3][3];
double trans_mat[3][3];
{
  int i, j;
  for (i = 0; i < 3; i++) {
    for (j = 0; j < 3; j++) {
      trans_mat[i][j] = mat[j][i];
    }
  }
}


x86 assembly (clang, -O0):
<transpose>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x3,-0x14(%rbp)
jge    117f <transpose+0x7f>
movl   $0x0,-0x18(%rbp)
cmpl   $0x3,-0x18(%rbp)
jge    116c <transpose+0x6c>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movslq -0x18(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1124 <transpose+0x24>
jmp    1171 <transpose+0x71>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1113 <transpose+0x13>
pop    %rbp
ret

x86 assembly (clang, -O2):
<transpose>:
movsd  (%rdi),%xmm0
movsd  %xmm0,(%rsi)
movsd  0x18(%rdi),%xmm0
movsd  %xmm0,0x8(%rsi)
movsd  0x30(%rdi),%xmm0
movsd  %xmm0,0x10(%rsi)
movsd  0x8(%rdi),%xmm0
movsd  %xmm0,0x18(%rsi)
movsd  0x20(%rdi),%xmm0
movsd  %xmm0,0x20(%rsi)
movsd  0x38(%rdi),%xmm0
movsd  %xmm0,0x28(%rsi)
movsd  0x10(%rdi),%xmm0
movsd  %xmm0,0x30(%rsi)
movsd  0x28(%rdi),%xmm0
movsd  %xmm0,0x38(%rsi)
movsd  0x40(%rdi),%xmm0
movsd  %xmm0,0x40(%rsi)
ret

LLVM IR (-O0):
define void @transpose([3 x double]* %0, [3 x double]* %1) {
%3 = alloca [3 x double]*
%4 = alloca [3 x double]*
%5 = alloca i32
%6 = alloca i32
store [3 x double]* %0, [3 x double]** %3
store [3 x double]* %1, [3 x double]** %4
store i32 0, i32* %5
br label %7
7: ; preds = %34, %2
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 3
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, 3
br i1 %13, label %14, label %33
14: ; preds = %11
%15 = load [3 x double]*, [3 x double]** %3
%16 = load i32, i32* %6
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [3 x double], [3 x double]* %15, i64 %17
%19 = load i32, i32* %5
%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
%23 = load [3 x double]*, [3 x double]** %4
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [3 x double], [3 x double]* %23, i64 %25
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [3 x double], [3 x double]* %26, i64 0, 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 @transpose([3 x double]* nocapture %0, [3 x double]* nocapture writeonly %1) {
%3 = getelementptr inbounds [3 x double], [3 x double]* %0, i64 0, i64 0
%4 = load double, double* %3
%5 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 0, i64 0
store double %4, double* %5
%6 = getelementptr inbounds [3 x double], [3 x double]* %0, i64 1, i64 0
%7 = load double, double* %6
%8 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 0, i64 1
store double %7, double* %8
%9 = getelementptr inbounds [3 x double], [3 x double]* %0, i64 2, i64 0
%10 = load double, double* %9
%11 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 0, i64 2
store double %10, double* %11
%12 = getelementptr inbounds [3 x double], [3 x double]* %0, i64 0, i64 1
%13 = load double, double* %12
%14 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 1, i64 0
store double %13, double* %14
%15 = getelementptr inbounds [3 x double], [3 x double]* %0, i64 1, i64 1
%16 = load double, double* %15
%17 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 1, i64 1
store double %16, double* %17
%18 = getelementptr inbounds [3 x double], [3 x double]* %0, i64 2, i64 1
%19 = load double, double* %18
%20 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 1, i64 2
store double %19, double* %20
%21 = getelementptr inbounds [3 x double], [3 x double]* %0, i64 0, i64 2
%22 = load double, double* %21
%23 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 2, i64 0
store double %22, double* %23
%24 = getelementptr inbounds [3 x double], [3 x double]* %0, i64 1, i64 2
%25 = load double, double* %24
%26 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 2, i64 1
store double %25, double* %26
%27 = getelementptr inbounds [3 x double], [3 x double]* %0, i64 2, i64 2
%28 = load double, double* %27
%29 = getelementptr inbounds [3 x double], [3 x double]* %1, i64 2, i64 2
store double %28, double* %29
ret void
}