#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 */
size_t matN_getIndex(int, int, int const);
int /*<<< orphan*/ matNd_copy(double *, double *, int const);
int /*<<< orphan*/ matNd_getColumn(double *, double const *, int, int const);
int /*<<< orphan*/ matNd_getRow(double *, double const *, int, int const);
double vecNd_dot(double *, double *, int const);
void matNd_mult_matNd_new(double result[], const double matA[],
                          const double matB[], const int n) {
  double tempMatrix[4 * 4];
  double vecA[4], vecB[4];
  for (int i = 0; i < n; i++) {
    matNd_getRow(vecA, matA, i, n);
    for (int j = 0; j < n; j++) {
      matNd_getColumn(vecB, matB, j, n);
      tempMatrix[matN_getIndex(i, j, n)] = vecNd_dot(vecA, vecB, n);
    }
  }
  matNd_copy(result, tempMatrix, n);
}


x86 assembly (clang, -O0):
<matNd_mult_matNd_new>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0xe4(%rbp)
mov    -0xe4(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    123e <matNd_mult_matNd_new+0xee>
lea    -0xc0(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0xe4(%rbp),%edx
mov    -0x1c(%rbp),%ecx
call   1030 <matNd_getRow@plt>
movl   $0x0,-0xe8(%rbp)
mov    -0xe8(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1225 <matNd_mult_matNd_new+0xd5>
lea    -0xe0(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0xe8(%rbp),%edx
mov    -0x1c(%rbp),%ecx
call   1060 <matNd_getColumn@plt>
lea    -0xc0(%rbp),%rdi
lea    -0xe0(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <vecNd_dot@plt>
movsd  %xmm0,-0xf0(%rbp)
ff
mov    -0xe4(%rbp),%edi
mov    -0xe8(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1070 <matN_getIndex@plt>
movsd  -0xf0(%rbp),%xmm0
ff
movsd  %xmm0,-0xa0(%rbp,%rax,8)
ff ff
mov    -0xe8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xe8(%rbp)
jmp    11a6 <matNd_mult_matNd_new+0x56>
jmp    122a <matNd_mult_matNd_new+0xda>
mov    -0xe4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xe4(%rbp)
jmp    1174 <matNd_mult_matNd_new+0x24>
mov    -0x8(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <matNd_copy@plt>
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matNd_mult_matNd_new>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xe8,%rsp
mov    %ecx,%ebx
mov    %rsi,0x10(%rsp)
mov    %rdi,0x8(%rsp)
test   %ecx,%ecx
jle    11eb <matNd_mult_matNd_new+0x9b>
mov    %rdx,%r15
xor    %ebp,%ebp
lea    0x40(%rsp),%r13
lea    0x20(%rsp),%r14
mov    %r13,%rdi
mov    0x10(%rsp),%rsi
mov    %ebp,%edx
mov    %ebx,%ecx
call   1030 <matNd_getRow@plt>
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12d,%edx
mov    %ebx,%ecx
call   1060 <matNd_getColumn@plt>
mov    %r13,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1040 <vecNd_dot@plt>
movsd  %xmm0,0x18(%rsp)
mov    %ebp,%edi
mov    %r12d,%esi
mov    %ebx,%edx
call   1070 <matN_getIndex@plt>
movsd  0x18(%rsp),%xmm0
movsd  %xmm0,0x60(%rsp,%rax,8)
add    $0x1,%r12d
cmp    %r12d,%ebx
jne    11a0 <matNd_mult_matNd_new+0x50>
add    $0x1,%ebp
cmp    %ebx,%ebp
jne    1180 <matNd_mult_matNd_new+0x30>
lea    0x60(%rsp),%rsi
mov    0x8(%rsp),%rdi
mov    %ebx,%edx
call   1050 <matNd_copy@plt>
add    $0xe8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @matNd_mult_matNd_new(double* %0, double* %1, double* %2, i32 %3) {
%5 = alloca double*
%6 = alloca double*
%7 = alloca double*
%8 = alloca i32
%9 = alloca [16 x double]
%10 = alloca [4 x double]
%11 = alloca [4 x double]
%12 = alloca i32
%13 = alloca i32
store double* %0, double** %5
store double* %1, double** %6
store double* %2, double** %7
store i32 %3, i32* %8
store i32 0, i32* %12
br label %14
14: ; preds = %47, %4
%15 = load i32, i32* %12
%16 = load i32, i32* %8
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %50
18: ; preds = %14
%19 = getelementptr inbounds [4 x double], [4 x double]* %10, i64 0, i64 0
%20 = load double*, double** %6
%21 = load i32, i32* %12
%22 = load i32, i32* %8
%23 = call i32 @matNd_getRow(double* %19, double* %20, i32 %21, i32 %22)
store i32 0, i32* %13
br label %24
24: ; preds = %43, %18
%25 = load i32, i32* %13
%26 = load i32, i32* %8
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %46
28: ; preds = %24
%29 = getelementptr inbounds [4 x double], [4 x double]* %11, i64 0, i64 0
%30 = load double*, double** %7
%31 = load i32, i32* %13
%32 = load i32, i32* %8
%33 = call i32 @matNd_getColumn(double* %29, double* %30, i32 %31, i32 %32)
%34 = getelementptr inbounds [4 x double], [4 x double]* %10, i64 0, i64 0
%35 = getelementptr inbounds [4 x double], [4 x double]* %11, i64 0, i64 0
%36 = load i32, i32* %8
%37 = call double @vecNd_dot(double* %34, double* %35, i32 %36)
%38 = load i32, i32* %12
%39 = load i32, i32* %13
%40 = load i32, i32* %8
%41 = call i64 @matN_getIndex(i32 %38, i32 %39, i32 %40)
%42 = getelementptr inbounds [16 x double], [16 x double]* %9, i64 0, i64 %41
store double %37, double* %42
br label %43
43: ; preds = %28
%44 = load i32, i32* %13
%45 = add nsw i32 %44, 1
store i32 %45, i32* %13
br label %24
46: ; preds = %24
br label %47
47: ; preds = %46
%48 = load i32, i32* %12
%49 = add nsw i32 %48, 1
store i32 %49, i32* %12
br label %14
50: ; preds = %14
%51 = load double*, double** %5
%52 = getelementptr inbounds [16 x double], [16 x double]* %9, i64 0, i64 0
%53 = load i32, i32* %8
%54 = call i32 @matNd_copy(double* %51, double* %52, i32 %53)
ret void
}

LLVM IR (-O2):
define void @matNd_mult_matNd_new(double* %0, double* %1, double* %2, i32 %3) {
%5 = alloca [16 x double]
%6 = alloca [4 x double]
%7 = alloca [4 x double]
%8 = bitcast [16 x double]* %5 to i8*
%9 = bitcast [4 x double]* %6 to i8*
%10 = bitcast [4 x double]* %7 to i8*
%11 = icmp sgt i32 %3, 0
br i1 %11, label %12, label %15
12: ; preds = %4
%13 = getelementptr inbounds [4 x double], [4 x double]* %6, i64 0, i64 0
%14 = getelementptr inbounds [4 x double], [4 x double]* %7, i64 0, i64 0
br label %18
15: ; preds = %21, %4
%16 = getelementptr inbounds [16 x double], [16 x double]* %5, i64 0, i64 0
%17 = call i32 @matNd_copy(double* %0, double* %16, i32 %3)
ret void
18: ; preds = %21, %12
%19 = phi i32 [ 0, %12 ], [ %22, %21 ]
%20 = call i32 @matNd_getRow(double* %13, double* %1, i32 %19, i32 %3)
br label %24
21: ; preds = %24
%22 = add nuw nsw i32 %19, 1
%23 = icmp eq i32 %22, %3
br i1 %23, label %15, label %18
24: ; preds = %18, %24
%25 = phi i32 [ %30, %24 ], [ 0, %18 ]
%26 = call i32 @matNd_getColumn(double* %14, double* %2, i32 %25, i32 %3)
%27 = call double @vecNd_dot(double* %13, double* %14, i32 %3)
%28 = call i64 @matN_getIndex(i32 %19, i32 %25, i32 %3)
%29 = getelementptr inbounds [16 x double], [16 x double]* %5, i64 0, i64 %28
store double %27, double* %29
%30 = add nuw nsw i32 %25, 1
%31 = icmp eq i32 %30, %3
br i1 %31, label %21, label %24
}