Program: 133097
Project: 133097
Buggy source:
/** 
 * @param context local context for app function
 * @param cmd AST for app function command
 * @param outArgs output arguments for app
 * @param hasSideEffects
 * @param deterministic
 * @throws UserException
 */
private void genAppFunctionBody(Context context,SwiftAST appBody,List<Var> inArgs,List<Var> outArgs,boolean hasSideEffects,boolean deterministic) throws UserException {
  assert(appBody.getType() == ExMParser.APP_BODY);
  assert(appBody.getChildCount() >= 1);
  SwiftAST cmd=appBody.child(0);
  assert(cmd.getType() == ExMParser.COMMAND);
  assert(cmd.getChildCount() >= 1);
  SwiftAST appNameT=cmd.child(0);
  assert(appNameT.getType() == ExMParser.STRING);
  String appName=Literals.extractLiteralString(context,appNameT);
  List<Var> args=evalAppCmdArgs(context,cmd);
  Redirects<Var> redirFutures=processAppRedirects(context,appBody.children(1));
  checkAppOutputs(context,appName,outArgs,args,redirFutures);
  Pair<Map<String,Var>,List<Var>> wait=selectAppWaitVars(context,args,redirFutures);
  Map<String,Var> fileNames=wait.val1;
  List<Var> waitVars=wait.val2;
  List<Var> passIn=new ArrayList<Var>();
  passIn.addAll(fileNames.values());
  passIn.addAll(args);
  String waitName=context.getFunctionContext().constructName("String_Node_Str");
  backend.startWaitStatement(waitName,waitVars,passIn,Collections.<Var>emptyList(),null,WaitMode.TASK_DISPATCH,true,TaskMode.LEAF);
  Pair<List<Arg>,Redirects<Arg>> retrieved=retrieveAppArgs(context,args,redirFutures,fileNames);
  List<Arg> localArgs=retrieved.val1;
  Redirects<Arg> localRedirects=retrieved.val2;
  List<Arg> localInFiles=new ArrayList<Arg>();
  for (  Var inArg : inArgs) {
    if (Types.isFile(inArg.type())) {
      Var localInputFile=varCreator.fetchValueOf(context,inArg);
      localInFiles.add(Arg.createVar(localInputFile));
    }
  }
  List<Var> localOutputs=new ArrayList<Var>(outArgs.size());
  List<Arg> localOutputFileNames=new ArrayList<Arg>(outArgs.size());
  for (  Var output : outArgs) {
    Var localOutput=varCreator.createValueOfVar(context,output);
    localOutputs.add(localOutput);
    Arg localOutputFileName=null;
    if (Types.isFile(output.type())) {
      localOutputFileName=Arg.createVar(varCreator.fetchValueOf(context,fileNames.get(output.name())));
    }
    localOutputFileNames.add(localOutputFileName);
  }
  backend.runExternal(appName,localArgs,localInFiles,localOutputs,localOutputFileNames,localRedirects,hasSideEffects,deterministic);
  for (int i=0; i < outArgs.size(); i++) {
    Var output=outArgs.get(i);
    Var localOutput=localOutputs.get(i);
    if (Types.isFile(output.type())) {
      backend.assignFile(output,Arg.createVar(localOutput));
      backend.decrLocalFileRef(localOutput);
    }
 else {
      assert(Types.isVoid(output.type()));
      backend.assignVoid(output,Arg.createVar(localOutput));
    }
  }
  backend.endWaitStatement(waitVars,passIn,Arrays.<Var>asList());
}

Fixed version (ground truth):
/** 
 * @param context local context for app function
 * @param cmd AST for app function command
 * @param outArgs output arguments for app
 * @param hasSideEffects
 * @param deterministic
 * @throws UserException
 */
private void genAppFunctionBody(Context context,SwiftAST appBody,List<Var> inArgs,List<Var> outArgs,boolean hasSideEffects,boolean deterministic) throws UserException {
  assert(appBody.getType() == ExMParser.APP_BODY);
  assert(appBody.getChildCount() >= 1);
  SwiftAST cmd=appBody.child(0);
  assert(cmd.getType() == ExMParser.COMMAND);
  assert(cmd.getChildCount() >= 1);
  SwiftAST appNameT=cmd.child(0);
  assert(appNameT.getType() == ExMParser.STRING);
  String appName=Literals.extractLiteralString(context,appNameT);
  List<Var> args=evalAppCmdArgs(context,cmd);
  Redirects<Var> redirFutures=processAppRedirects(context,appBody.children(1));
  checkAppOutputs(context,appName,outArgs,args,redirFutures);
  Pair<Map<String,Var>,List<Var>> wait=selectAppWaitVars(context,args,outArgs,redirFutures);
  Map<String,Var> fileNames=wait.val1;
  List<Var> waitVars=wait.val2;
  List<Var> passIn=new ArrayList<Var>();
  passIn.addAll(fileNames.values());
  passIn.addAll(args);
  String waitName=context.getFunctionContext().constructName("String_Node_Str");
  backend.startWaitStatement(waitName,waitVars,passIn,Collections.<Var>emptyList(),null,WaitMode.TASK_DISPATCH,true,TaskMode.LEAF);
  Pair<List<Arg>,Redirects<Arg>> retrieved=retrieveAppArgs(context,args,redirFutures,fileNames);
  List<Arg> localArgs=retrieved.val1;
  Redirects<Arg> localRedirects=retrieved.val2;
  List<Arg> localInFiles=new ArrayList<Arg>();
  for (  Var inArg : inArgs) {
    if (Types.isFile(inArg.type())) {
      Var localInputFile=varCreator.fetchValueOf(context,inArg);
      localInFiles.add(Arg.createVar(localInputFile));
    }
  }
  List<Var> localOutputs=new ArrayList<Var>(outArgs.size());
  List<Arg> localOutputFileNames=new ArrayList<Arg>(outArgs.size());
  for (  Var output : outArgs) {
    Var localOutput=varCreator.createValueOfVar(context,output);
    localOutputs.add(localOutput);
    Arg localOutputFileName=null;
    if (Types.isFile(output.type())) {
      localOutputFileName=Arg.createVar(varCreator.fetchValueOf(context,fileNames.get(output.name())));
    }
    localOutputFileNames.add(localOutputFileName);
  }
  backend.runExternal(appName,localArgs,localInFiles,localOutputs,localOutputFileNames,localRedirects,hasSideEffects,deterministic);
  for (int i=0; i < outArgs.size(); i++) {
    Var output=outArgs.get(i);
    Var localOutput=localOutputs.get(i);
    if (Types.isFile(output.type())) {
      backend.assignFile(output,Arg.createVar(localOutput));
      backend.decrLocalFileRef(localOutput);
    }
 else {
      assert(Types.isVoid(output.type()));
      backend.assignVoid(output,Arg.createVar(localOutput));
    }
  }
  backend.endWaitStatement(waitVars,passIn,Arrays.<Var>asList());
}