def METHOD_NAME(blocks, analysis):
    """The worklist algorithm for iterating a data flow analysis to a
    fixed point.
    """
    preds, succs = cfg.edges(blocks)
    # Switch between directions.
    if analysis.forward:
        first_block = list(blocks.keys())[0]  # Entry.
        in_edges = preds
        out_edges = succs
    else:
        first_block = list(blocks.keys())[-1]  # Exit.
        in_edges = succs
        out_edges = preds
    # Initialize.
    in_ = {first_block: analysis.init}
    out = {node: analysis.init for node in blocks}
    # Iterate.
    worklist = list(blocks.keys())
    while worklist:
        node = worklist.pop(0)
        inval = analysis.merge(out[n] for n in in_edges[node])
        in_[node] = inval
        outval = analysis.transfer(blocks[node], inval)
        if outval != out[node]:
            out[node] = outval
            worklist += out_edges[node]
    if analysis.forward:
        return in_, out
    else:
        return out, in_