def METHOD_NAME(layout):
    backend = layout.backend
    if layout.is_unknown:
        return METHOD_NAME(ak.contents.NumpyArray(backend.nplike.asarray([])))
    elif layout.is_indexed:
        return METHOD_NAME(layout.project())
    elif layout.is_union:
        if not any(
            x.is_option and not isinstance(x, ak.contents.UnmaskedArray)
            for x in layout.contents
        ):
            return layout
        tags = backend.index_nplike.asarray(layout.tags)
        index = backend.index_nplike.asarray(
            backend.nplike.asarray(layout.index), copy=True
        )
        bigmask = backend.index_nplike.empty(len(index), dtype=np.bool_)
        for tag, content in enumerate(layout.contents):
            if content.is_option and not isinstance(
                content, ak.contents.UnmaskedArray
            ):
                bigmask[:] = False
                bigmask[tags == tag] = backend.index_nplike.asarray(
                    content.mask_as_bool(valid_when=False)
                ).view(np.bool_)
                index[bigmask] = -1
        good = index >= 0
        return ak.contents.UnionArray(
            ak.index.Index8(tags[good]),
            ak.index.Index64(index[good]),
            layout.contents,
        )
    elif layout.is_option:
        return layout.project()
    else:
        return layout