Program: 149933
Project: 149933
Buggy source:
private void naiveUnroller(OPT_LSTNode t,OPT_IR ir){
  OPT_BitVector nloop=t.loop;
  OPT_BasicBlock seqStart=null;
  OPT_BasicBlockEnumeration bs;
  if (t.loop.populationCount() > MAX_BLOCKS_FOR_NAIVE_UNROLLING) {
    report("String_Node_Str");
    return;
  }
  report("String_Node_Str");
  OPT_CFGTransformations.killFallThroughs(ir,nloop);
  int bodyBlocks=nloop.populationCount();
  OPT_BasicBlock[] body=new OPT_BasicBlock[bodyBlocks];
{
    int i=0;
    bs=ir.getBasicBlocks(nloop);
    while (bs.hasMoreElements()) {
      OPT_BasicBlock b=bs.next();
      if (VM.VerifyAssertions)       VM._assert(!(b instanceof OPT_ExceptionHandlerBasicBlock));
      body[i++]=b;
      OPT_BasicBlock next=b.nextBasicBlockInCodeOrder();
      if (next == null || !OPT_CFGTransformations.inLoop(next,nloop))       ;
      seqStart=b;
    }
  }
  OPT_BasicBlock seqEnd=seqStart.nextBasicBlockInCodeOrder();
  if (seqEnd != null)   ir.cfg.breakCodeOrder(seqStart,seqEnd);
  OPT_BasicBlock seqLast=seqStart;
  OPT_BasicBlock firstHeaderCopy=null;
  OPT_BasicBlock currentBlock=seqLast;
  for (int i=1; i <= unrollFactor; ++i) {
    for (    OPT_BasicBlock bb : body) {
      seqLast=copyAndLinkBlock(ir,seqLast,bb);
      if (bb == t.header) {
        if (firstHeaderCopy == null) {
          firstHeaderCopy=seqLast;
        }
      }
    }
    currentBlock=seqLast;
    for (int j=0; j < bodyBlocks; ++j) {
      currentBlock.recomputeNormalOut(ir);
      OPT_BasicBlockEnumeration be=currentBlock.getOut();
      while (be.hasMoreElements()) {
        OPT_BasicBlock out=be.next();
        if (out != t.header && OPT_CFGTransformations.inLoop(out,nloop)) {
          OPT_BasicBlock outCopy=(OPT_BasicBlock)out.scratchObject;
          currentBlock.redirectOuts(out,outCopy,ir);
        }
      }
      currentBlock.recomputeNormalOut(ir);
      currentBlock=currentBlock.prevBasicBlockInCodeOrder();
    }
    if (i != 1) {
      for (int j=0; j < bodyBlocks; ++j) {
        OPT_BasicBlockEnumeration be=currentBlock.getOut();
        while (be.hasMoreElements()) {
          OPT_BasicBlock out=be.next();
          if (out == t.header) {
            OPT_BasicBlock headerCopy;
            headerCopy=(OPT_BasicBlock)t.header.scratchObject;
            currentBlock.redirectOuts(t.header,headerCopy,ir);
          }
        }
        currentBlock.recomputeNormalOut(ir);
        currentBlock=currentBlock.prevBasicBlockInCodeOrder();
      }
    }
  }
  if (seqEnd != null)   ir.cfg.linkInCodeOrder(seqLast,seqEnd);
  for (int j=0; j < bodyBlocks; ++j) {
    OPT_BasicBlockEnumeration be=body[j].getOut();
    while (be.hasMoreElements()) {
      OPT_BasicBlock out=be.next();
      if (out == t.header) {
        body[j].redirectOuts(t.header,firstHeaderCopy,ir);
      }
    }
    body[j].recomputeNormalOut(ir);
  }
  currentBlock=seqLast;
  for (int j=0; j < bodyBlocks; ++j) {
    OPT_BasicBlockEnumeration be=currentBlock.getOut();
    while (be.hasMoreElements()) {
      OPT_BasicBlock out=be.next();
      if (out == t.header) {
        currentBlock.redirectOuts(t.header,firstHeaderCopy,ir);
      }
    }
    currentBlock.recomputeNormalOut(ir);
    currentBlock=currentBlock.prevBasicBlockInCodeOrder();
  }
}

