#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*/ display_2d_square_array(int **);
int /*<<< orphan*/ getch();
int /*<<< orphan*/ printf(char *);
int main() {
  int i, j, k, x[5][5];
  for (i = 0, k = 1; i < 5; i++)
    for (j = 0; j < 5; j++)
      x[j][i] = k++;
  printf("Original Matrix \n");
  display_2d_square_array(x);
  for (i = 0; i < 5; i++)
    for (j = i; j < 5; j++) {
      if (j == i)
        continue;
      int temp = x[j][i];
      x[j][i] = x[i][j];
      x[i][j] = temp;
    }
  printf("Transpose of the Matrix \n");
  display_2d_square_array(x);
  getch();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x1,-0x10(%rbp)
cmpl   $0x5,-0x8(%rbp)
jge    11ad <main+0x7d>
movl   $0x0,-0xc(%rbp)
cmpl   $0x5,-0xc(%rbp)
jge    119a <main+0x6a>
mov    -0x10(%rbp),%edx
mov    %edx,%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
movslq -0xc(%rbp),%rcx
lea    -0x80(%rbp),%rax
imul   $0x14,%rcx,%rcx
add    %rcx,%rax
movslq -0x8(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1161 <main+0x31>
jmp    119f <main+0x6f>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1150 <main+0x20>
lea    0xe4c(%rip),%rdi
call   1040 <printf@plt>
lea    -0x80(%rbp),%rdi
call   1030 <display_2d_square_array@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x5,-0x8(%rbp)
jge    1279 <main+0x149>
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x5,-0xc(%rbp)
jge    1266 <main+0x136>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jne    11f4 <main+0xc4>
jmp    1258 <main+0x128>
movslq -0xc(%rbp),%rcx
lea    -0x80(%rbp),%rax
imul   $0x14,%rcx,%rcx
add    %rcx,%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x84(%rbp)
movslq -0x8(%rbp),%rcx
lea    -0x80(%rbp),%rax
imul   $0x14,%rcx,%rcx
add    %rcx,%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
movslq -0xc(%rbp),%rcx
lea    -0x80(%rbp),%rax
imul   $0x14,%rcx,%rcx
add    %rcx,%rax
movslq -0x8(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x84(%rbp),%edx
movslq -0x8(%rbp),%rcx
lea    -0x80(%rbp),%rax
imul   $0x14,%rcx,%rcx
add    %rcx,%rax
movslq -0xc(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11d9 <main+0xa9>
jmp    126b <main+0x13b>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11c9 <main+0x99>
lea    0xd92(%rip),%rdi
call   1040 <printf@plt>
lea    -0x80(%rbp),%rdi
call   1030 <display_2d_square_array@plt>
mov    $0x0,%al
call   1050 <getch@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x70,%rsp
movaps 0xec4(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0x14(%rsp),%rbx
movaps 0xec4(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xec8(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xecc(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xed0(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xed4(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movl   $0x19,0x60(%rsp)
lea    0xed0(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
call   1040 <display_2d_square_array@plt>
mov    $0xfffffffffffffff0,%rax
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%rbx),%ecx
mov    0x14(%rsp,%rax,1),%edx
mov    %edx,(%rbx)
mov    %ecx,0x14(%rsp,%rax,1)
add    $0x14,%rbx
add    $0x4,%rax
jne    11b0 <main+0x80>
lea    0x1c(%rsp),%rax
xor    %ecx,%ecx
nopl   (%rax)
mov    0x2c(%rsp,%rcx,4),%edx
mov    (%rax),%esi
mov    %esi,0x2c(%rsp,%rcx,4)
mov    %edx,(%rax)
add    $0x5,%rcx
add    $0x4,%rax
cmp    $0xf,%rcx
jne    11d0 <main+0xa0>
lea    0x34(%rsp),%rax
xor    %ecx,%ecx
jmp    120e <main+0xde>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x5,%rcx
add    $0x4,%rax
cmp    $0xa,%rcx
je     1222 <main+0xf2>
cmp    $0xfffffffffffffffb,%rcx
je     1200 <main+0xd0>
mov    0x44(%rsp,%rcx,4),%edx
mov    (%rax),%esi
mov    %esi,0x44(%rsp,%rcx,4)
mov    %edx,(%rax)
jmp    1200 <main+0xd0>
lea    0x4c(%rsp),%rax
mov    $0x17,%ecx
jmp    123e <main+0x10e>
xchg   %ax,%ax
add    $0x5,%rcx
add    $0x4,%rax
cmp    $0x1c,%rcx
je     1250 <main+0x120>
cmp    $0x12,%rcx
je     1230 <main+0x100>
mov    (%rsp,%rcx,4),%edx
mov    (%rax),%esi
mov    %esi,(%rsp,%rcx,4)
mov    %edx,(%rax)
jmp    1230 <main+0x100>
lea    0xe1a(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
call   1040 <display_2d_square_array@plt>
xor    %eax,%eax
call   1050 <getch@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Original Matrix \0A\00"
@.str.1 = [26 x i8] c"Transpose of the Matrix \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [5 x [5 x i32]]
%6 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i32 1, i32* %4
br label %7
7: ; preds = %27, %0
%8 = load i32, i32* %2
%9 = icmp slt i32 %8, 5
br i1 %9, label %10, label %30
10: ; preds = %7
store i32 0, i32* %3
br label %11
11: ; preds = %23, %10
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 5
br i1 %13, label %14, label %26
14: ; preds = %11
%15 = load i32, i32* %4
%16 = add nsw i32 %15, 1
store i32 %16, i32* %4
%17 = load i32, i32* %3
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [5 x [5 x i32]], [5 x [5 x i32]]* %5, i64 0, i64 %18
%20 = load i32, i32* %2
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [5 x i32], [5 x i32]* %19, i64 0, i64 %21
store i32 %15, i32* %22
br label %23
23: ; preds = %14
%24 = load i32, i32* %3
%25 = add nsw i32 %24, 1
store i32 %25, i32* %3
br label %11
26: ; preds = %11
br label %27
27: ; preds = %26
%28 = load i32, i32* %2
%29 = add nsw i32 %28, 1
store i32 %29, i32* %2
br label %7
30: ; preds = %7
%31 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%32 = getelementptr inbounds [5 x [5 x i32]], [5 x [5 x i32]]* %5, i64 0, i64 0
%33 = bitcast [5 x i32]* %32 to i32**
%34 = call i32 @display_2d_square_array(i32** %33)
store i32 0, i32* %2
br label %35
35: ; preds = %80, %30
%36 = load i32, i32* %2
%37 = icmp slt i32 %36, 5
br i1 %37, label %38, label %83
38: ; preds = %35
%39 = load i32, i32* %2
store i32 %39, i32* %3
br label %40
40: ; preds = %76, %38
%41 = load i32, i32* %3
%42 = icmp slt i32 %41, 5
br i1 %42, label %43, label %79
43: ; preds = %40
%44 = load i32, i32* %3
%45 = load i32, i32* %2
%46 = icmp eq i32 %44, %45
br i1 %46, label %47, label %48
47: ; preds = %43
br label %76
48: ; preds = %43
%49 = load i32, i32* %3
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [5 x [5 x i32]], [5 x [5 x i32]]* %5, i64 0, i64 %50
%52 = load i32, i32* %2
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [5 x i32], [5 x i32]* %51, i64 0, i64 %53
%55 = load i32, i32* %54
store i32 %55, i32* %6
%56 = load i32, i32* %2
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [5 x [5 x i32]], [5 x [5 x i32]]* %5, i64 0, i64 %57
%59 = load i32, i32* %3
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [5 x i32], [5 x i32]* %58, i64 0, i64 %60
%62 = load i32, i32* %61
%63 = load i32, i32* %3
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [5 x [5 x i32]], [5 x [5 x i32]]* %5, i64 0, i64 %64
%66 = load i32, i32* %2
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds [5 x i32], [5 x i32]* %65, i64 0, i64 %67
store i32 %62, i32* %68
%69 = load i32, i32* %6
%70 = load i32, i32* %2
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds [5 x [5 x i32]], [5 x [5 x i32]]* %5, i64 0, i64 %71
%73 = load i32, i32* %3
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds [5 x i32], [5 x i32]* %72, i64 0, i64 %74
store i32 %69, i32* %75
br label %76
76: ; preds = %48, %47
%77 = load i32, i32* %3
%78 = add nsw i32 %77, 1
store i32 %78, i32* %3
br label %40
79: ; preds = %40
br label %80
80: ; preds = %79
%81 = load i32, i32* %2
%82 = add nsw i32 %81, 1
store i32 %82, i32* %2
br label %35
83: ; preds = %35
%84 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%85 = getelementptr inbounds [5 x [5 x i32]], [5 x [5 x i32]]* %5, i64 0, i64 0
%86 = bitcast [5 x i32]* %85 to i32**
%87 = call i32 @display_2d_square_array(i32** %86)
%88 = call i32 (...) @getch()
ret i32 0
}

LLVM IR (-O2):
@str = [17 x i8] c"Original Matrix \00"
@str.2 = [25 x i8] c"Transpose of the Matrix \00"
define i32 @main() {
%1 = alloca [5 x [5 x i32]]
%2 = bitcast [5 x [5 x i32]]* %1 to i8*
%3 = getelementptr inbounds [5 x [5 x i32]], [5 x [5 x i32]]* %1, i64 0, i64 4, i64 0
%4 = getelementptr inbounds [5 x [5 x i32]], [5 x [5 x i32]]* %1, i64 0, i64 3, i64 1
%5 = getelementptr inbounds [5 x [5 x i32]], [5 x [5 x i32]]* %1, i64 0, i64 2, i64 2
%6 = bitcast [5 x [5 x i32]]* %1 to <4 x i32>*
store <4 x i32> <i32 1, i32 6, i32 11, i32 16>, <4 x i32>* %6
%7 = getelementptr inbounds [5 x [5 x i32]], [5 x [5 x i32]]* %1, i64 0, i64 1, i64 3
%8 = bitcast i32* %3 to <4 x i32>*
store <4 x i32> <i32 5, i32 10, i32 15, i32 20>, <4 x i32>* %8
%9 = getelementptr inbounds [5 x [5 x i32]], [5 x [5 x i32]]* %1, i64 0, i64 0, i64 4
%10 = bitcast i32* %9 to <4 x i32>*
store <4 x i32> <i32 21, i32 2, i32 7, i32 12>, <4 x i32>* %10
%11 = bitcast i32* %7 to <4 x i32>*
store <4 x i32> <i32 17, i32 22, i32 3, i32 8>, <4 x i32>* %11
%12 = bitcast i32* %5 to <4 x i32>*
store <4 x i32> <i32 13, i32 18, i32 23, i32 4>, <4 x i32>* %12
%13 = bitcast i32* %4 to <4 x i32>*
store <4 x i32> <i32 9, i32 14, i32 19, i32 24>, <4 x i32>* %13
%14 = getelementptr inbounds [5 x [5 x i32]], [5 x [5 x i32]]* %1, i64 0, i64 4, i64 4
store i32 25, i32* %14
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%16 = bitcast [5 x [5 x i32]]* %1 to i32**
%17 = call i32 @display_2d_square_array(i32** %16)
br label %18
18: ; preds = %0, %18
%19 = phi i64 [ %24, %18 ], [ 1, %0 ]
%20 = getelementptr inbounds [5 x [5 x i32]], [5 x [5 x i32]]* %1, i64 0, i64 %19, i64 0
%21 = load i32, i32* %20
%22 = getelementptr inbounds [5 x [5 x i32]], [5 x [5 x i32]]* %1, i64 0, i64 0, i64 %19
%23 = load i32, i32* %22
store i32 %23, i32* %20
store i32 %21, i32* %22
%24 = add nuw nsw i64 %19, 1
%25 = icmp eq i64 %24, 5
br i1 %25, label %26, label %18
26: ; preds = %18, %26
%27 = phi i64 [ %32, %26 ], [ 2, %18 ]
%28 = getelementptr inbounds [5 x [5 x i32]], [5 x [5 x i32]]* %1, i64 0, i64 %27, i64 1
%29 = load i32, i32* %28
%30 = getelementptr inbounds [5 x [5 x i32]], [5 x [5 x i32]]* %1, i64 0, i64 1, i64 %27
%31 = load i32, i32* %30
store i32 %31, i32* %28
store i32 %29, i32* %30
%32 = add nuw nsw i64 %27, 1
%33 = icmp eq i64 %32, 5
br i1 %33, label %34, label %26
34: ; preds = %26, %42
%35 = phi i64 [ %43, %42 ], [ 3, %26 ]
%36 = icmp eq i64 %35, 2
br i1 %36, label %42, label %37
37: ; preds = %34
%38 = getelementptr inbounds [5 x [5 x i32]], [5 x [5 x i32]]* %1, i64 0, i64 %35, i64 2
%39 = load i32, i32* %38
%40 = getelementptr inbounds [5 x [5 x i32]], [5 x [5 x i32]]* %1, i64 0, i64 2, i64 %35
%41 = load i32, i32* %40
store i32 %41, i32* %38
store i32 %39, i32* %40
br label %42
42: ; preds = %37, %34
%43 = add nuw nsw i64 %35, 1
%44 = icmp eq i64 %43, 5
br i1 %44, label %45, label %34
45: ; preds = %42, %53
%46 = phi i64 [ %54, %53 ], [ 4, %42 ]
%47 = icmp eq i64 %46, 3
br i1 %47, label %53, label %48
48: ; preds = %45
%49 = getelementptr inbounds [5 x [5 x i32]], [5 x [5 x i32]]* %1, i64 0, i64 %46, i64 3
%50 = load i32, i32* %49
%51 = getelementptr inbounds [5 x [5 x i32]], [5 x [5 x i32]]* %1, i64 0, i64 3, i64 %46
%52 = load i32, i32* %51
store i32 %52, i32* %49
store i32 %50, i32* %51
br label %53
53: ; preds = %48, %45
%54 = add nuw nsw i64 %46, 1
%55 = icmp eq i64 %54, 5
br i1 %55, label %56, label %45
56: ; preds = %53
%57 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.2, i64 0, i64 0))
%58 = call i32 @display_2d_square_array(i32** %16)
%59 = call i32 (...) @getch()
ret i32 0
}