nus-yam/ex-repair huggingface dataset:
Program: 133038
Project: 133038
Buggy source:
@Override public boolean tryUnroll(Logger logger,Block outerBlock){
  logger.trace("String_Node_Str" + loopName + "String_Node_Str"+ desiredUnroll);
  if (this.unrolled) {
    return false;
  }
 else   if (this.desiredUnroll > 1) {
    if (this.countVar != null) {
      logger.warn("String_Node_Str" + "String_Node_Str");
      return false;
    }
    doUnroll(logger,outerBlock,desiredUnroll);
    return true;
  }
 else   if (start.isIntVal() && end.isIntVal() && increment.isIntVal()) {
    long iters=calcIterations(start.getIntLit(),end.getIntLit(),increment.getIntLit());
    try {
      if (iters <= Settings.getLong(Settings.OPT_UNROLL_LOOP_THRESHOLD_ITERS)) {
        long instCount=loopBody.getInstructionCount();
        long extraInstructions=instCount * (iters - 1);
        long extraInstructionThreshold=Settings.getLong(Settings.OPT_UNROLL_LOOP_THRESHOLD_INSTS);
        if (extraInstructions <= extraInstructionThreshold) {
          doUnroll(logger,outerBlock,iters);
          return true;
        }
      }
    }
 catch (    InvalidOptionException e) {
      throw new STCRuntimeError(e.getMessage());
    }
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean tryUnroll(Logger logger,Block outerBlock){
  logger.trace("String_Node_Str" + loopName + "String_Node_Str"+ desiredUnroll);
  if (this.unrolled) {
    return false;
  }
 else   if (this.desiredUnroll > 1) {
    if (this.loopCounterVar != null) {
      logger.warn("String_Node_Str" + "String_Node_Str");
      return false;
    }
    doUnroll(logger,outerBlock,desiredUnroll);
    return true;
  }
 else   if (start.isIntVal() && end.isIntVal() && increment.isIntVal()) {
    long iters=calcIterations(start.getIntLit(),end.getIntLit(),increment.getIntLit());
    try {
      if (iters <= Settings.getLong(Settings.OPT_UNROLL_LOOP_THRESHOLD_ITERS)) {
        long instCount=loopBody.getInstructionCount();
        long extraInstructions=instCount * (iters - 1);
        long extraInstructionThreshold=Settings.getLong(Settings.OPT_UNROLL_LOOP_THRESHOLD_INSTS);
        if (extraInstructions <= extraInstructionThreshold) {
          doUnroll(logger,outerBlock,iters);
          return true;
        }
      }
    }
 catch (    InvalidOptionException e) {
      throw new STCRuntimeError(e.getMessage());
    }
  }
  return false;
}
Program: 133039
Project: 133039
Buggy source:
public static TclTree allocateUpdateable(String tclName,String typePrefix,Expression initReaders,Expression initWriters){
  return new Command(ALLOCATE_CUSTOM,new Token(tclName),new Token(typePrefix),initReaders,initWriters);
}

Fixed version (ground truth):
public static TclTree allocateUpdateable(String tclName,String typePrefix,Expression initReaders){
  return new Command(ALLOCATE_CUSTOM,new Token(tclName),new Token(typePrefix),initReaders);
}
Program: 133040
Project: 133040
Buggy source:
private void allocateUpdateable(Var var,Arg initReaders,Arg initWriters) throws UndefinedTypeException {
  String tprefix=typeToString(var.type().primType());
  pointStack.peek().add(Turbine.allocateUpdateable(prefixVar(var),tprefix,argToExpr(initReaders),argToExpr(initWriters)));
}

Fixed version (ground truth):
private void allocateUpdateable(Var var,Arg initReaders,Arg initWriters) throws UndefinedTypeException {
  String tprefix=typeToString(var.type().primType());
  pointStack.peek().add(Turbine.allocateUpdateable(prefixVar(var),tprefix,argToExpr(initReaders)));
}
Program: 133041
Project: 133041
Buggy source:
/** 
 * Return true if inst2 writes some of inst1's required vars
 * @param logger
 * @param inst1
 * @param inst1Inputs
 * @param inst2
 * @param inst2Inputs
 * @return
 */
private boolean writesInputs(Logger logger,Instruction inst1,List<Var> inst1Inputs,Instruction inst2,List<Var> inst2Inputs){
  if (inst2.op == Opcode.ADDRESS_OF && !inst1.getPiecewiseAssignedOutputs().isEmpty() && inst1.getPiecewiseAssignedOutputs().contains(inst2.getOutput(0))) {
    if (logger.isTraceEnabled())     logger.trace(inst2 + "String_Node_Str" + inst1);
    return true;
  }
  if (!inst2.getInitializedAliases().isEmpty()) {
    List<Var> initAliases=inst2.getInitializedAliases();
    for (    Var input : inst1.getOutputs()) {
      if (input.storage() == VarStorage.ALIAS && initAliases.contains(input)) {
        if (logger.isTraceEnabled())         logger.trace(inst2 + "String_Node_Str" + inst1);
        return true;
      }
    }
  }
  for (  Var inst2Output : inst2.getModifiedOutputs()) {
    if (inst1Inputs.contains(inst2Output)) {
      if (logger.isTraceEnabled())       logger.trace(inst2 + "String_Node_Str" + inst1);
      return true;
    }
  }
  return false;
}

Fixed version (ground truth):
/** 
 * Return true if inst2 writes some of inst1's required vars
 * @param logger
 * @param inst1
 * @param inst1Inputs
 * @param inst2
 * @param inst2Inputs
 * @return
 */
private boolean writesInputs(Logger logger,Instruction inst1,List<Var> inst1Inputs,Instruction inst2,List<Var> inst2Inputs){
  if (inst2.op == Opcode.ADDRESS_OF && !inst1.getPiecewiseAssignedOutputs().isEmpty() && inst1.getPiecewiseAssignedOutputs().contains(inst2.getOutput(0))) {
    if (logger.isTraceEnabled())     logger.trace(inst2 + "String_Node_Str" + inst1);
    return true;
  }
  if (initializesOutputs(inst1,inst2)) {
    if (logger.isTraceEnabled())     logger.trace(inst2 + "String_Node_Str" + inst1);
    return true;
  }
  for (  Var inst2Output : inst2.getModifiedOutputs()) {
    if (inst1Inputs.contains(inst2Output)) {
      if (logger.isTraceEnabled())       logger.trace(inst2 + "String_Node_Str" + inst1);
      return true;
    }
  }
  return false;
}
Program: 133042
Project: 133042
Buggy source:
private boolean varMustBeInitialized(Var v){
  return v.storage() == VarStorage.ALIAS || v.storage() == VarStorage.LOCAL;
}

Fixed version (ground truth):
private boolean varMustBeInitialized(Var v){
  return v.storage() == VarStorage.ALIAS || v.storage() == VarStorage.LOCAL || Types.isScalarUpdateable(v.type());
}
Program: 133043
Project: 133043
Buggy source:
@Override public List<Var> tryPiggyback(Counters<Var> increments,RefCountType type){
switch (op) {
case LOAD_BLOB:
case LOAD_BOOL:
case LOAD_FILE:
case LOAD_FLOAT:
case LOAD_INT:
case LOAD_REF:
case LOAD_STRING:
case LOAD_VOID:
{
      Var inVar=getInput(0).getVar();
      if (type == RefCountType.READERS) {
        long amt=increments.getCount(inVar);
        if (amt < 0) {
          assert(getInputs().size() == 1);
          this.args=Arrays.asList(args.get(0),args.get(1),Arg.createIntLit(amt * -1));
          return Collections.singletonList(inVar);
        }
      }
    }
case ARRAY_INSERT_IMM:
case ARRAY_INSERT_FUTURE:
{
    Var arr=getOutput(0);
    if (type == RefCountType.WRITERS) {
      long amt=increments.getCount(arr);
      if (amt < 0) {
        assert(getInputs().size() == 2);
        this.args=Arrays.asList(args.get(0),args.get(1),args.get(2),Arg.createIntLit(amt * -1));
        return Collections.singletonList(arr);
      }
    }
  }
}
return Var.NONE;
}

Fixed version (ground truth):
@Override public List<Var> tryPiggyback(Counters<Var> increments,RefCountType type){
switch (op) {
case LOAD_BLOB:
case LOAD_BOOL:
case LOAD_FILE:
case LOAD_FLOAT:
case LOAD_INT:
case LOAD_REF:
case LOAD_STRING:
case LOAD_VOID:
{
      Var inVar=getInput(0).getVar();
      if (type == RefCountType.READERS) {
        long amt=increments.getCount(inVar);
        if (amt < 0) {
          assert(getInputs().size() == 1);
          this.args=Arrays.asList(args.get(0),args.get(1),Arg.createIntLit(amt * -1));
          return Collections.singletonList(inVar);
        }
      }
      break;
    }
case ARRAY_INSERT_IMM:
case ARRAY_INSERT_FUTURE:
{
    Var arr=getOutput(0);
    if (type == RefCountType.WRITERS) {
      long amt=increments.getCount(arr);
      if (amt < 0) {
        assert(getInputs().size() == 2);
        this.args=Arrays.asList(args.get(0),args.get(1),args.get(2),Arg.createIntLit(amt * -1));
        return Collections.singletonList(arr);
      }
    }
    break;
  }
}
return Var.NONE;
}
Program: 133044
Project: 133044
Buggy source:
/** 
 * Try reordering instructions
 * @param logger
 * @param block
 */
private void reorderInBlock(Logger logger,Block block){
  logger.trace("String_Node_Str");
  ArrayList<Instruction> instructionsCopy=new ArrayList<Instruction>(block.getInstructions());
  ArrayList<Instruction> newInstructions=new ArrayList<Instruction>();
  MultiMap<Instruction,Instruction> after=new MultiMap<Instruction,Instruction>();
  boolean moved=false;
  for (int i=0; i < instructionsCopy.size(); i++) {
    Instruction inst1=instructionsCopy.get(i);
    boolean move=searchForInputWriter(logger,instructionsCopy,i,inst1,after);
    if (move) {
      moved=true;
    }
 else {
      newInstructions.add(inst1);
    }
  }
  if (moved) {
    rebuildInstructions(block,newInstructions,after);
    block.replaceInstructions(newInstructions);
    move++;
  }
 else {
    noMove++;
  }
  if (logger.isTraceEnabled())   logger.trace("String_Node_Str" + move + "String_Node_Str"+ (move + noMove));
}

Fixed version (ground truth):
/** 
 * Try reordering instructions
 * @param logger
 * @param block
 */
private void reorderInBlock(Logger logger,Block block){
  logger.trace("String_Node_Str");
  ArrayList<Instruction> instructionsCopy=new ArrayList<Instruction>(block.getInstructions());
  ArrayList<Instruction> newInstructions=new ArrayList<Instruction>();
  MultiMap<Instruction,Instruction> after=new MultiMap<Instruction,Instruction>();
  HashSet<Instruction> mustMove=new HashSet<Instruction>();
  boolean moved=false;
  for (int i=0; i < instructionsCopy.size(); i++) {
    Instruction inst1=instructionsCopy.get(i);
    boolean move=searchForInputWriter(logger,instructionsCopy,i,inst1,after,mustMove);
    if (logger.isTraceEnabled())     logger.trace("String_Node_Str" + inst1 + "String_Node_Str"+ move);
    if (move) {
      moved=true;
      if (logger.isTraceEnabled())       logger.trace("String_Node_Str" + inst1 + "String_Node_Str"+ after.get(inst1));
    }
 else {
      newInstructions.add(inst1);
    }
  }
  if (moved) {
    rebuildInstructions(block,newInstructions,after);
    block.replaceInstructions(newInstructions);
    move++;
  }
 else {
    noMove++;
  }
  if (logger.isTraceEnabled())   logger.trace("String_Node_Str" + move + "String_Node_Str"+ (move + noMove));
}
Program: 133045
Project: 133045
Buggy source:
private boolean searchForInputWriter(Logger logger,ArrayList<Instruction> instructionsCopy,int i,Instruction inst1,MultiMap<Instruction,Instruction> after){
  List<Var> inst1Inputs=getInputs(inst1);
  if (logger.isTraceEnabled())   logger.trace("String_Node_Str" + inst1 + "String_Node_Str"+ inst1Inputs);
  boolean move=false;
  boolean canMoveFurther=true;
  for (int j=i + 1; j < instructionsCopy.size(); j++) {
    Instruction inst2=instructionsCopy.get(j);
    if (writesInputs(logger,inst2,getInputs(inst2),inst1)) {
      after.put(inst1,inst2);
      canMoveFurther=false;
    }
    if (canMoveFurther && writesInputs(logger,inst1,inst1Inputs,inst2)) {
      if (pathExists(after,inst1,inst2)) {
        canMoveFurther=false;
      }
 else {
        after.put(inst2,inst1);
        move=true;
      }
    }
  }
  return move;
}

Fixed version (ground truth):
private boolean searchForInputWriter(Logger logger,ArrayList<Instruction> instructionsCopy,int i,Instruction inst1,MultiMap<Instruction,Instruction> after,HashSet<Instruction> mustMove){
  List<Var> inst1Inputs=getInputs(inst1);
  if (logger.isTraceEnabled())   logger.trace("String_Node_Str" + inst1 + "String_Node_Str"+ inst1Inputs);
  boolean move=mustMove.contains(inst1);
  boolean canMoveFurther=true;
  for (int j=i + 1; j < instructionsCopy.size(); j++) {
    Instruction inst2=instructionsCopy.get(j);
    List<Var> inst2Inputs=getInputs(inst2);
    if (writesInputs(logger,inst2,inst2Inputs,inst1,inst1Inputs,false)) {
      after.put(inst1,inst2);
      mustMove.add(inst2);
      canMoveFurther=false;
      if (!move) {
        break;
      }
    }
    if (canMoveFurther && writesInputs(logger,inst1,inst1Inputs,inst2,inst2Inputs,true)) {
      if (pathExists(after,inst1,inst2)) {
        canMoveFurther=false;
      }
 else {
        after.put(inst2,inst1);
        move=true;
      }
    }
  }
  return move;
}
Program: 133046
Project: 133046
Buggy source:
private boolean writesInputs(Logger logger,Instruction inst1,List<Var> inst1Inputs,Instruction inst2){
  if (inst2.op == Opcode.ADDRESS_OF && !inst1.getPiecewiseAssignedOutputs().isEmpty() && inst1.getPiecewiseAssignedOutputs().contains(inst2.getOutput(0))) {
    return true;
  }
  for (  Var inst2Output : inst2.getModifiedOutputs()) {
    if (inst1Inputs.contains(inst2Output)) {
      if (logger.isTraceEnabled())       logger.trace(inst2 + "String_Node_Str" + inst1);
      if (Collections.disjoint(inst1.getModifiedOutputs(),inst2.getModifiedOutputs())) {
        logger.trace("String_Node_Str");
        return true;
      }
      break;
    }
  }
  return false;
}

Fixed version (ground truth):
/** 
 * Return true if inst2 writes some of inst1's required vars
 * @param logger
 * @param inst1
 * @param inst1Inputs
 * @param inst2
 * @param inst2Inputs
 * @return
 */
private boolean writesInputs(Logger logger,Instruction inst1,List<Var> inst1Inputs,Instruction inst2,List<Var> inst2Inputs){
  if (inst2.op == Opcode.ADDRESS_OF && !inst1.getPiecewiseAssignedOutputs().isEmpty() && inst1.getPiecewiseAssignedOutputs().contains(inst2.getOutput(0))) {
    if (logger.isTraceEnabled())     logger.trace(inst2 + "String_Node_Str" + inst1);
    return true;
  }
  if (!inst2.getInitializedAliases().isEmpty()) {
    List<Var> initAliases=inst2.getInitializedAliases();
    for (    Var input : inst1.getOutputs()) {
      if (input.storage() == VarStorage.ALIAS && initAliases.contains(input)) {
        if (logger.isTraceEnabled())         logger.trace(inst2 + "String_Node_Str" + inst1);
        return true;
      }
    }
  }
  for (  Var inst2Output : inst2.getModifiedOutputs()) {
    if (inst1Inputs.contains(inst2Output)) {
      if (logger.isTraceEnabled())       logger.trace(inst2 + "String_Node_Str" + inst1);
      return true;
    }
  }
  return false;
}
Program: 133048
Project: 133048
Buggy source:
/** 
 * Try to squash together waits, e.g. wait (x) { < do some minor work that doesn't help with progress > wait (y) { < do some real work > } } gets changed to wait (x, y) { ... }
 * @param logger
 * @param fn
 * @param block
 */
private void squashWaits(Logger logger,Function fn,WaitStatement wait,ExecContext waitContext){
  Block block=wait.getBlock();
  WaitStatement innerWait=null;
  for (  Continuation c : block.getContinuations()) {
    if (c.isAsync()) {
      if (c.getType() == ContinuationType.WAIT_STATEMENT) {
        if (innerWait != null) {
          return;
        }
 else {
          innerWait=(WaitStatement)c;
        }
      }
 else {
        return;
      }
    }
  }
  ExecContext innerContext=innerWait.childContext(waitContext);
  if (innerContext != waitContext)   return;
  for (  Var waitVar : innerWait.getWaitVars()) {
    if (block.getVariables().contains(waitVar)) {
      return;
    }
  }
  if (!ProgressOpcodes.isNonProgress(block)) {
    return;
  }
  if (logger.isTraceEnabled())   logger.trace("String_Node_Str" + innerWait.getWaitVars() + "String_Node_Str"+ "String_Node_Str"+ wait.getWaitVars()+ "String_Node_Str");
  wait.addWaitVars(innerWait.getWaitVars());
  innerWait.inlineInto(block);
}

Fixed version (ground truth):
/** 
 * Try to squash together waits, e.g. wait (x) { < do some minor work that doesn't help with progress > wait (y) { < do some real work > } } gets changed to wait (x, y) { ... }
 * @param logger
 * @param fn
 * @param block
 */
private void squashWaits(Logger logger,Function fn,WaitStatement wait,ExecContext waitContext){
  Block block=wait.getBlock();
  WaitStatement innerWait=null;
  for (  Continuation c : block.getContinuations()) {
    if (c.isAsync()) {
      if (c.getType() == ContinuationType.WAIT_STATEMENT) {
        if (innerWait != null) {
          return;
        }
 else {
          innerWait=(WaitStatement)c;
        }
      }
 else {
        return;
      }
    }
  }
  if (innerWait == null)   return;
  ExecContext innerContext=innerWait.childContext(waitContext);
  if (innerContext != waitContext)   return;
  for (  Var waitVar : innerWait.getWaitVars()) {
    if (block.getVariables().contains(waitVar)) {
      return;
    }
  }
  if (!ProgressOpcodes.isNonProgress(block)) {
    return;
  }
  if (logger.isTraceEnabled())   logger.trace("String_Node_Str" + innerWait.getWaitVars() + "String_Node_Str"+ "String_Node_Str"+ wait.getWaitVars()+ "String_Node_Str");
  wait.addWaitVars(innerWait.getWaitVars());
  innerWait.inlineInto(block);
}
Program: 133049
Project: 133049
Buggy source:
/** 
 * Do one iteration of the iterative optimizer passes
 * @param icOutput
 * @param logger
 * @param prog
 * @param debug 
 * @param iteration
 * @param nIterations
 * @throws Exception
 */
private static void iterate(PrintStream icOutput,Logger logger,Program prog,boolean debug,long nIterations) throws UserException {
  FunctionInline inliner=new FunctionInline();
  for (long iteration=0; iteration < nIterations; iteration++) {
    OptimizerPipeline pipe=new OptimizerPipeline(icOutput);
    pipe.addPass(inliner);
    pipe.addPass(new FixupVariables());
    pipe.addPass(new ConstantFold());
    if (iteration == 0) {
      pipe.addPass(new LoopUnroller());
    }
    pipe.addPass(new HoistLoops());
    pipe.addPass(new ForwardDataflow());
    pipe.addPass(new ContinuationFusion());
    if (iteration == nIterations - (nIterations / 4) - 3) {
      pipe.addPass(new Pipeline());
      if (debug)       pipe.addPass(Validate.standardValidator());
    }
    boolean doWaitMerges=iteration == nIterations - (nIterations / 4) - 2;
    pipe.addPass(new WaitCoalescer(doWaitMerges));
    if (debug)     pipe.addPass(Validate.standardValidator());
    pipe.runPipeline(logger,prog,iteration);
  }
}

Fixed version (ground truth):
/** 
 * Do one iteration of the iterative optimizer passes
 * @param icOutput
 * @param logger
 * @param prog
 * @param debug 
 * @param iteration
 * @param nIterations
 * @throws Exception
 */
private static void iterate(PrintStream icOutput,Logger logger,Program prog,boolean debug,long nIterations) throws UserException {
  FunctionInline inliner=new FunctionInline();
  for (long iteration=0; iteration < nIterations; iteration++) {
    OptimizerPipeline pipe=new OptimizerPipeline(icOutput);
    pipe.addPass(inliner);
    pipe.addPass(new ConstantFold());
    if (iteration == 0) {
      pipe.addPass(new LoopUnroller());
    }
    pipe.addPass(new HoistLoops());
    pipe.addPass(new ForwardDataflow());
    pipe.addPass(new ContinuationFusion());
    if (iteration == nIterations - (nIterations / 4) - 3) {
      pipe.addPass(new Pipeline());
      if (debug)       pipe.addPass(Validate.standardValidator());
    }
    boolean doWaitMerges=iteration == nIterations - (nIterations / 4) - 2;
    pipe.addPass(new WaitCoalescer(doWaitMerges));
    if (debug)     pipe.addPass(Validate.standardValidator());
    pipe.runPipeline(logger,prog,iteration);
  }
}
Program: 133050
Project: 133050
Buggy source:
private void elimRefCountsCont(Logger logger,Function f,Continuation cont,HierarchicalSet<Var> parentAssignedAliasVars){
  for (  Block block : cont.getBlocks()) {
    Counters<Var> readIncrements=new Counters<Var>();
    Counters<Var> writeIncrements=new Counters<Var>();
    if (isSingleSpawnCont(cont)) {
      for (      Var keepOpen : cont.getKeepOpenVars()) {
        if (RefCounting.hasWriteRefCount(keepOpen)) {
          writeIncrements.decrement(keepOpen);
        }
      }
      for (      Var passedIn : cont.getPassedInVars()) {
        if (RefCounting.hasReadRefCount(passedIn)) {
          readIncrements.decrement(passedIn);
        }
      }
    }
    HierarchicalSet<Var> contAssignedAliasVars=parentAssignedAliasVars.makeChild();
    for (    Var v : cont.constructDefinedVars()) {
      if (v.storage() == VarStorage.ALIAS) {
        contAssignedAliasVars.add(v);
      }
    }
    elimRefCountsRec(logger,f,block,readIncrements,writeIncrements,contAssignedAliasVars);
  }
}

Fixed version (ground truth):
private void elimRefCountsCont(Logger logger,Function f,Continuation cont,HierarchicalSet<Var> parentAssignedAliasVars){
  for (  Block block : cont.getBlocks()) {
    Counters<Var> readIncrements=new Counters<Var>();
    Counters<Var> writeIncrements=new Counters<Var>();
    if (isSingleSpawnCont(cont) && cont.getType() != ContinuationType.LOOP) {
      for (      Var keepOpen : cont.getKeepOpenVars()) {
        if (RefCounting.hasWriteRefCount(keepOpen)) {
          writeIncrements.decrement(keepOpen);
        }
      }
      for (      Var passedIn : cont.getPassedInVars()) {
        if (RefCounting.hasReadRefCount(passedIn)) {
          readIncrements.decrement(passedIn);
        }
      }
    }
    HierarchicalSet<Var> contAssignedAliasVars=parentAssignedAliasVars.makeChild();
    for (    Var v : cont.constructDefinedVars()) {
      if (v.storage() == VarStorage.ALIAS) {
        contAssignedAliasVars.add(v);
      }
    }
    elimRefCountsRec(logger,f,block,readIncrements,writeIncrements,contAssignedAliasVars);
  }
}
Program: 133051
Project: 133051
Buggy source:
private void updateInstructionRefCount(Instruction inst,Counters<Var> readIncrements,Counters<Var> writeIncrements){
  Pair<List<Var>,List<Var>> refIncrs=inst.getIncrVars();
  List<Var> readIncrVars=refIncrs.val1;
  List<Var> writeIncrVars=refIncrs.val2;
  for (  Var v : readIncrVars) {
    if (RefCounting.hasReadRefCount(v)) {
      readIncrements.increment(v);
    }
  }
  for (  Var v : writeIncrVars) {
    if (RefCounting.hasWriteRefCount(v)) {
      writeIncrements.increment(v);
    }
  }
}

Fixed version (ground truth):
private void updateInstructionRefCount(Instruction inst,Counters<Var> readIncrements,Counters<Var> writeIncrements){
  Pair<List<Var>,List<Var>> refIncrs=inst.getIncrVars();
  List<Var> readIncrVars=refIncrs.val1;
  List<Var> writeIncrVars=refIncrs.val2;
  for (  Var v : readIncrVars) {
    if (RefCounting.hasReadRefCount(v)) {
      readIncrements.increment(v);
    }
  }
  for (  Var v : writeIncrVars) {
    if (RefCounting.hasWriteRefCount(v)) {
      writeIncrements.increment(v);
    }
  }
  if (inst.op == Opcode.LOOP_BREAK) {
    LoopBreak loopBreak=(LoopBreak)inst;
    for (    Var ko : loopBreak.getKeepOpenVars()) {
      assert(RefCounting.hasWriteRefCount(ko));
      writeIncrements.decrement(ko);
    }
    for (    Var pass : loopBreak.getUsedVars()) {
      if (RefCounting.hasReadRefCount(pass)) {
        readIncrements.decrement(pass);
      }
    }
  }
}
Program: 133052
Project: 133052
Buggy source:
private void updateContinuationRefCount(Continuation cont,Counters<Var> readIncrements,Counters<Var> writeIncrements){
  if (cont.isAsync() && cont.getType() == ContinuationType.WAIT_STATEMENT) {
    long incr=1;
    for (    Var passedIn : cont.getPassedInVars()) {
      if (RefCounting.hasReadRefCount(passedIn)) {
        readIncrements.add(passedIn,incr);
      }
    }
    for (    Var keepOpen : cont.getKeepOpenVars()) {
      if (RefCounting.hasWriteRefCount(keepOpen)) {
        writeIncrements.add(keepOpen,incr);
      }
    }
  }
}

Fixed version (ground truth):
private void updateContinuationRefCount(Continuation cont,Counters<Var> readIncrements,Counters<Var> writeIncrements){
  if (cont.isAsync() && isSingleSpawnCont(cont)) {
    long incr=1;
    for (    Var passedIn : cont.getPassedInVars()) {
      if (RefCounting.hasReadRefCount(passedIn)) {
        readIncrements.add(passedIn,incr);
      }
    }
    for (    Var keepOpen : cont.getKeepOpenVars()) {
      if (RefCounting.hasWriteRefCount(keepOpen)) {
        writeIncrements.add(keepOpen,incr);
      }
    }
  }
}
Program: 133053
Project: 133053
Buggy source:
@Override public void clearKeepOpenVars(){
  this.keepOpenVars.clear();
}

Fixed version (ground truth):
@Override public void clearKeepOpenVars(){
  super.clearKeepOpenVars();
  this.loopContinue.clearKeepOpenVars();
  this.loopBreak.clearKeepOpenVars();
}
Program: 133054
Project: 133054
Buggy source:
@Override public void addKeepOpenVars(Collection<Var> v){
  super.addKeepOpenVars(v);
  this.loopContinue.removeKeepOpenVars(v);
  this.loopBreak.removeKeepOpenVars(v);
}

Fixed version (ground truth):
@Override public void addKeepOpenVars(Collection<Var> v){
  this.keepOpenVars.addAll(v);
}
Program: 133055
Project: 133055
Buggy source:
@Override public void startLoop(String loopName,List<Var> loopVars,List<Boolean> definedHere,List<Var> initVals,List<Var> usedVariables,List<Var> keepOpenVars,List<Boolean> blockingVars){
  ArrayList<String> loopFnArgs=new ArrayList<String>();
  ArrayList<Value> firstIterArgs=new ArrayList<Value>();
  loopFnArgs.add(Turbine.LOCAL_STACK_NAME);
  firstIterArgs.add(new Value(Turbine.LOCAL_STACK_NAME));
  for (  Var arg : loopVars) {
    loopFnArgs.add(prefixVar(arg.name()));
  }
  for (  Var init : initVals) {
    firstIterArgs.add(varToExpr(init));
  }
  for (  Var uv : usedVariables) {
    loopFnArgs.add(prefixVar(uv.name()));
    firstIterArgs.add(varToExpr(uv));
  }
  ArrayList<Value> blockingVals=new ArrayList<Value>();
  assert(blockingVars.size() == initVals.size());
  for (int i=0; i < blockingVars.size(); i++) {
    Var iv=initVals.get(i);
    if (blockingVars.get(i)) {
      blockingVals.add(varToExpr(iv));
    }
  }
  incrementAllRefs(usedVariables,keepOpenVars);
  incrementReaders(initVals,null);
  String uniqueLoopName=uniqueTCLFunctionName(loopName);
  pointStack.peek().add(Turbine.loopRule(uniqueLoopName,firstIterArgs,blockingVals));
  Sequence loopBody=new Sequence();
  Proc loopProc=new Proc(uniqueLoopName,usedTclFunctionNames,loopFnArgs,loopBody);
  tree.add(loopProc);
  pointStack.push(loopBody);
  loopNameStack.push(uniqueLoopName);
}

Fixed version (ground truth):
@Override public void startLoop(String loopName,List<Var> loopVars,List<Boolean> definedHere,List<Var> initVals,List<Var> usedVariables,List<Var> keepOpenVars,List<Boolean> blockingVars){
  ArrayList<String> loopFnArgs=new ArrayList<String>();
  ArrayList<Value> firstIterArgs=new ArrayList<Value>();
  loopFnArgs.add(Turbine.LOCAL_STACK_NAME);
  firstIterArgs.add(new Value(Turbine.LOCAL_STACK_NAME));
  for (  Var arg : loopVars) {
    loopFnArgs.add(prefixVar(arg.name()));
  }
  for (  Var init : initVals) {
    firstIterArgs.add(varToExpr(init));
  }
  for (  Var uv : usedVariables) {
    loopFnArgs.add(prefixVar(uv.name()));
    firstIterArgs.add(varToExpr(uv));
  }
  ArrayList<Value> blockingVals=new ArrayList<Value>();
  assert(blockingVars.size() == initVals.size());
  for (int i=0; i < blockingVars.size(); i++) {
    Var iv=initVals.get(i);
    if (blockingVars.get(i)) {
      blockingVals.add(varToExpr(iv));
    }
  }
  String uniqueLoopName=uniqueTCLFunctionName(loopName);
  pointStack.peek().add(Turbine.loopRule(uniqueLoopName,firstIterArgs,blockingVals));
  Sequence loopBody=new Sequence();
  Proc loopProc=new Proc(uniqueLoopName,usedTclFunctionNames,loopFnArgs,loopBody);
  tree.add(loopProc);
  pointStack.push(loopBody);
  loopNameStack.push(uniqueLoopName);
}
Program: 133056
Project: 133056
Buggy source:
@Override public void loopBreak(List<Var> loopUsedVars,List<Var> keepOpenVars){
  decrementAllRefs(loopUsedVars,keepOpenVars);
}

Fixed version (ground truth):
@Override public void loopBreak(List<Var> loopUsedVars,List<Var> keepOpenVars){
}
Program: 133057
Project: 133057
Buggy source:
/** 
 * Find unneeded vars declared in local block
 * @param block
 * @param stillNeeded
 * @param dependentSets
 * @return
 */
private static Set<Var> unneededVars(Block block,Set<Var> stillNeeded,List<List<Var>> dependentSets){
  HashSet<Var> toRemove=new HashSet<Var>();
  for (  List<Var> dependentSet : dependentSets) {
{
      boolean needed=false;
      for (      Var v : dependentSet) {
        if (stillNeeded.contains(v)) {
          needed=true;
          break;
        }
      }
      if (needed) {
        for (        Var v : dependentSet) {
          stillNeeded.add(v);
        }
      }
    }
  }
  for (  Var v : block.getVariables()) {
    if (!stillNeeded.contains(v)) {
      toRemove.add(v);
    }
  }
  return toRemove;
}

Fixed version (ground truth):
/** 
 * Find unneeded vars declared in local block
 * @param block
 * @param stillNeeded
 * @param dependentSets
 * @return
 */
private static Set<Var> unneededVars(Block block,Set<Var> stillNeeded,List<List<Var>> dependentSets){
  HashSet<Var> removeCandidates=new HashSet<Var>();
  for (  Var v : block.getVariables()) {
    if (!stillNeeded.contains(v)) {
      removeCandidates.add(v);
    }
  }
  Logger logger=Logging.getSTCLogger();
  if (logger.isTraceEnabled()) {
    logger.trace("String_Node_Str" + removeCandidates + "String_Node_Str"+ "String_Node_Str"+ dependentSets);
  }
  boolean converged=false;
  while (!converged && !dependentSets.isEmpty()) {
    Iterator<List<Var>> it=dependentSets.iterator();
    while (it.hasNext()) {
      List<Var> dependentSet=it.next();
      converged=true;
      boolean hasRemoveCandidate=false;
      boolean allRemoveCandidates=true;
      for (      Var v : dependentSet) {
        if (removeCandidates.contains(v)) {
          hasRemoveCandidate=true;
        }
 else {
          allRemoveCandidates=false;
        }
      }
      if (!hasRemoveCandidate) {
        it.remove();
      }
 else       if (!allRemoveCandidates) {
        for (        Var v : dependentSet) {
          removeCandidates.remove(v);
        }
        converged=false;
      }
    }
  }
  if (logger.isTraceEnabled()) {
    logger.trace("String_Node_Str" + removeCandidates + "String_Node_Str"+ "String_Node_Str"+ dependentSets);
  }
  return removeCandidates;
}
Program: 133058
Project: 133058
Buggy source:
private static List<ComputedValue> updateReplacements(Logger logger,Function function,Instruction inst,State av,HierarchicalMap<Var,Arg> replaceInputs,HierarchicalMap<Var,Arg> replaceAll){
}

Fixed version (ground truth):
private static void updateReplacements(Logger logger,Function function,Instruction inst,State av,List<ComputedValue> icvs,HierarchicalMap<Var,Arg> replaceInputs,HierarchicalMap<Var,Arg> replaceAll){
}
Program: 133059
Project: 133059
Buggy source:
private static boolean forwardDataflow(Logger logger,Function f,ExecContext execCx,Block block,ListIterator<Instruction> insts,State cv,HierarchicalMap<Var,Arg> replaceInputs,HierarchicalMap<Var,Arg> replaceAll) throws InvalidWriteException {
  boolean anotherPassNeeded=false;
  while (insts.hasNext()) {
    Instruction inst=insts.next();
    if (logger.isTraceEnabled()) {
      logger.trace("String_Node_Str" + replaceInputs);
      logger.trace("String_Node_Str" + replaceAll);
      logger.trace("String_Node_Str" + cv.availableVals);
      logger.trace("String_Node_Str" + cv.closed);
      logger.trace("String_Node_Str");
      logger.trace("String_Node_Str" + inst);
    }
    inst.renameInputs(replaceInputs);
    inst.renameVars(replaceAll);
    updateReplacements(logger,f,inst,cv,replaceInputs,replaceAll);
    if (logger.isTraceEnabled()) {
      logger.trace("String_Node_Str" + inst);
    }
    if (switchToImmediate(logger,f,execCx,block,cv,inst,insts)) {
      continue;
    }
    List<Var> in=inst.getBlockingInputs();
    if (in != null) {
      for (      Var ov : inst.getOutputs()) {
        if (!Types.isScalarValue(ov.type())) {
          cv.setDependencies(ov,in);
        }
      }
    }
    for (    Var out : inst.getClosedOutputs()) {
      cv.close(out,false);
    }
  }
  return anotherPassNeeded;
}

Fixed version (ground truth):
private static boolean forwardDataflow(Logger logger,Function f,ExecContext execCx,Block block,ListIterator<Instruction> insts,State cv,HierarchicalMap<Var,Arg> replaceInputs,HierarchicalMap<Var,Arg> replaceAll) throws InvalidWriteException {
  boolean anotherPassNeeded=false;
  while (insts.hasNext()) {
    Instruction inst=insts.next();
    if (logger.isTraceEnabled()) {
      logger.trace("String_Node_Str" + replaceInputs);
      logger.trace("String_Node_Str" + replaceAll);
      logger.trace("String_Node_Str" + cv.availableVals);
      logger.trace("String_Node_Str" + cv.closed);
      logger.trace("String_Node_Str");
      logger.trace("String_Node_Str" + inst);
    }
    inst.renameInputs(replaceInputs);
    inst.renameVars(replaceAll);
    List<ComputedValue> icvs=inst.getComputedValues(cv);
    List<Var> oldAliasOutputs=new ArrayList<Var>(inst.getInitializedAliases());
    updateReplacements(logger,f,inst,cv,icvs,replaceInputs,replaceAll);
    if (!oldAliasOutputs.isEmpty()) {
      assert(oldAliasOutputs.size() == 1);
      if (replaceAll.containsKey(oldAliasOutputs.get(0))) {
        logger.trace("String_Node_Str");
        insts.remove();
        continue;
      }
    }
    if (logger.isTraceEnabled()) {
      logger.trace("String_Node_Str" + inst);
    }
    if (switchToImmediate(logger,f,execCx,block,cv,inst,insts)) {
      continue;
    }
    List<Var> in=inst.getBlockingInputs();
    if (in != null) {
      for (      Var ov : inst.getOutputs()) {
        if (!Types.isScalarValue(ov.type())) {
          cv.setDependencies(ov,in);
        }
      }
    }
    for (    Var out : inst.getClosedOutputs()) {
      cv.close(out,false);
    }
  }
  return anotherPassNeeded;
}
Program: 133060
Project: 133060
Buggy source:
public static Instruction structLookup(Var oVar,Var structVar,String fieldName){
  return new TurbineOp(Opcode.STRUCT_LOOKUP,Arg.createVar(oVar),Arg.createVar(structVar),Arg.createStringLit(fieldName));
}

Fixed version (ground truth):
public static Instruction structLookup(Var oVar,Var structVar,String fieldName){
}
Program: 133062
Project: 133062
Buggy source:
public void arrayRefCreateNestedFuture(Var arrayResult,Var arrayVar,Var indexVar,Var outerArr){
  assert(Types.isArrayRef(arrayResult.type()));
  assert(Types.isArrayRef(arrayVar.type()));
  assert(Types.isInt(indexVar.type()));
  assert(Types.isArray(outerArr.type()));
  currBlock().addInstruction(TurbineOp.arrayRefCreateNestedComputed(arrayResult,arrayVar,indexVar,outerArr));
}

Fixed version (ground truth):
public void arrayRefCreateNestedFuture(Var arrayResult,Var outerArr,Var array,Var ix){
  assert(Types.isArrayRef(arrayResult.type()));
  assert(Types.isArrayRef(array.type()));
  assert(Types.isInt(ix.type()));
  assert(Types.isArray(outerArr.type()));
  currBlock().addInstruction(TurbineOp.arrayRefCreateNestedComputed(arrayResult,outerArr,array,ix));
}
Program: 133063
Project: 133063
Buggy source:
public static Instruction arrayRefCreateNestedComputed(Var arrayResult,Var arrayVar,Var indexVar,Var outerArr){
  return new TurbineOp(Opcode.ARRAYREF_CREATE_NESTED_FUTURE,Arg.createVar(arrayResult),Arg.createVar(arrayVar),Arg.createVar(indexVar),Arg.createVar(outerArr));
}

Fixed version (ground truth):
public static Instruction arrayRefCreateNestedComputed(Var arrayResult,Var outerArr,Var array,Var ix){
}
Program: 133064
Project: 133064
Buggy source:
public static Instruction arrayRefCreateNestedImmIx(Var arrayResult,Var outerArray,Var array,Arg ix){
  return new TurbineOp(Opcode.ARRAYREF_CREATE_NESTED_IMM,Arg.createVar(arrayResult),Arg.createVar(array),ix,Arg.createVar(outerArray));
}

Fixed version (ground truth):
public static Instruction arrayRefCreateNestedImmIx(Var arrayResult,Var outerArray,Var array,Arg ix){
}
Program: 133065
Project: 133065
Buggy source:
/** 
 * Do the manipulation necessary to allow an old instruction output variable to be replaced with a new one. Assume that newOut is a value type of oldOut
 * @param instBuffer append any fixup instructions here
 * @param newOut
 * @param oldOut
 */
public static void replaceInstructionOutputVar(Block block,List<Instruction> instBuffer,Var newOut,Var oldOut){
  block.declareVariable(newOut);
  if (Types.isRefTo(oldOut.type(),newOut.type())) {
    if (oldOut.storage() == VarStorage.ALIAS) {
      Var replacement=new Var(oldOut.type(),oldOut.name(),VarStorage.TEMP,oldOut.defType(),oldOut.mapping());
      block.replaceVarDeclaration(oldOut,replacement);
    }
    instBuffer.add(TurbineOp.addressOf(oldOut,newOut));
  }
 else {
    throw new STCRuntimeError("String_Node_Str" + "String_Node_Str" + oldOut + "String_Node_Str"+ newOut+ "String_Node_Str"+ "String_Node_Str");
  }
}

Fixed version (ground truth):
/** 
 * Do the manipulation necessary to allow an old instruction output variable to be replaced with a new one. Assume that newOut is a value type of oldOut
 * @param instBuffer append any fixup instructions here
 * @param newOut
 * @param oldOut
 */
public static void replaceInstructionOutputVar(Block block,List<Instruction> instBuffer,Var newOut,Var oldOut){
  block.declareVariable(newOut);
  if (Types.isRefTo(oldOut.type(),newOut.type())) {
    Var refVar;
    if (oldOut.storage() == VarStorage.ALIAS) {
      refVar=new Var(oldOut.type(),oldOut.name(),VarStorage.TEMP,oldOut.defType(),oldOut.mapping());
      block.replaceVarDeclaration(oldOut,refVar);
      Map<Var,Arg> renames=Collections.singletonMap(oldOut,Arg.createVar(refVar));
      for (      Instruction inst : instBuffer) {
        inst.renameVars(renames);
      }
    }
 else {
      refVar=oldOut;
    }
    instBuffer.add(TurbineOp.addressOf(refVar,newOut));
  }
 else {
    throw new STCRuntimeError("String_Node_Str" + "String_Node_Str" + oldOut + "String_Node_Str"+ newOut+ "String_Node_Str"+ "String_Node_Str");
  }
}
Program: 133066
Project: 133066
Buggy source:
private void checkVarReferences(Map<String,Var> declared,Instruction inst){
  for (  Arg i : inst.getInputs()) {
    if (i.isVar()) {
      checkVarReference(declared,i.getVar());
    }
  }
  for (  Var o : inst.getOutputs()) {
    checkVarReference(declared,o);
  }
}

Fixed version (ground truth):
private void checkVarReferences(Map<String,Var> declared,Instruction inst){
  for (  Arg i : inst.getInputs()) {
    if (i.isVar()) {
      checkVarReference(declared,i.getVar(),inst.toString());
    }
  }
  for (  Var o : inst.getOutputs()) {
    checkVarReference(declared,o,inst.toString());
  }
}
Program: 133067
Project: 133067
Buggy source:
private void checkVarReference(Map<String,Var> declared,Var referencedVar){
}

Fixed version (ground truth):
private void checkVarReference(Map<String,Var> declared,Var referencedVar,String context){
}
Program: 133068
Project: 133068
Buggy source:
public void replaceVarDeclaration(Var oldV,Var newV){
  ListIterator<Var> it=variables.listIterator();
  while (it.hasNext()) {
    Var curr=it.next();
    if (curr.name().equals(oldV.name())) {
      it.set(newV);
      return;
    }
  }
  throw new STCRuntimeError("String_Node_Str" + oldV.toString() + "String_Node_Str"+ "String_Node_Str");
}

Fixed version (ground truth):
public void replaceVarDeclaration(Var oldV,Var newV){
  if (!this.variables.contains(oldV)) {
    throw new STCRuntimeError("String_Node_Str" + oldV.toString() + "String_Node_Str");
  }
  Map<Var,Arg> replacement=Collections.singletonMap(oldV,Arg.createVar(newV));
  this.renameVars(replacement,false);
}
Program: 133069
Project: 133069
Buggy source:
/** 
 * Replace variable declarations
 * @param renames
 */
private void replaceVariableDeclarations(Map<Var,Arg> renames){
  ListIterator<Var> it=variables.listIterator();
  while (it.hasNext()) {
    Var v=it.next();
    if (v.isMapped()) {
      if (renames.containsKey(v)) {
        throw new STCRuntimeError("String_Node_Str" + "String_Node_Str" + "String_Node_Str");
      }
    }
 else {
      if (renames.containsKey(v)) {
        Arg replacement=renames.get(v);
        if (replacement.isVar()) {
          it.set(replacement.getVar());
        }
 else {
          it.remove();
        }
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Replace variable declarations
 * @param renames
 */
private void replaceVariableDeclarations(Map<Var,Arg> renames){
  ListIterator<Var> it=variables.listIterator();
  while (it.hasNext()) {
    Var v=it.next();
    if (renames.containsKey(v)) {
      Arg replacement=renames.get(v);
      if (replacement.isVar()) {
        it.set(replacement.getVar());
      }
 else {
        it.remove();
      }
    }
  }
}
Program: 133070
Project: 133070
Buggy source:
/** 
 * Do one iteration of the iterative optimizer passes
 * @param icOutput
 * @param logger
 * @param prog
 * @param debug 
 * @param iteration
 * @param nIterations
 * @throws Exception
 */
private static void iterate(PrintStream icOutput,Logger logger,Program prog,boolean debug,long nIterations) throws UserException {
  FunctionInline inliner=new FunctionInline();
  for (long iteration=0; iteration < nIterations; iteration++) {
    OptimizerPipeline pipe=new OptimizerPipeline(icOutput);
    pipe.addPass(inliner);
    pipe.addPass(new ConstantFold());
    if ((iteration % 3) == 2) {
      pipe.addPass(new LoopUnroller());
    }
    boolean aggressive=iteration > (nIterations * 2 / 3);
    pipe.addPass(new HoistLoops(aggressive));
    pipe.addPass(new ReorderInstructions());
    pipe.addPass(new ForwardDataflow());
    pipe.addPass(new ContinuationFusion());
    if (iteration == nIterations - (nIterations / 4) - 3) {
      pipe.addPass(new Pipeline());
      if (debug)       pipe.addPass(Validate.standardValidator());
    }
    boolean doWaitMerges=iteration == nIterations - (nIterations / 4) - 2;
    pipe.addPass(new WaitCoalescer(doWaitMerges));
    if (debug)     pipe.addPass(Validate.standardValidator());
    pipe.runPipeline(logger,prog,iteration);
  }
}

Fixed version (ground truth):
/** 
 * Do one iteration of the iterative optimizer passes
 * @param icOutput
 * @param logger
 * @param prog
 * @param debug 
 * @param iteration
 * @param nIterations
 * @throws Exception
 */
private static void iterate(PrintStream icOutput,Logger logger,Program prog,boolean debug,long nIterations) throws UserException {
  FunctionInline inliner=new FunctionInline();
  for (long iteration=0; iteration < nIterations; iteration++) {
    OptimizerPipeline pipe=new OptimizerPipeline(icOutput);
    pipe.addPass(inliner);
    pipe.addPass(new ConstantFold());
    if ((iteration % 3) == 2) {
      pipe.addPass(new LoopUnroller());
      pipe.addPass(Validate.standardValidator());
    }
    boolean aggressive=iteration > (nIterations * 2 / 3);
    pipe.addPass(new HoistLoops(aggressive));
    pipe.addPass(new ReorderInstructions());
    pipe.addPass(new ForwardDataflow());
    pipe.addPass(new ContinuationFusion());
    if (iteration == nIterations - (nIterations / 4) - 3) {
      pipe.addPass(new Pipeline());
      if (debug)       pipe.addPass(Validate.standardValidator());
    }
    boolean doWaitMerges=iteration == nIterations - (nIterations / 4) - 2;
    pipe.addPass(new WaitCoalescer(doWaitMerges));
    if (debug)     pipe.addPass(Validate.standardValidator());
    pipe.runPipeline(logger,prog,iteration);
  }
}
Program: 133071
Project: 133071
Buggy source:
private void renameInDefs(Map<Var,Arg> renames,boolean inputsOnly){
  renameMappingInputs(renames);
  if (!inputsOnly) {
    replaceVariableDeclarations(renames);
  }
}

Fixed version (ground truth):
private void renameInDefs(Map<Var,Arg> renames,boolean inputsOnly){
  List<Pair<Var,Var>> changedMappedVars=new ArrayList<Pair<Var,Var>>();
  ListIterator<Var> it=variables.listIterator();
  while (it.hasNext()) {
    Var original, var;
    var=original=it.next();
    boolean removed=false;
    if (!inputsOnly) {
      if (renames.containsKey(var)) {
        Arg replacement=renames.get(var);
        if (replacement.isVar()) {
          var=replacement.getVar();
          it.set(var);
        }
 else {
          it.remove();
          removed=true;
        }
      }
    }
    if (!removed && var.isMapped()) {
      assert(!var.mapping().isMapped());
      if (renames.containsKey(var.mapping())) {
        Arg newMapping=renames.get(var.mapping());
        if (newMapping.isVar() && !newMapping.getVar().equals(var.mapping())) {
          it.remove();
          var=new Var(var.type(),var.name(),var.storage(),var.defType(),newMapping.getVar());
          changedMappedVars.add(Pair.create(original,var));
        }
      }
    }
  }
  if (!changedMappedVars.isEmpty()) {
    for (    Pair<Var,Var> change : changedMappedVars) {
      Var oldV=change.val1;
      Var newV=change.val2;
      this.variables.add(newV);
      renames.put(oldV,Arg.createVar(newV));
    }
  }
}
Program: 133072
Project: 133072
Buggy source:
/** 
 * @return list of vars that need write refcount increment
 */
public List<Var> getWriteIncrVars(){
  return Var.NONE;
}

Fixed version (ground truth):
@Override public List<Var> getWriteIncrVars(){
  if (functionName.equals(Builtins.RANGE) || functionName.equals(Builtins.RANGE_STEP)) {
    return Arrays.asList(getOutput(0));
  }
  return Var.NONE;
}
Program: 133073
Project: 133073
Buggy source:
public static Instruction arrayCreateNestedComputed(Var arrayResult,Var array,Var ix){
  return new TurbineOp(Opcode.ARRAY_CREATE_NESTED_FUTURE,Arg.createVar(arrayResult),Arg.createVar(array),Arg.createVar(ix));
}

Fixed version (ground truth):
public static Instruction arrayCreateNestedComputed(Var arrayResult,Var array,Var ix){
  assert(Types.isArrayRef(arrayResult.type()));
  assert(Types.isArray(array.type()));
  assert(Types.isInt(ix.type()));
  return new TurbineOp(Opcode.ARRAY_CREATE_NESTED_FUTURE,Arg.createVar(arrayResult),Arg.createVar(array),Arg.createVar(ix));
}
Program: 133074
Project: 133074
Buggy source:
private void elimRefCountsRec(Logger logger,Function f,Block block,Counters<Var> readIncrements,Counters<Var> writeIncrements,Set<Var> parentAssignedAliasVars){
  fixBlockRefCounting(logger,block,readIncrements,writeIncrements,parentAssignedAliasVars);
  Set<Var> assignedAliasVars=new HashSet<Var>();
  findAssignedAliasVars(block,assignedAliasVars);
  assignedAliasVars.addAll(parentAssignedAliasVars);
  for (  Continuation cont : block.getContinuations()) {
    elimRefCountsCont(logger,f,cont,assignedAliasVars);
  }
}

Fixed version (ground truth):
private void elimRefCountsRec(Logger logger,Function f,Block block,Counters<Var> readIncrements,Counters<Var> writeIncrements,HierarchicalSet<Var> parentAssignedAliasVars){
  fixBlockRefCounting(logger,block,readIncrements,writeIncrements,parentAssignedAliasVars);
  HierarchicalSet<Var> assignedAliasVars=parentAssignedAliasVars.makeChild();
  findAssignedAliasVars(block,assignedAliasVars);
  for (  Continuation cont : block.getContinuations()) {
    elimRefCountsCont(logger,f,cont,assignedAliasVars);
  }
}
Program: 133075
Project: 133075
Buggy source:
@Override public void optimize(Logger logger,Function f) throws UserException {
  elimRefCountsRec(logger,f,f.getMainblock(),new Counters<Var>(),new Counters<Var>(),Collections.<Var>emptySet());
}

Fixed version (ground truth):
@Override public void optimize(Logger logger,Function f) throws UserException {
  elimRefCountsRec(logger,f,f.getMainblock(),new Counters<Var>(),new Counters<Var>(),new HierarchicalSet<Var>());
}