Program: 132618
Project: 132618
Buggy source:
private Function switchToValuePassing(Logger logger,ForeignFunctions foreignFuncs,Function fn,Set<FnID> usedFunctionNames){
  if (fn.blockingInputs().isEmpty())   return null;
  List<Var> switchVars=new ArrayList<Var>();
  for (  WaitVar input : fn.blockingInputs()) {
    if (Types.isPrimFuture(input.var)) {
      Type valueT=Types.retrievedType(input.var.type());
      if (Semantics.canPassToChildTask(valueT)) {
        switchVars.add(input.var);
      }
    }
  }
  if (switchVars.isEmpty())   return null;
  List<Pair<Var,Var>> futValPairs=createValueVars(fn,switchVars);
  Map<Var,Var> switched=new HashMap<Var,Var>();
  for (  Pair<Var,Var> fv : futValPairs) {
    switched.put(fv.val1,fv.val2);
    assert(fv.val2 != null);
  }
  List<Var> newIList=buildNewInputList(fn,switched);
  FnID newID=selectUniqueID(fn.id(),usedFunctionNames);
  Block callNewFunction=callNewFunctionCode(foreignFuncs,fn,newID,switchVars);
  Block newBlock=fn.swapBlock(callNewFunction);
  for (  Pair<Var,Var> fv : futValPairs) {
    Var tmpfuture=new Var(fv.val1.type(),fv.val1.name(),Alloc.STACK,DefType.LOCAL_USER,VarProvenance.renamed(fv.val1));
    newBlock.renameVars(fn.id(),Collections.singletonMap(fv.val1,tmpfuture.asArg()),RenameMode.REPLACE_VAR,true);
    newBlock.addVariable(tmpfuture);
    Instruction store=TurbineOp.storePrim(tmpfuture,fv.val2.asArg());
    newBlock.addInstructionFront(store);
  }
  List<WaitVar> newBlocking=new ArrayList<WaitVar>();
  for (  WaitVar wv : fn.blockingInputs()) {
    if (!switchVars.contains(wv.var)) {
      newBlocking.add(wv);
    }
  }
  return new Function(newID,newIList,newBlocking,fn.getOutputList(),fn.mode(),newBlock);
}

Fixed version (ground truth):
private Function switchToValuePassing(Logger logger,ForeignFunctions foreignFuncs,Function fn,Set<FnID> usedFnIDs){
  if (fn.blockingInputs().isEmpty())   return null;
  List<Var> switchVars=new ArrayList<Var>();
  for (  WaitVar input : fn.blockingInputs()) {
    if (Types.isPrimFuture(input.var)) {
      Type valueT=Types.retrievedType(input.var.type());
      if (Semantics.canPassToChildTask(valueT)) {
        switchVars.add(input.var);
      }
    }
  }
  if (switchVars.isEmpty())   return null;
  List<Pair<Var,Var>> futValPairs=createValueVars(fn,switchVars);
  Map<Var,Var> switched=new HashMap<Var,Var>();
  for (  Pair<Var,Var> fv : futValPairs) {
    switched.put(fv.val1,fv.val2);
    assert(fv.val2 != null);
  }
  List<Var> newIList=buildNewInputList(fn,switched);
  FnID newID=selectUniqueID(fn.id(),usedFnIDs);
  Block callNewFunction=callNewFunctionCode(foreignFuncs,fn,newID,switchVars);
  Block newBlock=fn.swapBlock(callNewFunction);
  for (  Pair<Var,Var> fv : futValPairs) {
    Var tmpfuture=new Var(fv.val1.type(),fv.val1.name(),Alloc.STACK,DefType.LOCAL_USER,VarProvenance.renamed(fv.val1));
    newBlock.renameVars(fn.id(),Collections.singletonMap(fv.val1,tmpfuture.asArg()),RenameMode.REPLACE_VAR,true);
    newBlock.addVariable(tmpfuture);
    Instruction store=TurbineOp.storePrim(tmpfuture,fv.val2.asArg());
    newBlock.addInstructionFront(store);
  }
  List<WaitVar> newBlocking=new ArrayList<WaitVar>();
  for (  WaitVar wv : fn.blockingInputs()) {
    if (!switchVars.contains(wv.var)) {
      newBlocking.add(wv);
    }
  }
  return new Function(newID,newIList,newBlocking,fn.getOutputList(),fn.mode(),newBlock);
}