nus-yam/ex-repair huggingface dataset:
Program: 132728
Project: 132728
Buggy source:
/** 
 * Fuse the other loop into this loop
 */
public void fuseInto(RangeLoop o,boolean insertAtTop){
  Map<Var,Arg> renames=new HashMap<Var,Arg>();
  renames.put(o.loopVar,Arg.createVar(this.loopVar));
  if (loopCounterVar != null)   renames.put(o.loopCounterVar,Arg.createVar(this.loopCounterVar));
  o.renameVars(renames,RenameMode.REPLACE_VAR,true);
  this.fuseIntoAbstract(o,insertAtTop);
}

Fixed version (ground truth):
/** 
 * Fuse the other loop into this loop
 */
public void fuseInto(String function,RangeLoop o,boolean insertAtTop){
  Map<Var,Arg> renames=new HashMap<Var,Arg>();
  renames.put(o.loopVar,Arg.createVar(this.loopVar));
  if (loopCounterVar != null)   renames.put(o.loopCounterVar,Arg.createVar(this.loopCounterVar));
  o.renameVars(function,renames,RenameMode.REPLACE_VAR,true);
  this.fuseIntoAbstract(o,insertAtTop);
}
Program: 132729
Project: 132729
Buggy source:
@Override public Pair<Boolean,List<Continuation>> tryUnroll(Logger logger,Block outerBlock){
  logger.trace("String_Node_Str" + loopName + "String_Node_Str"+ desiredUnroll);
  boolean expandLoops=isExpandLoopsEnabled();
  boolean fullUnroll=isFullUnrollEnabled();
  if (!this.unrolled && this.desiredUnroll > 1) {
    if (this.loopCounterVar != null) {
      logger.warn("String_Node_Str" + "String_Node_Str");
      return NO_UNROLL;
    }
    return Pair.create(true,doUnroll(logger,outerBlock,desiredUnroll));
  }
 else   if (expandLoops || fullUnroll) {
    long instCount=loopBody.getInstructionCount();
    long iterCount=constIterCount();
    if (expandLoops && iterCount >= 0) {
      if (iterCount <= getUnrollMaxIters(true)) {
        long extraInstructions=instCount * (iterCount - 1);
        if (extraInstructions <= getUnrollMaxExtraInsts(true)) {
          return Pair.create(true,doUnroll(logger,outerBlock,(int)iterCount));
        }
      }
    }
    if (!fullUnroll) {
      logger.trace("String_Node_Str");
      return NO_UNROLL;
    }
    if (this.unrolled) {
      return NO_UNROLL;
    }
    long threshold=getUnrollMaxExtraInsts(false);
    long unrollFactor=Math.min(getUnrollMaxIters(false),(threshold / instCount) + 1);
    if (unrollFactor > 1) {
      return Pair.create(true,doUnroll(logger,outerBlock,(int)unrollFactor));
    }
  }
  return NO_UNROLL;
}

Fixed version (ground truth):
@Override public Pair<Boolean,List<Continuation>> tryUnroll(Logger logger,String function,Block outerBlock){
  logger.trace("String_Node_Str" + loopName + "String_Node_Str"+ desiredUnroll);
  boolean expandLoops=isExpandLoopsEnabled();
  boolean fullUnroll=isFullUnrollEnabled();
  if (!this.unrolled && this.desiredUnroll > 1) {
    if (this.loopCounterVar != null) {
      logger.warn("String_Node_Str" + "String_Node_Str");
      return NO_UNROLL;
    }
    return Pair.create(true,doUnroll(logger,function,outerBlock,desiredUnroll));
  }
 else   if (expandLoops || fullUnroll) {
    long instCount=loopBody.getInstructionCount();
    long iterCount=constIterCount();
    if (expandLoops && iterCount >= 0) {
      if (iterCount <= getUnrollMaxIters(true)) {
        long extraInstructions=instCount * (iterCount - 1);
        if (extraInstructions <= getUnrollMaxExtraInsts(true)) {
          return Pair.create(true,doUnroll(logger,function,outerBlock,(int)iterCount));
        }
      }
    }
    if (!fullUnroll) {
      logger.trace("String_Node_Str");
      return NO_UNROLL;
    }
    if (this.unrolled) {
      return NO_UNROLL;
    }
    long threshold=getUnrollMaxExtraInsts(false);
    long unrollFactor=Math.min(getUnrollMaxIters(false),(threshold / instCount) + 1);
    if (unrollFactor > 1) {
      return Pair.create(true,doUnroll(logger,function,outerBlock,(int)unrollFactor));
    }
  }
  return NO_UNROLL;
}
Program: 132731
Project: 132731
Buggy source:
private List<Arg> canonicalizeAssignValue(GlobalConstants consts,ArgCV val){
  if (val.isArrayMemberVal() || val.isArrayMember()) {
    Arg arr=byAlias.findCanonical(val.getInput(0));
    Arg ix=byValue.findCanonical(val.getInput(1));
    return Arrays.asList(arr,ix);
  }
 else   if (val.op == Opcode.GET_FILENAME_VAL) {
    return Arrays.asList(Arg.createStringLit("String_Node_Str"),byAlias.findCanonical(val.getInput(0)));
  }
 else {
    throw new STCRuntimeError("String_Node_Str" + val + "String_Node_Str");
  }
}

Fixed version (ground truth):
private List<Arg> canonicalizeAssignValue(GlobalConstants consts,ArgCV val){
  if (val.isArrayMemberVal() || val.isArrayMember()) {
    Arg arr=byAlias.findCanonical(val.getInput(0));
    Arg ix=byValue.findCanonical(val.getInput(1));
    return Arrays.asList(arr,ix);
  }
 else   if (val.isStructFieldVal() || val.isStructFieldAlias() || val.isStructFieldCopy()|| val.isStructFieldValRef()) {
    Arg struct=byAlias.findCanonical(val.getInput(0));
    Arg fieldName=byValue.findCanonical(val.getInput(1));
    return Arrays.asList(struct,fieldName);
  }
 else   if (val.isFilenameValCV() || val.isFilenameAliasCV() || val.isLocalFilenameCV()) {
    return Arrays.asList(Arg.createStringLit("String_Node_Str"),byAlias.findCanonical(val.getInput(0)));
  }
 else {
    throw new STCRuntimeError("String_Node_Str" + val + "String_Node_Str");
  }
}
Program: 132732
Project: 132732
Buggy source:
public static ValLoc makeFilenameLocal(Arg outFilename,Var inFile,IsAssign isAssign){
  assert(isAssign != IsAssign.TO_VALUE);
  assert(Types.isFileVal(inFile));
  assert(outFilename.isImmediateString());
  return build(ComputedValue.localFilenameCV(inFile),outFilename,Closed.YES_NOT_RECURSIVE,isAssign);
}

Fixed version (ground truth):
public static ValLoc makeFilenameLocal(Arg outFilename,Var inFile,IsAssign isAssign){
  assert(Types.isFileVal(inFile));
  assert(outFilename.isImmediateString());
  return build(ComputedValue.localFilenameCV(inFile),outFilename,Closed.YES_NOT_RECURSIVE,isAssign);
}
Program: 132733
Project: 132733
Buggy source:
/** 
 * Add specific CVs for special operations
 * @param res
 */
