Program: 132824
Project: 132824
Buggy source:
/** 
 * @param logger
 * @param fn
 * @param block
 * @param cv
 * @param inst
 * @param insts if instructions inserted, leaves iterator pointing at previous instruction
 * @return
 */
private boolean switchToImmediate(Logger logger,Function fn,ExecContext execCx,Block block,Congruences state,Instruction inst,ListIterator<Statement> stmts,int stmtIndex){
  if (!finalizedVarEnabled) {
    return false;
  }
  MakeImmRequest req=inst.canMakeImmediate(state.getClosed(stmtIndex),false);
  if (req == null) {
    return false;
  }
  Block insertContext;
  ListIterator<Statement> insertPoint;
  boolean noWaitRequired=req.mode == TaskMode.LOCAL || req.mode == TaskMode.SYNC || (req.mode == TaskMode.LOCAL_CONTROL && execCx == ExecContext.CONTROL);
  stmts.remove();
  if (noWaitRequired) {
    insertContext=block;
    insertPoint=stmts;
  }
 else {
    WaitStatement wait=new WaitStatement(fn.getName() + "String_Node_Str" + inst.shortOpName(),WaitVar.NONE,PassedVar.NONE,Var.NONE,WaitMode.TASK_DISPATCH,false,req.mode,inst.getTaskProps());
    insertContext=wait.getBlock();
    block.addContinuation(wait);
    insertPoint=insertContext.statementIterator();
  }
  List<Instruction> alt=new ArrayList<Instruction>();
  List<Fetched<Arg>> inVals=fetchInputsForSwitch(state,req,insertContext,noWaitRequired,alt);
  Map<Var,Var> filenameVals=loadOutputFileNames(state,stmtIndex,req.out,insertContext,insertPoint,req.mapOutVars);
  List<Var> outFetched=OptUtil.createLocalOpOutputVars(insertContext,insertPoint,req.out,filenameVals,req.mapOutVars);
  MakeImmChange change;
  change=inst.makeImmediate(new OptVarCreator(block),Fetched.makeList(req.out,outFetched),inVals);
  OptUtil.fixupImmChange(block,insertContext,inst,change,alt,outFetched,req.out,req.mapOutVars);
  if (logger.isTraceEnabled()) {
    logger.trace("String_Node_Str" + inst + "String_Node_Str"+ alt.toString());
  }
  for (  Instruction newInst : alt) {
    insertPoint.add(newInst);
  }
  if (stmts == insertPoint) {
    ICUtil.rewindIterator(stmts,alt.size());
  }
  return true;
}

Fixed version (ground truth):
/** 
 * @param logger
 * @param fn
 * @param block
 * @param cv
 * @param inst
 * @param insts if instructions inserted, leaves iterator pointing at previous instruction
 * @return
 */
private boolean switchToImmediate(Logger logger,Function fn,ExecContext execCx,Block block,Congruences state,Instruction inst,ListIterator<Statement> stmts,int stmtIndex){
  if (!finalizedVarEnabled) {
    return false;
  }
  MakeImmRequest req=inst.canMakeImmediate(state.getClosed(stmtIndex),false);
  if (req == null) {
    return false;
  }
  Block insertContext;
  ListIterator<Statement> insertPoint;
  boolean noWaitRequired=req.mode == TaskMode.LOCAL || req.mode == TaskMode.SYNC || (req.mode == TaskMode.LOCAL_CONTROL && execCx == ExecContext.CONTROL);
  stmts.remove();
  if (noWaitRequired) {
    insertContext=block;
    insertPoint=stmts;
  }
 else {
    WaitStatement wait=new WaitStatement(fn.getName() + "String_Node_Str" + inst.shortOpName(),WaitVar.NONE,PassedVar.NONE,Var.NONE,WaitMode.TASK_DISPATCH,false,req.mode,inst.getTaskProps());
    insertContext=wait.getBlock();
    block.addContinuation(wait);
    insertPoint=insertContext.statementIterator();
  }
  List<Instruction> alt=new ArrayList<Instruction>();
  List<Fetched<Arg>> inVals=fetchInputsForSwitch(state,req,insertContext,noWaitRequired,alt);
  if (logger.isTraceEnabled()) {
    logger.trace("String_Node_Str" + inVals + "String_Node_Str"+ inst+ "String_Node_Str"+ req.in);
  }
  Map<Var,Var> filenameVals=loadOutputFileNames(state,stmtIndex,req.out,insertContext,insertPoint,req.mapOutVars);
  List<Var> outFetched=OptUtil.createLocalOpOutputVars(insertContext,insertPoint,req.out,filenameVals,req.mapOutVars);
  MakeImmChange change;
  change=inst.makeImmediate(new OptVarCreator(block),Fetched.makeList(req.out,outFetched),inVals);
  OptUtil.fixupImmChange(block,insertContext,inst,change,alt,outFetched,req.out,req.mapOutVars);
  if (logger.isTraceEnabled()) {
    logger.trace("String_Node_Str" + inst + "String_Node_Str"+ alt.toString());
  }
  for (  Instruction newInst : alt) {
    insertPoint.add(newInst);
  }
  if (stmts == insertPoint) {
    ICUtil.rewindIterator(stmts,alt.size());
  }
  return true;
}