#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*/ print_matrix(size_t, int **);
int /*<<< orphan*/ printf(char *);
int scanf(char *, ...);
int /*<<< orphan*/ transpose(size_t, int **);
int main(void) {
  printf("Enter dimension N of matrix, followed by the NxN elements\n");
  printf("> ");
  size_t n;
  while (scanf("%zu", &n) == 1) {
    int matrix[n][n];
    size_t i, j;
    for (i = 0; i < n; i++) {
      for (j = 0; j < n; j++) {
        scanf("%d", &matrix[i][j]);
      }
    }
    transpose(n, matrix);
    print_matrix(n, matrix);
    printf("> ");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
call   1030 <printf@plt>
lea    0xed9(%rip),%rdi
call   1030 <printf@plt>
lea    0xed0(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
cmp    $0x1,%eax
jne    126e <main+0x12e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    %rax,%rcx
mov    %rsp,%rdx
mov    %rdx,-0x18(%rbp)
mov    %rax,%rdx
imul   %rdx,%rdx
lea    0xf(,%rdx,4),%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x40(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x20(%rbp)
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    123c <main+0xfc>
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1226 <main+0xe6>
mov    -0x40(%rbp),%rsi
mov    -0x48(%rbp),%rax
imul   -0x30(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    -0x38(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    11da <main+0x9a>
jmp    122b <main+0xeb>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11c4 <main+0x84>
mov    -0x40(%rbp),%rsi
mov    -0x10(%rbp),%rdi
call   1040 <transpose@plt>
mov    -0x40(%rbp),%rsi
mov    -0x10(%rbp),%rdi
call   1060 <print_matrix@plt>
lea    0xdde(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
jmp    1167 <main+0x27>
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
lea    0xea2(%rip),%rdi
call   1030 <puts@plt>
lea    0xe8c(%rip),%rdi
call   1040 <printf@plt>
lea    0xe83(%rip),%rdi
lea    -0x30(%rbp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
cmp    $0x1,%eax
jne    1273 <main+0x123>
lea    0xe6c(%rip),%rbx
jmp    11e5 <main+0x95>
nopl   (%rax)
xor    %edi,%edi
mov    -0x38(%rbp),%r14
mov    %r14,%rsi
call   1050 <transpose@plt>
mov    -0x30(%rbp),%rdi
mov    %r14,%rsi
call   1070 <print_matrix@plt>
lea    0xe3f(%rip),%rdi
call   1040 <printf@plt>
mov    -0x40(%rbp),%rsp
lea    0xe32(%rip),%rdi
lea    -0x30(%rbp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
cmp    $0x1,%eax
jne    1273 <main+0x123>
mov    %rsp,%rcx
mov    -0x30(%rbp),%rdx
mov    %rdx,%rax
imul   %rdx,%rax
mov    %rsp,%r13
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
cmpq   $0x0,-0x30(%rbp)
mov    %rcx,-0x40(%rbp)
mov    %r13,-0x38(%rbp)
je     11a0 <main+0x50>
shl    $0x2,%rdx
xor    %r15d,%r15d
mov    %rdx,-0x48(%rbp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r13,%r14
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
add    $0x1,%r12
mov    -0x30(%rbp),%rdi
add    $0x4,%r14
cmp    %rdi,%r12
jb     1240 <main+0xf0>
add    $0x1,%r15
mov    -0x48(%rbp),%rdx
add    %rdx,%r13
cmp    %rdi,%r15
jb     1230 <main+0xe0>
jmp    11a2 <main+0x52>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [59 x i8] c"Enter dimension N of matrix, followed by the NxN elements\0A\00"
@.str.1 = [3 x i8] c"> \00"
@.str.2 = [4 x i8] c"%zu\00"
@.str.3 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
store i32 0, i32* %1
%8 = call i32 @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %10
10: ; preds = %42, %0
%11 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64* %2)
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %51
13: ; preds = %10
%14 = load i64, i64* %2
%15 = load i64, i64* %2
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %3
%17 = mul nuw i64 %14, %15
%18 = alloca i32, i64 %17
store i64 %14, i64* %4
store i64 %15, i64* %5
store i64 0, i64* %6
br label %19
19: ; preds = %39, %13
%20 = load i64, i64* %6
%21 = load i64, i64* %2
%22 = icmp ult i64 %20, %21
br i1 %22, label %23, label %42
23: ; preds = %19
store i64 0, i64* %7
br label %24
24: ; preds = %35, %23
%25 = load i64, i64* %7
%26 = load i64, i64* %2
%27 = icmp ult i64 %25, %26
br i1 %27, label %28, label %38
28: ; preds = %24
%29 = load i64, i64* %6
%30 = mul nsw i64 %29, %15
%31 = getelementptr inbounds i32, i32* %18, i64 %30
%32 = load i64, i64* %7
%33 = getelementptr inbounds i32, i32* %31, i64 %32
%34 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %33)
br label %35
35: ; preds = %28
%36 = load i64, i64* %7
%37 = add i64 %36, 1
store i64 %37, i64* %7
br label %24
38: ; preds = %24
br label %39
39: ; preds = %38
%40 = load i64, i64* %6
%41 = add i64 %40, 1
store i64 %41, i64* %6
br label %19
42: ; preds = %19
%43 = load i64, i64* %2
%44 = bitcast i32* %18 to i32**
%45 = call i32 @transpose(i64 %43, i32** %44)
%46 = load i64, i64* %2
%47 = bitcast i32* %18 to i32**
%48 = call i32 @print_matrix(i64 %46, i32** %47)
%49 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%50 = load i8*, i8** %3
br label %10
51: ; preds = %10
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"> \00"
@.str.2 = [4 x i8] c"%zu\00"
@.str.3 = [3 x i8] c"%d\00"
@str = [58 x i8] c"Enter dimension N of matrix, followed by the NxN elements\00"
define i32 @main() {
%1 = alloca i64
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @str, i64 0, i64 0))
%3 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%4 = bitcast i64* %1 to i8*
%5 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64* %1)
%6 = icmp eq i32 %5, 1
br i1 %6, label %7, label %37
7: ; preds = %0, %28
%8 = load i64, i64* %1
%9 = call i8* @llvm.stacksave()
%10 = mul nuw i64 %8, %8
%11 = alloca i32, i64 %10
%12 = load i64, i64* %1
%13 = icmp eq i64 %12, 0
br i1 %13, label %28, label %14
14: ; preds = %7, %25
%15 = phi i64 [ %26, %25 ], [ 0, %7 ]
%16 = mul nsw i64 %15, %8
%17 = getelementptr inbounds i32, i32* %11, i64 %16
br label %18
18: ; preds = %14, %18
%19 = phi i64 [ 0, %14 ], [ %22, %18 ]
%20 = getelementptr inbounds i32, i32* %17, i64 %19
%21 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %20)
%22 = add nuw i64 %19, 1
%23 = load i64, i64* %1
%24 = icmp ult i64 %22, %23
br i1 %24, label %18, label %25
25: ; preds = %18
%26 = add nuw i64 %15, 1
%27 = icmp ult i64 %26, %23
br i1 %27, label %14, label %28
28: ; preds = %25, %7
%29 = phi i64 [ 0, %7 ], [ %23, %25 ]
%30 = bitcast i32* %11 to i32**
%31 = call i32 @transpose(i64 %29, i32** %30)
%32 = load i64, i64* %1
%33 = call i32 @print_matrix(i64 %32, i32** %30)
%34 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%35 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64* %1)
%36 = icmp eq i32 %35, 1
br i1 %36, label %7, label %37
37: ; preds = %28, %0
ret i32 0
}