c version
emscripten's code