Append all nodes from a strongly connected component to a list of ordered nodes and ensure the topological
        order.

        :param networkx.DiGraph graph: The graph where all nodes belong to.
        :param list ordered_nodes:     Ordered nodes.
        :param iterable scc:           A set of nodes that forms a strongly connected component in the graph.
        :return:                       None

def _append_scc(graph, ordered_nodes, scc):
        """
        Append all nodes from a strongly connected component to a list of ordered nodes and ensure the topological
        order.

        :param networkx.DiGraph graph: The graph where all nodes belong to.
        :param list ordered_nodes:     Ordered nodes.
        :param iterable scc:           A set of nodes that forms a strongly connected component in the graph.
        :return:                       None
        """

        # find the first node in the strongly connected component that is the successor to any node in ordered_nodes
        loop_head = None
        for parent_node in reversed(ordered_nodes):
            for n in scc:
                if n in graph[parent_node]:
                    loop_head = n
                    break

            if loop_head is not None:
                break

        if loop_head is None:
            # randomly pick one
            loop_head = next(iter(scc))

        subgraph = graph.subgraph(scc).copy()  # type: networkx.DiGraph
        for src, _ in list(subgraph.in_edges(loop_head)):
            subgraph.remove_edge(src, loop_head)

        ordered_nodes.extend(CFGUtils.quasi_topological_sort_nodes(subgraph))