Fix handling of optimized-away for/while/foreach blocks

Another interesting case not handled by this patch is when the
block only contains an empty do{} block.