implement loop finder
generate correct? code for branch in loop