the serial C version for comparison