Program: 133047
Project: 133047
Buggy source:
/** 
 * After this function is called, in the TCL context at the top of the stack will be available the bottom, top (inclusive) and increment of the split in tcl values: TCLTMP_RANGE_LO TCLTMP_RANGE_HI and TCLTMP_RANGE_INC
 * @param loopName
 * @param usedVariables
 * @param keepOpenVars
 * @param splitDegree
 * @param leafDegree 
 * @param startE start of range (inclusive)
 * @param endE end of range (inclusive)
 * @param incrE
 */
private void startRangeSplit(String loopName,List<Var> usedVariables,List<Var> keepOpenVars,int splitDegree,int leafDegree,Expression startE,Expression endE,Expression incrE){
  List<Var> allUsedVars=Var.varListUnion(usedVariables,keepOpenVars);
  List<String> commonFormalArgs=new ArrayList<String>();
  commonFormalArgs.add(Turbine.LOCAL_STACK_NAME);
  for (  Var uv : allUsedVars) {
    commonFormalArgs.add(prefixVar(uv.name()));
  }
  commonFormalArgs.add(TCLTMP_RANGE_LO);
  commonFormalArgs.add(TCLTMP_RANGE_HI);
  commonFormalArgs.add(TCLTMP_RANGE_INC);
  List<String> outerFormalArgs=new ArrayList<String>(commonFormalArgs);
  Value loVal=new Value(TCLTMP_RANGE_LO);
  Value hiVal=new Value(TCLTMP_RANGE_HI);
  Value incVal=new Value(TCLTMP_RANGE_INC);
  List<Expression> commonArgs=new ArrayList<Expression>();
  commonArgs.add(new Value(Turbine.LOCAL_STACK_NAME));
  for (  Var uv : allUsedVars) {
    commonArgs.add(varToExpr(uv));
  }
  List<Expression> outerCallArgs=new ArrayList<Expression>(commonArgs);
  outerCallArgs.add(startE);
  outerCallArgs.add(endE);
  outerCallArgs.add(incrE);
  List<Expression> innerCallArgs=new ArrayList<Expression>(commonArgs);
  innerCallArgs.add(loVal);
  innerCallArgs.add(hiVal);
  innerCallArgs.add(incVal);
  Sequence outer=new Sequence();
  String outerProcName=uniqueTCLFunctionName(loopName + "String_Node_Str");
  tree.add(new Proc(outerProcName,usedTclFunctionNames,outerFormalArgs,outer));
  Sequence inner=new Sequence();
  String innerProcName=uniqueTCLFunctionName(loopName + "String_Node_Str");
  tree.add(new Proc(innerProcName,usedTclFunctionNames,commonFormalArgs,inner));
  pointStack.peek().add(new SetVariable(TCLTMP_ITERSTOTAL,rangeItersLeft(startE,endE,incrE)));
  incrementAllRefs(usedVariables,keepOpenVars,new Value(TCLTMP_ITERSTOTAL));
  pointStack.peek().add(new Command(outerProcName,outerCallArgs));
  outer.add(new SetVariable(TCLTMP_ITERSLEFT,rangeItersLeft(new Value(TCLTMP_RANGE_LO),new Value(TCLTMP_RANGE_HI),new Value(TCLTMP_RANGE_INC))));
  Expression doneSplitting=Square.arithExpr(new Value(TCLTMP_ITERSLEFT),new Token("String_Node_Str"),new LiteralInt(leafDegree));
  Sequence thenB=new Sequence();
  Sequence elseB=new Sequence();
  If splitIf=new If(doneSplitting,thenB,elseB);
  outer.add(splitIf);
  thenB.add(new Command(innerProcName,innerCallArgs));
  Sequence splitBody=new Sequence();
  String splitStart="String_Node_Str";
  String skip="String_Node_Str";
  elseB.add(new SetVariable(skip,Square.arithExpr(new Token(String.format("String_Node_Str",splitDegree,new Value(TCLTMP_ITERSLEFT),leafDegree,new Value(TCLTMP_RANGE_INC))))));
  ForLoop splitLoop=new ForLoop(splitStart,loVal,hiVal,new Value(skip),splitBody);
  elseB.add(splitLoop);
  ArrayList<Expression> outerRecCall=new ArrayList<Expression>();
  outerRecCall.add(new Token(outerProcName));
  outerRecCall.addAll(commonArgs);
  outerRecCall.add(new Value(splitStart));
  Square splitEnd=Square.arithExpr(new Token(String.format("String_Node_Str",TCLTMP_RANGE_HI,splitStart,skip)));
  outerRecCall.add(splitEnd);
  outerRecCall.add(incVal);
  splitBody.add(Turbine.rule(outerProcName,new ArrayList<Value>(0),new TclList(outerRecCall),TaskMode.CONTROL,Target.rankAny(),true));
  pointStack.push(inner);
}

