fix iteration bug and add feature: combine function group according to cast inst