private void addSpecialCVs(List<ValLoc> cvs){
  if (isImpl(SpecialFunction.INPUT_FILE) || isImpl(SpecialFunction.UNCACHED_INPUT_FILE) || isImpl(SpecialFunction.INPUT_URL)) {
    if (op == Opcode.CALL_FOREIGN) {
      cvs.add(ValLoc.makeFilename(getInput(0),getOutput(0)));
    }
 else     if (op == Opcode.CALL_FOREIGN_LOCAL) {
      cvs.add(ValLoc.makeFilenameLocal(getInput(0),getOutput(0),IsAssign.NO));
    }
  }
 else   if (op == Opcode.CALL_FOREIGN_LOCAL && (isImpl(SpecialFunction.RANGE) || isImpl(SpecialFunction.RANGE_STEP))) {
    addRangeCVs(cvs);
  }
 else   if (isImpl(SpecialFunction.SIZE)) {
    cvs.add(makeContainerSizeCV(IsAssign.NO));
  }
 else   if (isImpl(SpecialFunction.CONTAINS)) {
    cvs.add(makeArrayContainsCV(IsAssign.NO));
  }
}

Fixed version (ground truth):
/** 
 * Add specific CVs for special operations
 * @param res
 */
private void addSpecialCVs(List<ValLoc> cvs){
  if (isImpl(SpecialFunction.INPUT_FILE) || isImpl(SpecialFunction.UNCACHED_INPUT_FILE) || isImpl(SpecialFunction.INPUT_URL)) {
    if (op == Opcode.CALL_FOREIGN) {
      cvs.add(ValLoc.makeFilename(getInput(0),getOutput(0),IsAssign.TO_VALUE));
    }
 else     if (op == Opcode.CALL_FOREIGN_LOCAL) {
      cvs.add(ValLoc.makeFilenameLocal(getInput(0),getOutput(0),IsAssign.TO_VALUE));
    }
  }
 else   if (op == Opcode.CALL_FOREIGN_LOCAL && (isImpl(SpecialFunction.RANGE) || isImpl(SpecialFunction.RANGE_STEP))) {
    addRangeCVs(cvs);
  }
 else   if (isImpl(SpecialFunction.SIZE)) {
    cvs.add(makeContainerSizeCV(IsAssign.NO));
  }
 else   if (isImpl(SpecialFunction.CONTAINS)) {
    cvs.add(makeArrayContainsCV(IsAssign.NO));
  }
}
Program: 132735
Project: 132735
Buggy source:
private List<Violation> arrayAssign(Context context,int arrayDepth,AssignOp op){
  if (assigned != Ternary.FALSE) {
    if (arrayAssignDepth != arrayDepth) {
      return Arrays.asList(makeArrDepthViolation(context,arrayDepth));
    }
    assigned=Ternary.TRUE;
  }
 else {
    assigned=Ternary.TRUE;
    arrayAssignDepth=arrayDepth;
  }
  return null;
}

Fixed version (ground truth):
private List<Violation> arrayAssign(Context context,int arrayDepth,AssignOp op){
  if (assigned != Ternary.FALSE) {
    if (arrayAssignDepth != arrayDepth) {
      return Arrays.asList(makeArrDepthViolation(context,arrayDepth));
    }
    this.assigned=Ternary.TRUE;
  }
 else {
    this.assigned=Ternary.TRUE;
    arrayAssignDepth=arrayDepth;
  }
  return Collections.emptyList();
}
Program: 132736
Project: 132736
Buggy source:
private List<Violation> structAssign(Context context,List<String> fieldPath,int arrayDepth,AssignOp op){
  VInfo fieldVInfo;
  if (structFields != null) {
    if (this.assigned != Ternary.FALSE) {
      return Arrays.asList(new Violation(ViolationType.ERROR,"String_Node_Str" + this.name + "String_Node_Str",context));
    }
    String field=fieldPath.get(0);
    if (structFields.containsKey(field)) {
      fieldVInfo=structFields.get(field);
    }
 else {
      return Arrays.asList(new Violation(ViolationType.ERROR,"String_Node_Str" + field + "String_Node_Str"+ this.name+ "String_Node_Str"+ ((StructType)type).getStructTypeName(),context));
    }
  }
 else {
    return Arrays.asList(new Violation(ViolationType.ERROR,"String_Node_Str" + this.name + "String_Node_Str",context));
  }
  fieldPath.remove(0);
  return fieldVInfo.assign(context,fieldPath,arrayDepth,op);
}

Fixed version (ground truth):
private List<Violation> structAssign(Context context,List<String> fieldPath,int arrayDepth,AssignOp op){
  VInfo fieldVInfo;
  List<Violation> errs=new ArrayList<Violation>();
  if (structFields != null) {
    if (this.assigned == Ternary.TRUE) {
      return Arrays.asList(new Violation(ViolationType.ERROR,"String_Node_Str" + fieldPath + "String_Node_Str"+ this.name+ "String_Node_Str",context));
    }
 else     if (this.assigned == Ternary.MAYBE) {
      errs.add(new Violation(ViolationType.WARNING,"String_Node_Str" + fieldPath + "String_Node_Str"+ this.name+ "String_Node_Str",context));
    }
    String field=fieldPath.get(0);
    if (structFields.containsKey(field)) {
      fieldVInfo=structFields.get(field);
    }
 else {
      return Arrays.asList(new Violation(ViolationType.ERROR,"String_Node_Str" + field + "String_Node_Str"+ this.name+ "String_Node_Str"+ ((StructType)type).getStructTypeName(),context));
    }
  }
 else {
    return Arrays.asList(new Violation(ViolationType.ERROR,"String_Node_Str" + this.name + "String_Node_Str",context));
  }
  fieldPath.remove(0);
  errs.addAll(fieldVInfo.assign(context,fieldPath,arrayDepth,op));
  mergeStructFieldWriteInfo(context);
  return errs;
}
Program: 132737
Project: 132737
Buggy source:
/** 
 * make a copy, except it might be in a different scope All of the usage tracking is reset
 */
public VInfo makeEmptyCopy(boolean locallyDeclared){
  HashMap<String,VInfo> structFieldsNew=null;
  if (structFields != null) {
    structFieldsNew=new HashMap<String,VInfo>();
    for (    Entry<String,VInfo> e : structFields.entrySet()) {
      structFieldsNew.put(e.getKey(),e.getValue().makeEmptyCopy(locallyDeclared));
    }
  }
  return new VInfo(type,hasMapping,structFields,locallyDeclared,name,Ternary.FALSE,Ternary.FALSE,Ternary.FALSE,0,-1);
}

Fixed version (ground truth):
/** 
 * make a copy, except it might be in a different scope All of the usage tracking is reset
 */
public VInfo makeEmptyCopy(boolean locallyDeclared){
  HashMap<String,VInfo> structFieldsNew=null;
  if (structFields != null) {
    structFieldsNew=new HashMap<String,VInfo>();
    for (    Entry<String,VInfo> e : structFields.entrySet()) {
      structFieldsNew.put(e.getKey(),e.getValue().makeEmptyCopy(locallyDeclared));
    }
  }
  return new VInfo(type,hasMapping,structFieldsNew,locallyDeclared,name,Ternary.FALSE,Ternary.FALSE,Ternary.FALSE,0,-1);
}
Program: 132738
Project: 132738
Buggy source:
/** 
 * Handles the situation where there are nested scopes
 * @param branches list of a set of mutually exclusive nested scopes
 * @param exhaustive are these branches exhaustive
 * @return
 */
