Program: 62185
Project: 62185
Buggy source:
protected List<GraphTargetItem> printGraph(List<GraphPart> visited,List localData,Stack<GraphTargetItem> stack,List<GraphPart> allParts,GraphPart parent,GraphPart part,GraphPart stopPart,List<Loop> loops,HashMap<Loop,List<GraphTargetItem>> forFinalCommands){
  if (visited.contains(part)) {
  }
 else {
    visited.add(part);
  }
  List<GraphTargetItem> ret=new ArrayList<GraphTargetItem>();
  try {
    boolean debugMode=false;
    if (debugMode) {
      System.err.println("String_Node_Str" + part);
    }
    while (((part != null) && (part.getHeight() == 1)) && (code.size() > part.start) && (code.get(part.start).isJump())) {
      if (part == stopPart) {
        return ret;
      }
      GraphTargetItem lop=checkLoop(part.nextParts.get(0),stopPart,loops);
      if (lop == null) {
        part=part.nextParts.get(0);
      }
 else {
        break;
      }
    }
    if ((part != null) && (code.size() <= part.start)) {
      ret.add(new ScriptEndItem());
      return ret;
    }
    if (part == stopPart) {
      return ret;
    }
    if (part == null) {
    }
    part=checkPart(localData,part);
    if (part == null) {
      return ret;
    }
    if (part.ignored) {
      return ret;
    }
    List<String> fqn=new ArrayList<String>();
    List<GraphTargetItem> output=new ArrayList<GraphTargetItem>();
    List<GraphPart> parts=new ArrayList<GraphPart>();
    if (part instanceof GraphPartMulti) {
      parts=((GraphPartMulti)part).parts;
    }
 else {
      parts.add(part);
    }
    boolean isIf=false;
    int end=part.end;
    for (    GraphPart p : parts) {
      end=p.end;
      int start=p.start;
      isIf=false;
      try {
        output.addAll(code.translatePart(p,localData,stack,start,end));
        if ((end >= code.size() - 1) && p.nextParts.isEmpty()) {
          output.add(new ScriptEndItem());
        }
      }
 catch (      Exception ex) {
        Logger.getLogger(Graph.class.getName()).log(Level.SEVERE,"String_Node_Str",ex);
        return ret;
      }
    }
    if (part.nextParts.size() == 2) {
      if (!stack.isEmpty()) {
        GraphTargetItem top=stack.peek();
        if (false) {
          stack.pop();
          if (top.toBoolean()) {
            ret.addAll(output);
            ret.addAll(printGraph(visited,localData,stack,allParts,parent,part.nextParts.get(0),stopPart,loops,forFinalCommands));
            return ret;
          }
 else {
            ret.addAll(output);
            ret.addAll(printGraph(visited,localData,stack,allParts,parent,part.nextParts.get(1),stopPart,loops,forFinalCommands));
            return ret;
          }
        }
 else {
        }
      }
 else {
      }
    }
    if (part.nextParts.size() == 2) {
      if (part.nextParts.get(0) == part.nextParts.get(1)) {
        if (!stack.isEmpty()) {
          GraphTargetItem expr=stack.pop();
          if (expr instanceof LogicalOpItem) {
            expr=((LogicalOpItem)expr).invert();
          }
 else {
            expr=new NotItem(null,expr);
          }
          output.add(new IfItem(null,expr,new ArrayList<GraphTargetItem>(),new ArrayList<GraphTargetItem>()));
        }
        part.nextParts.remove(0);
      }
    }
    if (part.nextParts.size() == 2) {
      if ((stack.size() >= 2) && (stack.get(stack.size() - 1) instanceof NotItem) && (((NotItem)(stack.get(stack.size() - 1))).getOriginal().getNotCoerced() == stack.get(stack.size() - 2).getNotCoerced())) {
        ret.addAll(output);
        GraphPart sp0=getNextNoJump(part.nextParts.get(0));
        GraphPart sp1=getNextNoJump(part.nextParts.get(1));
        boolean reversed=false;
        List<GraphPart> loopContinues=getLoopsContinues(loops);
        loopContinues.add(part);
        if (sp1.leadsTo(code,sp0,loopContinues)) {
        }
 else         if (sp0.leadsTo(code,sp1,loopContinues)) {
          reversed=true;
        }
        GraphPart next=reversed ? sp0 : sp1;
        GraphTargetItem ti;
        if ((ti=checkLoop(next,stopPart,loops)) != null) {
          ret.add(ti);
        }
 else {
          printGraph(visited,localData,stack,allParts,parent,next,reversed ? sp1 : sp0,loops,forFinalCommands);
          GraphTargetItem second=stack.pop();
          GraphTargetItem first=stack.pop();
          if (!reversed) {
            AndItem a=new AndItem(null,first,second);
            stack.push(a);
            a.firstPart=part;
            if (second instanceof AndItem) {
              a.firstPart=((AndItem)second).firstPart;
            }
            if (second instanceof OrItem) {
              a.firstPart=((OrItem)second).firstPart;
            }
          }
 else {
            OrItem o=new OrItem(null,first,second);
            stack.push(o);
            o.firstPart=part;
            if (second instanceof AndItem) {
              o.firstPart=((AndItem)second).firstPart;
            }
            if (second instanceof OrItem) {
              o.firstPart=((OrItem)second).firstPart;
            }
          }
          next=reversed ? sp1 : sp0;
          if ((ti=checkLoop(next,stopPart,loops)) != null) {
            ret.add(ti);
          }
 else {
            ret.addAll(printGraph(visited,localData,stack,allParts,parent,next,stopPart,loops,forFinalCommands));
          }
        }
        return ret;
      }
 else       if ((stack.size() >= 2) && (stack.get(stack.size() - 1).getNotCoerced() == stack.get(stack.size() - 2).getNotCoerced())) {
        ret.addAll(output);
        GraphPart sp0=getNextNoJump(part.nextParts.get(0));
        GraphPart sp1=getNextNoJump(part.nextParts.get(1));
        boolean reversed=false;
        List<GraphPart> loopContinues=getLoopsContinues(loops);
        loopContinues.add(part);
        if (sp1.leadsTo(code,sp0,loopContinues)) {
        }
 else         if (sp0.leadsTo(code,sp1,loopContinues)) {
          reversed=true;
        }
        GraphPart next=reversed ? sp0 : sp1;
        GraphTargetItem ti;
        if ((ti=checkLoop(next,stopPart,loops)) != null) {
          ret.add(ti);
        }
 else {
          printGraph(visited,localData,stack,allParts,parent,next,reversed ? sp1 : sp0,loops,forFinalCommands);
          GraphTargetItem second=stack.pop();
          GraphTargetItem first=stack.pop();
          if (reversed) {
            AndItem a=new AndItem(null,first,second);
            stack.push(a);
            a.firstPart=part;
            if (second instanceof AndItem) {
              a.firstPart=((AndItem)second).firstPart;
            }
            if (second instanceof OrItem) {
              a.firstPart=((AndItem)second).firstPart;
            }
          }
 else {
            OrItem o=new OrItem(null,first,second);
            stack.push(o);
            o.firstPart=part;
            if (second instanceof OrItem) {
              o.firstPart=((OrItem)second).firstPart;
            }
            if (second instanceof OrItem) {
              o.firstPart=((OrItem)second).firstPart;
            }
          }
          next=reversed ? sp1 : sp0;
          if ((ti=checkLoop(next,stopPart,loops)) != null) {
            ret.add(ti);
          }
 else {
            ret.addAll(printGraph(visited,localData,stack,allParts,parent,next,stopPart,loops,forFinalCommands));
          }
        }
        return ret;
      }
    }
    List<GraphPart> loopContinues=getLoopsContinues(loops);
    boolean loop=false;
    boolean reversed=false;
    boolean whileTrue=false;
    Loop whileTrueLoop=null;
    if ((!part.nextParts.isEmpty()) && part.nextParts.get(0).leadsTo(code,part,loopContinues)) {
      if ((part.nextParts.size() > 1) && part.nextParts.get(1).leadsTo(code,part,loopContinues)) {
        if (output.isEmpty()) {
          whileTrueLoop=new Loop(loops.size(),part,null);
          loops.add(whileTrueLoop);
          whileTrue=true;
        }
 else {
          loop=true;
        }
      }
 else {
        loop=true;
      }
    }
 else     if ((part.nextParts.size() > 1) && part.nextParts.get(1).leadsTo(code,part,loopContinues)) {
      loop=true;
      reversed=true;
    }
    Loop lc=null;
    if (part.leadsTo(code,part,loopContinues)) {
      lc=new Loop(loops.size(),part,null);
      loops.add(lc);
    }
    List<GraphTargetItem> retChecked=null;
    if ((retChecked=check(code,localData,allParts,stack,parent,part,stopPart,loops,output,forFinalCommands)) != null) {
      if (lc != null) {
        List<GraphTargetItem> trueExp=new ArrayList<GraphTargetItem>();
        trueExp.add(new TrueItem(null));
        boolean chwt=true;
        if (!retChecked.isEmpty()) {
          checkContinueAtTheEnd(retChecked,lc);
          List<GraphTargetItem> finalCommands=forFinalCommands.get(lc);
          IfItem ifi=null;
          if ((finalCommands != null) && !finalCommands.isEmpty()) {
            if (finalCommands.get(finalCommands.size() - 1) instanceof IfItem) {
              ifi=(IfItem)finalCommands.get(finalCommands.size() - 1);
              finalCommands.remove(finalCommands.size() - 1);
            }
          }
 else           if (retChecked.get(retChecked.size() - 1) instanceof IfItem) {
            ifi=(IfItem)retChecked.get(retChecked.size() - 1);
            retChecked.remove(retChecked.size() - 1);
          }
          if (ifi != null) {
            if (ifi.onFalse.isEmpty()) {
              if (!ifi.onTrue.isEmpty()) {
                if (ifi.onTrue.get(ifi.onTrue.size() - 1) instanceof ExitItem) {
                  whileTrue=false;
                  List<GraphTargetItem> tr=new ArrayList<GraphTargetItem>();
                  GraphTargetItem ex=ifi.expression;
                  if (ex instanceof LogicalOpItem) {
                    ex=((LogicalOpItem)ex).invert();
                  }
 else {
                    ex=new NotItem(null,ex);
                  }
                  if ((finalCommands != null) && (!finalCommands.isEmpty())) {
                    tr.addAll(finalCommands);
                  }
                  tr.add(ex);
                  ret.add(new DoWhileItem(null,lc,retChecked,tr));
                  ret.addAll(ifi.onTrue);
                  chwt=false;
                }
              }
            }
          }
        }
        if (chwt) {
          ret.add(new WhileItem(null,lc,trueExp,retChecked));
        }
      }
 else {
        ret.addAll(retChecked);
      }
      return ret;
    }
 else {
      if (lc != null) {
        loops.remove(lc);
      }
    }
    if (((part.nextParts.size() == 2) || ((part.nextParts.size() == 1) && loop))) {
      boolean doWhile=loop;
      if (loop && output.isEmpty()) {
        doWhile=false;
      }
      Loop currentLoop=null;
      if (loop) {
        currentLoop=new Loop(loops.size(),part,null);
        loops.add(currentLoop);
      }
      if ((!whileTrue) && loop && (part.nextParts.size() > 1)&& (!doWhile)) {
        currentLoop.loopBreak=part.nextParts.get(reversed ? 0 : 1);
      }
      forFinalCommands.put(currentLoop,new ArrayList<GraphTargetItem>());
      GraphTargetItem expr=null;
      if (part.nextParts.size() == 1) {
        expr=new TrueItem(null);
      }
 else {
        if (!stack.isEmpty()) {
          expr=stack.pop();
        }
      }
      if (doWhile) {
      }
 else {
        ret.addAll(output);
      }
      if (loop) {
        GraphPart f=expr.getFirstPart();
        if (f != null) {
          currentLoop.loopContinue=f;
        }
      }
      GraphPart loopBodyStart=null;
      if ((reversed == loop) || doWhile) {
        if (expr instanceof LogicalOpItem) {
          expr=((LogicalOpItem)expr).invert();
        }
 else {
          expr=new NotItem(null,expr);
        }
      }
      loopContinues=getLoopsContinues(loops);
      GraphPart next=part.getNextPartPath(loopContinues);
      List<GraphTargetItem> retx=ret;
      if ((!loop) || (doWhile && (part.nextParts.size() > 1))) {
        if (doWhile) {
          retx=output;
        }
        int stackSizeBefore=stack.size();
        Stack<GraphTargetItem> trueStack=(Stack<GraphTargetItem>)stack.clone();
        Stack<GraphTargetItem> falseStack=(Stack<GraphTargetItem>)stack.clone();
        GraphTargetItem lopTrue=checkLoop(part.nextParts.get(1),stopPart,loops);
        GraphTargetItem lopFalse=null;
        if (next != part.nextParts.get(0)) {
          lopFalse=checkLoop(part.nextParts.get(0),stopPart,loops);
        }
        List<GraphTargetItem> onTrue=new ArrayList<GraphTargetItem>();
        if (lopTrue != null) {
          onTrue.add(lopTrue);
        }
 else {
          if (debugMode) {
            System.err.println("String_Node_Str" + part + "String_Node_Str");
          }
          onTrue=printGraph(visited,prepareBranchLocalData(localData),trueStack,allParts,part,part.nextParts.get(1),next == null ? stopPart : next,loops,forFinalCommands);
          if (debugMode) {
            System.err.println("String_Node_Str" + part + "String_Node_Str");
          }
        }
        List<GraphTargetItem> onFalse=new ArrayList<GraphTargetItem>();
        if ((!onTrue.isEmpty()) && onTrue.get(onTrue.size() - 1) instanceof ExitItem) {
          next=part.nextParts.get(0);
        }
 else {
          if (lopFalse != null) {
            onFalse.add(lopFalse);
          }
 else {
            if (debugMode) {
              System.err.println("String_Node_Str" + part + "String_Node_Str");
            }
            if ((next == part.nextParts.get(0)) || (part.nextParts.get(0).path.equals(part.path) || part.nextParts.get(0).path.length() < part.path.length())) {
              onFalse=new ArrayList<GraphTargetItem>();
            }
 else {
              onFalse=(printGraph(visited,prepareBranchLocalData(localData),falseStack,allParts,part,part.nextParts.get(0),next == null ? stopPart : next,loops,forFinalCommands));
            }
            if (debugMode) {
              System.err.println("String_Node_Str" + part + "String_Node_Str");
            }
          }
        }
        if (isEmpty(onTrue) && isEmpty(onFalse) && (trueStack.size() > stackSizeBefore)&& (falseStack.size() > stackSizeBefore)) {
          stack.push(new TernarOpItem(null,expr,trueStack.pop(),falseStack.pop()));
        }
 else {
          List<GraphTargetItem> retw=retx;
          if (whileTrue) {
            retw=new ArrayList<GraphTargetItem>();
            retw.add(new IfItem(null,expr,onTrue,onFalse));
            List<GraphTargetItem> body=new ArrayList<GraphTargetItem>();
            if (next != null) {
              body=printGraph(visited,prepareBranchLocalData(localData),stack,allParts,part,next,stopPart,loops,forFinalCommands);
            }
            retw.addAll(body);
            if (!retw.isEmpty()) {
              checkContinueAtTheEnd(retw,whileTrueLoop);
              List<GraphTargetItem> finalCommands=forFinalCommands.get(whileTrueLoop);
              IfItem ifi=null;
              if ((finalCommands != null) && !finalCommands.isEmpty()) {
                if (finalCommands.get(finalCommands.size() - 1) instanceof IfItem) {
                  ifi=(IfItem)finalCommands.get(finalCommands.size() - 1);
                  finalCommands.remove(finalCommands.size() - 1);
                }
              }
 else               if (retw.get(retw.size() - 1) instanceof IfItem) {
                ifi=(IfItem)retw.get(retw.size() - 1);
                retw.remove(retw.size() - 1);
              }
              if (ifi != null) {
                if (ifi.onFalse.isEmpty()) {
                  if (!ifi.onTrue.isEmpty()) {
                    if (ifi.onTrue.get(ifi.onTrue.size() - 1) instanceof ExitItem) {
                      whileTrue=false;
                      List<GraphTargetItem> tr=new ArrayList<GraphTargetItem>();
                      GraphTargetItem ex=ifi.expression;
                      if (ex instanceof LogicalOpItem) {
                        ex=((LogicalOpItem)ex).invert();
                      }
 else {
                        ex=new NotItem(null,ex);
                      }
                      if ((finalCommands != null) && (!finalCommands.isEmpty())) {
                        tr.addAll(finalCommands);
                      }
                      tr.add(ex);
                      retx.add(new DoWhileItem(null,whileTrueLoop,retw,tr));
                      retx.addAll(ifi.onTrue);
                      next=null;
                    }
                  }
                }
              }
            }
            if (whileTrue) {
              List<GraphTargetItem> tr=new ArrayList<GraphTargetItem>();
              tr.add(new TrueItem(null));
              retx.add(new WhileItem(null,whileTrueLoop,tr,retw));
              next=null;
            }
          }
 else {
            retx.add(new IfItem(null,expr,onTrue,onFalse));
          }
        }
        if (doWhile) {
          loopBodyStart=next;
        }
        if (whileTrue) {
          loopBodyStart=part;
        }
      }
      if (loop) {
        List<GraphTargetItem> loopBody=new ArrayList<GraphTargetItem>();
        List<GraphTargetItem> finalCommands=null;
        GraphPart finalPart=null;
        GraphTargetItem ti;
        if ((loopBodyStart != null) && ((ti=checkLoop(loopBodyStart,stopPart,loops)) != null)) {
          loopBody.add(ti);
        }
 else {
          if (!(doWhile && (loopBodyStart == null))) {
            loopBody=printGraph(visited,prepareBranchLocalData(localData),stack,allParts,part,loopBodyStart != null ? loopBodyStart : part.nextParts.get(reversed ? 1 : 0),stopPart,loops,forFinalCommands);
          }
        }
        checkContinueAtTheEnd(loopBody,currentLoop);
        finalCommands=forFinalCommands.get(currentLoop);
        if (!finalCommands.isEmpty()) {
          ret.add(new ForTreeItem(null,currentLoop,new ArrayList<GraphTargetItem>(),expr,finalCommands,loopBody));
        }
 else {
          if (doWhile) {
            if (stack.isEmpty() || (part.nextParts.size() == 1)) {
              expr=new TrueItem(null);
            }
 else {
              expr=stack.pop();
            }
            loopBody.addAll(0,output);
            if (part.nextParts.size() == 1) {
              loopBody.addAll(printGraph(visited,prepareBranchLocalData(localData),stack,allParts,part,part.nextParts.get(0),stopPart,loops,forFinalCommands));
            }
            checkContinueAtTheEnd(loopBody,currentLoop);
            List<GraphTargetItem> newBody=new ArrayList<GraphTargetItem>();
            List<GraphTargetItem> nextcmds=new ArrayList<GraphTargetItem>();
            if ((!loopBody.isEmpty()) && (loopBody.get(loopBody.size() - 1) instanceof IfItem)) {
              IfItem ift=(IfItem)loopBody.get(loopBody.size() - 1);
              if ((!ift.onFalse.isEmpty()) && (ift.onFalse.get(ift.onFalse.size() - 1) instanceof ExitItem)) {
                if (ift.expression != null) {
                  expr=ift.expression;
                }
                nextcmds=ift.onFalse;
                newBody=ift.onTrue;
                loopBody.remove(loopBody.size() - 1);
              }
 else               if ((!ift.onTrue.isEmpty()) && (ift.onTrue.get(ift.onTrue.size() - 1) instanceof ExitItem)) {
                if (ift.expression != null) {
                  expr=ift.expression;
                  if (expr instanceof LogicalOpItem) {
                    expr=((LogicalOpItem)expr).invert();
                  }
 else {
                    expr=new NotItem(null,expr);
                  }
                }
                newBody=ift.onFalse;
                nextcmds=ift.onTrue;
                loopBody.remove(loopBody.size() - 1);
                if (newBody.isEmpty()) {
                }
              }
            }
            checkContinueAtTheEnd(newBody,currentLoop);
            if ((!newBody.isEmpty()) && (!(newBody.get(0) instanceof ScriptEndItem))) {
              loopBody.add(expr);
              ret.add(new WhileItem(null,currentLoop,loopBody,newBody));
              ret.addAll(nextcmds);
            }
 else {
              List<GraphTargetItem> ex=new ArrayList<GraphTargetItem>();
              ex.add(expr);
              ret.add(new DoWhileItem(null,currentLoop,loopBody,ex));
              ret.addAll(nextcmds);
            }
          }
 else {
            List<GraphTargetItem> ex=new ArrayList<GraphTargetItem>();
            ex.add(expr);
            ret.add(new WhileItem(null,currentLoop,ex,loopBody));
          }
        }
      }
      if ((!doWhile) && (!whileTrue) && loop&& (part.nextParts.size() > 1)) {
        loops.remove(currentLoop);
        next=part.nextParts.get(reversed ? 0 : 1);
      }
      if (doWhile) {
        next=null;
      }
      if (next != null) {
        GraphTargetItem ti=checkLoop(next,stopPart,loops);
        if (ti != null) {
          ret.add(ti);
        }
 else {
          if (debugMode) {
            System.err.println("String_Node_Str" + part + "String_Node_Str");
          }
          ret.addAll(printGraph(visited,localData,stack,allParts,part,next,stopPart,loops,forFinalCommands));
          if (debugMode) {
            System.err.println("String_Node_Str" + part + "String_Node_Str");
          }
        }
      }
    }
 else {
      ret.addAll(output);
    }
    onepart:     if (part.nextParts.size() == 1 && (!loop)) {
      GraphPart p=part.nextParts.get(0);
      GraphTargetItem lop=checkLoop(p,stopPart,loops);
      if (lop == null) {
        if (p.path.length() >= part.path.length()) {
          ret.addAll(printGraph(visited,localData,stack,allParts,part,p,stopPart,loops,forFinalCommands));
        }
 else {
          if ((p != stopPart) && (p.refs.size() > 1)) {
            List<GraphPart> nextList=new ArrayList<GraphPart>();
            populateParts(p,nextList);
            Loop nearestLoop=null;
            loopn:             for (            GraphPart n : nextList) {
              for (              Loop l : loops) {
                if (l.loopContinue == n) {
                  nearestLoop=l;
                  break loopn;
                }
              }
            }
            if ((nearestLoop != null)) {
              List<GraphTargetItem> finalCommands=printGraph(visited,localData,stack,allParts,part,p,nearestLoop.loopContinue,loops,forFinalCommands);
              nearestLoop.loopContinue=p;
              forFinalCommands.put(nearestLoop,finalCommands);
              ContinueItem cti=new ContinueItem(null,nearestLoop.id);
              ret.add(cti);
            }
          }
        }
      }
 else {
        ret.add(lop);
      }
    }
    return ret;
  }
 catch (  StackOverflowError soe) {
    ret.add(new CommentTreeItem(null,"String_Node_Str"));
    Logger.getLogger(Graph.class.getName()).log(Level.SEVERE,"String_Node_Str",soe);
    return ret;
  }
}