Fixed version (ground truth):
/** 
 * After this function is called, in the TCL context at the top of the stack will be available the bottom, top (inclusive) and increment of the split in tcl values: TCLTMP_RANGE_LO TCLTMP_RANGE_HI and TCLTMP_RANGE_INC
 * @param loopName
 * @param usedVariables
 * @param keepOpenVars
 * @param splitDegree
 * @param leafDegree 
 * @param startE start of range (inclusive)
 * @param endE end of range (inclusive)
 * @param incrE
 */
private void startRangeSplit(String loopName,List<Var> usedVariables,List<Var> keepOpenVars,int splitDegree,int leafDegree,Expression startE,Expression endE,Expression incrE){
  List<Var> allUsedVars=Var.varListUnion(usedVariables,keepOpenVars);
  List<String> commonFormalArgs=new ArrayList<String>();
  commonFormalArgs.add(Turbine.LOCAL_STACK_NAME);
  for (  Var uv : allUsedVars) {
    commonFormalArgs.add(prefixVar(uv.name()));
  }
  commonFormalArgs.add(TCLTMP_RANGE_LO);
  commonFormalArgs.add(TCLTMP_RANGE_HI);
  commonFormalArgs.add(TCLTMP_RANGE_INC);
  List<String> outerFormalArgs=new ArrayList<String>(commonFormalArgs);
  Value loVal=new Value(TCLTMP_RANGE_LO);
  Value hiVal=new Value(TCLTMP_RANGE_HI);
  Value incVal=new Value(TCLTMP_RANGE_INC);
  List<Expression> commonArgs=new ArrayList<Expression>();
  commonArgs.add(new Value(Turbine.LOCAL_STACK_NAME));
  for (  Var uv : allUsedVars) {
    commonArgs.add(varToExpr(uv));
  }
  List<Expression> outerCallArgs=new ArrayList<Expression>(commonArgs);
  outerCallArgs.add(startE);
  outerCallArgs.add(endE);
  outerCallArgs.add(incrE);
  List<Expression> innerCallArgs=new ArrayList<Expression>(commonArgs);
  innerCallArgs.add(loVal);
  innerCallArgs.add(hiVal);
  innerCallArgs.add(incVal);
  Sequence outer=new Sequence();
  String outerProcName=uniqueTCLFunctionName(loopName + "String_Node_Str");
  tree.add(new Proc(outerProcName,usedTclFunctionNames,outerFormalArgs,outer));
  Sequence inner=new Sequence();
  String innerProcName=uniqueTCLFunctionName(loopName + "String_Node_Str");
  tree.add(new Proc(innerProcName,usedTclFunctionNames,commonFormalArgs,inner));
  pointStack.peek().add(new SetVariable(TCLTMP_ITERSTOTAL,rangeItersLeft(startE,endE,incrE)));
  incrementAllRefs(usedVariables,keepOpenVars,new Value(TCLTMP_ITERSTOTAL));
  pointStack.peek().add(new Command(outerProcName,outerCallArgs));
  outer.add(new SetVariable(TCLTMP_ITERSLEFT,rangeItersLeft(new Value(TCLTMP_RANGE_LO),new Value(TCLTMP_RANGE_HI),new Value(TCLTMP_RANGE_INC))));
  Expression doneSplitting=Square.arithExpr(new Value(TCLTMP_ITERSLEFT),new Token("String_Node_Str"),new LiteralInt(leafDegree));
  Sequence thenB=new Sequence();
  Sequence elseB=new Sequence();
  If splitIf=new If(doneSplitting,thenB,elseB);
  outer.add(splitIf);
  thenB.add(new Command(innerProcName,innerCallArgs));
  Sequence splitBody=new Sequence();
  String splitStart="String_Node_Str";
  String skip="String_Node_Str";
  elseB.add(new SetVariable(skip,Square.arithExpr(new Token(String.format("String_Node_Str",leafDegree,new Value(TCLTMP_ITERSLEFT),splitDegree,new Value(TCLTMP_RANGE_INC))))));
  ForLoop splitLoop=new ForLoop(splitStart,loVal,hiVal,new Value(skip),splitBody);
  elseB.add(splitLoop);
  ArrayList<Expression> outerRecCall=new ArrayList<Expression>();
  outerRecCall.add(new Token(outerProcName));
  outerRecCall.addAll(commonArgs);
  outerRecCall.add(new Value(splitStart));
  Square splitEnd=Square.arithExpr(new Token(String.format("String_Node_Str",TCLTMP_RANGE_HI,splitStart,skip)));
  outerRecCall.add(splitEnd);
  outerRecCall.add(incVal);
  splitBody.add(Turbine.rule(outerProcName,new ArrayList<Value>(0),new TclList(outerRecCall),TaskMode.CONTROL,Target.rankAny(),true));
  pointStack.push(inner);
}