Program: 150067
Project: 150067
Buggy source:
/** 
 * Emit code to implement the tableswitch bytecode
 * @param defaultval bcIndex of the default target
 * @param low low value of switch
 * @param high high value of switch
 */
protected final void emit_tableswitch(int defaultval,int low,int high){
  int bTarget=biStart + defaultval;
  int mTarget=bytecodeMap[bTarget];
  int n=high - low + 1;
  int firstCounter=edgeCounterIdx;
  popInt(T0);
  if (VM_Assembler.fits(16,-low)) {
    asm.emitADDI(T0,-low,T0);
  }
 else {
    asm.emitLVAL(T1,low);
    asm.emitSUBFC(T0,T1,T0);
  }
  asm.emitLVAL(T2,n);
  asm.emitCMPL(T0,T2);
  if (options.EDGE_COUNTERS) {
    edgeCounterIdx+=n + 1;
    asm.emitLAddrToc(T2,VM_Entrypoints.edgeCountersField.getOffset());
    asm.emitLAddrOffset(T2,T2,getEdgeCounterOffset());
    VM_ForwardReference fr=asm.emitForwardBC(LT);
    incEdgeCounter(T2,S0,firstCounter + n);
    asm.emitB(mTarget,bTarget);
    fr.resolve(asm);
  }
 else {
    if (bTarget - SHORT_FORWARD_LIMIT < biStart) {
      asm.emitShortBC(GE,mTarget,bTarget);
    }
 else {
      asm.emitBC(GE,mTarget,bTarget);
    }
  }
  VM_ForwardReference fr1=asm.emitForwardBL();
  for (int i=0; i < n; i++) {
    int offset=bcodes.getTableSwitchOffset(i);
    bTarget=biStart + offset;
    mTarget=bytecodeMap[bTarget];
    asm.emitSwitchCase(i,mTarget,bTarget);
  }
  bcodes.skipTableSwitchOffsets(n);
  fr1.resolve(asm);
  asm.emitMFLR(T1);
  asm.emitSLWI(T0,T0,LOG_BYTES_IN_INT);
  if (options.EDGE_COUNTERS) {
    incEdgeCounterIdx(T2,S0,firstCounter,T0);
  }
  asm.emitLIntX(T0,T0,T1);
  asm.emitADD(T1,T1,T0);
  asm.emitMTCTR(T1);
  asm.emitBCCTR();
}

Fixed version (ground truth):
/** 
 * Emit code to implement the tableswitch bytecode
 * @param defaultval bcIndex of the default target
 * @param low low value of switch
 * @param high high value of switch
 */
protected final void emit_tableswitch(int defaultval,int low,int high){
  int bTarget=biStart + defaultval;
  int mTarget=bytecodeMap[bTarget];
  int n=high - low + 1;
  int firstCounter=edgeCounterIdx;
  popInt(T0);
  if (VM_Assembler.fits(-low,16)) {
    asm.emitADDI(T0,-low,T0);
  }
 else {
    asm.emitLVAL(T1,low);
    asm.emitSUBFC(T0,T1,T0);
  }
  asm.emitLVAL(T2,n);
  asm.emitCMPL(T0,T2);
  if (options.EDGE_COUNTERS) {
    edgeCounterIdx+=n + 1;
    asm.emitLAddrToc(T2,VM_Entrypoints.edgeCountersField.getOffset());
    asm.emitLAddrOffset(T2,T2,getEdgeCounterOffset());
    VM_ForwardReference fr=asm.emitForwardBC(LT);
    incEdgeCounter(T2,S0,firstCounter + n);
    asm.emitB(mTarget,bTarget);
    fr.resolve(asm);
  }
 else {
    if (bTarget - SHORT_FORWARD_LIMIT < biStart) {
      asm.emitShortBC(GE,mTarget,bTarget);
    }
 else {
      asm.emitBC(GE,mTarget,bTarget);
    }
  }
  VM_ForwardReference fr1=asm.emitForwardBL();
  for (int i=0; i < n; i++) {
    int offset=bcodes.getTableSwitchOffset(i);
    bTarget=biStart + offset;
    mTarget=bytecodeMap[bTarget];
    asm.emitSwitchCase(i,mTarget,bTarget);
  }
  bcodes.skipTableSwitchOffsets(n);
  fr1.resolve(asm);
  asm.emitMFLR(T1);
  asm.emitSLWI(T0,T0,LOG_BYTES_IN_INT);
  if (options.EDGE_COUNTERS) {
    incEdgeCounterIdx(T2,S0,firstCounter,T0);
  }
  asm.emitLIntX(T0,T0,T1);
  asm.emitADD(T1,T1,T0);
  asm.emitMTCTR(T1);
  asm.emitBCCTR();
}