from typing import Optional
from typing import Tuple


def resolve_bit_slice_indices(bit_count: int, start: Optional[int],
                              limit: Optional[int]) -> Tuple[int, int]:
  """Returns (start, width), resolving indices via DSLX bit slice semantics."""

  assert isinstance(bit_count, int), bit_count
  assert bit_count >= 0, bit_count
  if start is None:
    start = 0
  if limit is None:
    limit = bit_count
  if start < 0:
    start += bit_count
  if limit < 0:
    limit += bit_count
  limit = min(max(limit, 0), bit_count)
  start = min(max(start, 0), bit_count, limit)
  assert start >= 0
  assert limit >= start, (start, limit)
  return (start, limit - start)