Program: 101670
Project: 101670
Buggy source:
/** 
 * Convert us to a binary representation. There are sme distinctly endianist happenings here, but that is OK because we are reading the stuff we write here just below.
 * @param ref The Passage to convert
 * @return a byte array
 */
public static byte[] toBinaryRepresentation(Passage ref){
  int verses=ref.countVerses();
  int ranges=ref.countRanges(RestrictionType.NONE);
  int bitwise_size=BibleInfo.versesInBible() / 8;
  int ranged_size=(ranges * 4) + 1;
  int distinct_size=(verses * 2) + 1;
  if (bitwise_size <= ranged_size && bitwise_size <= distinct_size) {
    int array_size=binarySize(AbstractPassage.METHOD_COUNT) + (BibleInfo.versesInBible() / 8) + 1;
    byte[] buffer=new byte[array_size];
    int index=0;
    index+=toBinary(buffer,index,AbstractPassage.BITWISE,AbstractPassage.METHOD_COUNT);
    Iterator it=ref.iterator();
    while (it.hasNext()) {
      Verse verse=(Verse)it.next();
      int ord=verse.getOrdinal();
      int idx0=(ord / 8) + index;
      int bit=(ord % 8) - 1;
      buffer[idx0]|=1 << bit;
    }
    return buffer;
  }
 else   if (distinct_size <= ranged_size) {
    int array_size=binarySize(AbstractPassage.METHOD_COUNT) + binarySize(BibleInfo.versesInBible()) + (verses * binarySize(BibleInfo.versesInBible()));
    byte[] buffer=new byte[array_size];
    int index=0;
    index+=toBinary(buffer,index,AbstractPassage.DISTINCT,AbstractPassage.METHOD_COUNT);
    index+=toBinary(buffer,index,verses,BibleInfo.versesInBible());
    Iterator it=ref.iterator();
    while (it.hasNext()) {
      Verse verse=(Verse)it.next();
      int ord=verse.getOrdinal();
      index+=toBinary(buffer,index,ord,BibleInfo.versesInBible());
    }
    return buffer;
  }
 else {
    int array_size=binarySize(AbstractPassage.METHOD_COUNT) + binarySize(BibleInfo.versesInBible() / 2) + (2 * ranges * binarySize(BibleInfo.versesInBible()));
    byte[] buffer=new byte[array_size];
    int index=0;
    index+=toBinary(buffer,index,AbstractPassage.RANGED,AbstractPassage.METHOD_COUNT);
    index+=toBinary(buffer,index,ranges,BibleInfo.versesInBible() / 2);
    Iterator it=ref.rangeIterator(RestrictionType.NONE);
    while (it.hasNext()) {
      VerseRange range=(VerseRange)it.next();
      index+=toBinary(buffer,index,range.getStart().getOrdinal(),BibleInfo.versesInBible());
      index+=toBinary(buffer,index,range.getVerseCount(),BibleInfo.versesInBible());
    }
    return buffer;
  }
}

Fixed version (ground truth):
/** 
 * Convert us to a binary representation. There are some distinctly endianist happenings here, but that is OK because we are reading the stuff we write here just below.
 * @param ref The Passage to convert
 * @return a byte array
 */
public static byte[] toBinaryRepresentation(Passage ref){
  int verses=ref.countVerses();
  int ranges=ref.countRanges(RestrictionType.NONE);
  int bitwise_size=BibleInfo.versesInBible() / 8;
  int ranged_size=(ranges * 4) + 1;
  int distinct_size=(verses * 2) + 1;
  if (bitwise_size <= ranged_size && bitwise_size <= distinct_size) {
    int array_size=binarySize(AbstractPassage.METHOD_COUNT) + (BibleInfo.versesInBible() / 8) + 1;
    byte[] buffer=new byte[array_size];
    int index=0;
    index+=toBinary(buffer,index,AbstractPassage.BITWISE,AbstractPassage.METHOD_COUNT);
    Iterator it=ref.iterator();
    while (it.hasNext()) {
      Verse verse=(Verse)it.next();
      int ord=verse.getOrdinal();
      int idx0=(ord / 8) + index;
      int bit=(ord % 8) - 1;
      buffer[idx0]|=1 << bit;
    }
    return buffer;
  }
 else   if (distinct_size <= ranged_size) {
    int array_size=binarySize(AbstractPassage.METHOD_COUNT) + binarySize(BibleInfo.versesInBible()) + (verses * binarySize(BibleInfo.versesInBible()));
    byte[] buffer=new byte[array_size];
    int index=0;
    index+=toBinary(buffer,index,AbstractPassage.DISTINCT,AbstractPassage.METHOD_COUNT);
    index+=toBinary(buffer,index,verses,BibleInfo.versesInBible());
    Iterator it=ref.iterator();
    while (it.hasNext()) {
      Verse verse=(Verse)it.next();
      int ord=verse.getOrdinal();
      index+=toBinary(buffer,index,ord,BibleInfo.versesInBible());
    }
    return buffer;
  }
 else {
    int array_size=binarySize(AbstractPassage.METHOD_COUNT) + binarySize(BibleInfo.versesInBible() / 2) + (2 * ranges * binarySize(BibleInfo.versesInBible()));
    byte[] buffer=new byte[array_size];
    int index=0;
    index+=toBinary(buffer,index,AbstractPassage.RANGED,AbstractPassage.METHOD_COUNT);
    index+=toBinary(buffer,index,ranges,BibleInfo.versesInBible() / 2);
    Iterator it=ref.rangeIterator(RestrictionType.NONE);
    while (it.hasNext()) {
      VerseRange range=(VerseRange)it.next();
      index+=toBinary(buffer,index,range.getStart().getOrdinal(),BibleInfo.versesInBible());
      index+=toBinary(buffer,index,range.getVerseCount(),BibleInfo.versesInBible());
    }
    return buffer;
  }
}