<awangdev>Total Occurrence of Target_1.java
public int totalOccurrence(int[] A, int target) {
    	if (A == null || A.length == 0) {
    		return 0;
    	}
    	int start = 0;
    	int end = A.length - 1;
    	int mid = start + (end - start)/2;
    	int first = 0;
    	int last = 0;
    	while (start + 1 < end){
    		mid = start + (end - start)/2;
    		if (A[mid] == target) {
				if (mid - 1 >= 0 && A[mid - 1] == target) {
					end = mid;
				} else {
					break;
				}
			} else if (A[mid] < target) {
				start = mid;
			} else {
				end = mid;
			}
    	}
    	if (A[start] == target) {
    		first = start;
    	} else if (A[mid] == target){
    		first = mid;
    	} else if (A[end] == target){
    		first = end;
    	} else {
    		return 0;
    	}
    	if (mid + 1 < A.length && A[mid + 1] != target) {
    		return 1;
    	}

    	start = first;
    	last = start + 1;
    	end = A.length - 1;
    	while (start + 1 < end){
    		mid = start + (end - start)/2;
    		if (A[mid] == target) {
				if (mid + 1 < A.length && A[mid + 1] == target) {
					start = mid;
				} else {
					break;
				}
			} else if (A[mid] < target) {
				start = mid;
			} else {
				end = mid;
			}
    	}

    	if (A[end] == target) {
    		last = end;
    	} else if (A[mid] == target){
    		last = mid;
    	} else if (A[start] == target) {
    		last = start;
    	} 
    	return last - first + 1;
    }
public int sample_funcname ( int [ ] var_0 , int var_1 ) {
  if ( var_0 == null || var_0 . length == 0 ) {
    return 0 ;
  }
  int var_5 = 0 ;
  int var_7 = var_0 . length - 1 ;
  int var_9 = var_5 + ( var_7 - var_5 ) / 2 ;
  int var_10 = 0 ;
  int var_11 = 0 ;
  while ( var_5 + 1 < var_7 ) {
    var_9 = var_5 + ( var_7 - var_5 ) / 2 ;
    if ( var_0 [ var_9 ] == var_1 ) {
      if ( var_9 - 1 >= 0 && var_0 [ var_9 - 1 ] == var_1 ) {
        var_7 = var_9 ;
      }
      else {
        break ;
      }
    }
    else if ( var_0 [ var_9 ] < var_1 ) {
      var_5 = var_9 ;
    }
    else {
      var_7 = var_9 ;
    }
  }
  if ( var_0 [ var_5 ] == var_1 ) {
    var_10 = var_5 ;
  }
  else if ( var_0 [ var_9 ] == var_1 ) {
    var_10 = var_9 ;
  }
  else if ( var_0 [ var_7 ] == var_1 ) {
    var_10 = var_7 ;
  }
  else {
    return 0 ;
  }
  if ( var_9 + 1 < var_0 . length && var_0 [ var_9 + 1 ] != var_1 ) {
    return 1 ;
  }
  var_5 = var_10 ;
  var_11 = var_5 + 1 ;
  var_7 = var_0 . length - 1 ;
  while ( var_5 + 1 < var_7 ) {
    var_9 = var_5 + ( var_7 - var_5 ) / 2 ;
    if ( var_0 [ var_9 ] == var_1 ) {
      if ( var_9 + 1 < var_0 . length && var_0 [ var_9 + 1 ] == var_1 ) {
        var_5 = var_9 ;
      }
      else {
        break ;
      }
    }
    else if ( var_0 [ var_9 ] < var_1 ) {
      var_5 = var_9 ;
    }
    else {
      var_7 = var_9 ;
    }
  }
  if ( var_0 [ var_7 ] == var_1 ) {
    var_11 = var_7 ;
  }
  else if ( var_0 [ var_9 ] == var_1 ) {
    var_11 = var_9 ;
  }
  else if ( var_0 [ var_5 ] == var_1 ) {
    var_11 = var_5 ;
  }
  return var_11 - var_10 + 1 ;
}
