Program: 79496
Project: 79496
Buggy source:
public void run(){
  for (  IRFunction irFunction : ir.getFuncs().values()) {
    FuncInfo funcInfo=new FuncInfo();
    for (    PhysicalRegister preg : irFunction.getUsedPhysicalGeneralRegs()) {
      if (preg.isCalleeSave())       funcInfo.usedCalleeSaveRegs.add(preg);
      if (preg.isCallerSave())       funcInfo.usedCallerSaveRegs.add(preg);
    }
    funcInfo.numStackSlot=irFunction.getStackSlots().size();
    for (int i=0; i < funcInfo.numStackSlot; ++i) {
      funcInfo.stackSlotOffsetMap.put(irFunction.getStackSlots().get(i),-i * Configuration.getRegSize());
    }
    if ((funcInfo.usedCalleeSaveRegs.size() + funcInfo.numStackSlot) % 2 == 0) {
      ++funcInfo.numStackSlot;
    }
    funcInfo.numExtraArgs=irFunction.getArgVRegList().size() - 6;
    if (funcInfo.numExtraArgs < 0)     funcInfo.numExtraArgs=0;
    int extraArgOffset=-(funcInfo.usedCalleeSaveRegs.size() + funcInfo.numStackSlot + 1) * Configuration.getRegSize();
    for (int i=6; i < irFunction.getArgVRegList().size(); ++i) {
      funcInfo.stackSlotOffsetMap.put(irFunction.getArgsStackSlotMap().get(irFunction.getArgVRegList().get(i)),extraArgOffset);
      extraArgOffset-=Configuration.getRegSize();
    }
    funcInfoMap.put(irFunction,funcInfo);
  }
  for (  IRFunction irFunction : funcInfoMap.keySet()) {
    FuncInfo funcInfo=funcInfoMap.get(irFunction);
    funcInfo.recursiveUsedRegs.addAll(irFunction.getUsedPhysicalGeneralRegs());
    for (    IRFunction calleeFunc : irFunction.recursiveCalleeSet) {
      funcInfo.recursiveUsedRegs.addAll(calleeFunc.getUsedPhysicalGeneralRegs());
    }
  }
  for (  IRFunction irFunction : ir.getFuncs().values()) {
    FuncInfo funcInfo=funcInfoMap.get(irFunction);
    BasicBlock entryBB=irFunction.getStartBB();
    IRInstruction firstInst=entryBB.getFirstInst();
    for (    PhysicalRegister preg : funcInfo.usedCalleeSaveRegs) {
      firstInst.prependInst(new IRPush(entryBB,preg));
    }
    if (funcInfo.numStackSlot > 0)     firstInst.prependInst(new IRBinaryOperation(entryBB,rsp,IRBinaryOperation.IRBinaryOp.SUB,rsp,new IntImmediate(funcInfo.numStackSlot * Configuration.getRegSize())));
    for (    BasicBlock bb : irFunction.getReversePostOrder()) {
      for (IRInstruction inst=bb.getFirstInst(); inst != null; inst=inst.getNextInst()) {
        if (inst instanceof IRFunctionCall) {
          IRFunction calleeFunc=((IRFunctionCall)inst).getFunc();
          FuncInfo calleeInfo=funcInfoMap.get(calleeFunc);
          for (          PhysicalRegister preg : funcInfo.usedCallerSaveRegs) {
            if (calleeInfo.recursiveUsedRegs.contains(preg)) {
              inst.prependInst(new IRPush(inst.getParentBB(),preg));
            }
          }
          List<RegValue> args=((IRFunctionCall)inst).getArgs();
          if (calleeFunc.isBuiltIn()) {
          }
 else {
            if (args.size() > 0)             inst.prependInst(new IRMove(inst.getParentBB(),rdi,args.get(0)));
            if (args.size() > 1)             inst.prependInst(new IRMove(inst.getParentBB(),rsi,args.get(1)));
            if (args.size() > 2)             inst.prependInst(new IRMove(inst.getParentBB(),rdx,args.get(2)));
            if (args.size() > 3)             inst.prependInst(new IRMove(inst.getParentBB(),rcx,args.get(3)));
            if (args.size() > 4)             inst.prependInst(new IRMove(inst.getParentBB(),r8,args.get(4)));
            if (args.size() > 5)             inst.prependInst(new IRMove(inst.getParentBB(),r9,args.get(5)));
            if (funcInfo.numExtraArgs % 2 == 1) {
              inst.prependInst(new IRPush(inst.getParentBB(),new IntImmediate(0)));
            }
            for (int i=args.size() - 1; i > 5; --i) {
              inst.prependInst(new IRPush(inst.getParentBB(),args.get(i)));
            }
          }
          if (funcInfo.numExtraArgs > 0) {
            int numPushArg=(funcInfo.numExtraArgs % 2 == 0) ? funcInfo.numExtraArgs : funcInfo.numExtraArgs + 1;
            inst.appendInst(new IRBinaryOperation(inst.getParentBB(),rsp,IRBinaryOperation.IRBinaryOp.SUB,rsp,new IntImmediate(numPushArg * Configuration.getRegSize())));
          }
          if (((IRFunctionCall)inst).getDest() != null) {
            inst.appendInst(new IRMove(inst.getParentBB(),((IRFunctionCall)inst).getDest(),rax));
          }
          for (          PhysicalRegister preg : funcInfo.usedCallerSaveRegs) {
            if (calleeInfo.recursiveUsedRegs.contains(preg)) {
              inst.appendInst(new IRPush(inst.getParentBB(),preg));
            }
          }
        }
 else         if (inst instanceof IRHeapAlloc) {
          for (          PhysicalRegister preg : funcInfo.usedCallerSaveRegs) {
            inst.prependInst(new IRPush(inst.getParentBB(),preg));
          }
          inst.prependInst(new IRMove(inst.getParentBB(),rdi,((IRHeapAlloc)inst).getAllocSize()));
          inst.appendInst(new IRMove(inst.getParentBB(),((IRHeapAlloc)inst).getDest(),rax));
          for (          PhysicalRegister preg : funcInfo.usedCallerSaveRegs) {
            inst.appendInst(new IRPush(inst.getParentBB(),preg));
          }
        }
 else         if (inst instanceof IRLoad) {
          if (((IRLoad)inst).getAddr() instanceof StackSlot) {
            ((IRLoad)inst).setAddrOffset(funcInfo.stackSlotOffsetMap.get(((IRLoad)inst).getAddr()));
            ((IRLoad)inst).setAddr(rsp);
          }
        }
 else         if (inst instanceof IRStore) {
          if (((IRStore)inst).getAddr() instanceof StackSlot) {
            ((IRStore)inst).setAddrOffset(funcInfo.stackSlotOffsetMap.get(((IRStore)inst).getAddr()));
            ((IRStore)inst).setAddr(rsp);
          }
        }
 else         if (inst instanceof IRMove) {
          if (((IRMove)inst).getLhs() == ((IRMove)inst).getRhs()) {
            inst.remove();
          }
        }
      }
      IRReturn retInst=irFunction.getRetInstList().get(0);
      if (retInst.getRetValue() != null) {
        retInst.prependInst(new IRMove(retInst.getParentBB(),rax,retInst.getRetValue()));
      }
    }
    BasicBlock exitBB=irFunction.getEndBB();
    IRInstruction lastInst=exitBB.getLastInst();
    if (funcInfo.numStackSlot > 0)     lastInst.prependInst(new IRBinaryOperation(entryBB,rsp,IRBinaryOperation.IRBinaryOp.ADD,rsp,new IntImmediate(funcInfo.numStackSlot * Configuration.getRegSize())));
    for (int i=funcInfo.usedCalleeSaveRegs.size() - 1; i >= 0; --i) {
      lastInst.prependInst(new IRPop(entryBB,funcInfo.usedCalleeSaveRegs.get(i)));
    }
  }
}

