examples/muxing: factorize write_interleave code