import re


def filter_whitespaces(text):
    """Filters redundant whitespaces.

    Adds spaces around pointers, behind commas.
    """
    text = re.sub(r'\s*\*\s*', ' * ', text)
    text = re.sub(r'\*\s+\*', '**', text)
    text = re.sub(r'\*\s+\*', '**', text)  # need for 3+ pointers
    text = re.sub(r'\s*,\s*', ', ', text)
    text = re.sub(r'\s+', ' ', text)
    text = re.sub(r'\s*\)\s*', ')', text)
    text = re.sub(r'\s*\(\s*', '(', text)
    text = re.sub(r'\s*\{\s*', '{ ', text)
    text = re.sub(r'\s*\}\s*', ' }', text)
    text = re.sub(r'\s*\[\s*', '[', text)
    text = re.sub(r'\s*\]\s*', ']', text)
    return text