Program: 61589
Project: 61589
Buggy source:
protected List<GraphTargetItem> printGraph(List<GraphPart> visited,BaseLocalData localData,TranslateStack stack,List<GraphPart> allParts,GraphPart parent,GraphPart part,List<GraphPart> stopPart,List<Loop> loops,List<GraphTargetItem> ret,int staticOperation,String path,int recursionLevel) throws InterruptedException {
  if (Thread.currentThread().isInterrupted()) {
    throw new InterruptedException();
  }
  if (stopPart == null) {
    stopPart=new ArrayList<>();
  }
  if (recursionLevel > allParts.size() + 1) {
    throw new TranslateException("String_Node_Str");
  }
  if (visited.contains(part)) {
  }
 else {
    visited.add(part);
  }
  if (ret == null) {
    ret=new ArrayList<>();
  }
  boolean debugMode=false;
  if (debugMode) {
    System.err.println("String_Node_Str" + part + "String_Node_Str"+ part.nextParts.size());
  }
  if (part == null) {
    return ret;
  }
  part=checkPart(stack,localData,part,allParts);
  if (part == null) {
    return ret;
  }
  if (part.ignored) {
    return ret;
  }
  List<GraphPart> loopContinues=getLoopsContinues(loops);
  boolean isLoop=false;
  Loop currentLoop=null;
  for (  Loop el : loops) {
    if ((el.loopContinue == part) && (el.phase == 0)) {
      currentLoop=el;
      currentLoop.phase=1;
      isLoop=true;
      break;
    }
  }
  if (debugMode) {
    System.err.println("String_Node_Str" + loops.size());
  }
  for (int l=loops.size() - 1; l >= 0; l--) {
    Loop el=loops.get(l);
    if (el == currentLoop) {
      if (debugMode) {
        System.err.println("String_Node_Str" + el);
      }
      continue;
    }
    if (el.phase != 1) {
      if (debugMode) {
      }
      continue;
    }
    if (el.loopBreak == part) {
      if (currentLoop != null) {
        currentLoop.phase=0;
      }
      if (debugMode) {
        System.err.println("String_Node_Str");
      }
      ret.add(new BreakItem(null,el.id));
      return ret;
    }
    if (el.loopPreContinue == part) {
      if (currentLoop != null) {
        currentLoop.phase=0;
      }
      if (debugMode) {
        System.err.println("String_Node_Str");
      }
      ret.add(new ContinueItem(null,el.id));
      return ret;
    }
    if (el.loopContinue == part) {
      if (currentLoop != null) {
        currentLoop.phase=0;
      }
      if (debugMode) {
        System.err.println("String_Node_Str");
      }
      ret.add(new ContinueItem(null,el.id));
      return ret;
    }
  }
  if (stopPart.contains(part)) {
    if (currentLoop != null) {
      currentLoop.phase=0;
    }
switch (part.stopPartType) {
case AND_OR:
      part.setAndOrStack(stack);
    break;
case COMMONPART:
  part.setCommonPartStack(stack);
break;
case NONE:
break;
}
return ret;
}
if ((part != null) && (code.size() <= part.start)) {
ret.add(new ScriptEndItem());
return ret;
}
List<GraphTargetItem> currentRet=ret;
UniversalLoopItem loopItem=null;
if (isLoop) {
loopItem=new UniversalLoopItem(null,currentLoop);
currentRet.add(loopItem);
loopItem.commands=new ArrayList<>();
currentRet=loopItem.commands;
}
boolean parseNext=true;
List<GraphTargetItem> output=new ArrayList<>();
List<GraphPart> parts=new ArrayList<>();
if (part instanceof GraphPartMulti) {
parts=((GraphPartMulti)part).parts;
}
 else {
parts.add(part);
}
for (GraphPart p : parts) {
int end=p.end;
int start=p.start;
output.addAll(code.translatePart(p,localData,stack,start,end,staticOperation,path));
if ((end >= code.size() - 1) && p.nextParts.isEmpty()) {
output.add(new ScriptEndItem());
}
}
if (parseNext) {
List<GraphTargetItem> retCheck=check(code,localData,allParts,stack,parent,part,stopPart,loops,output,currentLoop,staticOperation,path);
if (retCheck != null) {
if (!retCheck.isEmpty()) {
currentRet.addAll(retCheck);
}
parseNext=false;
}
 else {
currentRet.addAll(output);
}
}
if (parseNext && 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())) {
GraphPart sp0=getNextNoJump(part.nextParts.get(0),localData);
GraphPart sp1=getNextNoJump(part.nextParts.get(1),localData);
boolean reversed=false;
loopContinues=getLoopsContinues(loops);
loopContinues.add(part);
if (sp1.leadsTo(localData,this,code,sp0,loops)) {
}
 else if (sp0.leadsTo(localData,this,code,sp1,loops)) {
reversed=true;
}
GraphPart next=reversed ? sp0 : sp1;
GraphTargetItem ti;
if ((ti=checkLoop(next,stopPart,loops)) != null) {
currentRet.add(ti);
}
 else {
List<GraphPart> stopPart2=new ArrayList<>(stopPart);
GraphPart andOrStopPart=reversed ? sp1 : sp0;
andOrStopPart.stopPartType=GraphPart.StopPartType.AND_OR;
stopPart2.add(andOrStopPart);
printGraph(visited,localData,stack,allParts,parent,next,stopPart2,loops,null,staticOperation,path,recursionLevel + 1);
stack=andOrStopPart.andOrStack;
GraphTargetItem second=stack.pop();
GraphTargetItem first=stack.pop();
andOrStopPart.stopPartType=GraphPart.StopPartType.NONE;
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) {
currentRet.add(ti);
}
 else {
currentRet.addAll(printGraph(visited,localData,stack,allParts,parent,next,stopPart,loops,null,staticOperation,path,recursionLevel + 1));
}
}
parseNext=false;
}
 else if ((stack.size() >= 2) && (stack.get(stack.size() - 1).getNotCoerced() == stack.get(stack.size() - 2).getNotCoerced())) {
GraphPart sp0=getNextNoJump(part.nextParts.get(0),localData);
GraphPart sp1=getNextNoJump(part.nextParts.get(1),localData);
boolean reversed=false;
loopContinues=getLoopsContinues(loops);
loopContinues.add(part);
if (sp1.leadsTo(localData,this,code,sp0,loops)) {
}
 else if (sp0.leadsTo(localData,this,code,sp1,loops)) {
reversed=true;
}
GraphPart next=reversed ? sp0 : sp1;
GraphTargetItem ti;
if ((ti=checkLoop(next,stopPart,loops)) != null) {
currentRet.add(ti);
}
 else {
List<GraphPart> stopPart2=new ArrayList<>(stopPart);
GraphPart andOrStopPart=reversed ? sp1 : sp0;
andOrStopPart.stopPartType=GraphPart.StopPartType.AND_OR;
stopPart2.add(andOrStopPart);
printGraph(visited,localData,stack,allParts,parent,next,stopPart2,loops,null,staticOperation,path,recursionLevel + 1);
stack=andOrStopPart.andOrStack;
GraphTargetItem second=stack.pop();
GraphTargetItem first=stack.pop();
andOrStopPart.stopPartType=GraphPart.StopPartType.NONE;
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) {
currentRet.add(ti);
}
 else {
currentRet.addAll(printGraph(visited,localData,stack,allParts,parent,next,stopPart,loops,null,staticOperation,path,recursionLevel + 1));
}
}
parseNext=false;
}
}
if (parseNext) {
if (false && part.nextParts.size() > 2) {
GraphPart next=getMostCommonPart(localData,part.nextParts,loops);
List<GraphPart> vis=new ArrayList<>();
GraphTargetItem switchedItem=stack.pop();
List<GraphTargetItem> caseValues=new ArrayList<>();
List<List<GraphTargetItem>> caseCommands=new ArrayList<>();
List<GraphTargetItem> defaultCommands=new ArrayList<>();
List<Integer> valueMappings=new ArrayList<>();
Loop swLoop=new Loop(loops.size(),null,next);
swLoop.phase=1;
loops.add(swLoop);
boolean first=false;
int pos=0;
for (GraphPart p : part.nextParts) {
if (!first) {
caseValues.add(new IntegerValueItem(null,pos++));
if (vis.contains(p)) {
  valueMappings.add(caseCommands.size() - 1);
  continue;
}
valueMappings.add(caseCommands.size());
}
List<GraphPart> stopPart2=new ArrayList<>();
if (next != null) {
stopPart2.add(next);
}
 else if (!stopPart.isEmpty()) {
stopPart2.add(stopPart.get(stopPart.size() - 1));
}
for (GraphPart p2 : part.nextParts) {
if (p2 == p) {
  continue;
}
if (!stopPart2.contains(p2)) {
  stopPart2.add(p2);
}
}
if (next != p) {
if (first) {
  defaultCommands=printGraph(visited,prepareBranchLocalData(localData),stack,allParts,part,p,stopPart2,loops,null,staticOperation,path,recursionLevel + 1);
}
 else {
  caseCommands.add(printGraph(visited,prepareBranchLocalData(localData),stack,allParts,part,p,stopPart2,loops,null,staticOperation,path,recursionLevel + 1));
}
vis.add(p);
}
first=false;
}
SwitchItem sw=new SwitchItem(null,swLoop,switchedItem,caseValues,caseCommands,defaultCommands,valueMappings);
currentRet.add(sw);
swLoop.phase=2;
if (next != null) {
currentRet.addAll(printGraph(visited,localData,stack,allParts,part,next,stopPart,loops,null,staticOperation,path,recursionLevel + 1));
}
}
GraphPart nextOnePart=null;
if (part.nextParts.size() == 2) {
GraphTargetItem expr=stack.pop();
if (expr instanceof LogicalOpItem) {
expr=((LogicalOpItem)expr).invert();
}
 else {
expr=new NotItem(null,expr);
}
if (staticOperation != SOP_USE_STATIC) {
if (expr.isCompileTime()) {
boolean doJump=EcmaScript.toBoolean(expr.getResult());
if (doJump) {
  nextOnePart=part.nextParts.get(0);
}
 else {
  nextOnePart=part.nextParts.get(1);
}
if (staticOperation == SOP_REMOVE_STATIC) {
}
}
}
if (nextOnePart == null) {
List<GraphPart> nps;
nps=part.nextParts;
GraphPart next=getCommonPart(localData,nps,loops);
TranslateStack trueStack=(TranslateStack)stack.clone();
TranslateStack falseStack=(TranslateStack)stack.clone();
int trueStackSizeBefore=trueStack.size();
int falseStackSizeBefore=falseStack.size();
List<GraphTargetItem> onTrue=new ArrayList<>();
boolean isEmpty=nps.get(0) == nps.get(1);
if (isEmpty) {
next=nps.get(0);
}
List<GraphPart> stopPart2=new ArrayList<>(stopPart);
GraphPart.CommonPartStack commonPartStack=null;
if ((!isEmpty) && (next != null)) {
commonPartStack=next.new CommonPartStack();
if (next.commonPartStacks == null) {
  next.commonPartStacks=new ArrayList<>();
}
next.stopPartType=GraphPart.StopPartType.COMMONPART;
stopPart2.add(next);
}
if (!isEmpty) {
if (next != null) {
  next.commonPartStacks.add(commonPartStack);
  commonPartStack.isTrueStack=true;
}
onTrue=printGraph(visited,prepareBranchLocalData(localData),trueStack,allParts,part,nps.get(1),stopPart2,loops,null,staticOperation,path,recursionLevel + 1);
}
List<GraphTargetItem> onFalse=new ArrayList<>();
if (!isEmpty) {
if (next != null) {
  commonPartStack.isTrueStack=false;
}
onFalse=printGraph(visited,prepareBranchLocalData(localData),falseStack,allParts,part,nps.get(0),stopPart2,loops,null,staticOperation,path,recursionLevel + 1);
}
if ((!isEmpty) && (next != null)) {
if ((commonPartStack.trueStack != null) && (commonPartStack.falseStack != null)) {
  trueStack=commonPartStack.trueStack;
  falseStack=commonPartStack.falseStack;
}
next.commonPartStacks.remove(next.commonPartStacks.size() - 1);
if (next.commonPartStacks.isEmpty()) {
  next.stopPartType=GraphPart.StopPartType.NONE;
}
}
if (isEmpty(onTrue) && isEmpty(onFalse) && (trueStack.size() == trueStackSizeBefore + 1)&& (falseStack.size() == falseStackSizeBefore + 1)) {
stack.push(new TernarOpItem(null,expr,trueStack.pop(),falseStack.pop()));
}
 else {
currentRet.add(new IfItem(null,expr,onTrue,onFalse));
}
if (next != null) {
if (trueStack.size() != trueStackSizeBefore || falseStack.size() != falseStackSizeBefore) {
  onTrue=printGraph(visited,localData,trueStack,allParts,part,next,stopPart,loops,null,staticOperation,path,recursionLevel + 1);
  onFalse=printGraph(visited,localData,falseStack,allParts,part,next,stopPart,loops,null,staticOperation,path,recursionLevel + 1);
  if (isEmpty(onTrue) && isEmpty(onFalse) && (trueStack.size() == trueStackSizeBefore + 1)&& (falseStack.size() == falseStackSizeBefore + 1)) {
    stack.push(new TernarOpItem(null,expr,trueStack.pop(),falseStack.pop()));
  }
 else {
    currentRet.add(new IfItem(null,expr,onTrue,onFalse));
  }
}
 else {
  printGraph(visited,localData,stack,allParts,part,next,stopPart,loops,currentRet,staticOperation,path,recursionLevel + 1);
}
}
}
}
if (part.nextParts.size() == 1) {
nextOnePart=part.nextParts.get(0);
}
if (nextOnePart != null) {
printGraph(visited,localData,stack,allParts,part,part.nextParts.get(0),stopPart,loops,currentRet,staticOperation,path,recursionLevel + 1);
}
}
if (isLoop) {
LoopItem li=loopItem;
boolean loopTypeFound=false;
boolean hasContinue=false;
processIfs(loopItem.commands);
checkContinueAtTheEnd(loopItem.commands,currentLoop);
List<ContinueItem> continues=loopItem.getContinues();
for (ContinueItem c : continues) {
if (c.loopId == currentLoop.id) {
hasContinue=true;
break;
}
}
if (!hasContinue) {
if (currentLoop.loopPreContinue != null) {
List<GraphPart> stopContPart=new ArrayList<>();
stopContPart.add(currentLoop.loopContinue);
GraphPart precoBackup=currentLoop.loopPreContinue;
currentLoop.loopPreContinue=null;
loopItem.commands.addAll(printGraph(visited,localData,new TranslateStack(),allParts,null,precoBackup,stopContPart,loops,null,staticOperation,path,recursionLevel + 1));
}
}
if (!loopTypeFound && (!loopItem.commands.isEmpty())) {
if (loopItem.commands.get(0) instanceof IfItem) {
IfItem ifi=(IfItem)loopItem.commands.get(0);
List<GraphTargetItem> bodyBranch=null;
boolean inverted=false;
boolean breakpos2=false;
if ((ifi.onTrue.size() == 1) && (ifi.onTrue.get(0) instanceof BreakItem)) {
BreakItem bi=(BreakItem)ifi.onTrue.get(0);
if (bi.loopId == currentLoop.id) {
  bodyBranch=ifi.onFalse;
  inverted=true;
}
}
 else if ((ifi.onFalse.size() == 1) && (ifi.onFalse.get(0) instanceof BreakItem)) {
BreakItem bi=(BreakItem)ifi.onFalse.get(0);
if (bi.loopId == currentLoop.id) {
  bodyBranch=ifi.onTrue;
}
}
 else if (loopItem.commands.size() == 2 && (loopItem.commands.get(1) instanceof BreakItem)) {
BreakItem bi=(BreakItem)loopItem.commands.get(1);
if (bi.loopId == currentLoop.id) {
  bodyBranch=ifi.onTrue;
  breakpos2=true;
}
}
if (bodyBranch != null) {
int index=ret.indexOf(loopItem);
ret.remove(index);
List<GraphTargetItem> exprList=new ArrayList<>();
GraphTargetItem expr=ifi.expression;
if (inverted) {
  if (expr instanceof LogicalOpItem) {
    expr=((LogicalOpItem)expr).invert();
  }
 else {
    expr=new NotItem(null,expr);
  }
}
exprList.add(expr);
List<GraphTargetItem> commands=new ArrayList<>();
commands.addAll(bodyBranch);
loopItem.commands.remove(0);
if (breakpos2) {
  loopItem.commands.remove(0);
}
commands.addAll(loopItem.commands);
checkContinueAtTheEnd(commands,currentLoop);
List<GraphTargetItem> finalComm=new ArrayList<>();
if (currentLoop.loopPreContinue != null) {
  GraphPart backup=currentLoop.loopPreContinue;
  currentLoop.loopPreContinue=null;
  List<GraphPart> stopPart2=new ArrayList<>(stopPart);
  stopPart2.add(currentLoop.loopContinue);
  finalComm=printGraph(visited,localData,new TranslateStack(),allParts,null,backup,stopPart2,loops,null,staticOperation,path,recursionLevel + 1);
  currentLoop.loopPreContinue=backup;
  checkContinueAtTheEnd(finalComm,currentLoop);
}
if (!finalComm.isEmpty()) {
  ret.add(index,li=new ForItem(null,currentLoop,new ArrayList<GraphTargetItem>(),exprList.get(exprList.size() - 1),finalComm,commands));
}
 else {
  ret.add(index,li=new WhileItem(null,currentLoop,exprList,commands));
}
loopTypeFound=true;
}
}
}
if (!loopTypeFound && (!loopItem.commands.isEmpty())) {
if (loopItem.commands.get(loopItem.commands.size() - 1) instanceof IfItem) {
IfItem ifi=(IfItem)loopItem.commands.get(loopItem.commands.size() - 1);
List<GraphTargetItem> bodyBranch=null;
boolean inverted=false;
if ((ifi.onTrue.size() == 1) && (ifi.onTrue.get(0) instanceof BreakItem)) {
BreakItem bi=(BreakItem)ifi.onTrue.get(0);
if (bi.loopId == currentLoop.id) {
  bodyBranch=ifi.onFalse;
  inverted=true;
}
}
 else if ((ifi.onFalse.size() == 1) && (ifi.onFalse.get(0) instanceof BreakItem)) {
BreakItem bi=(BreakItem)ifi.onFalse.get(0);
if (bi.loopId == currentLoop.id) {
  bodyBranch=ifi.onTrue;
}
}
if (bodyBranch != null) {
int index=ret.indexOf(loopItem);
ret.remove(index);
List<GraphTargetItem> exprList=new ArrayList<>();
GraphTargetItem expr=ifi.expression;
if (inverted) {
  if (expr instanceof LogicalOpItem) {
    expr=((LogicalOpItem)expr).invert();
  }
 else {
    expr=new NotItem(null,expr);
  }
}
checkContinueAtTheEnd(bodyBranch,currentLoop);
List<GraphTargetItem> commands=new ArrayList<>();
if (!bodyBranch.isEmpty()) {
  ret.add(index,loopItem);
}
 else {
  loopItem.commands.remove(loopItem.commands.size() - 1);
  commands.addAll(loopItem.commands);
  commands.addAll(bodyBranch);
  exprList.add(expr);
  checkContinueAtTheEnd(commands,currentLoop);
  ret.add(index,li=new DoWhileItem(null,currentLoop,commands,exprList));
}
loopTypeFound=true;
}
}
}
if (!loopTypeFound) {
if (currentLoop.loopPreContinue != null) {
loopTypeFound=true;
GraphPart backup=currentLoop.loopPreContinue;
currentLoop.loopPreContinue=null;
List<GraphPart> stopPart2=new ArrayList<>(stopPart);
stopPart2.add(currentLoop.loopContinue);
List<GraphTargetItem> finalComm=printGraph(visited,localData,new TranslateStack(),allParts,null,backup,stopPart2,loops,null,staticOperation,path,recursionLevel + 1);
currentLoop.loopPreContinue=backup;
checkContinueAtTheEnd(finalComm,currentLoop);
if (!finalComm.isEmpty()) {
if (finalComm.get(finalComm.size() - 1) instanceof IfItem) {
  IfItem ifi=(IfItem)finalComm.get(finalComm.size() - 1);
  boolean ok=false;
  boolean invert=false;
  if (((ifi.onTrue.size() == 1) && (ifi.onTrue.get(0) instanceof BreakItem) && (((BreakItem)ifi.onTrue.get(0)).loopId == currentLoop.id)) && ((ifi.onTrue.size() == 1) && (ifi.onFalse.get(0) instanceof ContinueItem) && (((ContinueItem)ifi.onFalse.get(0)).loopId == currentLoop.id))) {
    ok=true;
    invert=true;
  }
  if (((ifi.onTrue.size() == 1) && (ifi.onTrue.get(0) instanceof ContinueItem) && (((ContinueItem)ifi.onTrue.get(0)).loopId == currentLoop.id)) && ((ifi.onTrue.size() == 1) && (ifi.onFalse.get(0) instanceof BreakItem) && (((BreakItem)ifi.onFalse.get(0)).loopId == currentLoop.id))) {
    ok=true;
  }
  if (ok) {
    finalComm.remove(finalComm.size() - 1);
    int index=ret.indexOf(loopItem);
    ret.remove(index);
    List<GraphTargetItem> exprList=new ArrayList<>(finalComm);
    GraphTargetItem expr=ifi.expression;
    if (invert) {
      if (expr instanceof LogicalOpItem) {
        expr=((LogicalOpItem)expr).invert();
      }
 else {
        expr=new NotItem(null,expr);
      }
    }
    exprList.add(expr);
    ret.add(index,li=new DoWhileItem(null,currentLoop,loopItem.commands,exprList));
  }
}
}
}
}
if (!loopTypeFound) {
checkContinueAtTheEnd(loopItem.commands,currentLoop);
}
currentLoop.phase=2;
GraphTargetItem replaced=checkLoop(li,localData,loops);
if (replaced != li) {
int index=ret.indexOf(li);
ret.remove(index);
if (replaced != null) {
ret.add(index,replaced);
}
}
if (currentLoop.loopBreak != null) {
ret.addAll(printGraph(visited,localData,stack,allParts,part,currentLoop.loopBreak,stopPart,loops,null,staticOperation,path,recursionLevel + 1));
}
}
return ret;
}