Fixed version (ground truth):
public void run(){
  for (  IRFunction irFunction : ir.getFuncs().values()) {
    FuncInfo funcInfo=new FuncInfo();
    for (    PhysicalRegister preg : irFunction.getUsedPhysicalGeneralRegs()) {
      if (preg.isCalleeSave())       funcInfo.usedCalleeSaveRegs.add(preg);
      if (preg.isCallerSave())       funcInfo.usedCallerSaveRegs.add(preg);
    }
    funcInfo.numStackSlot=irFunction.getStackSlots().size();
    for (int i=0; i < funcInfo.numStackSlot; ++i) {
      funcInfo.stackSlotOffsetMap.put(irFunction.getStackSlots().get(i),-i * Configuration.getRegSize());
    }
    if ((funcInfo.usedCalleeSaveRegs.size() + funcInfo.numStackSlot) % 2 == 0) {
      ++funcInfo.numStackSlot;
    }
    funcInfo.numExtraArgs=irFunction.getArgVRegList().size() - 6;
    if (funcInfo.numExtraArgs < 0)     funcInfo.numExtraArgs=0;
    int extraArgOffset=-(funcInfo.usedCalleeSaveRegs.size() + funcInfo.numStackSlot + 1) * Configuration.getRegSize();
    for (int i=6; i < irFunction.getArgVRegList().size(); ++i) {
      funcInfo.stackSlotOffsetMap.put(irFunction.getArgsStackSlotMap().get(irFunction.getArgVRegList().get(i)),extraArgOffset);
      extraArgOffset-=Configuration.getRegSize();
    }
    funcInfoMap.put(irFunction,funcInfo);
  }
  for (  IRFunction irFunction : funcInfoMap.keySet()) {
    FuncInfo funcInfo=funcInfoMap.get(irFunction);
    funcInfo.recursiveUsedRegs.addAll(irFunction.getUsedPhysicalGeneralRegs());
    for (    IRFunction calleeFunc : irFunction.recursiveCalleeSet) {
      funcInfo.recursiveUsedRegs.addAll(calleeFunc.getUsedPhysicalGeneralRegs());
    }
  }
  for (  IRFunction irFunction : ir.getFuncs().values()) {
    FuncInfo funcInfo=funcInfoMap.get(irFunction);
    BasicBlock entryBB=irFunction.getStartBB();
    IRInstruction firstInst=entryBB.getFirstInst();
    for (    PhysicalRegister preg : funcInfo.usedCalleeSaveRegs) {
      firstInst.prependInst(new IRPush(entryBB,preg));
    }
    if (funcInfo.numStackSlot > 0)     firstInst.prependInst(new IRBinaryOperation(entryBB,rsp,IRBinaryOperation.IRBinaryOp.SUB,rsp,new IntImmediate(funcInfo.numStackSlot * Configuration.getRegSize())));
    for (    BasicBlock bb : irFunction.getReversePostOrder()) {
      for (IRInstruction inst=bb.getFirstInst(); inst != null; inst=inst.getNextInst()) {
        if (inst instanceof IRFunctionCall) {
          IRFunction calleeFunc=((IRFunctionCall)inst).getFunc();
          FuncInfo calleeInfo=funcInfoMap.get(calleeFunc);
          for (          PhysicalRegister preg : funcInfo.usedCallerSaveRegs) {
            if (calleeInfo.recursiveUsedRegs.contains(preg)) {
              inst.prependInst(new IRPush(inst.getParentBB(),preg));
            }
          }
          List<RegValue> args=((IRFunctionCall)inst).getArgs();
          if (calleeFunc.isBuiltIn()) {
          }
 else {
            if (args.size() > 0)             inst.prependInst(new IRMove(inst.getParentBB(),rdi,args.get(0)));
            if (args.size() > 1)             inst.prependInst(new IRMove(inst.getParentBB(),rsi,args.get(1)));
            if (args.size() > 2)             inst.prependInst(new IRMove(inst.getParentBB(),rdx,args.get(2)));
            if (args.size() > 3)             inst.prependInst(new IRMove(inst.getParentBB(),rcx,args.get(3)));
            if (args.size() > 4)             inst.prependInst(new IRMove(inst.getParentBB(),r8,args.get(4)));
            if (args.size() > 5)             inst.prependInst(new IRMove(inst.getParentBB(),r9,args.get(5)));
            if (funcInfo.numExtraArgs % 2 == 1) {
              inst.prependInst(new IRPush(inst.getParentBB(),new IntImmediate(0)));
            }
            for (int i=args.size() - 1; i > 5; --i) {
              inst.prependInst(new IRPush(inst.getParentBB(),args.get(i)));
            }
          }
          if (funcInfo.numExtraArgs > 0) {
            int numPushArg=(funcInfo.numExtraArgs % 2 == 0) ? funcInfo.numExtraArgs : funcInfo.numExtraArgs + 1;
            inst.appendInst(new IRBinaryOperation(inst.getParentBB(),rsp,IRBinaryOperation.IRBinaryOp.SUB,rsp,new IntImmediate(numPushArg * Configuration.getRegSize())));
          }
          if (((IRFunctionCall)inst).getDest() != null) {
            inst.appendInst(new IRMove(inst.getParentBB(),((IRFunctionCall)inst).getDest(),rax));
          }
          for (          PhysicalRegister preg : funcInfo.usedCallerSaveRegs) {
            if (calleeInfo.recursiveUsedRegs.contains(preg)) {
              inst.appendInst(new IRPush(inst.getParentBB(),preg));
            }
          }
        }
 else         if (inst instanceof IRHeapAlloc) {
          for (          PhysicalRegister preg : funcInfo.usedCallerSaveRegs) {
            inst.prependInst(new IRPush(inst.getParentBB(),preg));
          }
          inst.prependInst(new IRMove(inst.getParentBB(),rdi,((IRHeapAlloc)inst).getAllocSize()));
          inst.appendInst(new IRMove(inst.getParentBB(),((IRHeapAlloc)inst).getDest(),rax));
          for (          PhysicalRegister preg : funcInfo.usedCallerSaveRegs) {
            inst.appendInst(new IRPop(inst.getParentBB(),preg));
          }
        }
 else         if (inst instanceof IRLoad) {
          if (((IRLoad)inst).getAddr() instanceof StackSlot) {
            ((IRLoad)inst).setAddrOffset(funcInfo.stackSlotOffsetMap.get(((IRLoad)inst).getAddr()));
            ((IRLoad)inst).setAddr(rsp);
          }
        }
 else         if (inst instanceof IRStore) {
          if (((IRStore)inst).getAddr() instanceof StackSlot) {
            ((IRStore)inst).setAddrOffset(funcInfo.stackSlotOffsetMap.get(((IRStore)inst).getAddr()));
            ((IRStore)inst).setAddr(rsp);
          }
        }
 else         if (inst instanceof IRMove) {
          if (((IRMove)inst).getLhs() == ((IRMove)inst).getRhs()) {
            inst.remove();
          }
        }
      }
    }
    IRReturn retInst=irFunction.getRetInstList().get(0);
    if (retInst.getRetValue() != null) {
      retInst.prependInst(new IRMove(retInst.getParentBB(),rax,retInst.getRetValue()));
    }
    BasicBlock exitBB=irFunction.getEndBB();
    IRInstruction lastInst=exitBB.getLastInst();
    if (funcInfo.numStackSlot > 0)     lastInst.prependInst(new IRBinaryOperation(entryBB,rsp,IRBinaryOperation.IRBinaryOp.ADD,rsp,new IntImmediate(funcInfo.numStackSlot * Configuration.getRegSize())));
    for (int i=funcInfo.usedCalleeSaveRegs.size() - 1; i >= 0; --i) {
      lastInst.prependInst(new IRPop(entryBB,funcInfo.usedCalleeSaveRegs.get(i)));
    }
  }
}