public ArrayList<Violation> mergeBranchInfo(Context context,List<VInfo> branches,boolean exhaustive){
  if (branches.size() == 0) {
    throw new STCRuntimeError("String_Node_Str");
  }
  mergeBranchReadInfo(branches,exhaustive);
  ArrayList<Violation> errs=mergeBranchWriteInfo(context,branches,exhaustive);
  if (structFields != null) {
    for (    VInfo fieldVI : this.structFields.values()) {
      List<VInfo> vis=new ArrayList<VInfo>(branches.size());
      for (int i=0; i < branches.size(); i++) {
        vis.add(branches.get(i).getFieldVInfo(fieldVI.getName()));
      }
      errs.addAll(fieldVI.mergeBranchInfo(context,branches,exhaustive));
    }
  }
  return errs;
}

Fixed version (ground truth):
/** 
 * Handles the situation where there are nested scopes
 * @param branches list of a set of mutually exclusive nested scopes
 * @param exhaustive are these branches exhaustive
 * @return
 */
public ArrayList<Violation> mergeBranchInfo(Context context,List<VInfo> branches,boolean exhaustive){
  if (branches.size() == 0) {
    throw new STCRuntimeError("String_Node_Str");
  }
  mergeBranchReadInfo(branches,exhaustive);
  ArrayList<Violation> errs=mergeBranchWriteInfo(context,branches,exhaustive);
  if (structFields != null) {
    for (    VInfo fieldVI : this.structFields.values()) {
      List<VInfo> vis=new ArrayList<VInfo>(branches.size());
      for (int i=0; i < branches.size(); i++) {
        vis.add(branches.get(i).getFieldVInfo(fieldVI.getName()));
      }
      ArrayList<Violation> mergeErrs=fieldVI.mergeBranchInfo(context,branches,exhaustive);
      errs.addAll(mergeErrs);
    }
  }
  return errs;
}
Program: 132739
Project: 132739
Buggy source:
private List<Violation> plainAssign(Context context,AssignOp op){
  if (assigned == Ternary.TRUE || (op == AssignOp.ASSIGN && appended == Ternary.TRUE)) {
    return Arrays.asList(new Violation(ViolationType.ERROR,"String_Node_Str" + name + "String_Node_Str",context));
  }
  ArrayList<Violation> res=new ArrayList<Violation>();
  if (assigned == Ternary.MAYBE || (op == AssignOp.ASSIGN && appended == Ternary.MAYBE)) {
    res.add(new Violation(ViolationType.WARNING,"String_Node_Str" + "String_Node_Str" + name,context));
  }
  if (op == AssignOp.ASSIGN) {
    if (Types.isStruct(type)) {
      for (      VInfo fieldVI : this.structFields.values()) {
        fieldVI.plainAssign(context,op);
      }
    }
    this.assigned=Ternary.TRUE;
  }
 else {
    assert(op == AssignOp.APPEND);
    this.appended=Ternary.TRUE;
  }
  return res;
}

Fixed version (ground truth):
private List<Violation> plainAssign(Context context,AssignOp op){
  if (assigned == Ternary.TRUE || (op == AssignOp.ASSIGN && appended == Ternary.TRUE)) {
    return Arrays.asList(new Violation(ViolationType.ERROR,"String_Node_Str" + name + "String_Node_Str",context));
  }
  ArrayList<Violation> res=new ArrayList<Violation>();
  if (assigned == Ternary.MAYBE || (op == AssignOp.ASSIGN && appended == Ternary.MAYBE)) {
    res.add(new Violation(ViolationType.WARNING,"String_Node_Str" + "String_Node_Str" + name,context));
  }
  if (op == AssignOp.ASSIGN) {
    if (Types.isStruct(type)) {
      for (      VInfo fieldVI : this.structFields.values()) {
        fieldVI.plainAssign(context,op);
      }
    }
    this.assigned=Ternary.TRUE;
  }
 else {
    assert(op == AssignOp.APPEND);
    this.assigned=Ternary.TRUE;
  }
  return res;
}
Program: 132740
Project: 132740
Buggy source:
private VInfo(Type type,boolean mapped,boolean locallyDeclared,String name,Ternary assigned,Ternary read,Ternary appended,int arrayAssignDepth,int maxReadDepth){
  this.type=type;
  this.hasMapping=mapped;
  if (Types.isStruct(type)) {
    structFields=new HashMap<String,VInfo>();
    for (    StructField f : ((StructType)type).getFields()) {
      structFields.put(f.getName(),new VInfo(f.getType(),mapped,name + "String_Node_Str" + f.getName(),locallyDeclared));
    }
  }
 else {
    structFields=null;
  }
  this.declaredInCurrentScope=locallyDeclared;
  this.name=name;
  this.assigned=assigned;
  this.appended=appended;
  this.read=read;
  this.arrayAssignDepth=arrayAssignDepth;
  this.maxReadDepth=maxReadDepth;
}

Fixed version (ground truth):
private VInfo(Type type,boolean mapped,boolean locallyDeclared,String name,Ternary assigned,Ternary read,Ternary appended,int arrayAssignDepth,int maxReadDepth){
  this.type=type;
  this.hasMapping=mapped;
  if (Types.isStruct(type)) {
    structFields=new HashMap<String,VInfo>();
    for (    StructField f : ((StructType)type.getImplType()).getFields()) {
      VInfo fieldVInfo=new VInfo(f.getType(),mapped,name + "String_Node_Str" + f.getName(),locallyDeclared);
      structFields.put(f.getName(),fieldVInfo);
    }
  }
 else {
    structFields=null;
  }
  this.declaredInCurrentScope=locallyDeclared;
  this.name=name;
  this.assigned=assigned;
  this.appended=appended;
  this.read=read;
  this.arrayAssignDepth=arrayAssignDepth;
  this.maxReadDepth=maxReadDepth;
}
Program: 132742
Project: 132742
Buggy source:
/** 
 * Called when any assignment occurs (i.e x = ...). These assignments can take the form: x(.<struct field>)*([<array_index>]) e.g. myVar = ... myVar.x.y = ... myVar[0] = ... myVar.x.y.z[0][1][2] = .. but not: myVar[0].x
 * @param fieldPath the path of struct fields (can be null for no path)
 * @param arrayDepth the number of array indices at end of assignment
 * @param op 
 */
public List<Violation> assign(Context context,List<String> fieldPath,int arrayDepth,AssignOp op){
  if (fieldPath != null && fieldPath.size() > 0) {
    return structAssign(context,fieldPath,arrayDepth,op);
  }
 else   if (arrayDepth > 0) {
    return arrayAssign(context,arrayDepth,op);
  }
 else {
    assert(arrayDepth == 0);
    assert(fieldPath == null || fieldPath.size() == 0);
    return plainAssign(context,op);
  }
}

