Program: 132725
Project: 132725
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),state.getClosedLocs(stmtIndex),state.retrieveResultAvail(),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<Statement> alt=new ArrayList<Statement>();
  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);
  List<Var> outFetched=OptUtil.createLocalOpOutputVars(insertContext,insertPoint,req.out,filenameVals);
  MakeImmChange change;
  change=inst.makeImmediate(new OptVarCreator(block),Fetched.makeList(req.out,outFetched,true),inVals);
  OptUtil.fixupImmChange(block,insertContext,inst,change,alt,outFetched,req.out);
  if (logger.isTraceEnabled()) {
    logger.trace("String_Node_Str" + inst + "String_Node_Str"+ alt.toString());
  }
  for (  Statement newStmt : alt) {
    insertPoint.add(newStmt);
  }
  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),state.getClosedLocs(stmtIndex),state.retrieveResultAvail(),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<Statement> alt=new ArrayList<Statement>();
  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);
  List<Var> outFetched=OptUtil.createLocalOpOutputVars(insertContext,insertPoint,req.out,filenameVals);
  MakeImmChange change;
  change=inst.makeImmediate(new OptVarCreator(block),Fetched.makeList(req.out,outFetched,true),inVals);
  OptUtil.fixupImmChange(fn.getName(),block,insertContext,inst,change,alt,outFetched,req.out);
  if (logger.isTraceEnabled()) {
    logger.trace("String_Node_Str" + inst + "String_Node_Str"+ alt.toString());
  }
  for (  Statement newStmt : alt) {
    insertPoint.add(newStmt);
  }
  if (stmts == insertPoint) {
    ICUtil.rewindIterator(stmts,alt.size());
  }
  return true;
}