Program: 33365
Project: 33365
Buggy source:
/** 
 * Flip the endian of the input byte-compacted array
 * @param input the input byte array which is byte compacted
 * @param offset the offset to start the reading input
 * @param len number of bytes to read
 * @param bits number of bits for the data before compaction
 * @param scanLineStride scan line stride to skip bits
 * @param bigEndian whether or not the input data is in big endian order
 * @return a byte array with the endian flipped
 */
public static byte[] flipEndian(byte[] input,int offset,int len,int bits,int scanLineStride,boolean bigEndian){
  long value=0;
  int bits_remain=0;
  int temp_byte=0;
  int empty_bits=8;
  byte[] output=new byte[input.length];
  int strideCounter=0;
  int end=offset + len;
  int bufIndex=0;
  int temp=bits;
  boolean bigEndianOut=!bigEndian;
  loop:   while (true) {
    if (!bigEndian)     value=(temp_byte >> (8 - bits_remain));
 else     value=(temp_byte & MASK[bits_remain]);
    while (bits > bits_remain) {
      if (offset >= end) {
        break loop;
      }
      temp_byte=input[offset++] & 0xff;
      if (bigEndian)       value=((value << 8) | temp_byte);
 else       value|=(temp_byte << bits_remain);
      bits_remain+=8;
    }
    bits_remain-=bits;
    if (bigEndian)     value=(value >> (bits_remain));
    if (bigEndianOut) {
      temp=bits - empty_bits;
      output[bufIndex]|=((value >>> temp) & MASK[empty_bits]);
      while (temp > 8) {
        output[++bufIndex]|=((value >>> (temp - 8)) & MASK[8]);
        temp-=8;
      }
      if (temp > 0) {
        output[++bufIndex]|=((value & MASK[temp]) << (8 - temp));
        temp-=8;
      }
    }
 else {
      temp=bits;
      output[bufIndex]|=((value & MASK[empty_bits]) << (8 - empty_bits));
      value>>=empty_bits;
      temp-=empty_bits;
      while (temp > 8) {
        output[++bufIndex]|=(value & 0xff);
        value>>=8;
        temp-=8;
      }
      if (temp > 0) {
        output[++bufIndex]|=(value & MASK[temp]);
        temp-=8;
      }
    }
    empty_bits=-temp;
    if (++strideCounter % scanLineStride == 0) {
      empty_bits=0;
      bits_remain=0;
    }
  }
  return output;
}

Fixed version (ground truth):
/** 
 * Flip the endian of the input byte-compacted array
 * @param input the input byte array which is byte compacted
 * @param offset the offset to start the reading input
 * @param len number of bytes to read
 * @param bits number of bits for the data before compaction
 * @param scanLineStride scan line stride to skip bits
 * @param bigEndian whether or not the input data is in big endian order
 * @return a byte array with the endian flipped
 */
public static byte[] flipEndian(byte[] input,int offset,int len,int bits,int scanLineStride,boolean bigEndian){
  long value=0;
  int bits_remain=0;
  long temp_byte=0;
  int empty_bits=8;
  byte[] output=new byte[input.length];
  int strideCounter=0;
  int end=offset + len;
  int bufIndex=0;
  int temp=bits;
  boolean bigEndianOut=!bigEndian;
  loop:   while (true) {
    if (!bigEndian)     value=(temp_byte >> (8 - bits_remain));
 else     value=(temp_byte & MASK[bits_remain]);
    while (bits > bits_remain) {
      if (offset >= end) {
        break loop;
      }
      temp_byte=input[offset++] & 0xff;
      if (bigEndian)       value=((value << 8) | temp_byte);
 else       value|=(temp_byte << bits_remain);
      bits_remain+=8;
    }
    bits_remain-=bits;
    if (bigEndian)     value=(value >> bits_remain);
    if (bigEndianOut) {
      temp=bits - empty_bits;
      output[bufIndex]|=((value >> temp) & MASK[empty_bits]);
      while (temp > 8) {
        output[++bufIndex]|=((value >> (temp - 8)) & MASK[8]);
        temp-=8;
      }
      if (temp > 0) {
        output[++bufIndex]|=((value & MASK[temp]) << (8 - temp));
        temp-=8;
      }
    }
 else {
      temp=bits;
      output[bufIndex]|=((value & MASK[empty_bits]) << (8 - empty_bits));
      value>>=empty_bits;
      temp-=empty_bits;
      while (temp > 8) {
        output[++bufIndex]|=(value & 0xff);
        value>>=8;
        temp-=8;
      }
      if (temp > 0) {
        output[++bufIndex]|=(value & MASK[temp]);
        temp-=8;
      }
    }
    empty_bits=-temp;
    if (++strideCounter % scanLineStride == 0) {
      empty_bits=0;
      bits_remain=0;
    }
  }
  return output;
}