#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ fail(char *, int);
int matrix_transpose(float *r, float *a, int nn) {
  int n;
  switch (nn) {
  case 1:
    n = 1;
    break;
  case 4:
    n = 2;
    break;
  case 9:
    n = 3;
    break;
  default:
    fail("can not transpose object of size %d", nn);
  }
  assert(n * n == nn);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      r[i * n + j] = a[j * n + i];
  return nn;
}


x86 assembly (clang, -O0):
<matrix_transpose>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x1,%eax
je     1169 <matrix_transpose+0x49>
jmp    1147 <matrix_transpose+0x27>
mov    -0x24(%rbp),%eax
sub    $0x4,%eax
je     1175 <matrix_transpose+0x55>
jmp    1158 <matrix_transpose+0x38>
mov    -0x24(%rbp),%eax
sub    $0x9,%eax
je     1181 <matrix_transpose+0x61>
jmp    118d <matrix_transpose+0x6d>
movl   $0x1,-0x18(%rbp)
jmp    119c <matrix_transpose+0x7c>
movl   $0x2,-0x18(%rbp)
jmp    119c <matrix_transpose+0x7c>
movl   $0x3,-0x18(%rbp)
jmp    119c <matrix_transpose+0x7c>
mov    -0x14(%rbp),%esi
lea    0xe69(%rip),%rdi
call   1030 <fail@plt>
mov    -0x18(%rbp),%eax
imul   -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1226 <matrix_transpose+0x106>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1213 <matrix_transpose+0xf3>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
imul   -0x18(%rbp),%ecx
add    -0x1c(%rbp),%ecx
movslq %ecx,%rcx
movss  (%rax,%rcx,4),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
imul   -0x18(%rbp),%ecx
add    -0x20(%rbp),%ecx
movslq %ecx,%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11cd <matrix_transpose+0xad>
jmp    1218 <matrix_transpose+0xf8>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ba <matrix_transpose+0x9a>
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matrix_transpose>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%r12
mov    $0x1,%bl
cmp    $0x1,%edx
je     114f <matrix_transpose+0x2f>
cmp    $0x9,%r14d
je     1154 <matrix_transpose+0x34>
cmp    $0x4,%r14d
jne    115c <matrix_transpose+0x3c>
mov    $0x2,%r13d
jmp    116d <matrix_transpose+0x4d>
mov    %r14d,%r13d
jmp    116d <matrix_transpose+0x4d>
mov    $0x3,%r13d
jmp    116d <matrix_transpose+0x4d>
lea    0xe9d(%rip),%rdi
mov    %r14d,%esi
call   1030 <fail@plt>
xor    %ebx,%ebx
mov    %r13d,%eax
imul   %r13d,%eax
xor    %edi,%edi
cmp    %r14d,%eax
sete   %dil
call   1040 <assert@plt>
test   %bl,%bl
je     1228 <matrix_transpose+0x108>
mov    %r13d,%r8d
mov    %r8d,%ecx
and    $0xfffffffe,%ecx
lea    0x0(,%r8,4),%rdx
lea    0x0(,%r8,8),%rsi
lea    0x4(%r12),%rdi
xor    %r10d,%r10d
mov    %r15,%r9
jmp    11c0 <matrix_transpose+0xa0>
add    $0x1,%r10
add    $0x4,%r9
add    %rdx,%rdi
cmp    %r8,%r10
je     1228 <matrix_transpose+0x108>
cmp    $0x1,%r13d
jne    11d0 <matrix_transpose+0xb0>
xor    %ebp,%ebp
jmp    1200 <matrix_transpose+0xe0>
nopw   0x0(%rax,%rax,1)
mov    %r9,%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
movss  (%rbx),%xmm0
movss  %xmm0,-0x4(%rdi,%rbp,4)
movss  (%rbx,%rdx,1),%xmm0
movss  %xmm0,(%rdi,%rbp,4)
add    $0x2,%rbp
add    %rsi,%rbx
cmp    %rbp,%rcx
jne    11e0 <matrix_transpose+0xc0>
test   $0x1,%r8b
je     11b0 <matrix_transpose+0x90>
mov    %r10,%rbx
imul   %r8,%rbx
mov    %rbp,%rax
imul   %r8,%rax
add    %r10,%rax
movss  (%r15,%rax,4),%xmm0
add    %rbp,%rbx
movss  %xmm0,(%r12,%rbx,4)
jmp    11b0 <matrix_transpose+0x90>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [36 x i8] c"can not transpose object of size %d\00"
define i32 @matrix_transpose(float* %0, float* %1, i32 %2) {
%4 = alloca float*
%5 = alloca float*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store float* %0, float** %4
store float* %1, float** %5
store i32 %2, i32* %6
%10 = load i32, i32* %6
switch i32 %10, label %14 [
i32 1, label %11
i32 4, label %12
i32 9, label %13
]
11: ; preds = %3
store i32 1, i32* %7
br label %17
12: ; preds = %3
store i32 2, i32* %7
br label %17
13: ; preds = %3
store i32 3, i32* %7
br label %17
14: ; preds = %3
%15 = load i32, i32* %6
%16 = call i32 @fail(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %14, %13, %12, %11
%18 = load i32, i32* %7
%19 = load i32, i32* %7
%20 = mul nsw i32 %18, %19
%21 = load i32, i32* %6
%22 = icmp eq i32 %20, %21
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
store i32 0, i32* %8
br label %25
25: ; preds = %56, %17
%26 = load i32, i32* %8
%27 = load i32, i32* %7
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %59
29: ; preds = %25
store i32 0, i32* %9
br label %30
30: ; preds = %52, %29
%31 = load i32, i32* %9
%32 = load i32, i32* %7
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %55
34: ; preds = %30
%35 = load float*, float** %5
%36 = load i32, i32* %9
%37 = load i32, i32* %7
%38 = mul nsw i32 %36, %37
%39 = load i32, i32* %8
%40 = add nsw i32 %38, %39
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds float, float* %35, i64 %41
%43 = load float, float* %42
%44 = load float*, float** %4
%45 = load i32, i32* %8
%46 = load i32, i32* %7
%47 = mul nsw i32 %45, %46
%48 = load i32, i32* %9
%49 = add nsw i32 %47, %48
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds float, float* %44, i64 %50
store float %43, float* %51
br label %52
52: ; preds = %34
%53 = load i32, i32* %9
%54 = add nsw i32 %53, 1
store i32 %54, i32* %9
br label %30
55: ; preds = %30
br label %56
56: ; preds = %55
%57 = load i32, i32* %8
%58 = add nsw i32 %57, 1
store i32 %58, i32* %8
br label %25
59: ; preds = %25
%60 = load i32, i32* %6
ret i32 %60
}

LLVM IR (-O2):
@.str = [36 x i8] c"can not transpose object of size %d\00"
define i32 @matrix_transpose(float* nocapture writeonly %0, float* nocapture %1, i32 returned %2) {
switch i32 %2, label %6 [
i32 1, label %8
i32 4, label %4
i32 9, label %5
]
4: ; preds = %3
br label %8
5: ; preds = %3
br label %8
6: ; preds = %3
%7 = tail call i32 @fail(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %2)
br label %8
8: ; preds = %3, %6, %5, %4
%9 = phi i1 [ true, %3 ], [ false, %6 ], [ true, %5 ], [ true, %4 ]
%10 = phi i32 [ %2, %3 ], [ undef, %6 ], [ 3, %5 ], [ 2, %4 ]
%11 = mul nuw nsw i32 %10, %10
%12 = icmp eq i32 %11, %2
%13 = zext i1 %12 to i32
%14 = tail call i32 @assert(i32 %13)
br i1 %9, label %15, label %25
15: ; preds = %8
%16 = zext i32 %10 to i64
%17 = zext i32 %10 to i64
%18 = and i64 %17, 1
%19 = icmp eq i32 %10, 1
%20 = and i64 %17, 4294967294
%21 = icmp eq i64 %18, 0
br label %22
22: ; preds = %35, %15
%23 = phi i64 [ 0, %15 ], [ %36, %35 ]
%24 = mul nsw i64 %23, %16
br i1 %19, label %26, label %38
25: ; preds = %35, %8
ret i32 %2
26: ; preds = %38, %22
%27 = phi i64 [ 0, %22 ], [ %54, %38 ]
br i1 %21, label %35, label %28
28: ; preds = %26
%29 = mul nsw i64 %27, %16
%30 = add nuw nsw i64 %29, %23
%31 = getelementptr inbounds float, float* %1, i64 %30
%32 = load float, float* %31
%33 = add nuw nsw i64 %27, %24
%34 = getelementptr inbounds float, float* %0, i64 %33
store float %32, float* %34
br label %35
35: ; preds = %26, %28
%36 = add nuw nsw i64 %23, 1
%37 = icmp eq i64 %36, %17
br i1 %37, label %25, label %22
38: ; preds = %22, %38
%39 = phi i64 [ %54, %38 ], [ 0, %22 ]
%40 = phi i64 [ %55, %38 ], [ 0, %22 ]
%41 = mul nsw i64 %39, %16
%42 = add nuw nsw i64 %41, %23
%43 = getelementptr inbounds float, float* %1, i64 %42
%44 = load float, float* %43
%45 = add nuw nsw i64 %39, %24
%46 = getelementptr inbounds float, float* %0, i64 %45
store float %44, float* %46
%47 = or i64 %39, 1
%48 = mul nsw i64 %47, %16
%49 = add nuw nsw i64 %48, %23
%50 = getelementptr inbounds float, float* %1, i64 %49
%51 = load float, float* %50
%52 = add nuw nsw i64 %47, %24
%53 = getelementptr inbounds float, float* %0, i64 %52
store float %51, float* %53
%54 = add nuw nsw i64 %39, 2
%55 = add i64 %40, 2
%56 = icmp eq i64 %55, %20
br i1 %56, label %26, label %38
}