import typing


def NodeAttributesToBasicBlock(
  node_attributes: typing.Dict[str, str]
) -> typing.Dict[str, str]:
  """Get the basic block graph node attributes from a dot graph node.

  Args:
    node_attributes: The dictionary of dot graph information.

  Returns:
    A dictionary of node attributes.
  """
  label = node_attributes.get("label", "")
  if not label.startswith('"{'):
    raise ValueError(f"Unhandled label: '{label}'")
  # Lines are separated using '\l' in the dot label.
  lines = label.split("\l")
  return {
    # The name is in the first line.
    "name": lines[0][len('"{') :].split(":")[0],
    # All other lines except the last are either blank or contain instructions.
    "text": "\n".join(x.lstrip() for x in lines[1:-1] if x.lstrip()),
  }