Program: 132816
Project: 132816
Buggy source:
/** 
 * @param context local context for app function
 * @param appBody AST for app function body
 * @param inArgs input arguments for app function
 * @param outArgs output arguments for app function
 * @param hasSideEffects
 * @param deterministic
 * @param val 
 * @param props 
 * @param suppressions 
 * @throws UserException
 */
private void genAppFunctionBody(Context context,SwiftAST appBody,List<Var> inArgs,List<Var> outArgs,boolean hasSideEffects,boolean deterministic,AsyncExecutor asyncExec,TaskProps props,Set<Suppression> suppressions) 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);
  Pair<List<Var>,Boolean> evaledArgs=evalAppCmdArgs(context,cmd);
  List<Var> cmdArgs=evaledArgs.val1;
  boolean openedEvalWait=evaledArgs.val2;
  Redirects<Var> redirFutures=processAppRedirects(context,appBody.children(1));
  checkAppOutputs(context,appName,outArgs,cmdArgs,redirFutures,suppressions);
  Pair<Map<String,Var>,List<WaitVar>> wait=selectAppWaitVars(context,cmdArgs,inArgs,outArgs,redirFutures);
  Map<String,Var> fileNames=wait.val1;
  List<WaitVar> waitVars=wait.val2;
  String waitName=context.getFunctionContext().constructName("String_Node_Str");
  backend.startWaitStatement(waitName,VarRepr.backendVars(waitVars),WaitMode.TASK_DISPATCH,true,TaskMode.WORKER,props);
  Pair<List<Arg>,Redirects<Arg>> retrieved=retrieveAppArgs(context,cmdArgs,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=exprWalker.retrieveToVar(context,inArg);
      localInFiles.add(Arg.createVar(localInputFile));
    }
  }
  List<Var> localOutputs=new ArrayList<Var>(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(exprWalker.retrieveToVar(context,fileNames.get(output.name())));
      backend.initLocalOutFile(VarRepr.backendVar(localOutput),VarRepr.backendArg(localOutputFileName),VarRepr.backendVar(output));
    }
  }
  List<Arg> beLocalArgs=VarRepr.backendArgs(localArgs);
  List<Var> beLocalOutputs=VarRepr.backendVars(localOutputs);
  List<Arg> beLocalInfiles=VarRepr.backendArgs(localInFiles);
  Redirects<Arg> beLocalRedirects=new Redirects<Arg>(VarRepr.backendArg(localRedirects.stdin,true),VarRepr.backendArg(localRedirects.stdout,true),VarRepr.backendArg(localRedirects.stderr,true));
  if (asyncExec == null) {
    backend.runExternal(appName,beLocalArgs,beLocalInfiles,beLocalOutputs,beLocalRedirects,hasSideEffects,deterministic);
  }
 else {
    String aeName=context.constructName("String_Node_Str");
    Map<String,Arg> taskProps=new HashMap<String,Arg>();
    beLocalRedirects.addProps(taskProps);
    backend.startAsyncExec(aeName,asyncExec,appName,beLocalOutputs,beLocalArgs,taskProps,!deterministic);
  }
  for (int i=0; i < outArgs.size(); i++) {
    Var output=outArgs.get(i);
    Var localOutput=localOutputs.get(i);
    if (Types.isFile(output.type())) {
      exprWalker.assign(output,Arg.createVar(localOutput));
      if (output.isMapped() != Ternary.TRUE && output.type().fileKind().supportsTmpImmediate()) {
        backend.decrLocalFileRef(VarRepr.backendVar(localOutput));
      }
    }
 else {
      assert(Types.isVoid(output.type()));
      exprWalker.assign(output,localOutput.asArg());
    }
  }
  if (asyncExec != null) {
    backend.endAsyncExec();
  }
  backend.endWaitStatement();
  if (openedEvalWait) {
    backend.endWaitStatement();
  }
}

Fixed version (ground truth):
/** 
 * @param context local context for app function
 * @param appBody AST for app function body
 * @param inArgs input arguments for app function
 * @param outArgs output arguments for app function
 * @param hasSideEffects
 * @param deterministic
 * @param val 
 * @param props 
 * @param suppressions 
 * @throws UserException
 */
private void genAppFunctionBody(Context context,SwiftAST appBody,List<Var> inArgs,List<Var> outArgs,boolean hasSideEffects,boolean deterministic,AsyncExecutor asyncExec,TaskProps props,Set<Suppression> suppressions) 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);
  Pair<List<Var>,Boolean> evaledArgs=evalAppCmdArgs(context,cmd);
  List<Var> cmdArgs=evaledArgs.val1;
  boolean openedEvalWait=evaledArgs.val2;
  Redirects<Var> redirFutures=processAppRedirects(context,appBody.children(1));
  checkAppOutputs(context,appName,outArgs,cmdArgs,redirFutures,suppressions);
  Pair<Map<String,Var>,List<WaitVar>> wait=selectAppWaitVars(context,cmdArgs,inArgs,outArgs,redirFutures);
  Map<String,Var> fileNames=wait.val1;
  List<WaitVar> waitVars=wait.val2;
  String waitName=context.getFunctionContext().constructName("String_Node_Str");
  backend.startWaitStatement(waitName,VarRepr.backendWaitVars(waitVars),WaitMode.TASK_DISPATCH,true,TaskMode.WORKER,props);
  Pair<List<Arg>,Redirects<Arg>> retrieved=retrieveAppArgs(context,cmdArgs,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=exprWalker.retrieveToVar(context,inArg);
      localInFiles.add(Arg.createVar(localInputFile));
    }
  }
  List<Var> localOutputs=new ArrayList<Var>(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(exprWalker.retrieveToVar(context,fileNames.get(output.name())));
      backend.initLocalOutFile(VarRepr.backendVar(localOutput),VarRepr.backendArg(localOutputFileName),VarRepr.backendVar(output));
    }
  }
  List<Arg> beLocalArgs=VarRepr.backendArgs(localArgs);
  List<Var> beLocalOutputs=VarRepr.backendVars(localOutputs);
  List<Arg> beLocalInfiles=VarRepr.backendArgs(localInFiles);
  Redirects<Arg> beLocalRedirects=new Redirects<Arg>(VarRepr.backendArg(localRedirects.stdin,true),VarRepr.backendArg(localRedirects.stdout,true),VarRepr.backendArg(localRedirects.stderr,true));
  if (asyncExec == null) {
    backend.runExternal(appName,beLocalArgs,beLocalInfiles,beLocalOutputs,beLocalRedirects,hasSideEffects,deterministic);
  }
 else {
    String aeName=context.constructName("String_Node_Str");
    Map<String,Arg> taskProps=new HashMap<String,Arg>();
    beLocalRedirects.addProps(taskProps);
    backend.startAsyncExec(aeName,asyncExec,appName,beLocalOutputs,beLocalArgs,taskProps,!deterministic);
  }
  for (int i=0; i < outArgs.size(); i++) {
    Var output=outArgs.get(i);
    Var localOutput=localOutputs.get(i);
    if (Types.isFile(output.type())) {
      exprWalker.assign(output,Arg.createVar(localOutput));
      if (output.isMapped() != Ternary.TRUE && output.type().fileKind().supportsTmpImmediate()) {
        backend.decrLocalFileRef(VarRepr.backendVar(localOutput));
      }
    }
 else {
      assert(Types.isVoid(output.type()));
      exprWalker.assign(output,localOutput.asArg());
    }
  }
  if (asyncExec != null) {
    backend.endAsyncExec();
  }
  backend.endWaitStatement();
  if (openedEvalWait) {
    backend.endWaitStatement();
  }
}