first draft of c version for performance comparisons