Program: 133032
Project: 133032
Buggy source:
/** 
 * Handle foreach loop as special case where we want to increment <# of iterations> * <needed increments inside loop> before loop
 */
private void addIncrementsToForeachLoop(Continuation c){
  AbstractForeachLoop loop=(AbstractForeachLoop)c;
  Counters<Var> readIncrs=new Counters<Var>();
  Counters<Var> writeIncrs=new Counters<Var>();
  if (loop.isAsync()) {
    for (    PassedVar v : loop.getPassedVars()) {
      if (!v.writeOnly && RefCounting.hasReadRefCount(v.var)) {
        readIncrs.increment(v.var);
      }
    }
    for (    Var v : loop.getKeepOpenVars()) {
      if (RefCounting.hasWriteRefCount(v)) {
        writeIncrs.increment(v);
      }
    }
  }
  Block loopBody=loop.getLoopBody();
  ListIterator<Instruction> it=loopBody.instructionIterator();
  while (it.hasNext()) {
    Instruction inst=it.next();
    if (inst.op == Opcode.INCR_REF || inst.op == Opcode.INCR_WRITERS) {
      Var var=inst.getOutput(0);
      Arg amount=inst.getInput(0);
      if (amount.isIntVal() && definedOutsideCont(loop,loopBody,var)) {
        if (inst.op == Opcode.INCR_REF) {
          readIncrs.increment(var);
        }
 else {
          assert(inst.op == Opcode.INCR_WRITERS);
          writeIncrs.increment(var);
        }
        it.remove();
      }
    }
 else {
      break;
    }
  }
  for (  Entry<Var,Long> read : readIncrs.entries()) {
    loop.addStartIncrement(new RefCount(read.getKey(),RefCountType.READERS,Arg.createIntLit(read.getValue())));
  }
  for (  Entry<Var,Long> write : writeIncrs.entries()) {
    loop.addStartIncrement(new RefCount(write.getKey(),RefCountType.WRITERS,Arg.createIntLit(write.getValue())));
  }
}

Fixed version (ground truth):
/** 
 * Handle foreach loop as special case where we want to increment <# of iterations> * <needed increments inside loop> before loop
 */
private void addIncrementsToForeachLoop(Continuation c){
  AbstractForeachLoop loop=(AbstractForeachLoop)c;
  Counters<Var> readIncrs=new Counters<Var>();
  Counters<Var> writeIncrs=new Counters<Var>();
  if (loop.isAsync()) {
    for (    PassedVar v : loop.getPassedVars()) {
      if (!v.writeOnly && RefCounting.hasReadRefCount(v.var)) {
        readIncrs.increment(v.var);
      }
    }
    for (    Var v : loop.getKeepOpenVars()) {
      if (RefCounting.hasWriteRefCount(v)) {
        writeIncrs.increment(v);
      }
    }
  }
  Block loopBody=loop.getLoopBody();
  ListIterator<Instruction> it=loopBody.instructionIterator();
  while (it.hasNext()) {
    Instruction inst=it.next();
    if (inst.op == Opcode.INCR_REF || inst.op == Opcode.INCR_WRITERS) {
      Var var=inst.getOutput(0);
      Arg amount=inst.getInput(0);
      if (amount.isIntVal() && definedOutsideCont(loop,loopBody,var)) {
        if (inst.op == Opcode.INCR_REF) {
          readIncrs.add(var,amount.getIntLit());
        }
 else {
          assert(inst.op == Opcode.INCR_WRITERS);
          writeIncrs.add(var,amount.getIntLit());
        }
        it.remove();
      }
    }
 else {
      break;
    }
  }
  for (  Entry<Var,Long> read : readIncrs.entries()) {
    loop.addStartIncrement(new RefCount(read.getKey(),RefCountType.READERS,Arg.createIntLit(read.getValue())));
  }
  for (  Entry<Var,Long> write : writeIncrs.entries()) {
    loop.addStartIncrement(new RefCount(write.getKey(),RefCountType.WRITERS,Arg.createIntLit(write.getValue())));
  }
}