Add support for tail duplication to BranchFolding, and extend