// File: grame-cncm[P]digraph/./dglib/digraphop.hh
// Function: digraph<char, int> subgraph<char, int>(digraph<char, int> const&, std::set<char, std::less<char>, std::allocator<char>> const&)
digraph<N, A> subgraph(const digraph<N, A>& G, const std::set<N>& S)
{
    digraph<N, A> R;     // the (R)esulting graph
    std::set<N>   W{S};  // nodes (W)aiting to be processed
    std::set<N>   P;     // nodes already (P)rocessed
    while (!W.empty()) {
        std::set<N> M;  // (M)ore nodes to process at next iteration
        for (auto n : W) {
            R.add(n);     // add n to the resulting graph
            P.insert(n);  // mark n as processed
            for (const auto& a : G.connections(n)) {
                R.add(n, a.first, a.second);       // add its adjacent nodes
                if (P.find(a.first) == P.end()) {  // is it new ?
                    M.insert(a.first);             // we will have to process it
                }
            }
        }
        W = M;
    }
    return R;
}

// Assembly:
subq $0x178, %rsp            # imm = 0x178
movq %rdi, 0x38(%rsp)
movq %rdi, %rax
movq %rax, 0x40(%rsp)
movq %rdi, 0x170(%rsp)
movq %rsi, 0x168(%rsp)
movq %rdx, 0x160(%rsp)
movb $0x0, 0x15f(%rsp)
callq 0x24270
movq 0x160(%rsp), %rsi
leaq 0x128(%rsp), %rdi
callq 0xe770
jmp 0x265a0
leaq 0xe8(%rsp), %rdi
callq 0x5200
leaq 0x128(%rsp), %rdi
callq 0x37e10
xorb $-0x1, %al
testb $0x1, %al
jne 0x265c5
jmp 0x26845
leaq 0xb8(%rsp), %rdi
callq 0x5200
leaq 0x128(%rsp), %rax
movq %rax, 0xb0(%rsp)
movq 0xb0(%rsp), %rdi
callq 0xa150
movq %rax, 0xa8(%rsp)
movq 0xb0(%rsp), %rdi
callq 0xa180
movq %rax, 0xa0(%rsp)
leaq 0xa8(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0xa1b0
testb $0x1, %al
jne 0x2662a
jmp 0x2681c
leaq 0xa8(%rsp), %rdi
callq 0xa1d0
movq 0x38(%rsp), %rdi
movb (%rax), %al
movb %al, 0x9f(%rsp)
movsbl 0x9f(%rsp), %esi
callq 0x2d4d0
jmp 0x26654
leaq 0xe8(%rsp), %rdi
leaq 0x9f(%rsp), %rsi
callq 0x6840
movb %dl, 0x2f(%rsp)
movq %rax, 0x30(%rsp)
jmp 0x26674
movb 0x2f(%rsp), %al
movq 0x30(%rsp), %rcx
movq %rcx, 0x88(%rsp)
movb %al, 0x90(%rsp)
movq 0x168(%rsp), %rdi
leaq 0x9f(%rsp), %rsi
callq 0x2ada0
movq %rax, 0x20(%rsp)
jmp 0x266a8
movq 0x20(%rsp), %rax
movq %rax, 0x80(%rsp)
movq 0x80(%rsp), %rdi
callq 0x2add0
movq %rax, 0x78(%rsp)
movq 0x80(%rsp), %rdi
callq 0x2ae00
movq %rax, 0x70(%rsp)
leaq 0x78(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x2ae30
testb $0x1, %al
jne 0x266f1
jmp 0x26808
leaq 0x78(%rsp), %rdi
callq 0x2ae50
movq 0x38(%rsp), %rdi
movq %rax, 0x68(%rsp)
movq 0x68(%rsp), %rdx
movq %rdx, %rcx
addq $0x4, %rcx
leaq 0x9f(%rsp), %rsi
callq 0x242b0
jmp 0x26720
movq 0x68(%rsp), %rsi
leaq 0xe8(%rsp), %rdi
callq 0x37e30
movq %rax, 0x18(%rsp)
jmp 0x26739
movq 0x18(%rsp), %rax
movq %rax, 0x60(%rsp)
leaq 0xe8(%rsp), %rdi
callq 0xa180
movq %rax, 0x58(%rsp)
leaq 0x60(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0xe460
testb $0x1, %al
jne 0x2676d
jmp 0x267f7
movq 0x68(%rsp), %rsi
leaq 0xb8(%rsp), %rdi
callq 0x6840
movb %dl, 0xf(%rsp)
movq %rax, 0x10(%rsp)
jmp 0x2678a
movb 0xf(%rsp), %al
movq 0x10(%rsp), %rcx
movq %rcx, 0x48(%rsp)
movb %al, 0x50(%rsp)
jmp 0x267f7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x120(%rsp)
movl %eax, 0x11c(%rsp)
jmp 0x26888
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x120(%rsp)
movl %eax, 0x11c(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0x5620
leaq 0xe8(%rsp), %rdi
callq 0x5620
leaq 0x128(%rsp), %rdi
callq 0x5620
jmp 0x26888
jmp 0x267f9
leaq 0x78(%rsp), %rdi
callq 0x2ae70
jmp 0x266d9
jmp 0x2680a
leaq 0xa8(%rsp), %rdi
callq 0xa350
jmp 0x2660c
leaq 0x128(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
callq 0x37e70
jmp 0x26833
leaq 0xb8(%rsp), %rdi
callq 0x5620
jmp 0x265ad
movb $0x1, 0x15f(%rsp)
leaq 0xe8(%rsp), %rdi
callq 0x5620
leaq 0x128(%rsp), %rdi
callq 0x5620
testb $0x1, 0x15f(%rsp)
jne 0x2687b
movq 0x38(%rsp), %rdi
callq 0x24610
movq 0x40(%rsp), %rax
addq $0x178, %rsp            # imm = 0x178
retq
movq 0x38(%rsp), %rdi
callq 0x24610
movq 0x120(%rsp), %rdi
callq 0x2290
nop