human
Complete the below
def _legalize(module, dmm, fndesc):

    ''''Legalize the code in the module.
    Returns True if the module is legal for the rewrite pass that remove
    unnecessary refcount.'
    '''
 ... Can you provide a the Python code you requested?
assistant
#Here is the Python code you requested.
    def valid_output(ty):
        '\n                                Valid    output    are    any    type    that    does    not    need    refcount\n                                '
        model = dmm[ty]
        return (not model.contains_nrt_meminfo())
    def valid_input(ty):
        '\n                                Valid    input    are    any    type    that    does    not    need    refcount    except    Array.\n                                '
        return (valid_output(ty) or isinstance(ty, types.Array))
    argtypes = fndesc.argtypes
    restype = fndesc.restype
    calltypes = fndesc.calltypes
    for argty in argtypes:
        if (not valid_input(argty)):
            return False
    if (not valid_output(restype)):
        return False
    for callty in calltypes.values():
        if ((callty is not None) and (not valid_output(callty.return_type))):
            return False
    for fn in module.functions:
        if fn.name.startswith('NRT_'):
            if (fn.name not in _accepted_nrtfns):
                return False
    return True