Adding utility functions for detecting and manipulating branches.

This PR pulls out some of the helper routines from the specialized_branched_loops code in PR #482 and provides some correctness testing for these visitors and mutators. These functions might be useful in other contexts, but the main reason for pulling them out into their own file is to help the readability of the specialize_branched_loops code, and make it easier to test them independently.
Sorry, the stack order I was talking about is not the stack of values for each variable in the scope, but the stack of Lets, i.e. the order in which each variable is added to the scope. Maybe that doesn't make sense in general though.