Program: 62196
Project: 62196
Buggy source:
@Override protected List<GraphTargetItem> check(GraphSource code,List localData,List<GraphPart> allParts,Stack<GraphTargetItem> stack,GraphPart parent,GraphPart part,GraphPart stopPart,List<Loop> loops,List<GraphTargetItem> output,HashMap<Loop,List<GraphTargetItem>> forFinalCommands){
  if (!output.isEmpty()) {
    if (output.get(output.size() - 1) instanceof StoreRegisterTreeItem) {
      StoreRegisterTreeItem str=(StoreRegisterTreeItem)output.get(output.size() - 1);
      if (str.value instanceof EnumerateTreeItem) {
        output.remove(output.size() - 1);
      }
    }
  }
  List<GraphTargetItem> ret=null;
  if ((part.nextParts.size() == 2) && (!stack.isEmpty()) && (stack.peek() instanceof StrictEqTreeItem)) {
    GraphTargetItem switchedObject=null;
    if (!output.isEmpty()) {
      if (output.get(output.size() - 1) instanceof StoreRegisterTreeItem) {
        switchedObject=((StoreRegisterTreeItem)output.get(output.size() - 1)).value;
      }
    }
    if (switchedObject == null) {
      switchedObject=new DirectValueTreeItem(null,-1,new Null(),null);
    }
    HashMap<Integer,GraphTargetItem> caseValuesMap=new HashMap<Integer,GraphTargetItem>();
    int pos=0;
    StrictEqTreeItem set=(StrictEqTreeItem)stack.pop();
    caseValuesMap.put(pos,set.rightSide);
    if (set.leftSide instanceof StoreRegisterTreeItem) {
      switchedObject=((StoreRegisterTreeItem)set.leftSide).value;
    }
    List<GraphPart> caseBodyParts=new ArrayList<GraphPart>();
    caseBodyParts.add(part.nextParts.get(0));
    GraphTargetItem top=null;
    int cnt=1;
    while (part.nextParts.size() > 1 && part.nextParts.get(1).getHeight() > 1 && code.get(part.nextParts.get(1).end) instanceof ActionIf && ((top=translatePartGetStack(localData,part.nextParts.get(1),stack)) instanceof StrictEqTreeItem)) {
      cnt++;
      part=part.nextParts.get(1);
      pos++;
      caseBodyParts.add(part.nextParts.get(0));
      set=(StrictEqTreeItem)top;
      caseValuesMap.put(pos,set.rightSide);
    }
    if (cnt == 1) {
      stack.push(set);
    }
 else {
      part=part.nextParts.get(1);
      GraphPart defaultPart=part;
      List<GraphPart> defaultAndLastPart=new ArrayList<GraphPart>();
      defaultAndLastPart.add(defaultPart);
      defaultAndLastPart.add(caseBodyParts.get(caseBodyParts.size() - 1));
      GraphPart defaultPart2=getCommonPart(defaultAndLastPart);
      List<GraphTargetItem> defaultCommands=new ArrayList<GraphTargetItem>();
      defaultCommands=printGraph(localData,stack,allParts,null,defaultPart,defaultPart2,loops,forFinalCommands);
      List<GraphPart> loopContinues=new ArrayList<GraphPart>();
      for (      Loop l : loops) {
        if (l.loopContinue != null) {
          loopContinues.add(l.loopContinue);
        }
      }
      List<GraphPart> breakParts=new ArrayList<GraphPart>();
      for (int g=0; g < caseBodyParts.size(); g++) {
        if (g < caseBodyParts.size() - 1) {
          if (caseBodyParts.get(g).leadsTo(code,caseBodyParts.get(g + 1),loopContinues)) {
            continue;
          }
        }
        GraphPart nsp=caseBodyParts.get(g).getNextSuperPartPath(loopContinues);
        if (nsp != null) {
          breakParts.add(nsp);
        }
      }
      Collections.sort(breakParts,new Comparator<GraphPart>(){
        @Override public int compare(        GraphPart o1,        GraphPart o2){
          return o2.path.length() - o1.path.length();
        }
      }
);
      GraphPart breakPart=breakParts.isEmpty() ? null : breakParts.get(0);
      if ((defaultPart2 != breakPart) && (defaultCommands.isEmpty())) {
        defaultPart=defaultPart2;
      }
      List<GraphTargetItem> caseValues=new ArrayList<GraphTargetItem>();
      for (int i=0; i < caseBodyParts.size(); i++) {
        if (caseValuesMap.containsKey(i)) {
          caseValues.add(caseValuesMap.get(i));
        }
 else {
          continue;
        }
      }
      List<List<GraphTargetItem>> caseCommands=new ArrayList<List<GraphTargetItem>>();
      GraphPart next=null;
      next=breakPart;
      GraphTargetItem ti=checkLoop(next,stopPart,loops);
      Loop currentLoop=new Loop(loops.size(),null,next);
      loops.add(currentLoop);
      List<Integer> valuesMapping=new ArrayList<Integer>();
      List<GraphPart> caseBodies=new ArrayList<GraphPart>();
      for (int i=0; i < caseValues.size(); i++) {
        GraphPart cur=caseBodyParts.get(i);
        if (!caseBodies.contains(cur)) {
          caseBodies.add(cur);
        }
        valuesMapping.add(caseBodies.indexOf(cur));
      }
      if (defaultPart == breakPart) {
        defaultPart=null;
      }
      if ((defaultPart != null) && (defaultCommands.isEmpty())) {
        defaultCommands=printGraph(localData,stack,allParts,null,defaultPart,next,loops,forFinalCommands);
      }
      List<GraphPart> ignored=new ArrayList<GraphPart>();
      for (      Loop l : loops) {
        ignored.add(l.loopContinue);
      }
      for (int i=0; i < caseBodies.size(); i++) {
        List<GraphTargetItem> cc=new ArrayList<GraphTargetItem>();
        GraphPart nextCase=null;
        nextCase=next;
        if (next != null) {
          if (i < caseBodies.size() - 1) {
            if (!caseBodies.get(i).leadsTo(code,caseBodies.get(i + 1),ignored)) {
              cc.add(new BreakItem(null,currentLoop.id));
            }
 else {
              nextCase=caseBodies.get(i + 1);
            }
          }
 else           if (!defaultCommands.isEmpty()) {
            if (!caseBodies.get(i).leadsTo(code,defaultPart,ignored)) {
              cc.add(new BreakItem(null,currentLoop.id));
            }
 else {
              nextCase=defaultPart;
            }
          }
        }
        cc.addAll(0,printGraph(localData,stack,allParts,null,caseBodies.get(i),nextCase,loops,forFinalCommands));
        if (cc.size() >= 2) {
          if (cc.get(cc.size() - 1) instanceof BreakItem) {
            if ((cc.get(cc.size() - 2) instanceof ContinueItem) || (cc.get(cc.size() - 2) instanceof BreakItem)) {
              cc.remove(cc.size() - 1);
            }
          }
        }
        caseCommands.add(cc);
      }
      ret=new ArrayList<GraphTargetItem>();
      if (!output.isEmpty()) {
        if (output.get(output.size() - 1) instanceof StoreRegisterTreeItem) {
          output.remove(output.size() - 1);
        }
      }
      ret.addAll(output);
      SwitchItem sti=new SwitchItem(null,currentLoop,switchedObject,caseValues,caseCommands,defaultCommands,valuesMapping);
      ret.add(sti);
      if (next != null) {
        if (ti != null) {
          ret.add(ti);
        }
 else {
          ret.addAll(printGraph(localData,stack,allParts,null,next,stopPart,loops,forFinalCommands));
        }
      }
    }
  }
  return ret;
}

