Convert mdec.cpp to C