```python
def find_last_occurrence(A, x):
    """
    Finds the index of the last occurrence of a given number in a sorted array.

    Args:
        A: A list of numbers, sorted in non-decreasing order.
        x: The number to search for.

    Returns:
        The index of the last occurrence of x in A.
        Returns -1 if x is not found in A.
    """
    low = 0
    high = len(A) - 1
    result = -1

    while low <= high:
        mid = low + (high - low) // 2

        if A[mid] == x:
            # We found an occurrence. This could be the last one.
            # We store this index and continue searching in the right half
            # to see if a later occurrence exists.
            result = mid
            low = mid + 1
        elif A[mid] < x:
            # If the middle element is less than x, the last occurrence
            # must be in the right half of the array.
            low = mid + 1
        else:  # A[mid] > x
            # If the middle element is greater than x, the last occurrence
            # must be in the left half of the array.
            high = mid - 1

    return result
```