Fixed version (ground truth):
/** 
 * Called when any assignment occurs (i.e x = ...). These assignments can take the form: x(.<struct field>)*([<array_index>]) e.g. myVar = ... myVar.x.y = ... myVar[0] = ... myVar.x.y.z[0][1][2] = .. but not: myVar[0].x
 * @param fieldPath the path of struct fields (can be null for no path)
 * @param arrayDepth the number of array indices at end of assignment
 * @param op 
 * @return list of violations, should not be null
 */
public List<Violation> assign(Context context,List<String> fieldPath,int arrayDepth,AssignOp op){
  Logger logger=Logging.getSTCLogger();
  if (logger.isTraceEnabled()) {
    logger.trace("String_Node_Str" + this.name + "String_Node_Str"+ fieldPath);
  }
  List<Violation> violations;
  if (fieldPath != null && fieldPath.size() > 0) {
    violations=structAssign(context,fieldPath,arrayDepth,op);
  }
 else   if (arrayDepth > 0) {
    violations=arrayAssign(context,arrayDepth,op);
  }
 else {
    assert(arrayDepth == 0);
    assert(fieldPath == null || fieldPath.size() == 0);
    violations=plainAssign(context,op);
  }
  if (logger.isTraceEnabled()) {
    logger.trace("String_Node_Str" + violations);
  }
  return violations;
}
Program: 132743
Project: 132743
Buggy source:
@Override public void retrieveRef(Var dst,Var src,Arg acquireRead,Arg acquireWrite,Arg decr){
  assert(Types.isRef(src.type()));
  assert(acquireRead.isIntVal());
  assert(acquireWrite.isIntVal());
  if (acquireWrite.isVar() || acquireWrite.getIntLit() > 0) {
    assert(Types.isAssignableRefTo(src.type(),dst.type(),true));
  }
 else {
    assert(Types.isAssignableRefTo(src.type(),dst.type()));
  }
  assert(decr.isImmediateInt());
  Expression acquireReadExpr=argToExpr(acquireRead);
  Expression acquireWriteExpr=argToExpr(acquireWrite);
  TypeName refType=refRepresentationType(dst.type());
  TclTree deref;
  if (acquireWriteExpr.equals(Arg.ZERO)) {
    deref=Turbine.readRefGet(prefixVar(dst),varToExpr(src),refType,acquireReadExpr,argToExpr(decr));
  }
 else {
    deref=Turbine.readWriteRefGet(prefixVar(dst),varToExpr(src),refType,acquireReadExpr,acquireWriteExpr,argToExpr(decr));
  }
  pointAdd(deref);
}

Fixed version (ground truth):
@Override public void retrieveRef(Var dst,Var src,Arg acquireRead,Arg acquireWrite,Arg decr){
  assert(Types.isRef(src.type()));
  assert(acquireRead.isIntVal());
  assert(acquireWrite.isIntVal());
  if (acquireWrite.isVar() || acquireWrite.getIntLit() > 0) {
    assert(Types.isAssignableRefTo(src.type(),dst.type(),true));
  }
 else {
    assert(Types.isAssignableRefTo(src.type(),dst.type()));
  }
  assert(decr.isImmediateInt());
  Expression acquireReadExpr=argToExpr(acquireRead);
  Expression acquireWriteExpr=argToExpr(acquireWrite);
  TypeName refType=refRepresentationType(dst.type());
  TclTree deref;
  if (acquireWrite.equals(Arg.ZERO)) {
    deref=Turbine.readRefGet(prefixVar(dst),varToExpr(src),refType,acquireReadExpr,argToExpr(decr));
  }
 else {
    deref=Turbine.readWriteRefGet(prefixVar(dst),varToExpr(src),refType,acquireReadExpr,acquireWriteExpr,argToExpr(decr));
  }
  pointAdd(deref);
}
Program: 132744
Project: 132744
Buggy source:
private void startForeachInner(Value arrayContents,Var memberVar,Var loopCountVar){
  Sequence curr=point();
  boolean haveKeys=loopCountVar != null;
  Sequence loopBody=new Sequence();
  String tclMemberVar=prefixVar(memberVar);
  String tclCountVar=haveKeys ? prefixVar(loopCountVar) : null;
  Sequence tclLoop;
  if (haveKeys) {
    tclLoop=new DictFor(new Token(tclCountVar),new Token(tclMemberVar),arrayContents,loopBody);
  }
 else {
    tclLoop=new ForEach(new Token(tclMemberVar),arrayContents,loopBody);
  }
  curr.add(tclLoop);
  pointPush(loopBody);
}

Fixed version (ground truth):
private void startForeachInner(Value arrayContents,Var memberVar,Var loopCountVar,boolean isDict){
  Sequence curr=point();
  Sequence loopBody=new Sequence();
  String tclMemberVar=prefixVar(memberVar);
  String tclCountVar=(loopCountVar != null) ? prefixVar(loopCountVar) : TCLTMP_IGNORE;
  Sequence tclLoop;
  if (isDict) {
    tclLoop=new DictFor(new Token(tclCountVar),new Token(tclMemberVar),arrayContents,loopBody);
  }
 else {
    tclLoop=new ForEach(new Token(tclMemberVar),arrayContents,loopBody);
  }
  curr.add(tclLoop);
  pointPush(loopBody);
}
Program: 132747
Project: 132747
Buggy source:
private void updateInfo(Logger logger,Block block,ArrayInfo info,Instruction inst,Set<Var> candidates){
  if (inst.op == Opcode.ARR_STORE) {
    Var arr=inst.getOutput(0);
    if (candidates.contains(arr)) {
      BlockVarInfo entry=info.getEntry(block,arr);
      entry.insertImmHere=true;
    }
  }
 else {
    for (    Var out : inst.getOutputs()) {
      if (isValidCandidate(out,false) && !initsAlias(inst,out)) {
        BlockVarInfo entry=info.getEntry(block,out);
        entry.otherModHere=true;
        if (logger.isTraceEnabled()) {
          logger.trace("String_Node_Str" + out + "String_Node_Str"+ inst);
        }
      }
    }
  }
}

Fixed version (ground truth):
private void updateInfo(Logger logger,Map<String,Function> funcMap,Block block,ArrayInfo info,Instruction inst,Set<Var> candidates){
  if (inst.op == Opcode.ARR_STORE) {
    Var arr=inst.getOutput(0);
    if (candidates.contains(arr)) {
      BlockVarInfo entry=info.getEntry(block,arr);
      entry.insertImmHere=true;
    }
  }
 else {
    for (    Var out : inst.getOutputs()) {
      if (isValidCandidate(out,false) && !initsAlias(inst,out)) {
        BlockVarInfo entry=info.getEntry(block,out);
        entry.otherModHere=true;
        if (logger.isTraceEnabled()) {
          logger.trace("String_Node_Str" + out + "String_Node_Str"+ inst);
        }
      }
    }
    Pair<List<VarCount>,List<VarCount>> inRC=inst.inRefCounts(funcMap);
    List<VarCount> inWriteRC=inRC.val2;
    for (    VarCount written : inWriteRC) {
      if (written.count != 0 && isValidCandidate(written.var,false)) {
        BlockVarInfo entry=info.getEntry(block,written.var);
        entry.otherModHere=true;
        if (logger.isTraceEnabled()) {
          logger.trace("String_Node_Str" + written + "String_Node_Str"+ inst);
        }
      }
    }
  }
}
Program: 132748
Project: 132748
Buggy source:
/** 
 * Traverse and build up info about how array is modified in all blocks of function
 * @param logger
 * @param f
 * @return
 */
