Program: 132957
Project: 132957
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 splitDegree
 * @param leafDegree 
 * @param startE start of range (inclusive)
 * @param endE end of range (inclusive)
 * @param incrE
 * @param usedVariables
 * @param keepOpenVars
 */
private void startRangeSplit(String loopName,List<PassedVar> passedVars,List<RefCount> perIterIncrs,int splitDegree,int leafDegree,Expression startE,Expression endE,Expression incrE){
  List<String> commonFormalArgs=new ArrayList<String>();
  commonFormalArgs.add(Turbine.LOCAL_STACK_NAME);
  for (  PassedVar pv : passedVars) {
    commonFormalArgs.add(prefixVar(pv.var.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 (  PassedVar pv : passedVars) {
    commonArgs.add(varToExpr(pv.var));
  }
  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 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 done=new TclExpr(new Value(TCLTMP_ITERSLEFT),TclExpr.LTE,LiteralInt.ZERO);
  Sequence thenDoneB=new Sequence();
  If finishedIf=new If(done,thenDoneB);
  thenDoneB.add(new Command("String_Node_Str"));
  outer.add(finishedIf);
  Expression doneSplitting=new TclExpr(new Value(TCLTMP_ITERSLEFT),TclExpr.LTE,new LiteralInt(leafDegree));
  Sequence thenNoSplitB=new Sequence();
  Sequence elseSplitB=new Sequence();
  If splitIf=new If(doneSplitting,thenNoSplitB,elseSplitB);
  outer.add(splitIf);
  thenNoSplitB.add(new Command(innerProcName,innerCallArgs));
  Sequence splitBody=new Sequence();
  String splitStart="String_Node_Str";
  String skip="String_Node_Str";
  elseSplitB.add(new SetVariable(skip,TclExpr.mult(new Value(TCLTMP_RANGE_INC),TclExpr.max(new LiteralInt(leafDegree),TclExpr.group(TclExpr.paren(TclExpr.paren(new Value(TCLTMP_ITERSLEFT),TclExpr.MINUS,LiteralInt.ONE),TclExpr.DIV,new LiteralInt(splitDegree)),TclExpr.PLUS,LiteralInt.ONE)))));
  ForLoop splitLoop=new ForLoop(splitStart,loVal,hiVal,new Value(skip),splitBody);
  elseSplitB.add(splitLoop);
  ArrayList<Expression> outerRecCall=new ArrayList<Expression>();
  outerRecCall.add(new Token(outerProcName));
  outerRecCall.addAll(commonArgs);
  outerRecCall.add(new Value(splitStart));
  TclExpr splitEnd=new TclExpr(TclExpr.min(new Value(TCLTMP_RANGE_HI),TclExpr.group(new Value(splitStart),TclExpr.PLUS,new Value(skip),TclExpr.MINUS,LiteralInt.ONE)));
  outerRecCall.add(splitEnd);
  outerRecCall.add(incVal);
  splitBody.add(Turbine.rule(outerProcName,new ArrayList<Value>(0),new TclList(outerRecCall),TaskMode.CONTROL,Target.rankAny(),null,execContextStack.peek()));
  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 splitDegree
 * @param leafDegree 
 * @param startE start of range (inclusive)
 * @param endE end of range (inclusive)
 * @param incrE
 * @param usedVariables
 * @param keepOpenVars
 */
private void startRangeSplit(String loopName,List<PassedVar> passedVars,List<RefCount> perIterIncrs,int splitDegree,int leafDegree,Expression startE,Expression endE,Expression incrE){
  List<String> commonFormalArgs=new ArrayList<String>();
  commonFormalArgs.add(Turbine.LOCAL_STACK_NAME);
  for (  PassedVar pv : passedVars) {
    commonFormalArgs.add(prefixVar(pv.var.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 (  PassedVar pv : passedVars) {
    commonArgs.add(varToExpr(pv.var));
  }
  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 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 done=new TclExpr(new Value(TCLTMP_ITERSLEFT),TclExpr.LTE,LiteralInt.ZERO);
  Sequence thenDoneB=new Sequence();
  If finishedIf=new If(done,thenDoneB);
  thenDoneB.add(new Command("String_Node_Str"));
  outer.add(finishedIf);
  Expression doneSplitting=new TclExpr(new Value(TCLTMP_ITERSLEFT),TclExpr.LTE,new LiteralInt(leafDegree));
  Sequence thenNoSplitB=new Sequence();
  Sequence elseSplitB=new Sequence();
  If splitIf=new If(doneSplitting,thenNoSplitB,elseSplitB);
  outer.add(splitIf);
  thenNoSplitB.add(new Command(innerProcName,innerCallArgs));
  Sequence splitBody=new Sequence();
  String splitStart="String_Node_Str";
  String skip="String_Node_Str";
  elseSplitB.add(new SetVariable(skip,TclExpr.mult(new Value(TCLTMP_RANGE_INC),TclExpr.max(new LiteralInt(leafDegree),TclExpr.group(TclExpr.paren(TclExpr.paren(new Value(TCLTMP_ITERSLEFT),TclExpr.MINUS,LiteralInt.ONE),TclExpr.DIV,new LiteralInt(splitDegree)),TclExpr.PLUS,LiteralInt.ONE)))));
  ForLoop splitLoop=new ForLoop(splitStart,loVal,hiVal,new Value(skip),splitBody);
  elseSplitB.add(splitLoop);
  ArrayList<Expression> outerRecCall=new ArrayList<Expression>();
  outerRecCall.add(new Token(outerProcName));
  outerRecCall.addAll(commonArgs);
  outerRecCall.add(new Value(splitStart));
  TclExpr splitEndExpr=new TclExpr(TclExpr.min(new Value(TCLTMP_RANGE_HI),TclExpr.group(new Value(splitStart),TclExpr.PLUS,new Value(skip),TclExpr.MINUS,LiteralInt.ONE)));
  splitBody.add(new SetVariable(TCLTMP_SPLITEND,splitEndExpr));
  outerRecCall.add(new Value(TCLTMP_SPLITEND));
  outerRecCall.add(incVal);
  splitBody.add(Turbine.rule(outerProcName,new ArrayList<Value>(0),outerRecCall,TaskMode.CONTROL,Target.rankAny(),null,execContextStack.peek()));
  pointStack.push(inner);
}