def extents_to_chunks_with_clones(ids_and_extents: Sequence[Tuple[(InodeID, Extent)]]) -> Iterable[Tuple[(InodeID, Sequence[Chunk])]]:
    "\n    Converts the nested, history-preserving `Extent` structures into flat\n    sequences of `Chunk`s, while being careful to annotate cloned parts as\n    described in this file's docblock.  The `InodeID`s are needed to ensure\n    that the `Chunk`s' `Clone` objects refer to the appropriate files.\n    "
    id_to_leaf_idx_to_chunk_clones = _id_to_leaf_idx_to_chunk_clones(ids_and_extents)
    for (ino_id, extent) in ids_and_extents:
        leaf_to_chunk_clones = id_to_leaf_idx_to_chunk_clones.get(ino_id, {})
        new_chunks = []
        for (leaf_idx, (offset, length, extent)) in enumerate(extent.gen_trimmed_leaves()):
            chunk_clones = leaf_to_chunk_clones.get(leaf_idx, [])
            assert isinstance(extent.content, Extent.Kind)
            if (new_chunks and (new_chunks[(- 1)].kind == extent.content)):
                prev_length = new_chunks[(- 1)].length
                prev_clones = new_chunks[(- 1)].chunk_clones
            else:
                prev_length = 0
                prev_clones = set()
                new_chunks.append(None)
            new_chunks[(- 1)] = Chunk(kind=extent.content, length=(length + prev_length), chunk_clones=prev_clones)
            new_chunks[(- 1)].chunk_clones.update((ChunkClone(clone=clone, offset=((clone_offset + prev_length) - offset)) for (clone_offset, clone) in chunk_clones))
        (yield (ino_id, tuple((Chunk(kind=c.kind, length=c.length, chunk_clones=frozenset(c.chunk_clones)) for c in new_chunks))))
Converts the nested, history-preserving `Extent` structures into flat
sequences of `Chunk`s, while being careful to annotate cloned parts as
described in this file's docblock.  The `InodeID`s are needed to ensure
that the `Chunk`s' `Clone` objects refer to the appropriate files.
def extents_to_chunks_with_clones(ids_and_extents: Sequence[Tuple[(InodeID, Extent)]]) -> Iterable[Tuple[(InodeID, Sequence[Chunk])]]:
    "\n    Converts the nested, history-preserving `Extent` structures into flat\n    sequences of `Chunk`s, while being careful to annotate cloned parts as\n    described in this file's docblock.  The `InodeID`s are needed to ensure\n    that the `Chunk`s' `Clone` objects refer to the appropriate files.\n    "
    id_to_leaf_idx_to_chunk_clones = _id_to_leaf_idx_to_chunk_clones(ids_and_extents)
    for (ino_id, extent) in ids_and_extents:
        leaf_to_chunk_clones = id_to_leaf_idx_to_chunk_clones.get(ino_id, {})
        new_chunks = []
        for (leaf_idx, (offset, length, extent)) in enumerate(extent.gen_trimmed_leaves()):
            chunk_clones = leaf_to_chunk_clones.get(leaf_idx, [])
            assert isinstance(extent.content, Extent.Kind)
            if (new_chunks and (new_chunks[(- 1)].kind == extent.content)):
                prev_length = new_chunks[(- 1)].length
                prev_clones = new_chunks[(- 1)].chunk_clones
            else:
                prev_length = 0
                prev_clones = set()
                new_chunks.append(None)
            new_chunks[(- 1)] = Chunk(kind=extent.content, length=(length + prev_length), chunk_clones=prev_clones)
            new_chunks[(- 1)].chunk_clones.update((ChunkClone(clone=clone, offset=((clone_offset + prev_length) - offset)) for (clone_offset, clone) in chunk_clones))
        (yield (ino_id, tuple((Chunk(kind=c.kind, length=c.length, chunk_clones=frozenset(c.chunk_clones)) for c in new_chunks))))