private ArrayInfo buildInfo(Logger logger,Function f){
  HierarchicalSet<Var> candidates=new HierarchicalSet<Var>();
  ArrayInfo info=new ArrayInfo();
  buildAliasInfoRec(logger,f,f.mainBlock(),info,new AliasTracker());
  buildInfoRec(logger,f,f.mainBlock(),info,candidates);
  return info;
}

Fixed version (ground truth):
/** 
 * Traverse and build up info about how array is modified in all blocks of function
 * @param logger
 * @param f
 * @param funcMap 
 * @return
 */
private ArrayInfo buildInfo(Logger logger,Map<String,Function> funcMap,Function f){
  HierarchicalSet<Var> candidates=new HierarchicalSet<Var>();
  ArrayInfo info=new ArrayInfo();
  buildAliasInfoRec(logger,f,f.mainBlock(),info,new AliasTracker());
  buildInfoRec(logger,funcMap,f,f.mainBlock(),info,candidates);
  return info;
}
Program: 132749
Project: 132749
Buggy source:
private void buildInfoRec(Logger logger,Function f,Block block,ArrayInfo info,HierarchicalSet<Var> candidates){
  addBlockCandidates(f,block,info,candidates);
  for (  Statement stmt : block.getStatements()) {
switch (stmt.type()) {
case INSTRUCTION:
      updateInfo(logger,block,info,stmt.instruction(),candidates);
    break;
default :
  break;
}
}
for (Continuation c : block.allComplexStatements()) {
for (Block inner : c.getBlocks()) {
buildInfoRec(logger,f,inner,info,candidates.makeChild());
}
}
updateInfoBottomUp(logger,block,info,candidates);
if (logger.isTraceEnabled()) {
logger.trace("String_Node_Str" + System.identityHashCode(block) + "String_Node_Str"+ block.getType());
for (Var candidate : candidates) {
logger.trace(candidate + "String_Node_Str" + info.getEntry(block,candidate));
}
}
}

Fixed version (ground truth):
private void buildInfoRec(Logger logger,Map<String,Function> funcMap,Function f,Block block,ArrayInfo info,HierarchicalSet<Var> candidates){
  addBlockCandidates(f,block,info,candidates);
  for (  Statement stmt : block.getStatements()) {
switch (stmt.type()) {
case INSTRUCTION:
      updateInfo(logger,funcMap,block,info,stmt.instruction(),candidates);
    break;
default :
  break;
}
}
for (Continuation c : block.allComplexStatements()) {
for (Block inner : c.getBlocks()) {
buildInfoRec(logger,funcMap,f,inner,info,candidates.makeChild());
}
}
updateInfoBottomUp(logger,block,info,candidates);
if (logger.isTraceEnabled()) {
logger.trace("String_Node_Str" + System.identityHashCode(block) + "String_Node_Str"+ block.getType());
for (Var candidate : candidates) {
logger.trace(candidate + "String_Node_Str" + info.getEntry(block,candidate));
}
}
}
Program: 132752
Project: 132752
Buggy source:
public static <T>List<Fetched<T>> makeList(List<MakeImmVar> original,List<T> fetched){
  if (original == null) {
    original=Collections.emptyList();
  }
  if (fetched == null) {
    fetched=Collections.emptyList();
  }
  assert(original.size() == fetched.size());
  List<Fetched<T>> result=new ArrayList<Fetched<T>>(fetched.size());
  for (int i=0; i < fetched.size(); i++) {
    result.add(new Fetched<T>(original.get(i).var,fetched.get(i)));
  }
  return result;
}

Fixed version (ground truth):
/** 
 * @param original
 * @param fetched
 * @param includeAll if true, all were fetched.  If false, check fetched field of original
 * @return
 */
public static <T>List<Fetched<T>> makeList(List<MakeImmVar> original,List<T> fetched,boolean includeAll){
}
Program: 132753
Project: 132753
Buggy source:
public static void addOpEquiv(String builtinFunction,BuiltinOpcode op){
  equivalentOps.put(builtinFunction,op);
  equivalentOpsInv.put(op,builtinFunction);
}

Fixed version (ground truth):
public static void addOpEquiv(String functionName,BuiltinOpcode op){
  equivalentOps.put(functionName,op);
  equivalentOpsInv.put(op,functionName);
}
Program: 132755
Project: 132755
Buggy source:
/** 
 * Check that old output type was swapped correctly for making immediate
 * @param oldOut
 * @param newOut
 */
private void checkSwappedOutput(Var oldOut,Var newOut){
  Type exp=Types.retrievedType(oldOut.type(),recursiveInOut(op));
  assert(exp.equals(newOut.type()));
}

Fixed version (ground truth):
/** 
 * Check that old output type was swapped correctly for making immediate
 * @param oldOut
 * @param newOut
 */
private void checkSwappedOutput(Var oldOut,Var newOut){
  Type exp=Types.retrievedType(oldOut.type(),recursiveInOut(op,functionName));
  assert(exp.equals(newOut.type()));
}
Program: 132756
Project: 132756
Buggy source:
/** 
 * Returns true if we recursively pack and unpack inputs and outputs for this type of function call if converting to local version
 * @param op
 */
private static boolean recursiveInOut(Opcode op){
switch (op) {
case CALL_SYNC:
case CALL_LOCAL:
case CALL_LOCAL_CONTROL:
case CALL_CONTROL:
    return false;
case CALL_FOREIGN:
  return true;
default :
throw new STCRuntimeError("String_Node_Str" + op);
}
}

Fixed version (ground truth):
/** 
 * Returns true if we recursively pack and unpack inputs and outputs for this type of function call if converting to local version
 * @param op
 */
private static boolean recursiveInOut(Opcode op,String functionName){
switch (op) {
case CALL_SYNC:
case CALL_LOCAL:
case CALL_LOCAL_CONTROL:
case CALL_CONTROL:
case CALL_FOREIGN:
    if (ForeignFunctions.isForeignFunction(functionName)) {
      return ForeignFunctions.recursivelyUnpackedInOut(functionName);
    }
 else {
      return false;
    }
default :
  throw new STCRuntimeError("String_Node_Str" + op);
}
}
Program: 132757
Project: 132757
Buggy source:
/** 
 * Fix up any variables missing from the usedVariables passed through continuations. This is useful because it is easier to write other optimizations if they are allowed to mess up the usedVariables
 * @param updateLists modify tree and update pass and keep open lists
 */
public static void fixupProgram(Logger logger,Program prog,boolean updateLists){
  Set<Var> referencedGlobals=new HashSet<Var>();
  for (  Function fn : prog.getFunctions()) {
    fixupFunction(logger,prog.constants(),fn,referencedGlobals,updateLists);
  }
  if (updateLists)   removeUnusedGlobals(prog.constants(),referencedGlobals);
}

