Thank you for all the replies.Luite Stegeman - I was thinking that the LLVM IR code is optimized already or you can run LLVM IR optimization passes to get rid of such things. I think compiling with ghc -fllvm generates LLVM bitcode and then you can simply run emscripten on it to get Javascript - and it should work as expected.