Split out main() from template generation
Cleanup invariants and split out checking.

Can verify:
- Race-freedom using CHECK_RACE
- Barrier access using CHECK_BI, CHECK_BI_ACCESS and manually editing bpl to
exclude barrier invariant.
- Barrier invariant using CHECK_BI