Program: 40257
Project: 40257
Buggy source:
protected CAstNode copyNodes(CAstNode root,RewriteContext context,Map<Pair<CAstNode,NoKey>,CAstNode> nodeMap){
  int kind=root.getKind();
  if (kind == CAstNode.OBJECT_REF && context.inRead()) {
    CAstNode readLoop;
    CAstNode receiver=copyNodes(root.getChild(0),READ,nodeMap);
    CAstNode element=copyNodes(root.getChild(1),READ,nodeMap);
    if (element.getKind() == CAstNode.CONSTANT && element.getValue() instanceof String) {
      readLoop=makeConstRead(root,receiver,element,context,nodeMap);
    }
 else {
      readLoop=makeVarRead(root,receiver,element,context,nodeMap);
    }
    return readLoop;
  }
 else   if (kind == CAstNode.ASSIGN_PRE_OP || kind == CAstNode.ASSIGN_POST_OP) {
    AssignPreOrPostOpContext ctxt=new AssignPreOrPostOpContext();
    CAstNode lval=copyNodes(root.getChild(0),ctxt,nodeMap);
    CAstNode rval=copyNodes(root.getChild(1),READ,nodeMap);
    CAstNode op=copyNodes(root.getChild(2),READ,nodeMap);
    if (ctxt.receiverTemp != null) {
      String temp1=TEMP_NAME + (readTempCounter++);
      String temp2=TEMP_NAME + (readTempCounter++);
      CAstNode copy=Ast.makeNode(CAstNode.BLOCK_EXPR,Ast.makeNode(CAstNode.DECL_STMT,Ast.makeConstant(new InternalCAstSymbol(temp1,true,false)),lval),rval,Ast.makeNode(CAstNode.DECL_STMT,Ast.makeConstant(new InternalCAstSymbol(temp2,true,false)),Ast.makeNode(CAstNode.BINARY_EXPR,op,Ast.makeNode(CAstNode.VAR,Ast.makeConstant(temp1)),rval)),Ast.makeNode(CAstNode.ASSIGN,Ast.makeNode(CAstNode.OBJECT_REF,ctxt.receiverTemp,ctxt.elementTemp),Ast.makeNode(CAstNode.VAR,Ast.makeConstant(temp2))),Ast.makeNode(CAstNode.VAR,Ast.makeConstant((kind == CAstNode.ASSIGN_PRE_OP) ? temp2 : temp1)));
      nodeMap.put(Pair.make(root,context.key()),copy);
      return copy;
    }
 else {
      CAstNode copy=Ast.makeNode(kind,lval,rval,op);
      nodeMap.put(Pair.make(root,context.key()),copy);
      return copy;
    }
  }
 else   if (kind == CAstNode.ASSIGN) {
    CAstNode copy=Ast.makeNode(CAstNode.ASSIGN,copyNodes(root.getChild(0),ASSIGN,nodeMap),copyNodes(root.getChild(1),READ,nodeMap));
    nodeMap.put(Pair.make(root,context.key()),copy);
    return copy;
  }
 else   if (kind == CAstNode.BLOCK_EXPR) {
    CAstNode children[]=new CAstNode[root.getChildCount()];
    int last=(children.length - 1);
    for (int i=0; i < last; i++) {
      children[i]=copyNodes(root.getChild(i),READ,nodeMap);
    }
    children[last]=copyNodes(root.getChild(last),context,nodeMap);
    CAstNode copy=Ast.makeNode(CAstNode.BLOCK_EXPR,children);
    nodeMap.put(Pair.make(root,context.key()),copy);
    return copy;
  }
 else   if (root.getKind() == CAstNode.CONSTANT) {
    CAstNode copy=Ast.makeConstant(root.getValue());
    nodeMap.put(Pair.make(root,context.key()),copy);
    return copy;
  }
 else   if (root.getKind() == CAstNode.OPERATOR) {
    nodeMap.put(Pair.make(root,context.key()),root);
    return root;
  }
 else {
    CAstNode children[]=new CAstNode[root.getChildCount()];
    for (int i=0; i < children.length; i++) {
      children[i]=copyNodes(root.getChild(i),READ,nodeMap);
    }
    CAstNode copy=Ast.makeNode(kind,children);
    nodeMap.put(Pair.make(root,context.key()),copy);
    return copy;
  }
}