Fixed version (ground truth):
protected List<GraphTargetItem> printGraph(List<GraphPart> visited,List localData,Stack<GraphTargetItem> stack,List<GraphPart> allParts,GraphPart parent,GraphPart part,GraphPart stopPart,List<Loop> loops,HashMap<Loop,List<GraphTargetItem>> forFinalCommands){
  if (visited.contains(part)) {
  }
 else {
    visited.add(part);
  }
  List<GraphTargetItem> ret=new ArrayList<GraphTargetItem>();
  try {
    boolean debugMode=false;
    if (debugMode) {
      System.err.println("String_Node_Str" + part);
    }
    while (((part != null) && (part.getHeight() == 1)) && (code.size() > part.start) && (code.get(part.start).isJump())) {
      if (part == stopPart) {
        return ret;
      }
      GraphTargetItem lop=checkLoop(part.nextParts.get(0),stopPart,loops);
      if (lop == null) {
        part=part.nextParts.get(0);
      }
 else {
        break;
      }
    }
    if ((part != null) && (code.size() <= part.start)) {
      ret.add(new ScriptEndItem());
      return ret;
    }
    if (part == stopPart) {
      return ret;
    }
    if (part == null) {
    }
    part=checkPart(localData,part);
    if (part == null) {
      return ret;
    }
    if (part.ignored) {
      return ret;
    }
    List<String> fqn=new ArrayList<String>();
    List<GraphTargetItem> output=new ArrayList<GraphTargetItem>();
    List<GraphPart> parts=new ArrayList<GraphPart>();
    if (part instanceof GraphPartMulti) {
      parts=((GraphPartMulti)part).parts;
    }
 else {
      parts.add(part);
    }
    boolean isIf=false;
    int end=part.end;
    for (    GraphPart p : parts) {
      end=p.end;
      int start=p.start;
      isIf=false;
      try {
        output.addAll(code.translatePart(p,localData,stack,start,end));
        if ((end >= code.size() - 1) && p.nextParts.isEmpty()) {
          output.add(new ScriptEndItem());
        }
      }
 catch (      Exception ex) {
        Logger.getLogger(Graph.class.getName()).log(Level.SEVERE,"String_Node_Str",ex);
        return ret;
      }
    }
    if (part.nextParts.size() == 2) {
      if (!stack.isEmpty()) {
        GraphTargetItem top=stack.peek();
        if (false) {
          stack.pop();
          if (top.toBoolean()) {
            ret.addAll(output);
            ret.addAll(printGraph(visited,localData,stack,allParts,parent,part.nextParts.get(0),stopPart,loops,forFinalCommands));
            return ret;
          }
 else {
            ret.addAll(output);
            ret.addAll(printGraph(visited,localData,stack,allParts,parent,part.nextParts.get(1),stopPart,loops,forFinalCommands));
            return ret;
          }
        }
 else {
        }
      }
 else {
      }
    }
    if (part.nextParts.size() == 2) {
      if (part.nextParts.get(0) == part.nextParts.get(1)) {
        if (!stack.isEmpty()) {
          GraphTargetItem expr=stack.pop();
          if (expr instanceof LogicalOpItem) {
            expr=((LogicalOpItem)expr).invert();
          }
 else {
            expr=new NotItem(null,expr);
          }
          output.add(new IfItem(null,expr,new ArrayList<GraphTargetItem>(),new ArrayList<GraphTargetItem>()));
        }
        part.nextParts.remove(0);
      }
    }
    if (part.nextParts.size() == 2) {
      if ((stack.size() >= 2) && (stack.get(stack.size() - 1) instanceof NotItem) && (((NotItem)(stack.get(stack.size() - 1))).getOriginal().getNotCoerced() == stack.get(stack.size() - 2).getNotCoerced())) {
        ret.addAll(output);
        GraphPart sp0=getNextNoJump(part.nextParts.get(0));
        GraphPart sp1=getNextNoJump(part.nextParts.get(1));
        boolean reversed=false;
        List<GraphPart> loopContinues=getLoopsContinues(loops);
        loopContinues.add(part);
        if (sp1.leadsTo(code,sp0,loopContinues)) {
        }
 else         if (sp0.leadsTo(code,sp1,loopContinues)) {
          reversed=true;
        }
        GraphPart next=reversed ? sp0 : sp1;
        GraphTargetItem ti;
        if ((ti=checkLoop(next,stopPart,loops)) != null) {
          ret.add(ti);
        }
 else {
          printGraph(visited,localData,stack,allParts,parent,next,reversed ? sp1 : sp0,new ArrayList<Loop>(),forFinalCommands);
          GraphTargetItem second=stack.pop();
          GraphTargetItem first=stack.pop();
          if (!reversed) {
            AndItem a=new AndItem(null,first,second);
            stack.push(a);
            a.firstPart=part;
            if (second instanceof AndItem) {
              a.firstPart=((AndItem)second).firstPart;
            }
            if (second instanceof OrItem) {
              a.firstPart=((OrItem)second).firstPart;
            }
          }
 else {
            OrItem o=new OrItem(null,first,second);
            stack.push(o);
            o.firstPart=part;
            if (second instanceof AndItem) {
              o.firstPart=((AndItem)second).firstPart;
            }
            if (second instanceof OrItem) {
              o.firstPart=((OrItem)second).firstPart;
            }
          }
          next=reversed ? sp1 : sp0;
          if ((ti=checkLoop(next,stopPart,loops)) != null) {
            ret.add(ti);
          }
 else {
            ret.addAll(printGraph(visited,localData,stack,allParts,parent,next,stopPart,loops,forFinalCommands));
          }
        }
        return ret;
      }
 else       if ((stack.size() >= 2) && (stack.get(stack.size() - 1).getNotCoerced() == stack.get(stack.size() - 2).getNotCoerced())) {
        ret.addAll(output);
        GraphPart sp0=getNextNoJump(part.nextParts.get(0));
        GraphPart sp1=getNextNoJump(part.nextParts.get(1));
        boolean reversed=false;
        List<GraphPart> loopContinues=getLoopsContinues(loops);
        loopContinues.add(part);
        if (sp1.leadsTo(code,sp0,loopContinues)) {
        }
 else         if (sp0.leadsTo(code,sp1,loopContinues)) {
          reversed=true;
        }
        GraphPart next=reversed ? sp0 : sp1;
        GraphTargetItem ti;
        if ((ti=checkLoop(next,stopPart,loops)) != null) {
          ret.add(ti);
        }
 else {
          printGraph(visited,localData,stack,allParts,parent,next,reversed ? sp1 : sp0,new ArrayList<Loop>(),forFinalCommands);
          GraphTargetItem second=stack.pop();
          GraphTargetItem first=stack.pop();
          if (reversed) {
            AndItem a=new AndItem(null,first,second);
            stack.push(a);
            a.firstPart=part;
            if (second instanceof AndItem) {
              a.firstPart=((AndItem)second).firstPart;
            }
            if (second instanceof OrItem) {
              a.firstPart=((AndItem)second).firstPart;
            }
          }
 else {
            OrItem o=new OrItem(null,first,second);
            stack.push(o);
            o.firstPart=part;
            if (second instanceof OrItem) {
              o.firstPart=((OrItem)second).firstPart;
            }
            if (second instanceof OrItem) {
              o.firstPart=((OrItem)second).firstPart;
            }
          }
          next=reversed ? sp1 : sp0;
          if ((ti=checkLoop(next,stopPart,loops)) != null) {
            ret.add(ti);
          }
 else {
            ret.addAll(printGraph(visited,localData,stack,allParts,parent,next,stopPart,loops,forFinalCommands));
          }
        }
        return ret;
      }
    }
    List<GraphPart> loopContinues=getLoopsContinues(loops);
    boolean loop=false;
    boolean reversed=false;
    boolean whileTrue=false;
    Loop whileTrueLoop=null;
    if ((!part.nextParts.isEmpty()) && part.nextParts.get(0).leadsTo(code,part,loopContinues)) {
      if ((part.nextParts.size() > 1) && part.nextParts.get(1).leadsTo(code,part,loopContinues)) {
        if (output.isEmpty()) {
          whileTrueLoop=new Loop(loops.size(),part,null);
          loops.add(whileTrueLoop);
          whileTrue=true;
        }
 else {
          loop=true;
        }
      }
 else {
        loop=true;
      }
    }
 else     if ((part.nextParts.size() > 1) && part.nextParts.get(1).leadsTo(code,part,loopContinues)) {
      loop=true;
      reversed=true;
    }
    Loop lc=null;
    if (part.leadsTo(code,part,loopContinues)) {
      lc=new Loop(loops.size(),part,null);
      loops.add(lc);
    }
    List<GraphTargetItem> retChecked=null;
    if ((retChecked=check(code,localData,allParts,stack,parent,part,stopPart,loops,output,forFinalCommands)) != null) {
      if (lc != null) {
        List<GraphTargetItem> trueExp=new ArrayList<GraphTargetItem>();
        trueExp.add(new TrueItem(null));
        boolean chwt=true;
        if (!retChecked.isEmpty()) {
          checkContinueAtTheEnd(retChecked,lc);
          List<GraphTargetItem> finalCommands=forFinalCommands.get(lc);
          IfItem ifi=null;
          if ((finalCommands != null) && !finalCommands.isEmpty()) {
            if (finalCommands.get(finalCommands.size() - 1) instanceof IfItem) {
              ifi=(IfItem)finalCommands.get(finalCommands.size() - 1);
              finalCommands.remove(finalCommands.size() - 1);
            }
          }
 else           if (retChecked.get(retChecked.size() - 1) instanceof IfItem) {
            ifi=(IfItem)retChecked.get(retChecked.size() - 1);
            retChecked.remove(retChecked.size() - 1);
          }
          if (ifi != null) {
            if (ifi.onFalse.isEmpty()) {
              if (!ifi.onTrue.isEmpty()) {
                if (ifi.onTrue.get(ifi.onTrue.size() - 1) instanceof ExitItem) {
                  whileTrue=false;
                  List<GraphTargetItem> tr=new ArrayList<GraphTargetItem>();
                  GraphTargetItem ex=ifi.expression;
                  if (ex instanceof LogicalOpItem) {
                    ex=((LogicalOpItem)ex).invert();
                  }
 else {
                    ex=new NotItem(null,ex);
                  }
                  if ((finalCommands != null) && (!finalCommands.isEmpty())) {
                    tr.addAll(finalCommands);
                  }
                  tr.add(ex);
                  ret.add(new DoWhileItem(null,lc,retChecked,tr));
                  ret.addAll(ifi.onTrue);
                  chwt=false;
                }
              }
            }
          }
        }
        if (chwt) {
          ret.add(new WhileItem(null,lc,trueExp,retChecked));
        }
      }
 else {
        ret.addAll(retChecked);
      }
      return ret;
    }
 else {
      if (lc != null) {
        loops.remove(lc);
      }
    }
    if (((part.nextParts.size() == 2) || ((part.nextParts.size() == 1) && loop))) {
      boolean doWhile=loop;
      if (loop && output.isEmpty()) {
        doWhile=false;
      }
      Loop currentLoop=null;
      if (loop) {
        currentLoop=new Loop(loops.size(),part,null);
        loops.add(currentLoop);
      }
      if ((!whileTrue) && loop && (part.nextParts.size() > 1)&& (!doWhile)) {
        currentLoop.loopBreak=part.nextParts.get(reversed ? 0 : 1);
      }
      forFinalCommands.put(currentLoop,new ArrayList<GraphTargetItem>());
      GraphTargetItem expr=null;
      if (part.nextParts.size() == 1) {
        expr=new TrueItem(null);
      }
 else {
        if (!stack.isEmpty()) {
          expr=stack.pop();
        }
      }
      if (doWhile) {
      }
 else {
        ret.addAll(output);
      }
      if (loop) {
        GraphPart f=expr.getFirstPart();
        if (f != null) {
          currentLoop.loopContinue=f;
        }
      }
      GraphPart loopBodyStart=null;
      if ((reversed == loop) || doWhile) {
        if (expr instanceof LogicalOpItem) {
          expr=((LogicalOpItem)expr).invert();
        }
 else {
          expr=new NotItem(null,expr);
        }
      }
      loopContinues=getLoopsContinues(loops);
      GraphPart next=part.getNextPartPath(loopContinues);
      List<GraphTargetItem> retx=ret;
      if ((!loop) || (doWhile && (part.nextParts.size() > 1))) {
        if (doWhile) {
          retx=output;
        }
        int stackSizeBefore=stack.size();
        Stack<GraphTargetItem> trueStack=(Stack<GraphTargetItem>)stack.clone();
        Stack<GraphTargetItem> falseStack=(Stack<GraphTargetItem>)stack.clone();
        GraphTargetItem lopTrue=checkLoop(part.nextParts.get(1),stopPart,loops);
        GraphTargetItem lopFalse=null;
        if (next != part.nextParts.get(0)) {
          lopFalse=checkLoop(part.nextParts.get(0),stopPart,loops);
        }
        List<GraphTargetItem> onTrue=new ArrayList<GraphTargetItem>();
        if (lopTrue != null) {
          onTrue.add(lopTrue);
        }
 else {
          if (debugMode) {
            System.err.println("String_Node_Str" + part + "String_Node_Str");
          }
          onTrue=printGraph(visited,prepareBranchLocalData(localData),trueStack,allParts,part,part.nextParts.get(1),next == null ? stopPart : next,loops,forFinalCommands);
          if (debugMode) {
            System.err.println("String_Node_Str" + part + "String_Node_Str");
          }
        }
        List<GraphTargetItem> onFalse=new ArrayList<GraphTargetItem>();
        if ((!onTrue.isEmpty()) && onTrue.get(onTrue.size() - 1) instanceof ExitItem) {
          next=part.nextParts.get(0);
        }
 else {
          if (lopFalse != null) {
            onFalse.add(lopFalse);
          }
 else {
            if (debugMode) {
              System.err.println("String_Node_Str" + part + "String_Node_Str");
            }
            if ((next == part.nextParts.get(0)) || (part.nextParts.get(0).path.equals(part.path) || part.nextParts.get(0).path.length() < part.path.length())) {
              onFalse=new ArrayList<GraphTargetItem>();
            }
 else {
              onFalse=(printGraph(visited,prepareBranchLocalData(localData),falseStack,allParts,part,part.nextParts.get(0),next == null ? stopPart : next,loops,forFinalCommands));
            }
            if (debugMode) {
              System.err.println("String_Node_Str" + part + "String_Node_Str");
            }
          }
        }
        if (isEmpty(onTrue) && isEmpty(onFalse) && (trueStack.size() > stackSizeBefore)&& (falseStack.size() > stackSizeBefore)) {
          stack.push(new TernarOpItem(null,expr,trueStack.pop(),falseStack.pop()));
        }
 else {
          List<GraphTargetItem> retw=retx;
          if (whileTrue) {
            retw=new ArrayList<GraphTargetItem>();
            retw.add(new IfItem(null,expr,onTrue,onFalse));
            List<GraphTargetItem> body=new ArrayList<GraphTargetItem>();
            if (next != null) {
              body=printGraph(visited,prepareBranchLocalData(localData),stack,allParts,part,next,stopPart,loops,forFinalCommands);
            }
            retw.addAll(body);
            if (!retw.isEmpty()) {
              checkContinueAtTheEnd(retw,whileTrueLoop);
              List<GraphTargetItem> finalCommands=forFinalCommands.get(whileTrueLoop);
              IfItem ifi=null;
              if ((finalCommands != null) && !finalCommands.isEmpty()) {
                if (finalCommands.get(finalCommands.size() - 1) instanceof IfItem) {
                  ifi=(IfItem)finalCommands.get(finalCommands.size() - 1);
                  finalCommands.remove(finalCommands.size() - 1);
                }
              }
 else               if (retw.get(retw.size() - 1) instanceof IfItem) {
                ifi=(IfItem)retw.get(retw.size() - 1);
                retw.remove(retw.size() - 1);
              }
              if (ifi != null) {
                if (ifi.onFalse.isEmpty()) {
                  if (!ifi.onTrue.isEmpty()) {
                    if (ifi.onTrue.get(ifi.onTrue.size() - 1) instanceof ExitItem) {
                      whileTrue=false;
                      List<GraphTargetItem> tr=new ArrayList<GraphTargetItem>();
                      GraphTargetItem ex=ifi.expression;
                      if (ex instanceof LogicalOpItem) {
                        ex=((LogicalOpItem)ex).invert();
                      }
 else {
                        ex=new NotItem(null,ex);
                      }
                      if ((finalCommands != null) && (!finalCommands.isEmpty())) {
                        tr.addAll(finalCommands);
                      }
                      tr.add(ex);
                      retx.add(new DoWhileItem(null,whileTrueLoop,retw,tr));
                      retx.addAll(ifi.onTrue);
                      next=null;
                    }
                  }
                }
              }
            }
            if (whileTrue) {
              List<GraphTargetItem> tr=new ArrayList<GraphTargetItem>();
              tr.add(new TrueItem(null));
              retx.add(new WhileItem(null,whileTrueLoop,tr,retw));
              next=null;
            }
          }
 else {
            retx.add(new IfItem(null,expr,onTrue,onFalse));
          }
        }
        if (doWhile) {
          loopBodyStart=next;
        }
        if (whileTrue) {
          loopBodyStart=part;
        }
      }
      if (loop) {
        List<GraphTargetItem> loopBody=new ArrayList<GraphTargetItem>();
        List<GraphTargetItem> finalCommands=null;
        GraphPart finalPart=null;
        GraphTargetItem ti;
        if ((loopBodyStart != null) && ((ti=checkLoop(loopBodyStart,stopPart,loops)) != null)) {
          loopBody.add(ti);
        }
 else {
          if (!(doWhile && (loopBodyStart == null))) {
            loopBody=printGraph(visited,prepareBranchLocalData(localData),stack,allParts,part,loopBodyStart != null ? loopBodyStart : part.nextParts.get(reversed ? 1 : 0),stopPart,loops,forFinalCommands);
          }
        }
        checkContinueAtTheEnd(loopBody,currentLoop);
        finalCommands=forFinalCommands.get(currentLoop);
        checkContinueAtTheEnd(finalCommands,currentLoop);
        if (!finalCommands.isEmpty()) {
          ret.add(new ForTreeItem(null,currentLoop,new ArrayList<GraphTargetItem>(),expr,finalCommands,loopBody));
        }
 else {
          if (doWhile) {
            if (stack.isEmpty() || (part.nextParts.size() == 1)) {
              expr=new TrueItem(null);
            }
 else {
              expr=stack.pop();
            }
            loopBody.addAll(0,output);
            if (part.nextParts.size() == 1) {
              loopBody.addAll(printGraph(visited,prepareBranchLocalData(localData),stack,allParts,part,part.nextParts.get(0),stopPart,loops,forFinalCommands));
            }
            checkContinueAtTheEnd(loopBody,currentLoop);
            List<GraphTargetItem> newBody=new ArrayList<GraphTargetItem>();
            List<GraphTargetItem> nextcmds=new ArrayList<GraphTargetItem>();
            if ((!loopBody.isEmpty()) && (loopBody.get(loopBody.size() - 1) instanceof IfItem)) {
              IfItem ift=(IfItem)loopBody.get(loopBody.size() - 1);
              if ((!ift.onFalse.isEmpty()) && (ift.onFalse.get(ift.onFalse.size() - 1) instanceof ExitItem)) {
                if (ift.expression != null) {
                  expr=ift.expression;
                }
                nextcmds=ift.onFalse;
                newBody=ift.onTrue;
                loopBody.remove(loopBody.size() - 1);
              }
 else               if ((!ift.onTrue.isEmpty()) && (ift.onTrue.get(ift.onTrue.size() - 1) instanceof ExitItem)) {
                if (ift.expression != null) {
                  expr=ift.expression;
                  if (expr instanceof LogicalOpItem) {
                    expr=((LogicalOpItem)expr).invert();
                  }
 else {
                    expr=new NotItem(null,expr);
                  }
                }
                newBody=ift.onFalse;
                nextcmds=ift.onTrue;
                loopBody.remove(loopBody.size() - 1);
                if (newBody.isEmpty()) {
                }
              }
            }
            checkContinueAtTheEnd(newBody,currentLoop);
            if ((!newBody.isEmpty()) && (!(newBody.get(0) instanceof ScriptEndItem))) {
              loopBody.add(expr);
              ret.add(new WhileItem(null,currentLoop,loopBody,newBody));
              ret.addAll(nextcmds);
            }
 else {
              List<GraphTargetItem> ex=new ArrayList<GraphTargetItem>();
              ex.add(expr);
              ret.add(new DoWhileItem(null,currentLoop,loopBody,ex));
              ret.addAll(nextcmds);
            }
          }
 else {
            List<GraphTargetItem> ex=new ArrayList<GraphTargetItem>();
            ex.add(expr);
            ret.add(new WhileItem(null,currentLoop,ex,loopBody));
          }
        }
      }
      if ((!doWhile) && (!whileTrue) && loop&& (part.nextParts.size() > 1)) {
        loops.remove(currentLoop);
        next=part.nextParts.get(reversed ? 0 : 1);
      }
      if (doWhile) {
        next=null;
      }
      if (next != null) {
        GraphTargetItem ti=checkLoop(next,stopPart,loops);
        if (ti != null) {
          ret.add(ti);
        }
 else {
          if (debugMode) {
            System.err.println("String_Node_Str" + part + "String_Node_Str");
          }
          ret.addAll(printGraph(visited,localData,stack,allParts,part,next,stopPart,loops,forFinalCommands));
          if (debugMode) {
            System.err.println("String_Node_Str" + part + "String_Node_Str");
          }
        }
      }
    }
 else {
      ret.addAll(output);
    }
    onepart:     if (part.nextParts.size() == 1 && (!loop)) {
      GraphPart p=part.nextParts.get(0);
      GraphTargetItem lop=checkLoop(p,stopPart,loops);
      if (lop == null) {
        if (p.path.length() >= part.path.length()) {
          ret.addAll(printGraph(visited,localData,stack,allParts,part,p,stopPart,loops,forFinalCommands));
        }
 else {
          if ((p != stopPart) && (p.refs.size() > 1)) {
            List<GraphPart> nextList=new ArrayList<GraphPart>();
            populateParts(p,nextList);
            Loop nearestLoop=null;
            loopn:             for (            GraphPart n : nextList) {
              for (              Loop l : loops) {
                if (l.loopContinue == n) {
                  nearestLoop=l;
                  break loopn;
                }
              }
            }
            if ((nearestLoop != null)) {
              GraphPart oldCont=nearestLoop.loopContinue;
              nearestLoop.loopContinue=p;
              List<GraphTargetItem> finalCommands=printGraph(visited,localData,stack,allParts,part,p,oldCont,loops,forFinalCommands);
              forFinalCommands.put(nearestLoop,finalCommands);
              ContinueItem cti=new ContinueItem(null,nearestLoop.id);
              ret.add(cti);
            }
          }
        }
      }
 else {
        ret.add(lop);
      }
    }
    return ret;
  }
 catch (  StackOverflowError soe) {
    ret.add(new CommentTreeItem(null,"String_Node_Str"));
    Logger.getLogger(Graph.class.getName()).log(Level.SEVERE,"String_Node_Str",soe);
    return ret;
  }
}