tiling2: C version - fix wrong algorithm