Rotate an N x N 2D matrix by 90 degrees clockwise in-place.
Implement rotate_matrix(matrix), modifying the input square matrix without allocating another matrix. Return the same matrix after modification so the result can be inspected.
Input: A non-empty N x N matrix of integers.
Output: The rotated matrix, with the original matrix modified in-place.
The rotation must use O(1) additional space.
def rotate_matrix(matrix):