Program: 132518
Project: 132518
Buggy source:
@Override public void startForeachLoop(String loopName,Var container,Var memberVar,Var loopCountVar,int splitDegree,int leafDegree,boolean arrayClosed,List<PassedVar> passedVars,List<RefCount> perIterIncrs,ListMultimap<Var,RefCount> constIncrs){
  boolean haveKeys=loopCountVar != null;
  boolean isKVContainer;
  if (Types.isArray(container) || Types.isArrayLocal(container)) {
    assert(!haveKeys || Types.isArrayKeyVal(container,loopCountVar.asArg()));
    isKVContainer=true;
  }
 else {
    assert(Types.isBag(container) || Types.isBagLocal(container));
    assert(!haveKeys);
    isKVContainer=false;
  }
  boolean localContainer=Types.isContainerLocal(container);
  if (localContainer) {
    if (!arrayClosed || splitDegree >= 0) {
      throw new STCRuntimeError("String_Node_Str");
    }
    assert(Types.isElemType(container,memberVar));
  }
 else {
    assert(Types.isElemValType(container,memberVar));
  }
  if (!arrayClosed) {
    throw new STCRuntimeError("String_Node_Str");
  }
  boolean isDict;
  Value tclContainer;
  if (splitDegree <= 0) {
    if (localContainer) {
      tclContainer=varToExpr(container);
      isDict=isKVContainer;
    }
 else {
      tclContainer=new Value(TCLTMP_ARRAY_CONTENTS);
      pointAdd(Turbine.enumerateAll(tclContainer.variable(),varToExpr(container),haveKeys));
      isDict=haveKeys;
    }
    Expression containerSize;
    if (isDict) {
      containerSize=Turbine.dictSize(tclContainer);
    }
 else {
      containerSize=Turbine.listLength(tclContainer);
    }
    handleForeachContainerRefcounts(perIterIncrs,constIncrs,containerSize);
  }
 else {
    assert(!localContainer);
    tclContainer=new Value(TCLTMP_ARRAY_CONTENTS);
    startForeachSplit(loopName,container,tclContainer.variable(),splitDegree,leafDegree,haveKeys,passedVars,perIterIncrs,constIncrs);
    isDict=haveKeys;
  }
  startForeachInner(tclContainer,memberVar,loopCountVar,isDict);
}

Fixed version (ground truth):
@Override public void startForeachLoop(String loopName,Var container,Var memberVar,Var loopCountVar,int splitDegree,int leafDegree,boolean arrayClosed,List<PassedVar> passedVars,List<RefCount> perIterIncrs,ListMultimap<Var,RefCount> constIncrs,List<RefCount> perIterDecrs){
  boolean haveKeys=loopCountVar != null;
  boolean isKVContainer;
  if (Types.isArray(container) || Types.isArrayLocal(container)) {
    assert(!haveKeys || Types.isArrayKeyVal(container,loopCountVar.asArg()));
    isKVContainer=true;
  }
 else {
    assert(Types.isBag(container) || Types.isBagLocal(container));
    assert(!haveKeys);
    isKVContainer=false;
  }
  boolean localContainer=Types.isContainerLocal(container);
  if (localContainer) {
    if (!arrayClosed || splitDegree >= 0) {
      throw new STCRuntimeError("String_Node_Str");
    }
    assert(Types.isElemType(container,memberVar));
  }
 else {
    assert(Types.isElemValType(container,memberVar));
  }
  if (!arrayClosed) {
    throw new STCRuntimeError("String_Node_Str");
  }
  boolean isDict;
  Value tclContainer;
  if (splitDegree <= 0) {
    if (localContainer) {
      tclContainer=varToExpr(container);
      isDict=isKVContainer;
    }
 else {
      tclContainer=new Value(TCLTMP_ARRAY_CONTENTS);
      pointAdd(Turbine.enumerateAll(tclContainer.variable(),varToExpr(container),haveKeys));
      isDict=haveKeys;
    }
    Expression containerSize;
    if (isDict) {
      containerSize=Turbine.dictSize(tclContainer);
    }
 else {
      containerSize=Turbine.listLength(tclContainer);
    }
    handleForeachContainerRefcounts(perIterIncrs,constIncrs,containerSize);
  }
 else {
    assert(!localContainer);
    tclContainer=new Value(TCLTMP_ARRAY_CONTENTS);
    startForeachSplit(loopName,container,tclContainer.variable(),splitDegree,leafDegree,haveKeys,passedVars,perIterIncrs,constIncrs,perIterDecrs);
    isDict=haveKeys;
  }
  startForeachInner(tclContainer,memberVar,loopCountVar,isDict);
}