Fix #812: invalid internalizatin of variables into loop

Variables used in other loop should also be considered in the usage analysis.