Fixed version (ground truth):
protected List<GraphTargetItem> printGraph(List<GraphPart> visited,BaseLocalData localData,TranslateStack stack,List<GraphPart> allParts,GraphPart parent,GraphPart part,List<GraphPart> stopPart,List<Loop> loops,List<GraphTargetItem> ret,int staticOperation,String path,int recursionLevel) throws InterruptedException {
  if (Thread.currentThread().isInterrupted()) {
    throw new InterruptedException();
  }
  if (stopPart == null) {
    stopPart=new ArrayList<>();
  }
  if (recursionLevel > allParts.size() + 1) {
    throw new TranslateException("String_Node_Str");
  }
  if (visited.contains(part)) {
  }
 else {
    visited.add(part);
  }
  if (ret == null) {
    ret=new ArrayList<>();
  }
  boolean debugMode=false;
  if (debugMode) {
    System.err.println("String_Node_Str" + part + "String_Node_Str"+ part.nextParts.size());
  }
  if (part == null) {
    return ret;
  }
  part=checkPart(stack,localData,part,allParts);
  if (part == null) {
    return ret;
  }
  if (part.ignored) {
    return ret;
  }
  List<GraphPart> loopContinues=getLoopsContinues(loops);
  boolean isLoop=false;
  Loop currentLoop=null;
  for (  Loop el : loops) {
    if ((el.loopContinue == part) && (el.phase == 0)) {
      currentLoop=el;
      currentLoop.phase=1;
      isLoop=true;
      break;
    }
  }
  if (debugMode) {
    System.err.println("String_Node_Str" + loops.size());
  }
  for (int l=loops.size() - 1; l >= 0; l--) {
    Loop el=loops.get(l);
    if (el == currentLoop) {
      if (debugMode) {
        System.err.println("String_Node_Str" + el);
      }
      continue;
    }
    if (el.phase != 1) {
      if (debugMode) {
      }
      continue;
    }
    if (el.loopBreak == part) {
      if (currentLoop != null) {
        currentLoop.phase=0;
      }
      if (debugMode) {
        System.err.println("String_Node_Str");
      }
      ret.add(new BreakItem(null,el.id));
      return ret;
    }
    if (el.loopPreContinue == part) {
      if (currentLoop != null) {
        currentLoop.phase=0;
      }
      if (debugMode) {
        System.err.println("String_Node_Str");
      }
      ret.add(new ContinueItem(null,el.id));
      return ret;
    }
    if (el.loopContinue == part) {
      if (currentLoop != null) {
        currentLoop.phase=0;
      }
      if (debugMode) {
        System.err.println("String_Node_Str");
      }
      ret.add(new ContinueItem(null,el.id));
      return ret;
    }
  }
  if (stopPart.contains(part)) {
    if (currentLoop != null) {
      currentLoop.phase=0;
    }
switch (part.stopPartType) {
case AND_OR:
      part.setAndOrStack(stack);
    break;
case COMMONPART:
  part.setCommonPartStack(stack);
break;
case NONE:
break;
}
return ret;
}
if ((part != null) && (code.size() <= part.start)) {
ret.add(new ScriptEndItem());
return ret;
}
List<GraphTargetItem> currentRet=ret;
UniversalLoopItem loopItem=null;
if (isLoop) {
loopItem=new UniversalLoopItem(null,currentLoop);
currentRet.add(loopItem);
loopItem.commands=new ArrayList<>();
currentRet=loopItem.commands;
}
boolean parseNext=true;
List<GraphTargetItem> output=new ArrayList<>();
List<GraphPart> parts=new ArrayList<>();
if (part instanceof GraphPartMulti) {
parts=((GraphPartMulti)part).parts;
}
 else {
parts.add(part);
}
for (GraphPart p : parts) {
int end=p.end;
int start=p.start;
output.addAll(code.translatePart(p,localData,stack,start,end,staticOperation,path));
if ((end >= code.size() - 1) && p.nextParts.isEmpty()) {
output.add(new ScriptEndItem());
}
}
if (parseNext) {
List<GraphTargetItem> retCheck=check(code,localData,allParts,stack,parent,part,stopPart,loops,output,currentLoop,staticOperation,path);
if (retCheck != null) {
if (!retCheck.isEmpty()) {
currentRet.addAll(retCheck);
}
parseNext=false;
}
 else {
currentRet.addAll(output);
}
}
if (parseNext && 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())) {
GraphPart sp0=getNextNoJump(part.nextParts.get(0),localData);
GraphPart sp1=getNextNoJump(part.nextParts.get(1),localData);
boolean reversed=false;
loopContinues=getLoopsContinues(loops);
loopContinues.add(part);
if (sp1.leadsTo(localData,this,code,sp0,loops)) {
}
 else if (sp0.leadsTo(localData,this,code,sp1,loops)) {
reversed=true;
}
GraphPart next=reversed ? sp0 : sp1;
GraphTargetItem ti;
if ((ti=checkLoop(next,stopPart,loops)) != null) {
currentRet.add(ti);
}
 else {
List<GraphPart> stopPart2=new ArrayList<>(stopPart);
GraphPart andOrStopPart=reversed ? sp1 : sp0;
andOrStopPart.stopPartType=GraphPart.StopPartType.AND_OR;
stopPart2.add(andOrStopPart);
printGraph(visited,localData,stack,allParts,parent,next,stopPart2,loops,null,staticOperation,path,recursionLevel + 1);
stack=andOrStopPart.andOrStack;
GraphTargetItem second=stack.pop();
GraphTargetItem first=stack.pop();
andOrStopPart.stopPartType=GraphPart.StopPartType.NONE;
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) {
currentRet.add(ti);
}
 else {
currentRet.addAll(printGraph(visited,localData,stack,allParts,parent,next,stopPart,loops,null,staticOperation,path,recursionLevel + 1));
}
}
parseNext=false;
}
 else if ((stack.size() >= 2) && (stack.get(stack.size() - 1).getNotCoerced() == stack.get(stack.size() - 2).getNotCoerced())) {
GraphPart sp0=getNextNoJump(part.nextParts.get(0),localData);
GraphPart sp1=getNextNoJump(part.nextParts.get(1),localData);
boolean reversed=false;
loopContinues=getLoopsContinues(loops);
loopContinues.add(part);
if (sp1.leadsTo(localData,this,code,sp0,loops)) {
}
 else if (sp0.leadsTo(localData,this,code,sp1,loops)) {
reversed=true;
}
GraphPart next=reversed ? sp0 : sp1;
GraphTargetItem ti;
if ((ti=checkLoop(next,stopPart,loops)) != null) {
currentRet.add(ti);
}
 else {
List<GraphPart> stopPart2=new ArrayList<>(stopPart);
GraphPart andOrStopPart=reversed ? sp1 : sp0;
andOrStopPart.stopPartType=GraphPart.StopPartType.AND_OR;
stopPart2.add(andOrStopPart);
printGraph(visited,localData,stack,allParts,parent,next,stopPart2,loops,null,staticOperation,path,recursionLevel + 1);
stack=andOrStopPart.andOrStack;
GraphTargetItem second=stack.pop();
GraphTargetItem first=stack.pop();
andOrStopPart.stopPartType=GraphPart.StopPartType.NONE;
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 OrItem) {
  o.firstPart=((OrItem)second).firstPart;
}
if (second instanceof AndItem) {
  o.firstPart=((AndItem)second).firstPart;
}
}
next=reversed ? sp1 : sp0;
if ((ti=checkLoop(next,stopPart,loops)) != null) {
currentRet.add(ti);
}
 else {
currentRet.addAll(printGraph(visited,localData,stack,allParts,parent,next,stopPart,loops,null,staticOperation,path,recursionLevel + 1));
}
}
parseNext=false;
}
}
if (parseNext) {
if (false && part.nextParts.size() > 2) {
GraphPart next=getMostCommonPart(localData,part.nextParts,loops);
List<GraphPart> vis=new ArrayList<>();
GraphTargetItem switchedItem=stack.pop();
List<GraphTargetItem> caseValues=new ArrayList<>();
List<List<GraphTargetItem>> caseCommands=new ArrayList<>();
List<GraphTargetItem> defaultCommands=new ArrayList<>();
List<Integer> valueMappings=new ArrayList<>();
Loop swLoop=new Loop(loops.size(),null,next);
swLoop.phase=1;
loops.add(swLoop);
boolean first=false;
int pos=0;
for (GraphPart p : part.nextParts) {
if (!first) {
caseValues.add(new IntegerValueItem(null,pos++));
if (vis.contains(p)) {
  valueMappings.add(caseCommands.size() - 1);
  continue;
}
valueMappings.add(caseCommands.size());
}
List<GraphPart> stopPart2=new ArrayList<>();
if (next != null) {
stopPart2.add(next);
}
 else if (!stopPart.isEmpty()) {
stopPart2.add(stopPart.get(stopPart.size() - 1));
}
for (GraphPart p2 : part.nextParts) {
if (p2 == p) {
  continue;
}
if (!stopPart2.contains(p2)) {
  stopPart2.add(p2);
}
}
if (next != p) {
if (first) {
  defaultCommands=printGraph(visited,prepareBranchLocalData(localData),stack,allParts,part,p,stopPart2,loops,null,staticOperation,path,recursionLevel + 1);
}
 else {
  caseCommands.add(printGraph(visited,prepareBranchLocalData(localData),stack,allParts,part,p,stopPart2,loops,null,staticOperation,path,recursionLevel + 1));
}
vis.add(p);
}
first=false;
}
SwitchItem sw=new SwitchItem(null,swLoop,switchedItem,caseValues,caseCommands,defaultCommands,valueMappings);
currentRet.add(sw);
swLoop.phase=2;
if (next != null) {
currentRet.addAll(printGraph(visited,localData,stack,allParts,part,next,stopPart,loops,null,staticOperation,path,recursionLevel + 1));
}
}
GraphPart nextOnePart=null;
if (part.nextParts.size() == 2) {
GraphTargetItem expr=stack.pop();
if (expr instanceof LogicalOpItem) {
expr=((LogicalOpItem)expr).invert();
}
 else {
expr=new NotItem(null,expr);
}
if (staticOperation != SOP_USE_STATIC) {
if (expr.isCompileTime()) {
boolean doJump=EcmaScript.toBoolean(expr.getResult());
if (doJump) {
  nextOnePart=part.nextParts.get(0);
}
 else {
  nextOnePart=part.nextParts.get(1);
}
if (staticOperation == SOP_REMOVE_STATIC) {
}
}
}
if (nextOnePart == null) {
List<GraphPart> nps;
nps=part.nextParts;
GraphPart next=getCommonPart(localData,nps,loops);
TranslateStack trueStack=(TranslateStack)stack.clone();
TranslateStack falseStack=(TranslateStack)stack.clone();
int trueStackSizeBefore=trueStack.size();
int falseStackSizeBefore=falseStack.size();
List<GraphTargetItem> onTrue=new ArrayList<>();
boolean isEmpty=nps.get(0) == nps.get(1);
if (isEmpty) {
next=nps.get(0);
}
List<GraphPart> stopPart2=new ArrayList<>(stopPart);
GraphPart.CommonPartStack commonPartStack=null;
if ((!isEmpty) && (next != null)) {
commonPartStack=next.new CommonPartStack();
if (next.commonPartStacks == null) {
  next.commonPartStacks=new ArrayList<>();
}
next.stopPartType=GraphPart.StopPartType.COMMONPART;
stopPart2.add(next);
}
if (!isEmpty) {
if (next != null) {
  next.commonPartStacks.add(commonPartStack);
  commonPartStack.isTrueStack=true;
}
onTrue=printGraph(visited,prepareBranchLocalData(localData),trueStack,allParts,part,nps.get(1),stopPart2,loops,null,staticOperation,path,recursionLevel + 1);
}
List<GraphTargetItem> onFalse=new ArrayList<>();
if (!isEmpty) {
if (next != null) {
  commonPartStack.isTrueStack=false;
}
onFalse=printGraph(visited,prepareBranchLocalData(localData),falseStack,allParts,part,nps.get(0),stopPart2,loops,null,staticOperation,path,recursionLevel + 1);
}
if ((!isEmpty) && (next != null)) {
if ((commonPartStack.trueStack != null) && (commonPartStack.falseStack != null)) {
  trueStack=commonPartStack.trueStack;
  falseStack=commonPartStack.falseStack;
}
next.commonPartStacks.remove(next.commonPartStacks.size() - 1);
if (next.commonPartStacks.isEmpty()) {
  next.stopPartType=GraphPart.StopPartType.NONE;
}
}
if (isEmpty(onTrue) && isEmpty(onFalse) && (trueStack.size() == trueStackSizeBefore + 1)&& (falseStack.size() == falseStackSizeBefore + 1)) {
stack.push(new TernarOpItem(null,expr,trueStack.pop(),falseStack.pop()));
}
 else {
currentRet.add(new IfItem(null,expr,onTrue,onFalse));
}
if (next != null) {
if (trueStack.size() != trueStackSizeBefore || falseStack.size() != falseStackSizeBefore) {
  onTrue=printGraph(visited,localData,trueStack,allParts,part,next,stopPart,loops,null,staticOperation,path,recursionLevel + 1);
  onFalse=printGraph(visited,localData,falseStack,allParts,part,next,stopPart,loops,null,staticOperation,path,recursionLevel + 1);
  if (isEmpty(onTrue) && isEmpty(onFalse) && (trueStack.size() == trueStackSizeBefore + 1)&& (falseStack.size() == falseStackSizeBefore + 1)) {
    stack.push(new TernarOpItem(null,expr,trueStack.pop(),falseStack.pop()));
  }
 else {
    currentRet.add(new IfItem(null,expr,onTrue,onFalse));
  }
}
 else {
  printGraph(visited,localData,stack,allParts,part,next,stopPart,loops,currentRet,staticOperation,path,recursionLevel + 1);
}
}
}
}
if (part.nextParts.size() == 1) {
nextOnePart=part.nextParts.get(0);
}
if (nextOnePart != null) {
printGraph(visited,localData,stack,allParts,part,part.nextParts.get(0),stopPart,loops,currentRet,staticOperation,path,recursionLevel + 1);
}
}
if (isLoop) {
LoopItem li=loopItem;
boolean loopTypeFound=false;
boolean hasContinue=false;
processIfs(loopItem.commands);
checkContinueAtTheEnd(loopItem.commands,currentLoop);
List<ContinueItem> continues=loopItem.getContinues();
for (ContinueItem c : continues) {
if (c.loopId == currentLoop.id) {
hasContinue=true;
break;
}
}
if (!hasContinue) {
if (currentLoop.loopPreContinue != null) {
List<GraphPart> stopContPart=new ArrayList<>();
stopContPart.add(currentLoop.loopContinue);
GraphPart precoBackup=currentLoop.loopPreContinue;
currentLoop.loopPreContinue=null;
loopItem.commands.addAll(printGraph(visited,localData,new TranslateStack(),allParts,null,precoBackup,stopContPart,loops,null,staticOperation,path,recursionLevel + 1));
}
}
if (!loopTypeFound && (!loopItem.commands.isEmpty())) {
if (loopItem.commands.get(0) instanceof IfItem) {
IfItem ifi=(IfItem)loopItem.commands.get(0);
List<GraphTargetItem> bodyBranch=null;
boolean inverted=false;
boolean breakpos2=false;
if ((ifi.onTrue.size() == 1) && (ifi.onTrue.get(0) instanceof BreakItem)) {
BreakItem bi=(BreakItem)ifi.onTrue.get(0);
if (bi.loopId == currentLoop.id) {
  bodyBranch=ifi.onFalse;
  inverted=true;
}
}
 else if ((ifi.onFalse.size() == 1) && (ifi.onFalse.get(0) instanceof BreakItem)) {
BreakItem bi=(BreakItem)ifi.onFalse.get(0);
if (bi.loopId == currentLoop.id) {
  bodyBranch=ifi.onTrue;
}
}
 else if (loopItem.commands.size() == 2 && (loopItem.commands.get(1) instanceof BreakItem)) {
BreakItem bi=(BreakItem)loopItem.commands.get(1);
if (bi.loopId == currentLoop.id) {
  bodyBranch=ifi.onTrue;
  breakpos2=true;
}
}
if (bodyBranch != null) {
int index=ret.indexOf(loopItem);
ret.remove(index);
List<GraphTargetItem> exprList=new ArrayList<>();
GraphTargetItem expr=ifi.expression;
if (inverted) {
  if (expr instanceof LogicalOpItem) {
    expr=((LogicalOpItem)expr).invert();
  }
 else {
    expr=new NotItem(null,expr);
  }
}
exprList.add(expr);
List<GraphTargetItem> commands=new ArrayList<>();
commands.addAll(bodyBranch);
loopItem.commands.remove(0);
if (breakpos2) {
  loopItem.commands.remove(0);
}
commands.addAll(loopItem.commands);
checkContinueAtTheEnd(commands,currentLoop);
List<GraphTargetItem> finalComm=new ArrayList<>();
if (currentLoop.loopPreContinue != null) {
  GraphPart backup=currentLoop.loopPreContinue;
  currentLoop.loopPreContinue=null;
  List<GraphPart> stopPart2=new ArrayList<>(stopPart);
  stopPart2.add(currentLoop.loopContinue);
  finalComm=printGraph(visited,localData,new TranslateStack(),allParts,null,backup,stopPart2,loops,null,staticOperation,path,recursionLevel + 1);
  currentLoop.loopPreContinue=backup;
  checkContinueAtTheEnd(finalComm,currentLoop);
}
if (!finalComm.isEmpty()) {
  ret.add(index,li=new ForItem(null,currentLoop,new ArrayList<GraphTargetItem>(),exprList.get(exprList.size() - 1),finalComm,commands));
}
 else {
  ret.add(index,li=new WhileItem(null,currentLoop,exprList,commands));
}
loopTypeFound=true;
}
}
}
if (!loopTypeFound && (!loopItem.commands.isEmpty())) {
if (loopItem.commands.get(loopItem.commands.size() - 1) instanceof IfItem) {
IfItem ifi=(IfItem)loopItem.commands.get(loopItem.commands.size() - 1);
List<GraphTargetItem> bodyBranch=null;
boolean inverted=false;
if ((ifi.onTrue.size() == 1) && (ifi.onTrue.get(0) instanceof BreakItem)) {
BreakItem bi=(BreakItem)ifi.onTrue.get(0);
if (bi.loopId == currentLoop.id) {
  bodyBranch=ifi.onFalse;
  inverted=true;
}
}
 else if ((ifi.onFalse.size() == 1) && (ifi.onFalse.get(0) instanceof BreakItem)) {
BreakItem bi=(BreakItem)ifi.onFalse.get(0);
if (bi.loopId == currentLoop.id) {
  bodyBranch=ifi.onTrue;
}
}
if (bodyBranch != null) {
int index=ret.indexOf(loopItem);
ret.remove(index);
List<GraphTargetItem> exprList=new ArrayList<>();
GraphTargetItem expr=ifi.expression;
if (inverted) {
  if (expr instanceof LogicalOpItem) {
    expr=((LogicalOpItem)expr).invert();
  }
 else {
    expr=new NotItem(null,expr);
  }
}
checkContinueAtTheEnd(bodyBranch,currentLoop);
List<GraphTargetItem> commands=new ArrayList<>();
if (!bodyBranch.isEmpty()) {
  ret.add(index,loopItem);
}
 else {
  loopItem.commands.remove(loopItem.commands.size() - 1);
  commands.addAll(loopItem.commands);
  commands.addAll(bodyBranch);
  exprList.add(expr);
  checkContinueAtTheEnd(commands,currentLoop);
  ret.add(index,li=new DoWhileItem(null,currentLoop,commands,exprList));
}
loopTypeFound=true;
}
}
}
if (!loopTypeFound) {
if (currentLoop.loopPreContinue != null) {
loopTypeFound=true;
GraphPart backup=currentLoop.loopPreContinue;
currentLoop.loopPreContinue=null;
List<GraphPart> stopPart2=new ArrayList<>(stopPart);
stopPart2.add(currentLoop.loopContinue);
List<GraphTargetItem> finalComm=printGraph(visited,localData,new TranslateStack(),allParts,null,backup,stopPart2,loops,null,staticOperation,path,recursionLevel + 1);
currentLoop.loopPreContinue=backup;
checkContinueAtTheEnd(finalComm,currentLoop);
if (!finalComm.isEmpty()) {
if (finalComm.get(finalComm.size() - 1) instanceof IfItem) {
  IfItem ifi=(IfItem)finalComm.get(finalComm.size() - 1);
  boolean ok=false;
  boolean invert=false;
  if (((ifi.onTrue.size() == 1) && (ifi.onTrue.get(0) instanceof BreakItem) && (((BreakItem)ifi.onTrue.get(0)).loopId == currentLoop.id)) && ((ifi.onTrue.size() == 1) && (ifi.onFalse.get(0) instanceof ContinueItem) && (((ContinueItem)ifi.onFalse.get(0)).loopId == currentLoop.id))) {
    ok=true;
    invert=true;
  }
  if (((ifi.onTrue.size() == 1) && (ifi.onTrue.get(0) instanceof ContinueItem) && (((ContinueItem)ifi.onTrue.get(0)).loopId == currentLoop.id)) && ((ifi.onTrue.size() == 1) && (ifi.onFalse.get(0) instanceof BreakItem) && (((BreakItem)ifi.onFalse.get(0)).loopId == currentLoop.id))) {
    ok=true;
  }
  if (ok) {
    finalComm.remove(finalComm.size() - 1);
    int index=ret.indexOf(loopItem);
    ret.remove(index);
    List<GraphTargetItem> exprList=new ArrayList<>(finalComm);
    GraphTargetItem expr=ifi.expression;
    if (invert) {
      if (expr instanceof LogicalOpItem) {
        expr=((LogicalOpItem)expr).invert();
      }
 else {
        expr=new NotItem(null,expr);
      }
    }
    exprList.add(expr);
    ret.add(index,li=new DoWhileItem(null,currentLoop,loopItem.commands,exprList));
  }
}
}
}
}
if (!loopTypeFound) {
checkContinueAtTheEnd(loopItem.commands,currentLoop);
}
currentLoop.phase=2;
GraphTargetItem replaced=checkLoop(li,localData,loops);
if (replaced != li) {
int index=ret.indexOf(li);
ret.remove(index);
if (replaced != null) {
ret.add(index,replaced);
}
}
if (currentLoop.loopBreak != null) {
ret.addAll(printGraph(visited,localData,stack,allParts,part,currentLoop.loopBreak,stopPart,loops,null,staticOperation,path,recursionLevel + 1));
}
}
return ret;
}