#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 */
typedef int /*<<< orphan*/ G;

/* Variables and functions */
int /*<<< orphan*/ dump(size_t, size_t, int **);
scalar_t__ memcmp(int **, int **, int);
int /*<<< orphan*/ mulsq(size_t, int **, int **, int **);
int /*<<< orphan*/ printf(char *, size_t, size_t);
int /*<<< orphan*/ rands(size_t, size_t, int **);
int /*<<< orphan*/ row2col(size_t, size_t, int **, int **);
int /*<<< orphan*/ transpose(size_t, size_t, int **, int **);
void test_square_transpose(size_t n) {
  int A[n][n], B[n][n], C[n][n], D[n][n], E[n][n], F[n][n], G[n][n], H[n][n];
  rands(n, n, A);
  rands(n, n, B);
  mulsq(n, A, B, C);
  transpose(n, n, C, D);
  transpose(n, n, B, E);
  transpose(n, n, A, F);
  mulsq(n, E, F, G);
  mulsq(n, A, B, C);
  row2col(n, n, C, D);
  row2col(n, n, B, E);
  row2col(n, n, A, F);
  mulsq(n, E, F, H);
  if (memcmp(H, G, sizeof(G))) {
    printf("%zux%zu transpose mismatch\n", n, n);
    dump(n, n, G);
    dump(n, n, H);
  }
}


