from typing import MutableSequence


def _peel_nested_parens(input_str: str) -> MutableSequence[str]:
  """Extracts substrings from a string with nested parentheses.

  The returned sequence starts from the substring enclosed in the innermost
  parentheses and moves subsequently outwards. The contents of the inner
  substrings are removed from the outer ones. For example, given the string
  'lorem ipsum(dolor sit (consectetur adipiscing) amet)sed do eiusmod',
  this function produces the sequence
  ['consectetur adipiscing', 'dolor sit  amet', 'lorem ipsumsed do eiusmod'].

  Args:
    input_str: An input_str string consisting of zero or more nested
      parentheses.

  Returns:
    A sequence of substrings enclosed with in respective parentheses. See the
    description above for the precise detail of the output.
  """
  start = input_str.find('(')
  end = input_str.rfind(')')

  if start == -1 and end == -1:
    return [input_str]
  else:
    # Assertions to be re-raised into a meaningful error by the caller.
    assert start != -1  # '(' should be present if there is a ')'
    assert end != -1  # ')' should be present if there is a '('
    assert start < end  # '(' should come before ')'
    out = _peel_nested_parens(input_str[start + 1:end])
    out.append(input_str[:start] + input_str[end + 1:])
    return out