@target: mips, mipt2

package main;

const (
    LIN             = 20
    COL             = 20
    NUM_LINHAS_MULT = 5
)

var (
    preenchendo = false
    state int
    matrizA [LIN][COL]int 
    matrizB [LIN][COL]int
    matrizR [LIN][COL]int
)

func preenche(){
    var k = 1
    for i := 0; i < LIN ; i++ {
        for j := 0; j < COL ; j++ {
            matrizA[i][j] = k
            matrizB[i][j] = k
            k++
        }
    }
}

func multiplica(initial int) {
    aux   := 0
    limit := initial + NUM_LINHAS_MULT
    for i := initial; i < limit; i++ {
        for j := 0; j < COL; j++ {
            for k := 0; k < LIN; k++ {
                aux = aux + (matrizA[i][k] * matrizB[k][j])
            }
            matrizR[i][j] = aux
            aux = 0
        }
    }
}

func main() {
    if !preenchendo {
        preenchendo = true
        preenche()
        preenchendo = false
    }

    for preenchendo {
        continue
    }

    switch state {
        case 0:
            multiplica(0)
        case 1:
            multiplica(5)
        case 2:
            multiplica(10)
        case 3:
            multiplica(15)
    }
    state++
}
