#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*/ displayMatrix(double **, int, int);
int /*<<< orphan*/ freeMem(double **);
double **matrixMultiply(double **, double **, int, int, int);
int /*<<< orphan*/ printf(char *, int, int);
double **readMatrix(int *, int *);
int main() {
  int m = 1, n = 3, o = 4;
  double **C;
  double **A = readMatrix(&m, &n);
  printf("A[%dx%d]\n", m, n);
  displayMatrix(A, m, n);
  double **B = readMatrix(&n, &o);
  printf("B[%dx%d]\n", n, o);
  displayMatrix(B, n, o);
  printf("A*B[%dx%d]\n", m, o);
  C = matrixMultiply(A, B, m, n, o);
  displayMatrix(C, m, o);
  freeMem(A);
  freeMem(B);
  freeMem(C);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
movl   $0x3,-0xc(%rbp)
movl   $0x4,-0x10(%rbp)
lea    -0x8(%rbp),%rdi
lea    -0xc(%rbp),%rsi
call   1030 <readMatrix@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe6e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1070 <displayMatrix@plt>
lea    -0xc(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1030 <readMatrix@plt>
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xe48(%rip),%rdi
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1070 <displayMatrix@plt>
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xe25(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    -0x10(%rbp),%r8d
call   1060 <matrixMultiply@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1070 <displayMatrix@plt>
mov    -0x20(%rbp),%rdi
call   1050 <freeMem@plt>
mov    -0x28(%rbp),%rdi
call   1050 <freeMem@plt>
mov    -0x18(%rbp),%rdi
call   1050 <freeMem@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movl   $0x1,0xc(%rsp)
movl   $0x3,0x8(%rsp)
movl   $0x4,0x4(%rsp)
lea    0xc(%rsp),%rdi
lea    0x8(%rsp),%rbx
mov    %rbx,%rsi
call   1030 <readMatrix@plt>
mov    %rax,%r14
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
lea    0xe6b(%rip),%rdi
call   1040 <printf@plt>
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
mov    %r14,%rdi
call   1070 <displayMatrix@plt>
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <readMatrix@plt>
mov    %rax,%r15
mov    0x8(%rsp),%esi
mov    0x4(%rsp),%edx
lea    0xe43(%rip),%rdi
call   1040 <printf@plt>
mov    0x8(%rsp),%esi
mov    0x4(%rsp),%edx
mov    %r15,%rdi
call   1070 <displayMatrix@plt>
mov    0xc(%rsp),%esi
mov    0x4(%rsp),%edx
lea    0xe1d(%rip),%rdi
call   1040 <printf@plt>
mov    0xc(%rsp),%edx
mov    0x8(%rsp),%ecx
mov    0x4(%rsp),%r8d
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <matrixMultiply@plt>
mov    %rax,%rbx
mov    0xc(%rsp),%esi
mov    0x4(%rsp),%edx
mov    %rax,%rdi
call   1070 <displayMatrix@plt>
mov    %r14,%rdi
call   1050 <freeMem@plt>
mov    %r15,%rdi
call   1050 <freeMem@plt>
mov    %rbx,%rdi
call   1050 <freeMem@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c"A[%dx%d]\0A\00"
@.str.1 = [10 x i8] c"B[%dx%d]\0A\00"
@.str.2 = [12 x i8] c"A*B[%dx%d]\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca double**
%6 = alloca double**
%7 = alloca double**
store i32 0, i32* %1
store i32 1, i32* %2
store i32 3, i32* %3
store i32 4, i32* %4
%8 = call double** @readMatrix(i32* %2, i32* %3)
store double** %8, double*** %6
%9 = load i32, i32* %2
%10 = load i32, i32* %3
%11 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %10)
%12 = load double**, double*** %6
%13 = load i32, i32* %2
%14 = load i32, i32* %3
%15 = call i32 @displayMatrix(double** %12, i32 %13, i32 %14)
%16 = call double** @readMatrix(i32* %3, i32* %4)
store double** %16, double*** %7
%17 = load i32, i32* %3
%18 = load i32, i32* %4
%19 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %17, i32 %18)
%20 = load double**, double*** %7
%21 = load i32, i32* %3
%22 = load i32, i32* %4
%23 = call i32 @displayMatrix(double** %20, i32 %21, i32 %22)
%24 = load i32, i32* %2
%25 = load i32, i32* %4
%26 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %24, i32 %25)
%27 = load double**, double*** %6
%28 = load double**, double*** %7
%29 = load i32, i32* %2
%30 = load i32, i32* %3
%31 = load i32, i32* %4
%32 = call double** @matrixMultiply(double** %27, double** %28, i32 %29, i32 %30, i32 %31)
store double** %32, double*** %5
%33 = load double**, double*** %5
%34 = load i32, i32* %2
%35 = load i32, i32* %4
%36 = call i32 @displayMatrix(double** %33, i32 %34, i32 %35)
%37 = load double**, double*** %6
%38 = call i32 @freeMem(double** %37)
%39 = load double**, double*** %7
%40 = call i32 @freeMem(double** %39)
%41 = load double**, double*** %5
%42 = call i32 @freeMem(double** %41)
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"A[%dx%d]\0A\00"
@.str.1 = [10 x i8] c"B[%dx%d]\0A\00"
@.str.2 = [12 x i8] c"A*B[%dx%d]\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %1 to i8*
store i32 1, i32* %1
%5 = bitcast i32* %2 to i8*
store i32 3, i32* %2
%6 = bitcast i32* %3 to i8*
store i32 4, i32* %3
%7 = call double** @readMatrix(i32* %1, i32* %2)
%8 = load i32, i32* %1
%9 = load i32, i32* %2
%10 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %9)
%11 = load i32, i32* %1
%12 = load i32, i32* %2
%13 = call i32 @displayMatrix(double** %7, i32 %11, i32 %12)
%14 = call double** @readMatrix(i32* %2, i32* %3)
%15 = load i32, i32* %2
%16 = load i32, i32* %3
%17 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %15, i32 %16)
%18 = load i32, i32* %2
%19 = load i32, i32* %3
%20 = call i32 @displayMatrix(double** %14, i32 %18, i32 %19)
%21 = load i32, i32* %1
%22 = load i32, i32* %3
%23 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %21, i32 %22)
%24 = load i32, i32* %1
%25 = load i32, i32* %2
%26 = load i32, i32* %3
%27 = call double** @matrixMultiply(double** %7, double** %14, i32 %24, i32 %25, i32 %26)
%28 = load i32, i32* %1
%29 = load i32, i32* %3
%30 = call i32 @displayMatrix(double** %27, i32 %28, i32 %29)
%31 = call i32 @freeMem(double** %7)
%32 = call i32 @freeMem(double** %14)
%33 = call i32 @freeMem(double** %27)
ret i32 0
}