private int convert(List<Rule> rules, StringBuilder sb, String functionName, String recursionName, RuleType ruleType, int ruleNum) {
NormalizeVariables t = new NormalizeVariables();
Map<AttCompare, List<Rule>> grouping = rules.stream().collect(
Collectors.groupingBy(r -> new AttCompare(t.normalize(RewriteToTop.toLeft(r.body())), Sort.class.getName())));
Map<Tuple3<AttCompare, KLabel, AttCompare>, List<Rule>> groupByFirstPrefix = new HashMap<>();
for (Map.Entry<AttCompare, List<Rule>> entry : grouping.entrySet()) {
if (lookup == null) return null;
K left2 = t.normalize(RewriteToTop.toLeft(r.body()));
K normal = t.normalize(t.applyNormalization(lookup.klist().items().get(1), left2), left2);
return Tuple3.apply(left, lookup.klabel(), new AttCompare(normal, Sort.class.getName()));
})));
left = t.normalize(RewriteToTop.toLeft(r.body()));
lookup = t.normalize(t.applyNormalization(getLookup(r, 0).klist().items().get(1), left), left);
r = t.normalize(t.applyNormalization(r, left, lookup));
left = t.normalize(RewriteToTop.toLeft(r.body()));
lookup = t.normalize(t.applyNormalization(getLookup(r, 0).klist().items().get(1), left), left);
r = t.normalize(t.applyNormalization(r, left, lookup));