Is this something that could be exposed as a generic CLI tool to replace something like wasm-opt from Binaryen?
In general the whole concept behind Cheerp (C++ to WebAssembly + JavaScript compiler) is doing as much as possible at the LLVM IR level, JavaScript concept included, since it's easier and more powerful to do code transformation there.