code: def _resolve_filesystem_and_path(
      path,
      filesystem=None,
      allow_legacy_filesystem=False,
      memory_map=False,
  ):
      """
      Return filesystem/path from path which could be an URI or a plain
      filesystem path.
      """
      if not _is_path_like(path):
          if filesystem is not None:
              raise ValueError(
                  "'filesystem' passed but the specified path is file-like, so"
                  " there is nothing to open with 'filesystem'."
              )
          return filesystem, path
  
      if filesystem is not None:
          filesystem = _ensure_filesystem(
              filesystem,
              use_mmap=memory_map,
              allow_legacy_filesystem=allow_legacy_filesystem,
          )
          if isinstance(filesystem, LocalFileSystem):
              path = _stringify_path(path)
          elif not isinstance(path, str):
              raise TypeError(
                  "Expected string path; path-like objects are only allowed "
                  "with a local filesystem"
              )
          if not allow_legacy_filesystem:
              path = filesystem.normalize_path(path)
          return filesystem, path
  
      path = _stringify_path(path)
  
      # if filesystem is not given, try to automatically determine one
      # first check if the file exists as a local (relative) file path
      # if not then try to parse the path as an URI
      filesystem = LocalFileSystem(use_mmap=memory_map)
  
      try:
          file_info = filesystem.get_file_info(path)
      except ValueError:  # ValueError means path is likely an URI
          file_info = None
          exists_locally = False
      else:
          exists_locally = file_info.type != FileType.NotFound
  
      # if the file or directory doesn't exists locally, then assume that
      # the path is an URI describing the file system as well
      if not exists_locally:
          try:
              filesystem, path = FileSystem.from_uri(path)
          except ValueError as e:
              # neither an URI nor a locally existing path, so assume that
              # local path was given and propagate a nicer file not found error
              # instead of a more confusing scheme parsing error
              if "empty scheme" not in str(
                  e
              ) and "Cannot parse URI" not in str(e):
                  raise
      else:
          path = filesystem.normalize_path(path)
  
      return filesystem, path
  
imports: from pyarrow.util import _is_path_like, _stringify_path
  from pyarrow._fs import FileSelector, FileType, FileInfo, FileSystem, LocalFileSystem, SubTreeFileSystem, _MockFileSystem, FileSystemHandler, PyFileSystem, _copy_files, _copy_files_selector
label_desc: Use image node_id 4 for calling a global function with example usage: _resolve_filesystem_and_path(path, filesystem, allow_legacy_filesystem, memory_map) and returns: filesystem,  path, filesystem,  path, filesystem,  path