<awangdev>33. Search in Rotated Sorted Array_2.java
public int search(int[] A, int target) {
        if (A == null || A.length == 0) {
            return -1;
        }
        int p1 = 0;
        int p2 = A.length - 1;
        int start = p1;
        int end = p2;
        int mid = start + (end - start)/2;
        int breakPoint = 0;
        while (start + 1 < end) {
            mid = start + (end - start)/2;
            if (A[mid] == target) {
                return mid;
            } else if (A[mid] >= A[p1]) {
                start = mid;
            } else {
                end = mid;
            }
        }
        if (A[start] > A[end]) {
            breakPoint = start;
        } else {
            breakPoint = end;
        }

        if (A[p1] <= target && target <= A[breakPoint]) {
            start = p1;
            end = breakPoint;
        } else {
            start = breakPoint + 1;
            end = p2;
        }

        while (start + 1 < end) {
            mid = start + (end - start)/2;
            if (A[mid] == target) {
                return mid;
            } else if (A[mid] > target) {
                end = mid;
            } else {
                start = mid;
            }
        } 

        if (A[start] == target) {
            return start;
        } else if (A[end] == target) {
            return end;
        } 
        return -1;
    }
public int sample_funcname ( int [ ] var_0 , int var_1 ) {
  if ( var_0 == null || var_0 . length == 0 ) {
    return - 1 ;
  }
  int var_6 = 0 ;
  int var_7 = var_0 . length - 1 ;
  int var_8 = var_6 ;
  int var_9 = var_7 ;
  int var_11 = var_8 + ( var_9 - var_8 ) / 2 ;
  int var_12 = 0 ;
  while ( var_8 + 1 < var_9 ) {
    var_11 = var_8 + ( var_9 - var_8 ) / 2 ;
    if ( var_0 [ var_11 ] == var_1 ) {
      return var_11 ;
    }
    else if ( var_0 [ var_11 ] >= var_0 [ var_6 ] ) {
      var_8 = var_11 ;
    }
    else {
      var_9 = var_11 ;
    }
  }
  if ( var_0 [ var_8 ] > var_0 [ var_9 ] ) {
    var_12 = var_8 ;
  }
  else {
    var_12 = var_9 ;
  }
  if ( var_0 [ var_6 ] <= var_1 && var_1 <= var_0 [ var_12 ] ) {
    var_8 = var_6 ;
    var_9 = var_12 ;
  }
  else {
    var_8 = var_12 + 1 ;
    var_9 = var_7 ;
  }
  while ( var_8 + 1 < var_9 ) {
    var_11 = var_8 + ( var_9 - var_8 ) / 2 ;
    if ( var_0 [ var_11 ] == var_1 ) {
      return var_11 ;
    }
    else if ( var_0 [ var_11 ] > var_1 ) {
      var_9 = var_11 ;
    }
    else {
      var_8 = var_11 ;
    }
  }
  if ( var_0 [ var_8 ] == var_1 ) {
    return var_8 ;
  }
  else if ( var_0 [ var_9 ] == var_1 ) {
    return var_9 ;
  }
  return - 1 ;
}