Fixed version (ground truth):
/** 
 * Fix up any variables missing from the usedVariables passed through continuations. This is useful because it is easier to write other optimizations if they are allowed to mess up the usedVariables
 * @param updateLists modify tree and update pass and keep open lists
 */
public static void fixupProgram(Logger logger,Program prog,boolean updateLists){
  Set<Var> referencedGlobals=new HashSet<Var>();
  for (  Function fn : prog.getFunctions()) {
    if (updateLists) {
      fixupFunction(logger,prog.constants(),fn,referencedGlobals,FixupVarMode.REBUILD);
      fixupFunction(logger,prog.constants(),fn,referencedGlobals,FixupVarMode.ADD);
    }
 else {
      fixupFunction(logger,prog.constants(),fn,referencedGlobals,FixupVarMode.NO_UPDATE);
    }
  }
  if (updateLists)   removeUnusedGlobals(prog.constants(),referencedGlobals);
}
Program: 132758
Project: 132758
Buggy source:
private static void rebuildContinuationKeepOpenVars(Function function,Continuation continuation,HierarchicalSet<Var> visible,Set<Var> outerBlockVars,AliasTracker outerAliases,Result outer,Result inner){
  List<Var> keepOpen=new ArrayList<Var>();
  for (  Var v : inner.written) {
    if (!outerBlockVars.contains(v)) {
      outer.addWritten(v,outerAliases);
    }
    if (!visible.contains(v)) {
      throw new STCRuntimeError("String_Node_Str" + v + "String_Node_Str"+ "String_Node_Str"+ function.getName());
    }
    if (RefCounting.trackWriteRefCount(v)) {
      keepOpen.add(v);
    }
  }
  continuation.setKeepOpenVars(keepOpen);
}

Fixed version (ground truth):
private static void rebuildContinuationKeepOpenVars(Function function,Continuation continuation,HierarchicalSet<Var> visible,Set<Var> outerBlockVars,AliasTracker outerAliases,Result outer,Result inner,FixupVarMode fixupMode){
  List<Var> keepOpen=new ArrayList<Var>();
  for (  Var v : inner.written) {
    if (!outerBlockVars.contains(v)) {
      outer.addWritten(v,outerAliases);
    }
    if (!visible.contains(v)) {
      throw new STCRuntimeError("String_Node_Str" + v + "String_Node_Str"+ "String_Node_Str"+ function.getName());
    }
    if (RefCounting.trackWriteRefCount(v)) {
      keepOpen.add(v);
    }
  }
  if (fixupMode == FixupVarMode.REBUILD) {
    continuation.setKeepOpenVars(keepOpen);
  }
 else {
    assert(fixupMode == FixupVarMode.ADD);
    keepOpen.addAll(continuation.getKeepOpenVars());
    ICUtil.removeDuplicates(keepOpen);
    continuation.setKeepOpenVars(keepOpen);
  }
}
Program: 132759
Project: 132759
Buggy source:
/** 
 * @param logger
 * @param block 
 * @param visible allvariables logically visible in this block. will be modified in fn
 * @param referencedGlobals updated with names of any globals used
 * @param aliases 
 * @param updateLists 
 * @return
 */
private static Result fixupBlockRec(Logger logger,Function function,Block block,ExecContext execCx,HierarchicalSet<Var> visible,Set<Var> referencedGlobals,AliasTracker aliases,boolean updateLists){
  if (updateLists)   removeGlobalImports(block);
  Set<Var> blockVars=new HashSet<Var>();
  for (  Var v : block.getVariables()) {
    blockVars.add(v);
    visible.add(v);
  }
  List<Pair<Var,Var>> createdAliases=new ArrayList<Pair<Var,Var>>();
  Result result=new Result();
  findBlockNeeded(block,result,aliases,createdAliases);
  for (  Continuation c : block.allComplexStatements()) {
    fixupContinuationRec(logger,function,execCx,c,visible,referencedGlobals,aliases,blockVars,result,updateLists);
  }
  for (  Pair<Var,Var> a : createdAliases) {
    if (result.written.contains(a.val2)) {
      result.addWritten(a.val1,aliases);
    }
  }
  result.removeReadWrite(blockVars);
  if (execCx == ExecContext.CONTROL) {
    Set<Var> globals=addGlobalImports(block,visible,updateLists,result.allSets());
    referencedGlobals.addAll(globals);
    result.removeReadWrite(globals);
  }
  return result;
}

Fixed version (ground truth):
/** 
 * @param logger
 * @param block 
 * @param visible allvariables logically visible in this block. will be modified in fn
 * @param referencedGlobals updated with names of any globals used
 * @param aliases 
 * @param fixupMode  
 * @return
 */
private static Result fixupBlockRec(Logger logger,Function function,Block block,ExecContext execCx,HierarchicalSet<Var> visible,Set<Var> referencedGlobals,AliasTracker aliases,FixupVarMode fixupMode){
  if (fixupMode == FixupVarMode.REBUILD)   removeGlobalImports(block);
  Set<Var> blockVars=new HashSet<Var>();
  for (  Var v : block.getVariables()) {
    blockVars.add(v);
    visible.add(v);
  }
  List<Pair<Var,Var>> createdAliases=new ArrayList<Pair<Var,Var>>();
  Result result=new Result();
  findBlockNeeded(block,result,aliases,createdAliases);
  for (  Continuation c : block.allComplexStatements()) {
    fixupContinuationRec(logger,function,execCx,c,visible,referencedGlobals,aliases,blockVars,result,fixupMode);
  }
  for (  Pair<Var,Var> a : createdAliases) {
    if (result.written.contains(a.val2)) {
      result.addWritten(a.val1,aliases);
    }
  }
  result.removeReadWrite(blockVars);
  if (canImportGlobals(execCx)) {
    Set<Var> globals=addGlobalImports(block,visible,fixupMode,result.allSets());
    referencedGlobals.addAll(globals);
    result.removeReadWrite(globals);
  }
  return result;
}
Program: 132761
Project: 132761
Buggy source:
/** 
 * @param block
 * @param visible
 * @param neededSets sets of vars needed from outside bock
 * @return set of global vars
 */
private static Set<Var> addGlobalImports(Block block,HierarchicalSet<Var> visible,boolean updateLists,List<Set<Var>> neededSets){
  Set<Var> addedGlobals=new HashSet<Var>();
  for (  Set<Var> neededSet : neededSets) {
    for (    Var var : neededSet) {
      if (visible.contains(var)) {
        if (var.storage() == Alloc.GLOBAL_CONST) {
          if (updateLists && !addedGlobals.contains(var))           block.addVariable(var,true);
          addedGlobals.add(var);
        }
      }
    }
  }
  return addedGlobals;
}

Fixed version (ground truth):
/** 
 * @param block
 * @param visible
 * @param neededSets sets of vars needed from outside bock
 * @return set of global vars needed from outside
 */
