#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *, ...);
int main() {
  int i, j, m, n;
  printf("Enter the order of the matrix (m*n): ");
  scanf("%d*%d", &m, &n);
  int matrix[m][n];
  printf("Enter the elements of the matrix: \n");
  for (i = 0; i < m; i++) {
    for (j = 0; j < n; j++) {
      scanf("%d", &matrix[i][j]);
    }
  }
  printf("Transpose of the matrix: \n");
  for (i = 0; i < m; i++) {
    for (j = 0; j < n; j++) {
      printf("%d ", matrix[j][i]);
    }
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x41(%rbp)
call   1030 <printf@plt>
mov    -0x41(%rbp),%al
lea    0xedc(%rip),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1040 <scanf@plt>
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
mov    %rax,-0x40(%rbp)
mov    %rsp,%rdx
mov    %rdx,-0x20(%rbp)
mov    %rcx,%rdx
imul   %rax,%rdx
lea    0xf(,%rdx,4),%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x38(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x28(%rbp)
mov    %rax,-0x30(%rbp)
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1217 <main+0xf7>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1204 <main+0xe4>
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rcx
movslq -0x8(%rbp),%rax
imul   %rcx,%rax
shl    $0x2,%rax
add    %rax,%rsi
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11ba <main+0x9a>
jmp    1209 <main+0xe9>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11a7 <main+0x87>
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    12a1 <main+0x181>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1285 <main+0x165>
mov    -0x38(%rbp),%rax
mov    -0x40(%rbp),%rdx
movslq -0xc(%rbp),%rcx
imul   %rdx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    123f <main+0x11f>
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    122c <main+0x10c>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%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    0xea8(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xec0(%rip),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
xor    %eax,%eax
call   1060 <scanf@plt>
mov    %rsp,-0x40(%rbp)
mov    -0x30(%rbp),%eax
mov    -0x2c(%rbp),%r12d
imul   %r12,%rax
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%rcx
sub    %rax,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
lea    0xe8c(%rip),%rdi
call   1040 <puts@plt>
mov    -0x30(%rbp),%ecx
test   %ecx,%ecx
jle    1217 <main+0xd7>
mov    -0x2c(%rbp),%eax
lea    0x0(,%r12,4),%rdx
mov    %rdx,-0x48(%rbp)
lea    0xe63(%rip),%r14
mov    -0x38(%rbp),%rbx
xor    %r15d,%r15d
jmp    11e0 <main+0xa0>
nop
add    $0x1,%r15
movslq %ecx,%rdx
add    -0x48(%rbp),%rbx
cmp    %rdx,%r15
jge    1217 <main+0xd7>
test   %eax,%eax
jle    11d0 <main+0x90>
mov    %rbx,-0x50(%rbp)
xor    %r13d,%r13d
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
add    $0x1,%r13
movslq -0x2c(%rbp),%rax
add    $0x4,%rbx
cmp    %rax,%r13
jl     11f0 <main+0xb0>
mov    -0x30(%rbp),%ecx
mov    -0x50(%rbp),%rbx
jmp    11d0 <main+0x90>
lea    0xe35(%rip),%rdi
call   1040 <puts@plt>
cmpl   $0x0,-0x30(%rbp)
jle    1290 <main+0x150>
shl    $0x2,%r12
lea    0xdf8(%rip),%r15
xor    %r14d,%r14d
jmp    125c <main+0x11c>
nopl   0x0(%rax)
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%r14
movslq -0x30(%rbp),%rax
addq   $0x4,-0x38(%rbp)
cmp    %rax,%r14
jge    1290 <main+0x150>
cmpl   $0x0,-0x2c(%rbp)
jle    1240 <main+0x100>
mov    -0x38(%rbp),%r13
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    0x0(%r13),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
movslq -0x2c(%rbp),%rax
add    %r12,%r13
cmp    %rax,%rbx
jl     1270 <main+0x130>
jmp    1240 <main+0x100>
mov    -0x40(%rbp),%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [38 x i8] c"Enter the order of the matrix (m*n): \00"
@.str.1 = [6 x i8] c"%d*%d\00"
@.str.2 = [36 x i8] c"Enter the elements of the matrix: \0A\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [27 x i8] c"Transpose of the matrix: \0A\00"
@.str.5 = [4 x i8] c"%d \00"
@.str.6 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
store i32 0, i32* %1
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %4, i32* %5)
%11 = load i32, i32* %4
%12 = zext i32 %11 to i64
%13 = load i32, i32* %5
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %6
%16 = mul nuw i64 %12, %14
%17 = alloca i32, i64 %16
store i64 %12, i64* %7
store i64 %14, i64* %8
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %2
br label %19
19: ; preds = %41, %0
%20 = load i32, i32* %2
%21 = load i32, i32* %4
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %44
23: ; preds = %19
store i32 0, i32* %3
br label %24
24: ; preds = %37, %23
%25 = load i32, i32* %3
%26 = load i32, i32* %5
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %40
28: ; preds = %24
%29 = load i32, i32* %2
%30 = sext i32 %29 to i64
%31 = mul nsw i64 %30, %14
%32 = getelementptr inbounds i32, i32* %17, i64 %31
%33 = load i32, i32* %3
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32, i32* %32, i64 %34
%36 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %35)
br label %37
37: ; preds = %28
%38 = load i32, i32* %3
%39 = add nsw i32 %38, 1
store i32 %39, i32* %3
br label %24
40: ; preds = %24
br label %41
41: ; preds = %40
%42 = load i32, i32* %2
%43 = add nsw i32 %42, 1
store i32 %43, i32* %2
br label %19
44: ; preds = %19
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %2
br label %46
46: ; preds = %70, %44
%47 = load i32, i32* %2
%48 = load i32, i32* %4
%49 = icmp slt i32 %47, %48
br i1 %49, label %50, label %73
50: ; preds = %46
store i32 0, i32* %3
br label %51
51: ; preds = %65, %50
%52 = load i32, i32* %3
%53 = load i32, i32* %5
%54 = icmp slt i32 %52, %53
br i1 %54, label %55, label %68
55: ; preds = %51
%56 = load i32, i32* %3
%57 = sext i32 %56 to i64
%58 = mul nsw i64 %57, %14
%59 = getelementptr inbounds i32, i32* %17, i64 %58
%60 = load i32, i32* %2
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i32, i32* %59, i64 %61
%63 = load i32, i32* %62
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %63)
br label %65
65: ; preds = %55
%66 = load i32, i32* %3
%67 = add nsw i32 %66, 1
store i32 %67, i32* %3
br label %51
68: ; preds = %51
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %70
70: ; preds = %68
%71 = load i32, i32* %2
%72 = add nsw i32 %71, 1
store i32 %72, i32* %2
br label %46
73: ; preds = %46
%74 = load i8*, i8** %6
%75 = load i32, i32* %1
ret i32 %75
}

