In a Zemoso Technologies data-transformation pipeline, implement one function that processes nested array data and a square matrix. The function must flatten the nested array in left-to-right depth-first order, return the matrix elements in clockwise spiral order, and rotate the matrix 90 degrees clockwise in place.
The nested array may contain integers or arrays nested to arbitrary depth. The matrix contains integers and must remain square. Return a dictionary with keys flattened, spiral, and rotated. The rotated value must represent the matrix after in-place clockwise rotation. Assume the flattened array and matrix contain the same number of values, although the two results are independent.
You should avoid recursion for flattening because nesting depth may be large. The matrix rotation should use O(1) auxiliary space beyond the returned results.
Input: nested, a recursively nested list of integers, and matrix, an n x n list of lists of integers. Output: a dictionary containing three lists: the flattened values, spiral traversal values, and rotated matrix.
def flatten_and_transform(nested, matrix):