private static Set<Var> addGlobalImports(Block block,HierarchicalSet<Var> visible,FixupVarMode fixupMode,List<Set<Var>> neededSets){
  Set<Var> existingGlobals=new HashSet<Var>();
  if (fixupMode == FixupVarMode.ADD) {
    for (    Var v : block.getVariables()) {
      if (v.storage() == Alloc.GLOBAL_CONST) {
        existingGlobals.add(v);
      }
    }
  }
  for (  Set<Var> neededSet : neededSets) {
    for (    Var var : neededSet) {
      if (visible.contains(var)) {
        if (var.storage() == Alloc.GLOBAL_CONST) {
          if (fixupMode != FixupVarMode.NO_UPDATE && !existingGlobals.contains(var))           block.addVariable(var,true);
          existingGlobals.add(var);
        }
      }
    }
  }
  return existingGlobals;
}
Program: 132762
Project: 132762
Buggy source:
public static void fixupFunction(Logger logger,GlobalConstants constants,Function fn,Set<Var> referencedGlobals,boolean updateLists){
  HierarchicalSet<Var> fnargs=new HierarchicalSet<Var>();
  for (  Var v : fn.getInputList()) {
    fnargs.add(v);
  }
  for (  Var v : fn.getOutputList()) {
    fnargs.add(v);
  }
  fnargs.addAll(constants.vars());
  AliasTracker aliases=new AliasTracker();
  Result res=fixupBlockRec(logger,fn,fn.mainBlock(),ExecContext.CONTROL,fnargs,referencedGlobals,aliases,updateLists);
  if (updateLists) {
    for (int i=0; i < fn.getOutputList().size(); i++) {
      Var output=fn.getOutput(i);
      if (!res.read.contains(output) && !Types.hasReadableSideChannel(output.type())) {
        fn.makeOutputWriteOnly(i);
      }
    }
  }
  res.removeRead(fn.getInputList());
  res.removeReadWrite(fn.getOutputList());
  for (  Var v : fn.getInputList()) {
    if (Types.isPrimUpdateable(v.type())) {
      res.removeWritten(v);
    }
  }
  if (res.read.size() > 0) {
    throw new STCRuntimeError("String_Node_Str" + fn.getName() + "String_Node_Str"+ res.read.toString());
  }
  if (res.written.size() > 0) {
    throw new STCRuntimeError("String_Node_Str" + fn.getName() + "String_Node_Str"+ res.written.toString());
  }
  if (res.aliasWritten.size() > 0) {
    throw new STCRuntimeError("String_Node_Str" + fn.getName() + "String_Node_Str"+ res.aliasWritten.toString());
  }
}

Fixed version (ground truth):
public static void fixupFunction(Logger logger,GlobalConstants constants,Function fn,Set<Var> referencedGlobals,FixupVarMode fixupMode){
  HierarchicalSet<Var> fnargs=new HierarchicalSet<Var>();
  for (  Var v : fn.getInputList()) {
    fnargs.add(v);
  }
  for (  Var v : fn.getOutputList()) {
    fnargs.add(v);
  }
  fnargs.addAll(constants.vars());
  AliasTracker aliases=new AliasTracker();
  Result res=fixupBlockRec(logger,fn,fn.mainBlock(),ExecContext.CONTROL,fnargs,referencedGlobals,aliases,fixupMode);
  if (fixupMode != FixupVarMode.NO_UPDATE) {
    for (int i=0; i < fn.getOutputList().size(); i++) {
      Var output=fn.getOutput(i);
      if (!res.read.contains(output) && !Types.hasReadableSideChannel(output.type())) {
        fn.makeOutputWriteOnly(i);
      }
    }
  }
  res.removeRead(fn.getInputList());
  res.removeReadWrite(fn.getOutputList());
  for (  Var v : fn.getInputList()) {
    if (Types.isPrimUpdateable(v.type())) {
      res.removeWritten(v);
    }
  }
  if (res.read.size() > 0) {
    throw new STCRuntimeError("String_Node_Str" + fn.getName() + "String_Node_Str"+ res.read.toString());
  }
  if (res.written.size() > 0) {
    throw new STCRuntimeError("String_Node_Str" + fn.getName() + "String_Node_Str"+ res.written.toString());
  }
  if (res.aliasWritten.size() > 0) {
    throw new STCRuntimeError("String_Node_Str" + fn.getName() + "String_Node_Str"+ res.aliasWritten.toString());
  }
}
Program: 132766
Project: 132766
Buggy source:
private static void rebuildContinuationPassedVars(Function function,Continuation continuation,HierarchicalSet<Var> visibleVars,Set<Var> outerBlockVars,AliasTracker outerAliases,Result outer,Result inner){
  List<PassedVar> passedIn=new ArrayList<PassedVar>();
  for (  Var needed : inner.allNeeded()) {
    if (!visibleVars.contains(needed)) {
      throw new STCRuntimeError("String_Node_Str" + needed + "String_Node_Str"+ "String_Node_Str"+ function.getName());
    }
    boolean writeOnly=!inner.read.contains(needed);
    passedIn.add(new PassedVar(needed,writeOnly));
  }
  outer.addExcluding(inner,outerBlockVars);
  for (  PassedVar addtl : continuation.getMustPassVars()) {
    boolean mustAdd=true;
    ListIterator<PassedVar> it=passedIn.listIterator();
    while (it.hasNext()) {
      PassedVar existing=it.next();
      if (existing.var.equals(addtl.var)) {
        mustAdd=false;
        if (existing.writeOnly && !addtl.writeOnly) {
          it.set(addtl);
        }
      }
    }
    if (mustAdd) {
      passedIn.add(addtl);
    }
  }
  continuation.setPassedVars(passedIn);
}

Fixed version (ground truth):
private static void rebuildContinuationPassedVars(Function function,Continuation continuation,ExecContext contCx,HierarchicalSet<Var> visibleVars,Set<Var> outerBlockVars,AliasTracker outerAliases,Result outer,Result inner){
  List<PassedVar> passedIn=new ArrayList<PassedVar>();
  for (  Var needed : inner.allNeeded()) {
    if (!visibleVars.contains(needed)) {
      throw new STCRuntimeError("String_Node_Str" + needed + "String_Node_Str"+ "String_Node_Str"+ function.getName());
    }
    boolean writeOnly=!inner.read.contains(needed);
    passedIn.add(new PassedVar(needed,writeOnly));
  }
  outer.addExcluding(inner,outerBlockVars);
  for (  PassedVar addtl : continuation.getMustPassVars()) {
    boolean mustAdd=true;
    ListIterator<PassedVar> it=passedIn.listIterator();
    while (it.hasNext()) {
      PassedVar existing=it.next();
      if (existing.var.equals(addtl.var)) {
        mustAdd=false;
        if (existing.writeOnly && !addtl.writeOnly) {
          it.set(addtl);
        }
      }
    }
    if (mustAdd) {
      if (addtl.var.storage() == Alloc.GLOBAL_CONST) {
        if (contCx == ExecContext.WORKER) {
          passedIn.add(addtl);
        }
 else {
          assert(contCx == ExecContext.CONTROL);
          for (          Block b : continuation.getBlocks()) {
            if (!b.getVariables().contains(addtl.var)) {
              b.addVariable(addtl.var);
            }
          }
        }
      }
 else {
        passedIn.add(addtl);
      }
    }
  }
  continuation.setPassedVars(passedIn);
}
Program: 132768
Project: 132768
Buggy source:
/** 
 * Try to piggyback constant incrs/decrs from outside continuation. Called repeatedly until it returns null.
 * @param increments
 * @param type
 * @param dir whether to piggyback decrements or increments
 * @return if piggybacked, the var for which increments were piggybackedotherwise null
 */
