Program: 21790
Project: 21790
Buggy source:
/** 
 * Helper function to compute the angle change between two rotation matrices. Given a current rotation matrix (R) and a previous rotation matrix (prevR) computes the rotation around the x,y, and z axes which transforms prevR to R. outputs a 3 element vector containing the x,y, and z angle change at indexes 0, 1, and 2 respectively. <p> Each input matrix is either as a 3x3 or 4x4 row-major matrix depending on the length of the passed array: <p>If the array length is 9, then the array elements represent this matrix <pre> /  R[ 0]   R[ 1]   R[ 2]   \ |  R[ 3]   R[ 4]   R[ 5]   | \  R[ 6]   R[ 7]   R[ 8]   / </pre> <p>If the array length is 16, then the array elements represent this matrix <pre> /  R[ 0]   R[ 1]   R[ 2]   R[ 3]  \ |  R[ 4]   R[ 5]   R[ 6]   R[ 7]  | |  R[ 8]   R[ 9]   R[10]   R[11]  | \  R[12]   R[13]   R[14]   R[15]  / </pre>
 * @param R current rotation matrix
 * @param prevR previous rotation matrix
 * @param angleChange an array of floats in which the angle change is stored
 */
public static void getAngleChange(float[] angleChange,float[] R,float[] prevR){
  float rd1=0, rd4=0, rd6=0, rd7=0, rd8=0;
  float ri0=0, ri1=0, ri2=0, ri3=0, ri4=0, ri5=0, ri6=0, ri7=0, ri8=0;
  float pri0=0, pri1=0, pri2=0, pri3=0, pri4=0, pri5=0, pri6=0, pri7=0, pri8=0;
  int i, j, k;
  if (R.length == 9) {
    ri0=R[0];
    ri1=R[1];
    ri2=R[2];
    ri3=R[3];
    ri4=R[4];
    ri5=R[5];
    ri6=R[6];
    ri7=R[7];
    ri8=R[8];
  }
 else   if (R.length == 16) {
    ri0=R[0];
    ri1=R[1];
    ri2=R[2];
    ri3=R[4];
    ri4=R[5];
    ri5=R[6];
    ri6=R[8];
    ri7=R[9];
    ri8=R[10];
  }
  if (prevR.length == 9) {
    pri0=R[0];
    pri1=R[1];
    pri2=R[2];
    pri3=R[3];
    pri4=R[4];
    pri5=R[5];
    pri6=R[6];
    pri7=R[7];
    pri8=R[8];
  }
 else   if (prevR.length == 16) {
    pri0=R[0];
    pri1=R[1];
    pri2=R[2];
    pri3=R[4];
    pri4=R[5];
    pri5=R[6];
    pri6=R[8];
    pri7=R[9];
    pri8=R[10];
  }
  rd1=pri0 * ri1 + pri3 * ri4 + pri6 * ri7;
  rd4=pri1 * ri1 + pri4 * ri4 + pri7 * ri7;
  rd6=pri2 * ri0 + pri5 * ri3 + pri8 * ri6;
  rd7=pri2 * ri1 + pri5 * ri4 + pri8 * ri7;
  rd8=pri2 * ri2 + pri5 * ri5 + pri8 * ri8;
  angleChange[0]=(float)Math.atan2(rd1,rd4);
  angleChange[1]=(float)Math.asin(-rd7);
  angleChange[2]=(float)Math.atan2(-rd6,rd8);
}

Fixed version (ground truth):
/** 
 * Helper function to compute the angle change between two rotation matrices. Given a current rotation matrix (R) and a previous rotation matrix (prevR) computes the rotation around the x,y, and z axes which transforms prevR to R. outputs a 3 element vector containing the x,y, and z angle change at indexes 0, 1, and 2 respectively. <p> Each input matrix is either as a 3x3 or 4x4 row-major matrix depending on the length of the passed array: <p>If the array length is 9, then the array elements represent this matrix <pre> /  R[ 0]   R[ 1]   R[ 2]   \ |  R[ 3]   R[ 4]   R[ 5]   | \  R[ 6]   R[ 7]   R[ 8]   / </pre> <p>If the array length is 16, then the array elements represent this matrix <pre> /  R[ 0]   R[ 1]   R[ 2]   R[ 3]  \ |  R[ 4]   R[ 5]   R[ 6]   R[ 7]  | |  R[ 8]   R[ 9]   R[10]   R[11]  | \  R[12]   R[13]   R[14]   R[15]  / </pre>
 * @param R current rotation matrix
 * @param prevR previous rotation matrix
 * @param angleChange an array of floats in which the angle change is stored
 */
public static void getAngleChange(float[] angleChange,float[] R,float[] prevR){
  float rd1=0, rd4=0, rd6=0, rd7=0, rd8=0;
  float ri0=0, ri1=0, ri2=0, ri3=0, ri4=0, ri5=0, ri6=0, ri7=0, ri8=0;
  float pri0=0, pri1=0, pri2=0, pri3=0, pri4=0, pri5=0, pri6=0, pri7=0, pri8=0;
  int i, j, k;
  if (R.length == 9) {
    ri0=R[0];
    ri1=R[1];
    ri2=R[2];
    ri3=R[3];
    ri4=R[4];
    ri5=R[5];
    ri6=R[6];
    ri7=R[7];
    ri8=R[8];
  }
 else   if (R.length == 16) {
    ri0=R[0];
    ri1=R[1];
    ri2=R[2];
    ri3=R[4];
    ri4=R[5];
    ri5=R[6];
    ri6=R[8];
    ri7=R[9];
    ri8=R[10];
  }
  if (prevR.length == 9) {
    pri0=prevR[0];
    pri1=prevR[1];
    pri2=prevR[2];
    pri3=prevR[3];
    pri4=prevR[4];
    pri5=prevR[5];
    pri6=prevR[6];
    pri7=prevR[7];
    pri8=prevR[8];
  }
 else   if (prevR.length == 16) {
    pri0=prevR[0];
    pri1=prevR[1];
    pri2=prevR[2];
    pri3=prevR[4];
    pri4=prevR[5];
    pri5=prevR[6];
    pri6=prevR[8];
    pri7=prevR[9];
    pri8=prevR[10];
  }
  rd1=pri0 * ri1 + pri3 * ri4 + pri6 * ri7;
  rd4=pri1 * ri1 + pri4 * ri4 + pri7 * ri7;
  rd6=pri2 * ri0 + pri5 * ri3 + pri8 * ri6;
  rd7=pri2 * ri1 + pri5 * ri4 + pri8 * ri7;
  rd8=pri2 * ri2 + pri5 * ri5 + pri8 * ri8;
  angleChange[0]=(float)Math.atan2(rd1,rd4);
  angleChange[1]=(float)Math.asin(-rd7);
  angleChange[2]=(float)Math.atan2(-rd6,rd8);
}