Misc fixes to codegen. Work on kmeans.

Option and Indirection types are expected to be shared_ptrs in the library.
So now the code generator produces these types.
(Alternatively, we could migrate the library to use raw pointers).