Implement a solution for a 2D matrix manipulation problem.
Given an n x n integer matrix, rotate it 90 degrees clockwise in place and return the same matrix. The function must use O(1) additional space beyond the matrix.
Input: A non-empty square matrix represented as a list of lists. Output: The rotated matrix.
Example: [[1, 2], [3, 4]] becomes [[3, 1], [4, 2]].
Constraints: 1 <= n <= 500; each row has exactly n elements; values are integers.
def rotate_matrix(matrix):