C sources: restructure code to support Emscripten