Fixed version (ground truth):
@Override protected List<GraphTargetItem> check(GraphSource code,List localData,List<GraphPart> allParts,Stack<GraphTargetItem> stack,GraphPart parent,GraphPart part,GraphPart stopPart,List<Loop> loops,List<GraphTargetItem> output,HashMap<Loop,List<GraphTargetItem>> forFinalCommands){
  if (!output.isEmpty()) {
    if (output.get(output.size() - 1) instanceof StoreRegisterTreeItem) {
      StoreRegisterTreeItem str=(StoreRegisterTreeItem)output.get(output.size() - 1);
      if (str.value instanceof EnumerateTreeItem) {
        output.remove(output.size() - 1);
      }
    }
  }
  List<GraphTargetItem> ret=null;
  if ((part.nextParts.size() == 2) && (!stack.isEmpty()) && (stack.peek() instanceof StrictEqTreeItem)) {
    GraphTargetItem switchedObject=null;
    if (!output.isEmpty()) {
      if (output.get(output.size() - 1) instanceof StoreRegisterTreeItem) {
        switchedObject=((StoreRegisterTreeItem)output.get(output.size() - 1)).value;
      }
    }
    if (switchedObject == null) {
      switchedObject=new DirectValueTreeItem(null,-1,new Null(),null);
    }
    HashMap<Integer,GraphTargetItem> caseValuesMap=new HashMap<Integer,GraphTargetItem>();
    int pos=0;
    StrictEqTreeItem set=(StrictEqTreeItem)stack.pop();
    caseValuesMap.put(pos,set.rightSide);
    if (set.leftSide instanceof StoreRegisterTreeItem) {
      switchedObject=((StoreRegisterTreeItem)set.leftSide).value;
    }
    List<GraphPart> caseBodyParts=new ArrayList<GraphPart>();
    caseBodyParts.add(part.nextParts.get(0));
    GraphTargetItem top=null;
    int cnt=1;
    while (part.nextParts.size() > 1 && part.nextParts.get(1).getHeight() > 1 && code.get(part.nextParts.get(1).end) instanceof ActionIf && ((top=translatePartGetStack(localData,part.nextParts.get(1),stack)) instanceof StrictEqTreeItem)) {
      cnt++;
      part=part.nextParts.get(1);
      pos++;
      caseBodyParts.add(part.nextParts.get(0));
      set=(StrictEqTreeItem)top;
      caseValuesMap.put(pos,set.rightSide);
    }
    if (cnt == 1) {
      stack.push(set);
    }
 else {
      part=part.nextParts.get(1);
      GraphPart defaultPart=part;
      List<GraphPart> defaultAndLastPart=new ArrayList<GraphPart>();
      defaultAndLastPart.add(defaultPart);
      defaultAndLastPart.add(caseBodyParts.get(caseBodyParts.size() - 1));
      GraphPart defaultPart2=getCommonPart(defaultAndLastPart);
      List<GraphTargetItem> defaultCommands=new ArrayList<GraphTargetItem>();
      defaultCommands=printGraph(new ArrayList<GraphPart>(),localData,stack,allParts,null,defaultPart,defaultPart2,loops,forFinalCommands);
      List<GraphPart> loopContinues=new ArrayList<GraphPart>();
      for (      Loop l : loops) {
        if (l.loopContinue != null) {
          loopContinues.add(l.loopContinue);
        }
      }
      List<GraphPart> breakParts=new ArrayList<GraphPart>();
      for (int g=0; g < caseBodyParts.size(); g++) {
        if (g < caseBodyParts.size() - 1) {
          if (caseBodyParts.get(g).leadsTo(code,caseBodyParts.get(g + 1),loopContinues)) {
            continue;
          }
        }
        GraphPart nsp=caseBodyParts.get(g).getNextSuperPartPath(loopContinues);
        if (nsp != null) {
          breakParts.add(nsp);
        }
      }
      Collections.sort(breakParts,new Comparator<GraphPart>(){
        @Override public int compare(        GraphPart o1,        GraphPart o2){
          return o2.path.length() - o1.path.length();
        }
      }
);
      GraphPart breakPart=breakParts.isEmpty() ? null : breakParts.get(0);
      if ((defaultPart2 != breakPart) && (defaultCommands.isEmpty())) {
        defaultPart=defaultPart2;
      }
      List<GraphTargetItem> caseValues=new ArrayList<GraphTargetItem>();
      for (int i=0; i < caseBodyParts.size(); i++) {
        if (caseValuesMap.containsKey(i)) {
          caseValues.add(caseValuesMap.get(i));
        }
 else {
          continue;
        }
      }
      List<List<GraphTargetItem>> caseCommands=new ArrayList<List<GraphTargetItem>>();
      GraphPart next=null;
      next=breakPart;
      GraphTargetItem ti=checkLoop(next,stopPart,loops);
      Loop currentLoop=new Loop(loops.size(),null,next);
      loops.add(currentLoop);
      List<Integer> valuesMapping=new ArrayList<Integer>();
      List<GraphPart> caseBodies=new ArrayList<GraphPart>();
      for (int i=0; i < caseValues.size(); i++) {
        GraphPart cur=caseBodyParts.get(i);
        if (!caseBodies.contains(cur)) {
          caseBodies.add(cur);
        }
        valuesMapping.add(caseBodies.indexOf(cur));
      }
      if (defaultPart == breakPart) {
        defaultPart=null;
      }
      if ((defaultPart != null) && (defaultCommands.isEmpty())) {
        defaultCommands=printGraph(new ArrayList<GraphPart>(),localData,stack,allParts,null,defaultPart,next,loops,forFinalCommands);
      }
      List<GraphPart> ignored=new ArrayList<GraphPart>();
      for (      Loop l : loops) {
        ignored.add(l.loopContinue);
      }
      for (int i=0; i < caseBodies.size(); i++) {
        List<GraphTargetItem> cc=new ArrayList<GraphTargetItem>();
        GraphPart nextCase=null;
        nextCase=next;
        if (next != null) {
          if (i < caseBodies.size() - 1) {
            if (!caseBodies.get(i).leadsTo(code,caseBodies.get(i + 1),ignored)) {
              cc.add(new BreakItem(null,currentLoop.id));
            }
 else {
              nextCase=caseBodies.get(i + 1);
            }
          }
 else           if (!defaultCommands.isEmpty()) {
            if (!caseBodies.get(i).leadsTo(code,defaultPart,ignored)) {
              cc.add(new BreakItem(null,currentLoop.id));
            }
 else {
              nextCase=defaultPart;
            }
          }
        }
        cc.addAll(0,printGraph(new ArrayList<GraphPart>(),localData,stack,allParts,null,caseBodies.get(i),nextCase,loops,forFinalCommands));
        if (cc.size() >= 2) {
          if (cc.get(cc.size() - 1) instanceof BreakItem) {
            if ((cc.get(cc.size() - 2) instanceof ContinueItem) || (cc.get(cc.size() - 2) instanceof BreakItem)) {
              cc.remove(cc.size() - 1);
            }
          }
        }
        caseCommands.add(cc);
      }
      ret=new ArrayList<GraphTargetItem>();
      if (!output.isEmpty()) {
        if (output.get(output.size() - 1) instanceof StoreRegisterTreeItem) {
          output.remove(output.size() - 1);
        }
      }
      ret.addAll(output);
      SwitchItem sti=new SwitchItem(null,currentLoop,switchedObject,caseValues,caseCommands,defaultCommands,valuesMapping);
      ret.add(sti);
      if (next != null) {
        if (ti != null) {
          ret.add(ti);
        }
 else {
          ret.addAll(printGraph(new ArrayList<GraphPart>(),localData,stack,allParts,null,next,stopPart,loops,forFinalCommands));
        }
      }
    }
  }
  return ret;
}