#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 **addMatrices(int **, int **, int, int);
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ deallocateMatrix(int **, int);
int **getMatrix(int, int);
int /*<<< orphan*/ printMatrix(int **, int, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *, int *);
int main() {
  int n = 0, m = 0;
  printf("Enter the number of rows and columns: ");
  scanf("%d %d", &n, &m);
  assert(n > 0 && m > 0);
  printf("Enter matrix A:\n");
  int **A = getMatrix(n, m);
  printf("Enter matrix B:\n");
  int **B = getMatrix(n, m);
  int **C = addMatrices(A, B, n, m);
  printf("A + B = \n");
  printMatrix(C, n, m);
  deallocateMatrix(A, n);
  deallocateMatrix(B, n);
  deallocateMatrix(C, n);
}


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)
lea    0xe6c(%rip),%rdi
call   1030 <printf@plt>
lea    0xe87(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1070 <scanf@plt>
xor    %eax,%eax
cmpl   $0x0,-0x8(%rbp)
mov    %al,-0x29(%rbp)
jle    11c6 <main+0x56>
cmpl   $0x0,-0xc(%rbp)
setg   %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    0xe53(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1090 <getMatrix@plt>
mov    %rax,-0x18(%rbp)
lea    0xe49(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1090 <getMatrix@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
call   1080 <addMatrices@plt>
mov    %rax,-0x28(%rbp)
lea    0xe28(%rip),%rdi
call   1030 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1060 <printMatrix@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1050 <deallocateMatrix@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1050 <deallocateMatrix@plt>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1050 <deallocateMatrix@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0x8(%rsp)
movl   $0x0,0xc(%rsp)
lea    0xe60(%rip),%rdi
call   1040 <printf@plt>
lea    0xe7b(%rip),%rdi
lea    0x8(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   1080 <scanf@plt>
cmpl   $0x0,0x8(%rsp)
setg   %al
cmpl   $0x0,0xc(%rsp)
setg   %cl
and    %al,%cl
movzbl %cl,%edi
call   1050 <assert@plt>
lea    0xe51(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%edi
mov    0xc(%rsp),%esi
call   10a0 <getMatrix@plt>
mov    %rax,%r14
lea    0xe45(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%edi
mov    0xc(%rsp),%esi
call   10a0 <getMatrix@plt>
mov    %rax,%r15
mov    0x8(%rsp),%edx
mov    0xc(%rsp),%ecx
mov    %r14,%rdi
mov    %rax,%rsi
call   1090 <addMatrices@plt>
mov    %rax,%rbx
lea    0xe23(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%esi
mov    0xc(%rsp),%edx
mov    %rbx,%rdi
call   1070 <printMatrix@plt>
mov    0x8(%rsp),%esi
mov    %r14,%rdi
call   1060 <deallocateMatrix@plt>
mov    0x8(%rsp),%esi
mov    %r15,%rdi
call   1060 <deallocateMatrix@plt>
mov    0x8(%rsp),%esi
mov    %rbx,%rdi
call   1060 <deallocateMatrix@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [39 x i8] c"Enter the number of rows and columns: \00"
@.str.1 = [6 x i8] c"%d %d\00"
@.str.2 = [17 x i8] c"Enter matrix A:\0A\00"
@.str.3 = [17 x i8] c"Enter matrix B:\0A\00"
@.str.4 = [10 x i8] c"A + B = \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32**
%5 = alloca i32**
%6 = alloca i32**
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
%7 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %2, i32* %3)
%9 = load i32, i32* %2
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %0
%12 = load i32, i32* %3
%13 = icmp sgt i32 %12, 0
br label %14
14: ; preds = %11, %0
%15 = phi i1 [ false, %0 ], [ %13, %11 ]
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%19 = load i32, i32* %2
%20 = load i32, i32* %3
%21 = call i32** @getMatrix(i32 %19, i32 %20)
store i32** %21, i32*** %4
%22 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%23 = load i32, i32* %2
%24 = load i32, i32* %3
%25 = call i32** @getMatrix(i32 %23, i32 %24)
store i32** %25, i32*** %5
%26 = load i32**, i32*** %4
%27 = load i32**, i32*** %5
%28 = load i32, i32* %2
%29 = load i32, i32* %3
%30 = call i32** @addMatrices(i32** %26, i32** %27, i32 %28, i32 %29)
store i32** %30, i32*** %6
%31 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%32 = load i32**, i32*** %6
%33 = load i32, i32* %2
%34 = load i32, i32* %3
%35 = call i32 @printMatrix(i32** %32, i32 %33, i32 %34)
%36 = load i32**, i32*** %4
%37 = load i32, i32* %2
%38 = call i32 @deallocateMatrix(i32** %36, i32 %37)
%39 = load i32**, i32*** %5
%40 = load i32, i32* %2
%41 = call i32 @deallocateMatrix(i32** %39, i32 %40)
%42 = load i32**, i32*** %6
%43 = load i32, i32* %2
%44 = call i32 @deallocateMatrix(i32** %42, i32 %43)
%45 = load i32, i32* %1
ret i32 %45
}

LLVM IR (-O2):
@.str = [39 x i8] c"Enter the number of rows and columns: \00"
@.str.1 = [6 x i8] c"%d %d\00"
@str = [16 x i8] c"Enter matrix A:\00"
@str.5 = [16 x i8] c"Enter matrix B:\00"
@str.6 = [9 x i8] c"A + B = \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 @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%6 = call 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 = icmp sgt i32 %7, 0
%9 = load i32, i32* %2
%10 = icmp sgt i32 %9, 0
%11 = select i1 %8, i1 %10, i1 false
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%15 = load i32, i32* %1
%16 = load i32, i32* %2
%17 = call i32** @getMatrix(i32 %15, i32 %16)
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.5, i64 0, i64 0))
%19 = load i32, i32* %1
%20 = load i32, i32* %2
%21 = call i32** @getMatrix(i32 %19, i32 %20)
%22 = load i32, i32* %1
%23 = load i32, i32* %2
%24 = call i32** @addMatrices(i32** %17, i32** %21, i32 %22, i32 %23)
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.6, i64 0, i64 0))
%26 = load i32, i32* %1
%27 = load i32, i32* %2
%28 = call i32 @printMatrix(i32** %24, i32 %26, i32 %27)
%29 = load i32, i32* %1
%30 = call i32 @deallocateMatrix(i32** %17, i32 %29)
%31 = load i32, i32* %1
%32 = call i32 @deallocateMatrix(i32** %21, i32 %31)
%33 = load i32, i32* %1
%34 = call i32 @deallocateMatrix(i32** %24, i32 %33)
ret i32 0
}