[cleanup] Factor out some checks. NFC.

The core logic in main() is actually pretty simple, but there's lots of
stuff that has been added over time which obscures the flow of the code.
In upcoming patches, I'll be pulling more stuff out of the main
codepath.

I'm open to naming suggestions for these helper functions.