<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def profile_args(_args):
 """Return args for v1, v2, or v3 structure. Args: _args (dict):
 The args section from the profile. Returns: dict: A collapsed version of the args dict. """

        # TODO: clean this up in a way that works for both py2/3
        if (
            _args.get('app', {}).get('optional') is not None
            or _args.get('app', {}).get('required') is not None
        ):
            # detect v3 schema
            app_args_optional = _args.get('app', {}).get('optional', {})
            app_args_required = _args.get('app', {}).get('required', {})
            default_args = _args.get('default', {})
            _args = {}
            _args.update(app_args_optional)
            _args.update(app_args_required)
            _args.update(default_args)
        elif _args.get('app') is not None and _args.get('default') is not None:
            # detect v2 schema
            app_args = _args.get('app', {})
            default_args = _args.get('default', {})
            _args = {}
            _args.update(app_args)
            _args.update(default_args)

        return _args