def calculate_immediate_dominators(nodes, _dom, _sdom):
    """ Determine immediate dominators from dominators and strict dominators.
    """

    _idom = {}

    for node in nodes:
        if _sdom[node]:
            for x in _sdom[node]:
                if _dom[x] == _sdom[node]:
                    # This must be the only definition of idom:
                    assert node not in _idom
                    _idom[node] = x
    return _idom