void trnm(double *a, int n) {
  double s, *p, *q;
  int i, j, e;
  for (i = 0, e = n - 1; i < n - 1; ++i, --e, a += n + 1) {
    for (p = a + 1, q = a + n, j = 0; j < e; ++j) {
      s = *p;
      *p++ = *q;
      *q = s;
      q += n;
    }
  }
}


x86 assembly (clang, -O0):
<trnm>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11ea <trnm+0xea>
mov    -0x8(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    11b6 <trnm+0xb6>
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x28(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x20(%rbp)
movsd  %xmm0,(%rax)
movsd  -0x18(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0xc(%rbp),%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1152 <trnm+0x52>
jmp    11bb <trnm+0xbb>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x34(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x34(%rbp)
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    111b <trnm+0x1b>
pop    %rbp
ret

x86 assembly (clang, -O2):
<trnm>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
cmp    $0x2,%esi
jl     12f6 <trnm+0x1f6>
mov    %rsi,%rax
lea    -0x1(%rsi),%r11d
mov    %eax,%ecx
lea    0x1(%rcx),%r14
add    $0xfffffffe,%eax
mov    %rax,-0x8(%rsp)
lea    0x8(,%rcx,8),%r15
mov    %rcx,%rax
shl    $0x5,%rax
lea    0x0(,%rcx,8),%rdx
lea    (%rdx,%rdx,2),%r13
mov    %rcx,%rsi
shl    $0x4,%rsi
mov    %rsi,-0x48(%rsp)
lea    0x0(,%rcx,4),%r12
xor    %ebp,%ebp
mov    %rbp,-0x28(%rsp)
mov    %rcx,-0x10(%rsp)
mov    %rcx,-0x30(%rsp)
mov    %rax,-0x38(%rsp)
xor    %ecx,%ecx
mov    %rcx,-0x40(%rsp)
mov    %r11d,%r8d
xor    %r9d,%r9d
mov    %rdi,%rsi
mov    %r14,-0x18(%rsp)
mov    %r15,-0x20(%rsp)
mov    %r11d,-0x4c(%rsp)
jmp    11c1 <trnm+0xc1>
xchg   %ax,%ax
add    $0x1,%r9d
add    $0xffffffff,%r8d
lea    (%rsi,%r14,8),%rsi
sub    %r15,-0x40(%rsp)
add    %r15,-0x38(%rsp)
add    %r15,%r13
add    %r15,-0x48(%rsp)
add    %r14,-0x30(%rsp)
add    %r15,-0x28(%rsp)
cmp    %r11d,%r9d
je     12f6 <trnm+0x1f6>
test   %r8d,%r8d
jle    1190 <trnm+0x90>
mov    -0x8(%rsp),%rcx
sub    %r9d,%ecx
mov    %rsi,%r10
mov    %rsi,%rbx
cmp    $0x3,%ecx
jb     12aa <trnm+0x1aa>
mov    %r8d,%r11d
and    $0xfffffffc,%r11d
mov    -0x28(%rsp),%r10
mov    %r13,%r14
mov    -0x30(%rsp),%r13
mov    -0x48(%rsp),%r15
mov    %r14,%rcx
mov    -0x38(%rsp),%rbx
mov    -0x40(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  0x8(%rdi,%r10,1),%xmm0
movsd  (%rdi,%r13,8),%xmm1
movsd  %xmm1,0x8(%rdi,%r10,1)
movsd  %xmm0,(%rdi,%r13,8)
movsd  0x10(%rdi,%r10,1),%xmm0
movsd  (%rdi,%r15,1),%xmm1
movsd  %xmm1,0x10(%rdi,%r10,1)
movsd  %xmm0,(%rdi,%r15,1)
movsd  0x18(%rdi,%r10,1),%xmm0
movsd  (%rdi,%r14,1),%xmm1
movsd  %xmm1,0x18(%rdi,%r10,1)
movsd  %xmm0,(%rdi,%r14,1)
movsd  0x20(%rdi,%r10,1),%xmm0
movsd  (%rdi,%rbx,1),%xmm1
movsd  %xmm1,0x20(%rdi,%r10,1)
movsd  %xmm0,(%rdi,%rbx,1)
sub    %rax,%rbp
add    %rax,%rbx
add    %rax,%r14
add    %rax,%r15
add    %r12,%r13
add    $0x20,%r10
add    $0xfffffffc,%r11d
jne    1210 <trnm+0x110>
mov    %rdi,%rbx
sub    %rbp,%rbx
add    %rdi,%r10
mov    -0x4c(%rsp),%r11d
mov    -0x18(%rsp),%r14
mov    -0x20(%rsp),%r15
mov    %rcx,%r13
test   $0x3,%r8b
je     1190 <trnm+0x90>
mov    %r8d,%ebp
and    $0x3,%ebp
mov    -0x10(%rsp),%rcx
lea    (%rbx,%rcx,8),%rbx
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nop
movsd  0x8(%r10,%rcx,8),%xmm0
movsd  (%rbx),%xmm1
movsd  %xmm1,0x8(%r10,%rcx,8)
movsd  %xmm0,(%rbx)
add    %rdx,%rbx
add    $0x1,%rcx
cmp    %ecx,%ebp
jne    12d0 <trnm+0x1d0>
jmp    1190 <trnm+0x90>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @trnm(double* nocapture %0, i32 %1) {
%3 = add i32 %1, -1
%4 = icmp sgt i32 %1, 1
br i1 %4, label %5, label %62
5: ; preds = %2
%6 = zext i32 %1 to i64
%7 = add nuw nsw i32 %1, 1
%8 = zext i32 %7 to i64
%9 = add i32 %1, -2
br label %10
10: ; preds = %5, %57
%11 = phi i32 [ %3, %5 ], [ %59, %57 ]
%12 = phi i32 [ 0, %5 ], [ %58, %57 ]
%13 = phi double* [ %0, %5 ], [ %60, %57 ]
%14 = icmp sgt i32 %11, 0
br i1 %14, label %15, label %57
15: ; preds = %10
%16 = sub i32 %9, %12
%17 = and i32 %11, 3
%18 = icmp ult i32 %16, 3
br i1 %18, label %43, label %19
19: ; preds = %15
%20 = and i32 %11, -4
br label %21
21: ; preds = %21, %19
%22 = phi double* [ %13, %19 ], [ %38, %21 ]
%23 = phi double* [ %13, %19 ], [ %37, %21 ]
%24 = phi i32 [ 0, %19 ], [ %41, %21 ]
%25 = getelementptr inbounds double, double* %23, i64 1
%26 = getelementptr inbounds double, double* %22, i64 %6
%27 = load double, double* %25
%28 = load double, double* %26
store double %28, double* %25
store double %27, double* %26
%29 = getelementptr inbounds double, double* %23, i64 2
%30 = getelementptr inbounds double, double* %26, i64 %6
%31 = load double, double* %29
%32 = load double, double* %30
store double %32, double* %29
store double %31, double* %30
%33 = getelementptr inbounds double, double* %23, i64 3
%34 = getelementptr inbounds double, double* %30, i64 %6
%35 = load double, double* %33
%36 = load double, double* %34
store double %36, double* %33
store double %35, double* %34
%37 = getelementptr inbounds double, double* %23, i64 4
%38 = getelementptr inbounds double, double* %34, i64 %6
%39 = load double, double* %37
%40 = load double, double* %38
store double %40, double* %37
store double %39, double* %38
%41 = add i32 %24, 4
%42 = icmp eq i32 %41, %20
br i1 %42, label %43, label %21
43: ; preds = %21, %15
%44 = phi double* [ %13, %15 ], [ %38, %21 ]
%45 = phi double* [ %13, %15 ], [ %37, %21 ]
%46 = icmp eq i32 %17, 0
br i1 %46, label %57, label %47
47: ; preds = %43, %47
%48 = phi double* [ %52, %47 ], [ %44, %43 ]
%49 = phi double* [ %51, %47 ], [ %45, %43 ]
%50 = phi i32 [ %55, %47 ], [ 0, %43 ]
%51 = getelementptr inbounds double, double* %49, i64 1
%52 = getelementptr inbounds double, double* %48, i64 %6
%53 = load double, double* %51
%54 = load double, double* %52
store double %54, double* %51
store double %53, double* %52
%55 = add i32 %50, 1
%56 = icmp eq i32 %55, %17
br i1 %56, label %57, label %47
57: ; preds = %43, %47, %10
%58 = add nuw nsw i32 %12, 1
%59 = add nsw i32 %11, -1
%60 = getelementptr inbounds double, double* %13, i64 %8
%61 = icmp eq i32 %58, %3
br i1 %61, label %62, label %10
62: ; preds = %57, %2
ret void
}