I have looked at the diagrams. If a side effect occurs between Program A and Program B, then referential transparency is violated. Referential transparency is the "sacred principle" of algebra; if it is violated, no algebraic transformation is possible—unless I am mistaken or we are talking about a monadic continuation.