refactor i64 legalization code