C code adapted to use allocMatrix