Fixed version (ground truth):
protected CAstNode copyNodes(CAstNode root,RewriteContext context,Map<Pair<CAstNode,ExpanderKey>,CAstNode> nodeMap){
  int kind=root.getKind();
  if (kind == CAstNode.OBJECT_REF && context.inRead()) {
    CAstNode readLoop;
    CAstNode receiver=copyNodes(root.getChild(0),READ,nodeMap);
    CAstNode element=copyNodes(root.getChild(1),READ,nodeMap);
    if (element.getKind() == CAstNode.CONSTANT && element.getValue() instanceof String) {
      readLoop=makeConstRead(root,receiver,element,context,nodeMap);
    }
 else {
      readLoop=makeVarRead(root,receiver,element,context,nodeMap);
    }
    return readLoop;
  }
 else   if (kind == CAstNode.ASSIGN_PRE_OP || kind == CAstNode.ASSIGN_POST_OP) {
    AssignPreOrPostOpContext ctxt=new AssignPreOrPostOpContext();
    CAstNode lval=copyNodes(root.getChild(0),ctxt,nodeMap);
    CAstNode rval=copyNodes(root.getChild(1),READ,nodeMap);
    CAstNode op=copyNodes(root.getChild(2),READ,nodeMap);
    if (ctxt.receiverTemp != null) {
      String temp1=TEMP_NAME + (readTempCounter++);
      String temp2=TEMP_NAME + (readTempCounter++);
      CAstNode copy=Ast.makeNode(CAstNode.BLOCK_EXPR,Ast.makeNode(CAstNode.DECL_STMT,Ast.makeConstant(new InternalCAstSymbol(temp1,true,false)),lval),rval,Ast.makeNode(CAstNode.DECL_STMT,Ast.makeConstant(new InternalCAstSymbol(temp2,true,false)),Ast.makeNode(CAstNode.BINARY_EXPR,op,Ast.makeNode(CAstNode.VAR,Ast.makeConstant(temp1)),rval)),Ast.makeNode(CAstNode.ASSIGN,Ast.makeNode(CAstNode.OBJECT_REF,ctxt.receiverTemp,ctxt.elementTemp),Ast.makeNode(CAstNode.VAR,Ast.makeConstant(temp2))),Ast.makeNode(CAstNode.VAR,Ast.makeConstant((kind == CAstNode.ASSIGN_PRE_OP) ? temp2 : temp1)));
      nodeMap.put(Pair.make(root,context.key()),copy);
      return copy;
    }
 else {
      CAstNode copy=Ast.makeNode(kind,lval,rval,op);
      nodeMap.put(Pair.make(root,context.key()),copy);
      return copy;
    }
  }
 else   if (kind == CAstNode.ASSIGN) {
    CAstNode copy=Ast.makeNode(CAstNode.ASSIGN,copyNodes(root.getChild(0),ASSIGN,nodeMap),copyNodes(root.getChild(1),READ,nodeMap));
    nodeMap.put(Pair.make(root,context.key()),copy);
    return copy;
  }
 else   if (kind == CAstNode.BLOCK_EXPR) {
    CAstNode children[]=new CAstNode[root.getChildCount()];
    int last=(children.length - 1);
    for (int i=0; i < last; i++) {
      children[i]=copyNodes(root.getChild(i),READ,nodeMap);
    }
    children[last]=copyNodes(root.getChild(last),context,nodeMap);
    CAstNode copy=Ast.makeNode(CAstNode.BLOCK_EXPR,children);
    nodeMap.put(Pair.make(root,context.key()),copy);
    return copy;
  }
 else   if (root.getKind() == CAstNode.CONSTANT) {
    CAstNode copy=Ast.makeConstant(root.getValue());
    nodeMap.put(Pair.make(root,context.key()),copy);
    return copy;
  }
 else   if (root.getKind() == CAstNode.OPERATOR) {
    nodeMap.put(Pair.make(root,context.key()),root);
    return root;
  }
 else {
    CAstNode children[]=new CAstNode[root.getChildCount()];
    for (int i=0; i < children.length; i++) {
      children[i]=copyNodes(root.getChild(i),READ,nodeMap);
    }
    CAstNode copy=Ast.makeNode(kind,children);
    nodeMap.put(Pair.make(root,context.key()),copy);
    return copy;
  }
}