// File: /workspace/github_cpp_makefile_star2_O2/grame-cncm[P]digraph/./dglib/digraphop.hh
// Function: digraph<digraph<char, std::pair<std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, int>>>, int>>, std::pair<std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, int>>>, int>> partitionGraph<char, std::pair<std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, int>>>, int>>(digraph<char, std::pair<std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, int>>>, int>> const&, std::set<std::set<char, std::less<char>, std::allocator<char>>, std::less<std::set<char, std::less<char>, std::allocator<char>>>, std::allocator<std::set<char, std::less<char>, std::allocator<char>>>> const&)
inline digraph<digraph<N, A>, A> partitionGraph(const digraph<N, A>& g, const std::set<std::set<N>>& partition)
{
    std::map<N, digraph<N, A>> M;   // std::mapping between nodes and supernodes
    digraph<digraph<N, A>, A>  sg;  // the resulting supergraph

    // build the graph of supernodes

    // For each std::set s of the partition, create the corresponding graph sn
    // create also a std::mapping in order to retrieve the supernode a node
    /// belongs to.
    for (const auto& s : partition) {
        digraph<N, A> sn;                     // the supernode graph
        for (const N& n : s) {                // for each node of a cycle
            M.insert(std::make_pair(n, sn));  // remember its supernode
            sn.add(n);                        // and add it to the super node
        }
        sg.add(sn);  // and add the super node to the super graph
    }

    // compute the connections between the supernodes
    for (const auto& n1 : g.nodes()) {
        digraph<N, A> sn1(M[n1]);
        for (const auto& c : g.connections(n1)) {
            digraph<N, A> sn2(M[c.first]);
            if (sn1 == sn2) {
                // the connection is inside the same supernode
                sn1.add(n1, c.first, c.second);
            } else {
                // the connection is between supernodes
                sg.add(sn1, sn2, c.second);  // exploit the fact that add will keep the mini
            }
        }
    }

    return sg;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdx, %rbx
movq %rsi, 0x28(%rsp)
leaq 0x60(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
movq %rdi, (%rsp)
callq 0x9206
movq 0x18(%rbx), %r14
addq $0x8, %rbx
leaq 0x18(%rsp), %r15
leaq 0x30(%rsp), %r12
leaq 0x58(%rsp), %r13
movq %rbx, 0x8(%rsp)
cmpq %rbx, %r14
je 0x9096
movq %r15, %rdi
callq 0x25fa
movq 0x38(%r14), %rbx
movq %r14, 0x10(%rsp)
addq $0x28, %r14
cmpq %r14, %rbx
je 0x904f
leaq 0x20(%rbx), %rbp
movq %r12, %rdi
movq %rbp, %rsi
movq %r15, %rdx
callq 0x9704
movq %r13, %rdi
movq %r12, %rsi
callq 0x9534
leaq 0x40(%rsp), %rdi
callq 0x2efc
movsbl (%rbp), %esi
movq 0x18(%rsp), %rdi
callq 0x34b6
movq %rbx, %rdi
callq 0x2170
movq %rax, %rbx
jmp 0x9008
leaq 0x48(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x9c28
movq (%rsp), %rdi
movq %rbx, %rsi
callq 0x9232
leaq 0x50(%rsp), %rdi
callq 0x2efc
leaq 0x20(%rsp), %rdi
callq 0x2efc
movq 0x10(%rsp), %rdi
callq 0x2170
movq %rax, %r14
movq 0x8(%rsp), %rbx
jmp 0x8fea
movq 0x28(%rsp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rbx
addq $0x8, %rax
movq %rax, 0x8(%rsp)
leaq 0x58(%rsp), %rbp
leaq 0x18(%rsp), %r14
cmpq 0x8(%rsp), %rbx
je 0x9179
leaq 0x20(%rbx), %r13
movq %rbp, %rdi
movq %r13, %rsi
callq 0x9284
movq %rbx, 0x10(%rsp)
leaq 0x30(%rsp), %rdi
movq %rax, %rsi
callq 0x9c28
movq 0x28(%rsp), %rdi
movq %r13, %rsi
callq 0x439c
movq %rax, %rbx
movq 0x18(%rax), %r15
addq $0x8, %rbx
cmpq %rbx, %r15
je 0x915d
leaq 0x20(%r15), %r12
movq %rbp, %rdi
movq %r12, %rsi
callq 0x9284
movq %r14, %rdi
movq %rax, %rsi
callq 0x9c28
movq 0x30(%rsp), %rdi
leaq 0x28(%r15), %rcx
cmpq 0x18(%rsp), %rdi
je 0x913b
movq (%rsp), %rdi
leaq 0x30(%rsp), %rsi
movq %r14, %rdx
callq 0x92d2
jmp 0x9146
movq %r13, %rsi
movq %r12, %rdx
callq 0x340c
leaq 0x20(%rsp), %rdi
callq 0x2efc
movq %r15, %rdi
callq 0x2170
movq %rax, %r15
jmp 0x90f9
leaq 0x38(%rsp), %rdi
callq 0x2efc
movq 0x10(%rsp), %rdi
callq 0x2170
movq %rax, %rbx
jmp 0x90b5
leaq 0x58(%rsp), %rdi
callq 0xa32e
movq (%rsp), %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r15
jmp 0x91f3
jmp 0x91ac
jmp 0x91b1
movq %rax, %r15
leaq 0x50(%rsp), %rdi
jmp 0x91d2
movq %rax, %r15
jmp 0x91e6
movq %rax, %r15
jmp 0x91c3
movq %rax, %r15
leaq 0x20(%rsp), %rdi
callq 0x2efc
leaq 0x38(%rsp), %rdi
jmp 0x91e1
movq %rax, %r15
leaq 0x40(%rsp), %rdi
callq 0x2efc
jmp 0x91dc
movq %rax, %r15
leaq 0x20(%rsp), %rdi
callq 0x2efc
movq (%rsp), %rdi
addq $0x8, %rdi
callq 0x2efc
leaq 0x58(%rsp), %rdi
callq 0xa32e
movq %r15, %rdi
callq 0x2220
nop