public Var tryPiggyBack(RefCountsToPlace increments,RefCountType type,RCDir dir){
  for (  RefCount startIncr : startIncrements) {
    if (startIncr.type == type) {
      long incr=increments.getCount(startIncr.var);
      if ((dir == RCDir.DECR && incr < 0) || (dir == RCDir.INCR && incr > 0)) {
        addConstantStartIncrement(startIncr.var,type,Arg.createIntLit(incr));
        return startIncr.var;
      }
    }
  }
  return null;
}

Fixed version (ground truth):
/** 
 * Try to piggyback constant incrs/decrs from outside continuation. Called repeatedly until it returns null.
 * @param increments
 * @param type
 * @param dir whether to piggyback decrements or increments
 * @return if piggybacked, the var for which increments were piggybackedand amount (e.g. -2 if 2 decrements were piggybacked), otherwise null
 */
public VarCount tryPiggyBack(RefCountsToPlace increments,RefCountType type,RCDir dir){
  for (  RefCount startIncr : startIncrements) {
    if (startIncr.type == type) {
      long incr=increments.getCount(startIncr.var);
      if ((dir == RCDir.DECR && incr < 0) || (dir == RCDir.INCR && incr > 0)) {
        addConstantStartIncrement(startIncr.var,type,Arg.createIntLit(incr));
        return new VarCount(startIncr.var,incr);
      }
    }
  }
  return null;
}
Program: 132771
Project: 132771
Buggy source:
public static ValLoc assignValLoc(Var dst,Arg val,IsAssign isAssign,boolean recursive){
  ArgCV cv=assignCompVal(dst,recursive);
  if (cv == null)   return null;
  Closed closed=recursive ? Closed.YES_RECURSIVE : Closed.YES_NOT_RECURSIVE;
  return ValLoc.build(cv,dst.asArg(),closed,isAssign);
}

Fixed version (ground truth):
public static ValLoc assignValLoc(Var dst,Arg val,IsAssign isAssign,boolean recursive){
  ArgCV cv=assignCompVal(val,recursive);
  if (cv == null)   return null;
  Closed closed=recursive ? Closed.YES_RECURSIVE : Closed.YES_NOT_RECURSIVE;
  return ValLoc.build(cv,dst.asArg(),closed,isAssign);
}
Program: 132772
Project: 132772
Buggy source:
public static ArgCV assignCompVal(Var dst,boolean recursive){
  Type dstType=dst.type();
  if (Types.isPrimValue(dstType)) {
    BuiltinOpcode op;
switch (dstType.primType()) {
case BOOL:
      op=BuiltinOpcode.COPY_BOOL;
    break;
case INT:
  op=BuiltinOpcode.COPY_INT;
break;
case FLOAT:
op=BuiltinOpcode.COPY_FLOAT;
break;
case STRING:
op=BuiltinOpcode.COPY_STRING;
break;
case BLOB:
op=BuiltinOpcode.COPY_BLOB;
break;
case VOID:
op=BuiltinOpcode.COPY_VOID;
break;
default :
throw new STCRuntimeError("String_Node_Str" + dstType);
}
return new ArgCV(Opcode.LOCAL_OP,op,dst.asArg().asList());
}
 else {
Opcode op=Opcode.assignOpcode(dstType,recursive);
if (op != null) {
return new ArgCV(op,dst.asArg().asList());
}
}
throw new STCRuntimeError("String_Node_Str" + dst + (recursive ? "String_Node_Str" : "String_Node_Str"));
}

Fixed version (ground truth):
public static ArgCV assignCompVal(Arg dst,boolean recursive){
  Type dstType=dst.type();
  if (Types.isPrimValue(dstType)) {
    BuiltinOpcode op;
switch (dstType.primType()) {
case BOOL:
      op=BuiltinOpcode.COPY_BOOL;
    break;
case INT:
  op=BuiltinOpcode.COPY_INT;
break;
case FLOAT:
op=BuiltinOpcode.COPY_FLOAT;
break;
case STRING:
op=BuiltinOpcode.COPY_STRING;
break;
case BLOB:
op=BuiltinOpcode.COPY_BLOB;
break;
case VOID:
op=BuiltinOpcode.COPY_VOID;
break;
default :
throw new STCRuntimeError("String_Node_Str" + dstType);
}
return new ArgCV(Opcode.LOCAL_OP,op,dst.asList());
}
 else {
Opcode op=Opcode.assignOpcode(dstType,recursive);
if (op != null) {
return new ArgCV(op,dst.asList());
}
}
throw new STCRuntimeError("String_Node_Str" + dst + (recursive ? "String_Node_Str" : "String_Node_Str"));
}
Program: 132773
Project: 132773
Buggy source:
/** 
 * Add any inverse operations that can be directly inferred from a value that was just added
 * @param errContext
 * @param canonLoc
 * @param canonVal
 * @throws OptUnsafeError 
 */
private void addInverses(GlobalConstants consts,String errContext,Arg canonLoc,ArgOrCV canonVal,int stmtIndex) throws OptUnsafeError {
  if (canonVal.isCV() && canonVal.cv().inputs.size() == 1) {
    ComputedValue<Arg> cv=canonVal.cv();
    Arg invOutput=cv.getInput(0);
    if (cv.op().isAssign(false)) {
      ArgCV invVal=ComputedValue.retrieveCompVal(canonLoc.getVar(),false);
      updateInv(consts,errContext,invOutput,invVal,stmtIndex);
    }
 else     if (cv.op().isRecursiveAssign()) {
      ArgCV invVal=ComputedValue.retrieveCompVal(canonLoc.getVar(),true);
      updateInv(consts,errContext,invOutput,invVal,stmtIndex);
    }
 else     if (cv.op().isRetrieve(false)) {
      ArgCV invVal=ComputedValue.assignCompVal(invOutput.getVar(),false);
      updateInv(consts,errContext,invOutput,invVal,stmtIndex);
    }
 else     if (cv.op().isRecursiveRetrieve()) {
      ArgCV invVal=ComputedValue.assignCompVal(invOutput.getVar(),true);
      updateInv(consts,errContext,invOutput,invVal,stmtIndex);
      updateInv(consts,errContext,invOutput,invVal,stmtIndex);
    }
  }
 else   if (canonVal.isArg() && canonVal.arg().isVar() && canonVal.arg().getVar().storage() == Alloc.GLOBAL_CONST) {
    Var globalConst=canonVal.arg().getVar();
    Arg constVal=consts.lookupByVar(globalConst);
    assert(constVal != null);
    ArgCV invVal=ComputedValue.retrieveCompVal(globalConst,false);
    updateInv(consts,errContext,constVal,invVal,stmtIndex);
  }
}

Fixed version (ground truth):
/** 
 * Add any inverse operations that can be directly inferred from a value that was just added
 * @param errContext
 * @param canonLoc
 * @param canonVal
 * @throws OptUnsafeError 
 */
private void addInverses(GlobalConstants consts,String errContext,Arg canonLoc,ArgOrCV canonVal,int stmtIndex) throws OptUnsafeError {
}