void transpose(double arr[][20], int size) {
  int i = 0;
  int j = 0;
  double temp = 0.0;
  for (i = 1; i < size; i++) {
    for (j = 0; j < i; j++) {
      temp = arr[i][j];
      arr[i][j] = arr[j][i];
      arr[j][i] = temp;
    }
  }
}


x86 assembly (clang, -O0):
<transpose>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11de <transpose+0xde>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11cb <transpose+0xcb>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
imul   $0xa0,%rcx,%rcx
add    %rcx,%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
imul   $0xa0,%rcx,%rcx
add    %rcx,%rax
movslq -0x10(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
imul   $0xa0,%rcx,%rcx
add    %rcx,%rax
movslq -0x14(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x20(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
imul   $0xa0,%rcx,%rcx
add    %rcx,%rax
movslq -0x10(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113b <transpose+0x3b>
jmp    11d0 <transpose+0xd0>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1128 <transpose+0x28>
pop    %rbp
ret

x86 assembly (clang, -O2):
<transpose>:
cmp    $0x2,%esi
jl     11ed <transpose+0xed>
mov    %esi,%r8d
lea    0xa8(%rdi),%r9
mov    $0x1,%r11d
xor    %r10d,%r10d
mov    %r9,%rcx
jmp    114c <transpose+0x4c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%r11
add    $0x1,%r10
add    $0xa0,%rcx
add    $0x8,%r9
cmp    %r8,%r11
je     11ed <transpose+0xed>
test   %r10,%r10
je     11b0 <transpose+0xb0>
mov    %r11,%rdx
and    $0xfffffffffffffffe,%rdx
mov    %r9,%rsi
xor    %eax,%eax
nopl   (%rax)
movsd  -0x8(%rcx,%rax,8),%xmm0
movsd  -0xa0(%rsi),%xmm1
ff
movsd  %xmm1,-0x8(%rcx,%rax,8)
movsd  %xmm0,-0xa0(%rsi)
ff
movsd  (%rcx,%rax,8),%xmm0
movsd  (%rsi),%xmm1
movsd  %xmm1,(%rcx,%rax,8)
movsd  %xmm0,(%rsi)
add    $0x2,%rax
add    $0x140,%rsi
cmp    %rax,%rdx
jne    1160 <transpose+0x60>
test   $0x1,%r11b
je     1130 <transpose+0x30>
jmp    11bc <transpose+0xbc>
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
test   $0x1,%r11b
je     1130 <transpose+0x30>
lea    (%r11,%r11,4),%rdx
shl    $0x5,%rdx
add    %rdi,%rdx
movsd  (%rdx,%rax,8),%xmm0
lea    (%rax,%rax,4),%rsi
shl    $0x5,%rsi
add    %rdi,%rsi
movsd  (%rsi,%r11,8),%xmm1
movsd  %xmm1,(%rdx,%rax,8)
movsd  %xmm0,(%rsi,%r11,8)
jmp    1130 <transpose+0x30>
ret

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

LLVM IR (-O2):
define void @transpose([20 x double]* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 1
br i1 %3, label %4, label %40
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %6
6: ; preds = %4, %36
%7 = phi i64 [ 0, %4 ], [ %39, %36 ]
%8 = phi i64 [ 1, %4 ], [ %37, %36 ]
%9 = and i64 %8, 1
%10 = icmp eq i64 %7, 0
br i1 %10, label %28, label %11
11: ; preds = %6
%12 = and i64 %8, 9223372036854775806
br label %13
13: ; preds = %13, %11
%14 = phi i64 [ 0, %11 ], [ %25, %13 ]
%15 = phi i64 [ 0, %11 ], [ %26, %13 ]
%16 = getelementptr inbounds [20 x double], [20 x double]* %0, i64 %8, i64 %14
%17 = load double, double* %16
%18 = getelementptr inbounds [20 x double], [20 x double]* %0, i64 %14, i64 %8
%19 = load double, double* %18
store double %19, double* %16
store double %17, double* %18
%20 = or i64 %14, 1
%21 = getelementptr inbounds [20 x double], [20 x double]* %0, i64 %8, i64 %20
%22 = load double, double* %21
%23 = getelementptr inbounds [20 x double], [20 x double]* %0, i64 %20, i64 %8
%24 = load double, double* %23
store double %24, double* %21
store double %22, double* %23
%25 = add nuw nsw i64 %14, 2
%26 = add i64 %15, 2
%27 = icmp eq i64 %26, %12
br i1 %27, label %28, label %13
28: ; preds = %13, %6
%29 = phi i64 [ 0, %6 ], [ %25, %13 ]
%30 = icmp eq i64 %9, 0
br i1 %30, label %36, label %31
31: ; preds = %28
%32 = getelementptr inbounds [20 x double], [20 x double]* %0, i64 %8, i64 %29
%33 = load double, double* %32
%34 = getelementptr inbounds [20 x double], [20 x double]* %0, i64 %29, i64 %8
%35 = load double, double* %34
store double %35, double* %32
store double %33, double* %34
br label %36
36: ; preds = %28, %31
%37 = add nuw nsw i64 %8, 1
%38 = icmp eq i64 %37, %5
%39 = add i64 %7, 1
br i1 %38, label %40, label %6
40: ; preds = %36, %2
ret void
}