#include <stdio.h>

#include "ImC/imc_extension.h"

#define MAT_SIZE 10

int A[MAT_SIZE][MAT_SIZE] = {
    [0 ... MAT_SIZE - 1] = {[0 ... MAT_SIZE - 1] = 2}};
int B[MAT_SIZE][MAT_SIZE] = {
    [0 ... MAT_SIZE - 1] = {[0 ... MAT_SIZE - 1] = 2}};

void vMatMul() {
    // int IMC_REPEAT = 2000;
    int IMC_REPEAT = imcBENCH_REPEAT_COUNT;
    int C[MAT_SIZE * MAT_SIZE] = { 0 };

    for(int imc=0; imc<IMC_REPEAT; imc++) {

        IMC_UNROLL(3)
        for (int _i = 0; _i < MAT_SIZE * MAT_SIZE; _i++)
        {
            int sum = 0;
            int i = _i / MAT_SIZE;
            int j = _i % MAT_SIZE;
            IMC_UNROLL(MAT_SIZE)
            for(int k=0; k<MAT_SIZE; k++) {
                sum += A[i][k] * B[k][j];
            }
            C[_i] = sum;
        }
    }

    int sum = 0;

    for (int _i = 0; _i < MAT_SIZE * MAT_SIZE; _i++)
    {
        if(_i % MAT_SIZE == 0) {
            printf("\r\n");
        }
        printf("%d ", C[_i]);
        sum += C[_i];
    }
    printf("\r\n");

    printf("(OUT) sum: %d\r\n", sum);
}