fix PR5640 by tracking whether a block is the header of a loop more