x86 assembly (clang, -O0):
<test_square_transpose>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rcx
imul   %rcx,%rcx
lea    0xf(,%rcx,4),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdx
sub    %rcx,%rdx
mov    %rdx,-0xc8(%rbp)
mov    %rdx,%rsp
mov    %rax,-0x18(%rbp)
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
imul   %rcx,%rcx
lea    0xf(,%rcx,4),%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rcx
sub    %rsi,%rcx
mov    %rcx,-0xd0(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
imul   %rcx,%rcx
lea    0xf(,%rcx,4),%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rcx
sub    %rsi,%rcx
mov    %rcx,-0xe0(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
imul   %rcx,%rcx
lea    0xf(,%rcx,4),%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rcx
sub    %rsi,%rcx
mov    %rcx,-0xd8(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x48(%rbp)
mov    %rax,-0x50(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
imul   %rcx,%rcx
lea    0xf(,%rcx,4),%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rcx
sub    %rsi,%rcx
mov    %rcx,-0xc0(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x58(%rbp)
mov    %rax,-0x60(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
imul   %rcx,%rcx
lea    0xf(,%rcx,4),%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rcx
sub    %rsi,%rcx
mov    %rcx,-0xb8(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x68(%rbp)
mov    %rax,-0x70(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0xa0(%rbp)
mov    %rax,%rcx
mov    %rcx,-0x98(%rbp)
mov    %rax,%rcx
imul   %rcx,%rcx
lea    0xf(,%rcx,4),%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rcx
sub    %rsi,%rcx
mov    %rcx,-0xa8(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x78(%rbp)
mov    %rax,-0x80(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
mov    %rax,%rsi
imul   %rsi,%rsi
lea    0xf(,%rsi,4),%rdi
and    $0xfffffffffffffff0,%rdi
mov    %rsp,%rsi
sub    %rdi,%rsi
mov    %rsi,-0xb0(%rbp)
mov    %rsi,%rsp
mov    %rcx,-0x88(%rbp)
mov    %rax,-0x90(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1090 <rands@plt>
mov    -0xd0(%rbp),%rdx
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1090 <rands@plt>
mov    -0xe0(%rbp),%rcx
mov    -0xd0(%rbp),%rdx
mov    -0xc8(%rbp),%rsi
mov    -0x8(%rbp),%rdi
call   1070 <mulsq@plt>
mov    -0xe0(%rbp),%rdx
mov    -0xd8(%rbp),%rcx
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1080 <transpose@plt>
mov    -0xd0(%rbp),%rdx
mov    -0xc0(%rbp),%rcx
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1080 <transpose@plt>
mov    -0xc8(%rbp),%rdx
mov    -0xb8(%rbp),%rcx
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1080 <transpose@plt>
mov    -0xc0(%rbp),%rsi
mov    -0xb8(%rbp),%rdx
mov    -0xa8(%rbp),%rcx
mov    -0x8(%rbp),%rdi
call   1070 <mulsq@plt>
mov    -0xe0(%rbp),%rcx
mov    -0xd0(%rbp),%rdx
mov    -0xc8(%rbp),%rsi
mov    -0x8(%rbp),%rdi
call   1070 <mulsq@plt>
mov    -0xe0(%rbp),%rdx
mov    -0xd8(%rbp),%rcx
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <row2col@plt>
mov    -0xd0(%rbp),%rdx
mov    -0xc0(%rbp),%rcx
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <row2col@plt>
mov    -0xc8(%rbp),%rdx
mov    -0xb8(%rbp),%rcx
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <row2col@plt>
mov    -0xc0(%rbp),%rsi
mov    -0xb8(%rbp),%rdx
mov    -0xb0(%rbp),%rcx
mov    -0x8(%rbp),%rdi
call   1070 <mulsq@plt>
mov    -0xb0(%rbp),%rdi
mov    -0xa8(%rbp),%rsi
mov    -0xa0(%rbp),%rcx
mov    -0x98(%rbp),%rax
imul   %rcx,%rax
shl    $0x2,%rax
mov    %eax,%edx
call   1060 <memcmp@plt>
cmp    $0x0,%rax
je     14c4 <test_square_transpose+0x354>
mov    -0x8(%rbp),%rsi
mov    -0x8(%rbp),%rdx
lea    0xb69(%rip),%rdi
call   1040 <printf@plt>
mov    -0xa8(%rbp),%rdx
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <dump@plt>
mov    -0xb0(%rbp),%rdx
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <dump@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_square_transpose>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rdi,%rbx
mov    %rdi,%rax
imul   %rdi,%rax
mov    %rax,-0x60(%rbp)
mov    %rsp,%r13
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
mov    %rsp,%r14
sub    %rax,%r14
mov    %r14,%rsp
mov    %rsp,%rcx
sub    %rax,%rcx
mov    %rcx,%rsp
mov    %rcx,%r15
mov    %rsp,%rcx
sub    %rax,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rsp,%rcx
sub    %rax,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rsp,%rcx
sub    %rax,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rsp,%rcx
sub    %rax,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rsp,%rcx
sub    %rax,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rdi,%rsi
mov    %r13,%rdx
call   1090 <rands@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1090 <rands@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r14,%rdx
mov    %r15,-0x48(%rbp)
mov    %r15,%rcx
call   1070 <mulsq@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    -0x40(%rbp),%rcx
call   1080 <transpose@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    -0x50(%rbp),%r12
mov    %r12,%rcx
call   1080 <transpose@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
mov    %r13,%rdx
mov    -0x30(%rbp),%r15
mov    %r15,%rcx
call   1080 <transpose@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
mov    -0x38(%rbp),%rcx
call   1070 <mulsq@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r14,%rdx
mov    -0x48(%rbp),%r15
mov    %r15,%rcx
call   1070 <mulsq@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    -0x58(%rbp),%r15
mov    -0x40(%rbp),%rcx
call   1030 <row2col@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    -0x38(%rbp),%r14
mov    %r12,%rcx
call   1030 <row2col@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
mov    %r13,%rdx
mov    -0x30(%rbp),%r13
mov    %r13,%rcx
call   1030 <row2col@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
mov    %r15,%rcx
call   1070 <mulsq@plt>
mov    -0x60(%rbp),%rdx
shl    $0x2,%edx
mov    %r15,%rdi
mov    %r14,%rsi
call   1060 <memcmp@plt>
test   %rax,%rax
je     1321 <test_square_transpose+0x1b1>
lea    0xd06(%rip),%rdi
mov    %rbx,%rsi
mov    %rbx,%rdx
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1050 <dump@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1050 <dump@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [28 x i8] c"%zux%zu transpose mismatch\0A\00"
define void @test_square_transpose(i64 %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
%14 = alloca i64
%15 = alloca i64
%16 = alloca i64
%17 = alloca i64
%18 = alloca i64
%19 = alloca i64
store i64 %0, i64* %2
%20 = load i64, i64* %2
%21 = load i64, i64* %2
%22 = call i8* @llvm.stacksave()
store i8* %22, i8** %3
%23 = mul nuw i64 %20, %21
%24 = alloca i32, i64 %23
store i64 %20, i64* %4
store i64 %21, i64* %5
%25 = load i64, i64* %2
%26 = load i64, i64* %2
%27 = mul nuw i64 %25, %26
%28 = alloca i32, i64 %27
store i64 %25, i64* %6
store i64 %26, i64* %7
%29 = load i64, i64* %2
%30 = load i64, i64* %2
%31 = mul nuw i64 %29, %30
%32 = alloca i32, i64 %31
store i64 %29, i64* %8
store i64 %30, i64* %9
%33 = load i64, i64* %2
%34 = load i64, i64* %2
%35 = mul nuw i64 %33, %34
%36 = alloca i32, i64 %35
store i64 %33, i64* %10
store i64 %34, i64* %11
%37 = load i64, i64* %2
%38 = load i64, i64* %2
%39 = mul nuw i64 %37, %38
%40 = alloca i32, i64 %39
store i64 %37, i64* %12
store i64 %38, i64* %13
%41 = load i64, i64* %2
%42 = load i64, i64* %2
%43 = mul nuw i64 %41, %42
%44 = alloca i32, i64 %43
store i64 %41, i64* %14
store i64 %42, i64* %15
%45 = load i64, i64* %2
%46 = load i64, i64* %2
%47 = mul nuw i64 %45, %46
%48 = alloca i32, i64 %47
store i64 %45, i64* %16
store i64 %46, i64* %17
%49 = load i64, i64* %2
%50 = load i64, i64* %2
%51 = mul nuw i64 %49, %50
%52 = alloca i32, i64 %51
store i64 %49, i64* %18
store i64 %50, i64* %19
%53 = load i64, i64* %2
%54 = load i64, i64* %2
%55 = bitcast i32* %24 to i32**
%56 = call i32 @rands(i64 %53, i64 %54, i32** %55)
%57 = load i64, i64* %2
%58 = load i64, i64* %2
%59 = bitcast i32* %28 to i32**
%60 = call i32 @rands(i64 %57, i64 %58, i32** %59)
%61 = load i64, i64* %2
%62 = bitcast i32* %24 to i32**
%63 = bitcast i32* %28 to i32**
%64 = bitcast i32* %32 to i32**
%65 = call i32 @mulsq(i64 %61, i32** %62, i32** %63, i32** %64)
%66 = load i64, i64* %2
%67 = load i64, i64* %2
%68 = bitcast i32* %32 to i32**
%69 = bitcast i32* %36 to i32**
%70 = call i32 @transpose(i64 %66, i64 %67, i32** %68, i32** %69)
%71 = load i64, i64* %2
%72 = load i64, i64* %2
%73 = bitcast i32* %28 to i32**
%74 = bitcast i32* %40 to i32**
%75 = call i32 @transpose(i64 %71, i64 %72, i32** %73, i32** %74)
%76 = load i64, i64* %2
%77 = load i64, i64* %2
%78 = bitcast i32* %24 to i32**
%79 = bitcast i32* %44 to i32**
%80 = call i32 @transpose(i64 %76, i64 %77, i32** %78, i32** %79)
%81 = load i64, i64* %2
%82 = bitcast i32* %40 to i32**
%83 = bitcast i32* %44 to i32**
%84 = bitcast i32* %48 to i32**
%85 = call i32 @mulsq(i64 %81, i32** %82, i32** %83, i32** %84)
%86 = load i64, i64* %2
%87 = bitcast i32* %24 to i32**
%88 = bitcast i32* %28 to i32**
%89 = bitcast i32* %32 to i32**
%90 = call i32 @mulsq(i64 %86, i32** %87, i32** %88, i32** %89)
%91 = load i64, i64* %2
%92 = load i64, i64* %2
%93 = bitcast i32* %32 to i32**
%94 = bitcast i32* %36 to i32**
%95 = call i32 @row2col(i64 %91, i64 %92, i32** %93, i32** %94)
%96 = load i64, i64* %2
%97 = load i64, i64* %2
%98 = bitcast i32* %28 to i32**
%99 = bitcast i32* %40 to i32**
%100 = call i32 @row2col(i64 %96, i64 %97, i32** %98, i32** %99)
%101 = load i64, i64* %2
%102 = load i64, i64* %2
%103 = bitcast i32* %24 to i32**
%104 = bitcast i32* %44 to i32**
%105 = call i32 @row2col(i64 %101, i64 %102, i32** %103, i32** %104)
%106 = load i64, i64* %2
%107 = bitcast i32* %40 to i32**
%108 = bitcast i32* %44 to i32**
%109 = bitcast i32* %52 to i32**
%110 = call i32 @mulsq(i64 %106, i32** %107, i32** %108, i32** %109)
%111 = bitcast i32* %52 to i32**
%112 = bitcast i32* %48 to i32**
%113 = mul nuw i64 %45, %46
%114 = mul nuw i64 4, %113
%115 = trunc i64 %114 to i32
%116 = call i64 @memcmp(i32** %111, i32** %112, i32 %115)
%117 = icmp ne i64 %116, 0
br i1 %117, label %118, label %130
118: ; preds = %1
%119 = load i64, i64* %2
%120 = load i64, i64* %2
%121 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i64 %119, i64 %120)
%122 = load i64, i64* %2
%123 = load i64, i64* %2
%124 = bitcast i32* %48 to i32**
%125 = call i32 @dump(i64 %122, i64 %123, i32** %124)
%126 = load i64, i64* %2
%127 = load i64, i64* %2
%128 = bitcast i32* %52 to i32**
%129 = call i32 @dump(i64 %126, i64 %127, i32** %128)
br label %130
130: ; preds = %118, %1
%131 = load i8*, i8** %3
ret void
}

LLVM IR (-O2):
@.str = [28 x i8] c"%zux%zu transpose mismatch\0A\00"
define void @test_square_transpose(i64 %0) {
%2 = mul nuw i64 %0, %0
%3 = alloca i32, i64 %2
%4 = alloca i32, i64 %2
%5 = alloca i32, i64 %2
%6 = alloca i32, i64 %2
%7 = alloca i32, i64 %2
%8 = alloca i32, i64 %2
%9 = alloca i32, i64 %2
%10 = alloca i32, i64 %2
%11 = bitcast i32* %3 to i32**
%12 = call i32 @rands(i64 %0, i64 %0, i32** %11)
%13 = bitcast i32* %4 to i32**
%14 = call i32 @rands(i64 %0, i64 %0, i32** %13)
%15 = bitcast i32* %5 to i32**
%16 = call i32 @mulsq(i64 %0, i32** %11, i32** %13, i32** %15)
%17 = bitcast i32* %6 to i32**
%18 = call i32 @transpose(i64 %0, i64 %0, i32** %15, i32** %17)
%19 = bitcast i32* %7 to i32**
%20 = call i32 @transpose(i64 %0, i64 %0, i32** %13, i32** %19)
%21 = bitcast i32* %8 to i32**
%22 = call i32 @transpose(i64 %0, i64 %0, i32** %11, i32** %21)
%23 = bitcast i32* %9 to i32**
%24 = call i32 @mulsq(i64 %0, i32** %19, i32** %21, i32** %23)
%25 = call i32 @mulsq(i64 %0, i32** %11, i32** %13, i32** %15)
%26 = call i32 @row2col(i64 %0, i64 %0, i32** %15, i32** %17)
%27 = call i32 @row2col(i64 %0, i64 %0, i32** %13, i32** %19)
%28 = call i32 @row2col(i64 %0, i64 %0, i32** %11, i32** %21)
%29 = bitcast i32* %10 to i32**
%30 = call i32 @mulsq(i64 %0, i32** %19, i32** %21, i32** %29)
%31 = trunc i64 %2 to i32
%32 = shl i32 %31, 2
%33 = call i64 @memcmp(i32** %29, i32** %23, i32 %32)
%34 = icmp eq i64 %33, 0
br i1 %34, label %39, label %35
35: ; preds = %1
%36 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i64 %0, i64 %0)
%37 = call i32 @dump(i64 %0, i64 %0, i32** %23)
%38 = call i32 @dump(i64 %0, i64 %0, i32** %29)
br label %39
39: ; preds = %35, %1
ret void
}