#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 */
double dotProduct(int, double **, double **);
int /*<<< orphan*/ freeMat(int, double ***);
int /*<<< orphan*/ getCol(int, int, double **, int, double **);
int /*<<< orphan*/ getRow(int, int, double **, int, double **);
int /*<<< orphan*/ initMat(int, int, double ***);
void matrixMultiply(int m, int n, int p, double **left, double **right,
                    double **product) {
  int i = 0;
  int j = 0;
  double **v1;
  double **v2;
  initMat(n, 1, &v1);
  initMat(n, 1, &v2);
  for (i = 0; i < m; i++) {
    for (j = 0; j < p; j++) {
      getRow(m, n, left, i, v1);
      getCol(n, p, right, j, v2);
      product[i][j] = dotProduct(n, v1, v2);
    }
  }
  freeMat(n, &v1);
  freeMat(n, &v2);
}


x86 assembly (clang, -O0):
<matrixMultiply>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
lea    -0x38(%rbp),%rdx
call   1040 <initMat@plt>
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
lea    -0x40(%rbp),%rdx
call   1040 <initMat@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1235 <matrixMultiply+0xe5>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1222 <matrixMultiply+0xd2>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
mov    -0x38(%rbp),%r8
call   1070 <getRow@plt>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    -0x30(%rbp),%ecx
mov    -0x40(%rbp),%r8
call   1030 <getCol@plt>
mov    -0x8(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rdx
call   1060 <dotProduct@plt>
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x30(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11b7 <matrixMultiply+0x67>
jmp    1227 <matrixMultiply+0xd7>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11a4 <matrixMultiply+0x54>
mov    -0x8(%rbp),%edi
lea    -0x38(%rbp),%rsi
call   1050 <freeMat@plt>
mov    -0x8(%rbp),%edi
lea    -0x40(%rbp),%rsi
call   1050 <freeMat@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matrixMultiply>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r9,0x30(%rsp)
mov    %r8,0x28(%rsp)
mov    %rcx,0x20(%rsp)
mov    %edx,0x4(%rsp)
mov    %esi,%r12d
mov    %edi,%ebp
lea    0x10(%rsp),%rdx
mov    %esi,%edi
mov    $0x1,%esi
call   1040 <initMat@plt>
lea    0x8(%rsp),%rdx
mov    %r12d,%edi
mov    $0x1,%esi
call   1040 <initMat@plt>
test   %ebp,%ebp
jle    1238 <matrixMultiply+0xe8>
mov    0x4(%rsp),%ebx
mov    %ebp,%eax
mov    %rax,0x18(%rsp)
xor    %r14d,%r14d
mov    0x20(%rsp),%r13
jmp    11cb <matrixMultiply+0x7b>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%r14
cmp    0x18(%rsp),%r14
je     1238 <matrixMultiply+0xe8>
cmpl   $0x0,0x4(%rsp)
jle    11c0 <matrixMultiply+0x70>
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x10(%rsp),%r8
mov    %ebp,%edi
mov    %r12d,%esi
mov    %r13,%rdx
mov    %r14d,%ecx
call   1070 <getRow@plt>
mov    0x8(%rsp),%r8
mov    %r12d,%edi
mov    %ebx,%esi
mov    0x28(%rsp),%rdx
mov    %r15d,%ecx
call   1030 <getCol@plt>
mov    0x10(%rsp),%rsi
mov    0x8(%rsp),%rdx
mov    %r12d,%edi
call   1060 <dotProduct@plt>
mov    0x30(%rsp),%rdx
mov    (%rdx,%r14,8),%rax
movsd  %xmm0,(%rax,%r15,8)
add    $0x1,%r15
cmp    %r15,%rbx
jne    11e0 <matrixMultiply+0x90>
jmp    11c0 <matrixMultiply+0x70>
lea    0x10(%rsp),%rsi
mov    %r12d,%edi
call   1050 <freeMat@plt>
lea    0x8(%rsp),%rsi
mov    %r12d,%edi
call   1050 <freeMat@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @matrixMultiply(i32 %0, i32 %1, i32 %2, double** %3, double** %4, double** %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca double**
%11 = alloca double**
%12 = alloca double**
%13 = alloca i32
%14 = alloca i32
%15 = alloca double**
%16 = alloca double**
store i32 %0, i32* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store double** %3, double*** %10
store double** %4, double*** %11
store double** %5, double*** %12
store i32 0, i32* %13
store i32 0, i32* %14
%17 = load i32, i32* %8
%18 = call i32 @initMat(i32 %17, i32 1, double*** %15)
%19 = load i32, i32* %8
%20 = call i32 @initMat(i32 %19, i32 1, double*** %16)
store i32 0, i32* %13
br label %21
21: ; preds = %59, %6
%22 = load i32, i32* %13
%23 = load i32, i32* %7
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %62
25: ; preds = %21
store i32 0, i32* %14
br label %26
26: ; preds = %55, %25
%27 = load i32, i32* %14
%28 = load i32, i32* %9
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %58
30: ; preds = %26
%31 = load i32, i32* %7
%32 = load i32, i32* %8
%33 = load double**, double*** %10
%34 = load i32, i32* %13
%35 = load double**, double*** %15
%36 = call i32 @getRow(i32 %31, i32 %32, double** %33, i32 %34, double** %35)
%37 = load i32, i32* %8
%38 = load i32, i32* %9
%39 = load double**, double*** %11
%40 = load i32, i32* %14
%41 = load double**, double*** %16
%42 = call i32 @getCol(i32 %37, i32 %38, double** %39, i32 %40, double** %41)
%43 = load i32, i32* %8
%44 = load double**, double*** %15
%45 = load double**, double*** %16
%46 = call double @dotProduct(i32 %43, double** %44, double** %45)
%47 = load double**, double*** %12
%48 = load i32, i32* %13
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds double*, double** %47, i64 %49
%51 = load double*, double** %50
%52 = load i32, i32* %14
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds double, double* %51, i64 %53
store double %46, double* %54
br label %55
55: ; preds = %30
%56 = load i32, i32* %14
%57 = add nsw i32 %56, 1
store i32 %57, i32* %14
br label %26
58: ; preds = %26
br label %59
59: ; preds = %58
%60 = load i32, i32* %13
%61 = add nsw i32 %60, 1
store i32 %61, i32* %13
br label %21
62: ; preds = %21
%63 = load i32, i32* %8
%64 = call i32 @freeMat(i32 %63, double*** %15)
%65 = load i32, i32* %8
%66 = call i32 @freeMat(i32 %65, double*** %16)
ret void
}

LLVM IR (-O2):
define void @matrixMultiply(i32 %0, i32 %1, i32 %2, double** %3, double** %4, double** nocapture %5) {
%7 = alloca double**
%8 = alloca double**
%9 = bitcast double*** %7 to i8*
%10 = bitcast double*** %8 to i8*
%11 = call i32 @initMat(i32 %1, i32 1, double*** %7)
%12 = call i32 @initMat(i32 %1, i32 1, double*** %8)
%13 = icmp sgt i32 %0, 0
br i1 %13, label %14, label %40
14: ; preds = %6
%15 = icmp sgt i32 %2, 0
%16 = zext i32 %0 to i64
%17 = zext i32 %2 to i64
br label %18
18: ; preds = %14, %37
%19 = phi i64 [ 0, %14 ], [ %38, %37 ]
br i1 %15, label %20, label %37
20: ; preds = %18
%21 = getelementptr inbounds double*, double** %5, i64 %19
%22 = trunc i64 %19 to i32
br label %23
23: ; preds = %20, %23
%24 = phi i64 [ 0, %20 ], [ %35, %23 ]
%25 = load double**, double*** %7
%26 = call i32 @getRow(i32 %0, i32 %1, double** %3, i32 %22, double** %25)
%27 = load double**, double*** %8
%28 = trunc i64 %24 to i32
%29 = call i32 @getCol(i32 %1, i32 %2, double** %4, i32 %28, double** %27)
%30 = load double**, double*** %7
%31 = load double**, double*** %8
%32 = call double @dotProduct(i32 %1, double** %30, double** %31)
%33 = load double*, double** %21
%34 = getelementptr inbounds double, double* %33, i64 %24
store double %32, double* %34
%35 = add nuw nsw i64 %24, 1
%36 = icmp eq i64 %35, %17
br i1 %36, label %37, label %23
37: ; preds = %23, %18
%38 = add nuw nsw i64 %19, 1
%39 = icmp eq i64 %38, %16
br i1 %39, label %40, label %18
40: ; preds = %37, %6
%41 = call i32 @freeMat(i32 %1, double*** %7)
%42 = call i32 @freeMat(i32 %1, double*** %8)
ret void
}