import "./mimcFeistel" as MiMCFeistel;

def main<nInputs, nOutputs>(field[nInputs] ins, field k) -> field[nOutputs] {
    field[nInputs + nOutputs - 1][2] mut S = [[0; 2]; nInputs + nOutputs - 1];
    field[nOutputs] mut outs = [0; nOutputs];

    for u32 i in 0..nInputs {
        u32 j = i == 0 ? 0 : i - 1;
        S[i] = i == 0 ? MiMCFeistel(ins[0], 0, k) : MiMCFeistel(S[j][0] + ins[i], S[j][1], k);
    }

    outs[0] = S[nInputs - 1][0];

    for u32 i in 0..(nOutputs - 1) {
        S[nInputs + i] = MiMCFeistel(S[nInputs + i - 1][0], S[nInputs + i - 1][1], k);
        outs[i + 1] = S[nInputs + i][0];
    }

    return outs;
}