def function_map(code_body, mod_func):
    """
  Given the entire code body, it identifies all instances of functions and
  processes them using the mod_func function.

  1. Identify all definitions of functions (not nested, not class methods).
  2. Call the mod_func function with the header/body of the function.
  3. Insert in the result.
  """
    function_starts = []
    function_ends = []
    code_lines = code_body.split('\n')
    line = 0
    while line < len(code_lines):
        if len(function_starts) > len(function_ends) and len(code_lines[line]
            ) > 0 and code_lines[line][0] != ' ':
            function_ends.append(line)
        if code_lines[line].startswith('def '):
            function_starts.append(line)
        line += 1
    if len(function_starts) > len(function_ends):
        function_ends.append(line)
    for start, end in zip(function_starts, function_ends):
        func_def = '\n'.join(code_lines[start:end])
        mod_func_def = mod_func(func_def)
        code_body = code_body.replace(func_def, mod_func_def)
    return code_body