Fixed version (ground truth):
private void naiveUnroller(OPT_LSTNode t,OPT_IR ir){
  OPT_BitVector nloop=t.loop;
  OPT_BasicBlock seqStart=null;
  OPT_BasicBlockEnumeration bs;
  if (t.loop.populationCount() > MAX_BLOCKS_FOR_NAIVE_UNROLLING) {
    report("String_Node_Str");
    return;
  }
  report("String_Node_Str");
  OPT_CFGTransformations.killFallThroughs(ir,nloop);
  int bodyBlocks=nloop.populationCount();
  OPT_BasicBlock[] body=new OPT_BasicBlock[bodyBlocks];
{
    int i=0;
    bs=ir.getBasicBlocks(nloop);
    while (bs.hasMoreElements()) {
      OPT_BasicBlock b=bs.next();
      if (VM.VerifyAssertions)       VM._assert(!(b instanceof OPT_ExceptionHandlerBasicBlock));
      body[i++]=b;
      OPT_BasicBlock next=b.nextBasicBlockInCodeOrder();
      if (next == null || !OPT_CFGTransformations.inLoop(next,nloop))       seqStart=b;
    }
  }
  OPT_BasicBlock seqEnd=seqStart.nextBasicBlockInCodeOrder();
  if (seqEnd != null)   ir.cfg.breakCodeOrder(seqStart,seqEnd);
  OPT_BasicBlock seqLast=seqStart;
  OPT_BasicBlock firstHeaderCopy=null;
  OPT_BasicBlock currentBlock=seqLast;
  for (int i=1; i <= unrollFactor; ++i) {
    for (    OPT_BasicBlock bb : body) {
      seqLast=copyAndLinkBlock(ir,seqLast,bb);
      if (bb == t.header) {
        if (firstHeaderCopy == null) {
          firstHeaderCopy=seqLast;
        }
      }
    }
    currentBlock=seqLast;
    for (int j=0; j < bodyBlocks; ++j) {
      currentBlock.recomputeNormalOut(ir);
      OPT_BasicBlockEnumeration be=currentBlock.getOut();
      while (be.hasMoreElements()) {
        OPT_BasicBlock out=be.next();
        if (out != t.header && OPT_CFGTransformations.inLoop(out,nloop)) {
          OPT_BasicBlock outCopy=(OPT_BasicBlock)out.scratchObject;
          currentBlock.redirectOuts(out,outCopy,ir);
        }
      }
      currentBlock.recomputeNormalOut(ir);
      currentBlock=currentBlock.prevBasicBlockInCodeOrder();
    }
    if (i != 1) {
      for (int j=0; j < bodyBlocks; ++j) {
        OPT_BasicBlockEnumeration be=currentBlock.getOut();
        while (be.hasMoreElements()) {
          OPT_BasicBlock out=be.next();
          if (out == t.header) {
            OPT_BasicBlock headerCopy;
            headerCopy=(OPT_BasicBlock)t.header.scratchObject;
            currentBlock.redirectOuts(t.header,headerCopy,ir);
          }
        }
        currentBlock.recomputeNormalOut(ir);
        currentBlock=currentBlock.prevBasicBlockInCodeOrder();
      }
    }
  }
  if (seqEnd != null)   ir.cfg.linkInCodeOrder(seqLast,seqEnd);
  for (int j=0; j < bodyBlocks; ++j) {
    OPT_BasicBlockEnumeration be=body[j].getOut();
    while (be.hasMoreElements()) {
      OPT_BasicBlock out=be.next();
      if (out == t.header) {
        body[j].redirectOuts(t.header,firstHeaderCopy,ir);
      }
    }
    body[j].recomputeNormalOut(ir);
  }
  currentBlock=seqLast;
  for (int j=0; j < bodyBlocks; ++j) {
    OPT_BasicBlockEnumeration be=currentBlock.getOut();
    while (be.hasMoreElements()) {
      OPT_BasicBlock out=be.next();
      if (out == t.header) {
        currentBlock.redirectOuts(t.header,firstHeaderCopy,ir);
      }
    }
    currentBlock.recomputeNormalOut(ir);
    currentBlock=currentBlock.prevBasicBlockInCodeOrder();
  }
}