#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 count(int **, int, int);
int **createMatrix(int, int);
int /*<<< orphan*/ delMatrix(int **, int);
int /*<<< orphan*/ displayMatrix(int **, int, int);
int /*<<< orphan*/ inputMatrix(int **, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *, int *);
int **sparse(int **, int, int);
int **transposeSp(int **);
int main(void) {
  int row = 0, col = 0, i = 0;
  int **mat, **compr, **trans, nzc = 0;
  printf("Please enter the order of the matrix (row and column):\n");
  scanf("%d%d", &row, &col);
  mat = createMatrix(row, col);
  printf("Please enter the elements of the matrix:\n");
  inputMatrix(mat, row, col);
  printf("The given matrix is:\n\n");
  displayMatrix(mat, row, col);
  printf("\n");
  compr = sparse(mat, row, col);
  nzc = count(mat, row, col);
  printf("Number of non-zero elements is %d.\n", nzc);
  delMatrix(mat, row);
  printf("\nCompressed representation in COO format:\n\n");
  displayMatrix(compr, nzc + 1, 3);
  trans = transposeSp(compr);
  printf("\nTranspose in COO format: \n\n");
  displayMatrix(trans, nzc + 1, 3);
  delMatrix(compr, nzc + 1);
  delMatrix(trans, nzc + 1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x2c(%rbp)
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe68(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1090 <scanf@plt>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1080 <createMatrix@plt>
mov    %rax,-0x18(%rbp)
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1030 <inputMatrix@plt>
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   10a0 <displayMatrix@plt>
lea    0xebc(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1060 <sparse@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1040 <count@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%esi
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1070 <delMatrix@plt>
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x2c(%rbp),%esi
add    $0x1,%esi
mov    $0x3,%edx
call   10a0 <displayMatrix@plt>
mov    -0x20(%rbp),%rdi
call   10b0 <transposeSp@plt>
mov    %rax,-0x28(%rbp)
lea    0xe22(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
add    $0x1,%esi
mov    $0x3,%edx
call   10a0 <displayMatrix@plt>
mov    -0x20(%rbp),%rdi
mov    -0x2c(%rbp),%esi
add    $0x1,%esi
call   1070 <delMatrix@plt>
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
add    $0x1,%esi
call   1070 <delMatrix@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0x8(%rsp)
movl   $0x0,0xc(%rsp)
lea    0xe5a(%rip),%rdi
call   1060 <puts@plt>
lea    0xe25(%rip),%rdi
lea    0x8(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   10b0 <scanf@plt>
mov    0x8(%rsp),%edi
mov    0xc(%rsp),%esi
call   10a0 <createMatrix@plt>
mov    %rax,%rbx
lea    0xe5f(%rip),%rdi
call   1060 <puts@plt>
mov    0x8(%rsp),%esi
mov    0xc(%rsp),%edx
mov    %rbx,%rdi
call   1030 <inputMatrix@plt>
lea    0xe6c(%rip),%rdi
call   1060 <puts@plt>
mov    0x8(%rsp),%esi
mov    0xc(%rsp),%edx
mov    %rbx,%rdi
call   10c0 <displayMatrix@plt>
mov    $0xa,%edi
call   1050 <putchar@plt>
mov    0x8(%rsp),%esi
mov    0xc(%rsp),%edx
mov    %rbx,%rdi
call   1080 <sparse@plt>
mov    %rax,%r14
mov    0x8(%rsp),%esi
mov    0xc(%rsp),%edx
mov    %rbx,%rdi
call   1040 <count@plt>
mov    %eax,%ebp
lea    0xd9d(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x8(%rsp),%esi
mov    %rbx,%rdi
call   1090 <delMatrix@plt>
lea    0xe1b(%rip),%rdi
call   1060 <puts@plt>
add    $0x1,%ebp
mov    %r14,%rdi
mov    %ebp,%esi
mov    $0x3,%edx
call   10c0 <displayMatrix@plt>
mov    %r14,%rdi
call   10d0 <transposeSp@plt>
mov    %rax,%rbx
lea    0xe1d(%rip),%rdi
call   1060 <puts@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    $0x3,%edx
call   10c0 <displayMatrix@plt>
mov    %r14,%rdi
mov    %ebp,%esi
call   1090 <delMatrix@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1090 <delMatrix@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [56 x i8] c"Please enter the order of the matrix (row and column):\0A\00"
@.str.1 = [5 x i8] c"%d%d\00"
@.str.2 = [42 x i8] c"Please enter the elements of the matrix:\0A\00"
@.str.3 = [23 x i8] c"The given matrix is:\0A\0A\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [36 x i8] c"Number of non-zero elements is %d.\0A\00"
@.str.6 = [44 x i8] c"\0ACompressed representation in COO format:\0A\0A\00"
@.str.7 = [29 x i8] c"\0ATranspose in COO format: \0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32**
%6 = alloca i32**
%7 = alloca i32**
%8 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %8
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %2, i32* %3)
%11 = load i32, i32* %2
%12 = load i32, i32* %3
%13 = call i32** @createMatrix(i32 %11, i32 %12)
store i32** %13, i32*** %5
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0))
%15 = load i32**, i32*** %5
%16 = load i32, i32* %2
%17 = load i32, i32* %3
%18 = call i32 @inputMatrix(i32** %15, i32 %16, i32 %17)
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%20 = load i32**, i32*** %5
%21 = load i32, i32* %2
%22 = load i32, i32* %3
%23 = call i32 @displayMatrix(i32** %20, i32 %21, i32 %22)
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%25 = load i32**, i32*** %5
%26 = load i32, i32* %2
%27 = load i32, i32* %3
%28 = call i32** @sparse(i32** %25, i32 %26, i32 %27)
store i32** %28, i32*** %6
%29 = load i32**, i32*** %5
%30 = load i32, i32* %2
%31 = load i32, i32* %3
%32 = call i32 @count(i32** %29, i32 %30, i32 %31)
store i32 %32, i32* %8
%33 = load i32, i32* %8
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i32 %33)
%35 = load i32**, i32*** %5
%36 = load i32, i32* %2
%37 = call i32 @delMatrix(i32** %35, i32 %36)
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.6, i64 0, i64 0))
%39 = load i32**, i32*** %6
%40 = load i32, i32* %8
%41 = add nsw i32 %40, 1
%42 = call i32 @displayMatrix(i32** %39, i32 %41, i32 3)
%43 = load i32**, i32*** %6
%44 = call i32** @transposeSp(i32** %43)
store i32** %44, i32*** %7
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0))
%46 = load i32**, i32*** %7
%47 = load i32, i32* %8
%48 = add nsw i32 %47, 1
%49 = call i32 @displayMatrix(i32** %46, i32 %48, i32 3)
%50 = load i32**, i32*** %6
%51 = load i32, i32* %8
%52 = add nsw i32 %51, 1
%53 = call i32 @delMatrix(i32** %50, i32 %52)
%54 = load i32**, i32*** %7
%55 = load i32, i32* %8
%56 = add nsw i32 %55, 1
%57 = call i32 @delMatrix(i32** %54, i32 %56)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [5 x i8] c"%d%d\00"
@.str.5 = [36 x i8] c"Number of non-zero elements is %d.\0A\00"
@str = [55 x i8] c"Please enter the order of the matrix (row and column):\00"
@str.8 = [41 x i8] c"Please enter the elements of the matrix:\00"
@str.9 = [22 x i8] c"The given matrix is:\0A\00"
@str.10 = [43 x i8] c"\0ACompressed representation in COO format:\0A\00"
@str.11 = [28 x i8] c"\0ATranspose in COO format: \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%4 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %1, i32* %2)
%7 = load i32, i32* %1
%8 = load i32, i32* %2
%9 = call i32** @createMatrix(i32 %7, i32 %8)
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str.8, i64 0, i64 0))
%11 = load i32, i32* %1
%12 = load i32, i32* %2
%13 = call i32 @inputMatrix(i32** %9, i32 %11, i32 %12)
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.9, i64 0, i64 0))
%15 = load i32, i32* %1
%16 = load i32, i32* %2
%17 = call i32 @displayMatrix(i32** %9, i32 %15, i32 %16)
%18 = call i32 @putchar(i32 10)
%19 = load i32, i32* %1
%20 = load i32, i32* %2
%21 = call i32** @sparse(i32** %9, i32 %19, i32 %20)
%22 = load i32, i32* %1
%23 = load i32, i32* %2
%24 = call i32 @count(i32** %9, i32 %22, i32 %23)
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i32 %24)
%26 = load i32, i32* %1
%27 = call i32 @delMatrix(i32** %9, i32 %26)
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str.10, i64 0, i64 0))
%29 = add nsw i32 %24, 1
%30 = call i32 @displayMatrix(i32** %21, i32 %29, i32 3)
%31 = call i32** @transposeSp(i32** %21)
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.11, i64 0, i64 0))
%33 = call i32 @displayMatrix(i32** %31, i32 %29, i32 3)
%34 = call i32 @delMatrix(i32** %21, i32 %29)
%35 = call i32 @delMatrix(i32** %31, i32 %29)
ret i32 0
}