LLVM IR (-O2):
@.str = [38 x i8] c"Enter the order of the matrix (m*n): \00"
@.str.1 = [6 x i8] c"%d*%d\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.5 = [4 x i8] c"%d \00"
@str = [35 x i8] c"Enter the elements of the matrix: \00"
@str.7 = [26 x i8] c"Transpose of the matrix: \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %1, i32* %2)
%7 = load i32, i32* %1
%8 = zext i32 %7 to i64
%9 = load i32, i32* %2
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
%12 = mul nuw i64 %10, %8
%13 = alloca i32, i64 %12
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
%15 = load i32, i32* %1
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %43
17: ; preds = %0
%18 = load i32, i32* %2
br label %19
19: ; preds = %17, %37
%20 = phi i32 [ %15, %17 ], [ %38, %37 ]
%21 = phi i32 [ %18, %17 ], [ %39, %37 ]
%22 = phi i64 [ 0, %17 ], [ %40, %37 ]
%23 = icmp sgt i32 %21, 0
br i1 %23, label %24, label %37
24: ; preds = %19
%25 = mul nuw nsw i64 %22, %10
%26 = getelementptr inbounds i32, i32* %13, i64 %25
br label %27
27: ; preds = %24, %27
%28 = phi i64 [ 0, %24 ], [ %31, %27 ]
%29 = getelementptr inbounds i32, i32* %26, i64 %28
%30 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %29)
%31 = add nuw nsw i64 %28, 1
%32 = load i32, i32* %2
%33 = sext i32 %32 to i64
%34 = icmp slt i64 %31, %33
br i1 %34, label %27, label %35
35: ; preds = %27
%36 = load i32, i32* %1
br label %37
37: ; preds = %35, %19
%38 = phi i32 [ %36, %35 ], [ %20, %19 ]
%39 = phi i32 [ %32, %35 ], [ %21, %19 ]
%40 = add nuw nsw i64 %22, 1
%41 = sext i32 %38 to i64
%42 = icmp slt i64 %40, %41
br i1 %42, label %19, label %43
43: ; preds = %37, %0
%44 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.7, i64 0, i64 0))
%45 = load i32, i32* %1
%46 = icmp sgt i32 %45, 0
br i1 %46, label %47, label %69
47: ; preds = %43, %63
%48 = phi i64 [ %65, %63 ], [ 0, %43 ]
%49 = load i32, i32* %2
%50 = icmp sgt i32 %49, 0
br i1 %50, label %51, label %63
51: ; preds = %47
%52 = getelementptr inbounds i32, i32* %13, i64 %48
br label %53
53: ; preds = %51, %53
%54 = phi i64 [ 0, %51 ], [ %59, %53 ]
%55 = mul nuw nsw i64 %54, %10
%56 = getelementptr inbounds i32, i32* %52, i64 %55
%57 = load i32, i32* %56
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %57)
%59 = add nuw nsw i64 %54, 1
%60 = load i32, i32* %2
%61 = sext i32 %60 to i64
%62 = icmp slt i64 %59, %61
br i1 %62, label %53, label %63
63: ; preds = %53, %47
%64 = call i32 @putchar(i32 10)
%65 = add nuw nsw i64 %48, 1
%66 = load i32, i32* %1
%67 = sext i32 %66 to i64
%68 = icmp slt i64 %65, %67
br i1 %68, label %47, label %69
69: ; preds = %63, %43
ret i32 0
}