Convert page rewriting in `mergePages` to Cadence.

See #375.