Initial import of C implementation.