Any way you could output in Single Static Assignment for LLVM/MLIR and SSA SMTLIB lisp for solvers like Microsoft Z3/CVC5? You could then shell out to LLVM and Z3/CVC5 to make optimization passes, and give you an easy compile target for WASM with a little IO boilerplate.
%1 = ...
%2 = ...
(+ x3 x2 x1)