Replace cython-based extension module with a hand-written one.

This avoids the complexity of ensuring that cython is installed
at build time.
Make the C extension optional.