docs: def links(xmrs):
      """Return the list of Links for the *xmrs*."""
  
      # Links exist for every non-intrinsic argument that has a variable
      # that is the intrinsic variable of some other predicate, as well
      # as for label equalities when no argument link exists (even
      # considering transitivity).
      links = []
      prelinks = []
  
      _eps = xmrs._eps
      _hcons = xmrs._hcons
      _vars = xmrs._vars
  
      lsh = xmrs.labelset_heads
      lblheads = {v: lsh(v) for v, vd in _vars.items() if 'LBL' in vd['refs']}
  
      top = xmrs.top
      if top is not None:
          prelinks.append((0, top, None, top, _vars[top]))
  
      for nid, ep in _eps.items():
          for role, val in ep[3].items():
              if role == IVARG_ROLE or val not in _vars:
                  continue
              prelinks.append((nid, ep[2], role, val, _vars[val]))
  
      for src, srclbl, role, val, vd in prelinks:
          if IVARG_ROLE in vd['refs']:
              tgtnids = [n for n in vd['refs'][IVARG_ROLE]
                         if not _eps[n].is_quantifier()]
              if len(tgtnids) == 0:
                  continue  # maybe some bad MRS with a lonely quantifier
              tgt = tgtnids[0]  # what do we do if len > 1?
              tgtlbl = _eps[tgt][2]
              post = EQ_POST if srclbl == tgtlbl else NEQ_POST
          elif val in _hcons:
              lbl = _hcons[val][2]
              if lbl not in lblheads or len(lblheads[lbl]) == 0:
                  continue  # broken MRS; log this?
              tgt = lblheads[lbl][0]  # sorted list; first item is most "heady"
              post = H_POST
          elif 'LBL' in vd['refs']:
              if val not in lblheads or len(lblheads[val]) == 0:
                  continue  # broken MRS; log this?
              tgt = lblheads[val][0]  # again, should be sorted already
              post = HEQ_POST
          else:
              continue  # CARGs, maybe?
          links.append(Link(src, tgt, role, post))
  
      # now EQ links unattested by arg links
      for lbl, heads in lblheads.items():
          # I'm pretty sure this does what we want
          if len(heads) > 1:
              first = heads[0]
              for other in heads[1:]:
                  links.append(Link(other, first, BARE_EQ_ROLE, EQ_POST))
          # If not, something like this is more explicit
          # lblset = self.labelset(lbl)
          # sg = g.subgraph(lblset)
          # ns = [nid for nid, deg in sg.degree(lblset).items() if deg == 0]
          # head = self.labelset_head(lbl)
          # for n in ns:
          #     links.append(Link(head, n, post=EQ_POST))
      def _int(x):
          try:
              return int(x)
          except ValueError:
              return 0
      return sorted(
          links,
          key=lambda link: (_int(link.start), _int(link.end), link.rargname)
      )