// File: GAStudyGroup[P]GPX2/src/cross/gpx/sources/GPX2Fusion.cpp
// Function: GPX2Fusion::unfeasiblePartitionsConnected(std::map<int, Partition*, std::less<int>, std::allocator<std::pair<int const, Partition*>>>&, std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, Node*, 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, Node*>>>&)
bool GPX2Fusion::unfeasiblePartitionsConnected(GPX2Structs::PartitionMap &partitions, GPX2Structs::NodeMap& unitedGraph)
{ // Verifica as conexões das partições unfeasible
  // And set the connectionNode in the partition
    vector<pair<string,int>> nodesToCheck;
    vector<string> nodesAlreadyChecked;
    bool atLeastOneConnected{ false };

    // Pega todos os nós que serão verificados
    for (auto& it : partitions) {
        for (string id : it.second->getAccessNodes()) {
            nodesToCheck.push_back(make_pair(id,it.first));
        }
    }

    // Percorre o vetor para verificar as conexões
    for (pair<string,int> node : nodesToCheck) {
        //não precisa verificar novamente se já foi encontrado aonde aquele nó chega
        if(find(nodesAlreadyChecked.begin(),nodesAlreadyChecked.end(),node.first)==nodesAlreadyChecked.end()){
            nodesAlreadyChecked.push_back(node.first);

            auto res = GPX2Support::DFS_outside(node.first, partitions, unitedGraph);
            
            int partitionConnected = GPX2Support::whichPartition(res.second.back(),partitions);
            
            partitions[node.second]->getConnectedTo().push_back(Partition::ConnectionNode(partitionConnected, node.first, res.second.back()));

            //utilizando o back podemos pegar a ultima conexão adicionada
            // Verifica qual partição está conectada
            int connectedPartition = partitions[node.second]->getConnectedTo().back().connectedPartition;

            // Verifica o ID do nó na qual ela está conectada
            string connectedId = partitions[node.second]->getConnectedTo().back().connectedNode;

            // Caso ele esteja conectado a outra partição unfeasible, caso não seja "-1"
            if (connectedPartition != -1) {
                atLeastOneConnected = true;

                // Insere no vetor de conexões
                partitions[connectedPartition]->getConnectedTo().push_back(Partition::ConnectionNode(node.second, connectedId, node.first));

                nodesAlreadyChecked.push_back(connectedId);
            } else {
                // Apaga por estar conectado com uma feasible
                partitions[node.second]->getConnectedTo().erase(partitions[node.second]->getConnectedTo().end());
            }
        }
    }
    return (atLeastOneConnected);
}

// Assembly:
subq $0x3c8, %rsp            # imm = 0x3C8
movq %rdi, 0x3c0(%rsp)
movq %rsi, 0x3b8(%rsp)
leaq 0x3a0(%rsp), %rdi
callq 0x55aa0
leaq 0x388(%rsp), %rdi
callq 0x1e3e0
movb $0x0, 0x387(%rsp)
movq 0x3c0(%rsp), %rax
movq %rax, 0x378(%rsp)
movq 0x378(%rsp), %rdi
callq 0x54cc0
movq %rax, 0x370(%rsp)
movq 0x378(%rsp), %rdi
callq 0x54d10
movq %rax, 0x368(%rsp)
leaq 0x370(%rsp), %rdi
leaq 0x368(%rsp), %rsi
callq 0x54cf0
testb $0x1, %al
jne 0x543e1
jmp 0x54560
leaq 0x370(%rsp), %rdi
callq 0x54d40
movq %rax, 0x360(%rsp)
movq 0x360(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x67e80
movq %rax, 0xa0(%rsp)
jmp 0x54411
movq 0xa0(%rsp), %rax
movq %rax, 0x358(%rsp)
movq 0x358(%rsp), %rdi
callq 0x1e310
movq %rax, 0x340(%rsp)
movq 0x358(%rsp), %rdi
callq 0x1e340
movq %rax, 0x338(%rsp)
leaq 0x340(%rsp), %rdi
leaq 0x338(%rsp), %rsi
callq 0x1e370
testb $0x1, %al
jne 0x54469
jmp 0x5454c
leaq 0x340(%rsp), %rdi
callq 0x1e3b0
movq %rax, %rsi
leaq 0x318(%rsp), %rdi
callq 0x6200
jmp 0x54488
movq 0x360(%rsp), %rdx
leaq 0x2f0(%rsp), %rdi
leaq 0x318(%rsp), %rsi
callq 0x55ae0
jmp 0x544a7
leaq 0x3a0(%rsp), %rdi
leaq 0x2f0(%rsp), %rsi
callq 0x55ab0
jmp 0x544be
leaq 0x2f0(%rsp), %rdi
callq 0x55b20
leaq 0x318(%rsp), %rdi
callq 0x6988
leaq 0x340(%rsp), %rdi
callq 0x1e3c0
jmp 0x5444b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x350(%rsp)
movl %eax, 0x34c(%rsp)
jmp 0x54c8a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x350(%rsp)
movl %eax, 0x34c(%rsp)
jmp 0x5453a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x350(%rsp)
movl %eax, 0x34c(%rsp)
leaq 0x2f0(%rsp), %rdi
callq 0x55b20
leaq 0x318(%rsp), %rdi
callq 0x6988
jmp 0x54c8a
jmp 0x5454e
leaq 0x370(%rsp), %rdi
callq 0x552a0
jmp 0x543c3
leaq 0x3a0(%rsp), %rax
movq %rax, 0x2e8(%rsp)
movq 0x2e8(%rsp), %rdi
callq 0x55b30
movq %rax, 0x2e0(%rsp)
movq 0x2e8(%rsp), %rdi
callq 0x55b60
movq %rax, 0x2d8(%rsp)
leaq 0x2e0(%rsp), %rdi
leaq 0x2d8(%rsp), %rsi
callq 0x55b90
testb $0x1, %al
jne 0x545b8
jmp 0x54c57
leaq 0x2e0(%rsp), %rdi
callq 0x55bd0
movq %rax, %rsi
leaq 0x2b0(%rsp), %rdi
callq 0x55be0
jmp 0x545d7
leaq 0x388(%rsp), %rdi
movq %rdi, 0x90(%rsp)
callq 0x1e310
movq 0x90(%rsp), %rdi
movq %rax, 0x2a0(%rsp)
callq 0x1e340
movq %rax, 0x298(%rsp)
movq 0x2a0(%rsp), %rdi
movq 0x298(%rsp), %rsi
leaq 0x2b0(%rsp), %rdx
callq 0x49c90
movq %rax, 0x98(%rsp)
jmp 0x54630
movq 0x98(%rsp), %rax
movq %rax, 0x2a8(%rsp)
leaq 0x388(%rsp), %rdi
callq 0x1e340
movq %rax, 0x290(%rsp)
leaq 0x2a8(%rsp), %rdi
leaq 0x290(%rsp), %rsi
callq 0x55c20
testb $0x1, %al
jne 0x54673
jmp 0x54c29
leaq 0x388(%rsp), %rdi
leaq 0x2b0(%rsp), %rsi
callq 0x37210
jmp 0x5468a
leaq 0x250(%rsp), %rdi
leaq 0x2b0(%rsp), %rsi
callq 0x6200
jmp 0x546a1
movq 0x3c0(%rsp), %rdx
movq 0x3b8(%rsp), %rcx
leaq 0x270(%rsp), %rdi
leaq 0x250(%rsp), %rsi
callq 0x6be60
jmp 0x546c8
leaq 0x250(%rsp), %rdi
callq 0x6988
leaq 0x278(%rsp), %rdi
callq 0x47710
movq %rax, %rsi
leaq 0x228(%rsp), %rdi
callq 0x6200
jmp 0x546f4
movq 0x3c0(%rsp), %rsi
leaq 0x1f8(%rsp), %rdi
callq 0x55c60
jmp 0x5470b
leaq 0x228(%rsp), %rdi
leaq 0x1f8(%rsp), %rsi
callq 0x6c7f0
movl %eax, 0x8c(%rsp)
jmp 0x54729
leaq 0x1f8(%rsp), %rdi
callq 0x55c90
leaq 0x228(%rsp), %rdi
callq 0x6988
movl 0x8c(%rsp), %eax
movl %eax, 0x24c(%rsp)
movq 0x3c0(%rsp), %rdi
leaq 0x2d0(%rsp), %rsi
callq 0x55370
movq %rax, 0x80(%rsp)
jmp 0x54770
movq 0x80(%rsp), %rax
movq (%rax), %rdi
callq 0x67ee0
movq %rax, 0x78(%rsp)
jmp 0x54787
movl 0x24c(%rsp), %eax
movl %eax, 0x74(%rsp)
leaq 0x190(%rsp), %rdi
leaq 0x2b0(%rsp), %rsi
callq 0x6200
jmp 0x547a9
leaq 0x278(%rsp), %rdi
callq 0x47710
movq %rax, %rsi
leaq 0x170(%rsp), %rdi
callq 0x6200
jmp 0x547c8
movl 0x74(%rsp), %esi
leaq 0x1b0(%rsp), %rdi
leaq 0x190(%rsp), %rdx
leaq 0x170(%rsp), %rcx
callq 0x55cd0
jmp 0x547eb
movq 0x78(%rsp), %rdi
leaq 0x1b0(%rsp), %rsi
callq 0x55ca0
jmp 0x547ff
leaq 0x1b0(%rsp), %rdi
callq 0x55110
leaq 0x170(%rsp), %rdi
callq 0x6988
leaq 0x190(%rsp), %rdi
callq 0x6988
movq 0x3c0(%rsp), %rdi
leaq 0x2d0(%rsp), %rsi
callq 0x55370
movq %rax, 0x68(%rsp)
jmp 0x54842
movq 0x68(%rsp), %rax
movq (%rax), %rdi
callq 0x67ee0
movq %rax, 0x60(%rsp)
jmp 0x54856
movq 0x60(%rsp), %rdi
callq 0x55d60
movl (%rax), %eax
movl %eax, 0x16c(%rsp)
movq 0x3c0(%rsp), %rdi
leaq 0x2d0(%rsp), %rsi
callq 0x55370
movq %rax, 0x58(%rsp)
jmp 0x54885
movq 0x58(%rsp), %rax
movq (%rax), %rdi
callq 0x67ee0
movq %rax, 0x50(%rsp)
jmp 0x54899
movq 0x50(%rsp), %rdi
callq 0x55d60
movq %rax, %rsi
addq $0x28, %rsi
leaq 0x148(%rsp), %rdi
callq 0x6200
jmp 0x548b9
cmpl $-0x1, 0x16c(%rsp)
je 0x54b44
movb $0x1, 0x387(%rsp)
movq 0x3c0(%rsp), %rdi
leaq 0x16c(%rsp), %rsi
callq 0x55370
movq %rax, 0x48(%rsp)
jmp 0x548eb
movq 0x48(%rsp), %rax
movq (%rax), %rdi
callq 0x67ee0
movq %rax, 0x40(%rsp)
jmp 0x548ff
movl 0x2d0(%rsp), %eax
movl %eax, 0x3c(%rsp)
leaq 0xe0(%rsp), %rdi
leaq 0x148(%rsp), %rsi
callq 0x6200
jmp 0x54921
leaq 0xc0(%rsp), %rdi
leaq 0x2b0(%rsp), %rsi
callq 0x6200
jmp 0x54938
movl 0x3c(%rsp), %esi
leaq 0x100(%rsp), %rdi
leaq 0xe0(%rsp), %rdx
leaq 0xc0(%rsp), %rcx
callq 0x55cd0
jmp 0x5495b
movq 0x40(%rsp), %rdi
leaq 0x100(%rsp), %rsi
callq 0x55ca0
jmp 0x5496f
leaq 0x100(%rsp), %rdi
callq 0x55110
leaq 0xc0(%rsp), %rdi
callq 0x6988
leaq 0xe0(%rsp), %rdi
callq 0x6988
leaq 0x388(%rsp), %rdi
leaq 0x148(%rsp), %rsi
callq 0x37210
jmp 0x549ad
jmp 0x54bf1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x350(%rsp)
movl %eax, 0x34c(%rsp)
jmp 0x54c48
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x350(%rsp)
movl %eax, 0x34c(%rsp)
leaq 0x250(%rsp), %rdi
callq 0x6988
jmp 0x54c48
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x350(%rsp)
movl %eax, 0x34c(%rsp)
jmp 0x54c1a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x350(%rsp)
movl %eax, 0x34c(%rsp)
jmp 0x54a41
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x350(%rsp)
movl %eax, 0x34c(%rsp)
leaq 0x1f8(%rsp), %rdi
callq 0x55c90
leaq 0x228(%rsp), %rdi
callq 0x6988
jmp 0x54c1a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x350(%rsp)
movl %eax, 0x34c(%rsp)
jmp 0x54aad
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x350(%rsp)
movl %eax, 0x34c(%rsp)
jmp 0x54aa0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x350(%rsp)
movl %eax, 0x34c(%rsp)
leaq 0x1b0(%rsp), %rdi
callq 0x55110
leaq 0x170(%rsp), %rdi
callq 0x6988
leaq 0x190(%rsp), %rdi
callq 0x6988
jmp 0x54c1a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x350(%rsp)
movl %eax, 0x34c(%rsp)
jmp 0x54c0d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x350(%rsp)
movl %eax, 0x34c(%rsp)
jmp 0x54b32
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x350(%rsp)
movl %eax, 0x34c(%rsp)
jmp 0x54b25
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x350(%rsp)
movl %eax, 0x34c(%rsp)
leaq 0x100(%rsp), %rdi
callq 0x55110
leaq 0xc0(%rsp), %rdi
callq 0x6988
leaq 0xe0(%rsp), %rdi
callq 0x6988
jmp 0x54c0d
movq 0x3c0(%rsp), %rdi
leaq 0x2d0(%rsp), %rsi
callq 0x55370
movq %rax, 0x30(%rsp)
jmp 0x54b60
movq 0x30(%rsp), %rax
movq (%rax), %rdi
callq 0x67ee0
movq %rax, 0x28(%rsp)
jmp 0x54b74
movq 0x3c0(%rsp), %rdi
leaq 0x2d0(%rsp), %rsi
callq 0x55370
movq %rax, 0x20(%rsp)
jmp 0x54b90
movq 0x20(%rsp), %rax
movq (%rax), %rdi
callq 0x67ee0
movq %rax, 0x18(%rsp)
jmp 0x54ba4
movq 0x18(%rsp), %rdi
callq 0x54ea0
movq %rax, 0xb0(%rsp)
leaq 0xb8(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x554e0
movq 0x28(%rsp), %rdi
movq 0xb8(%rsp), %rsi
callq 0x55470
movq %rax, 0x10(%rsp)
jmp 0x54be4
movq 0x10(%rsp), %rax
movq %rax, 0xa8(%rsp)
leaq 0x148(%rsp), %rdi
callq 0x6988
leaq 0x270(%rsp), %rdi
callq 0x556d0
jmp 0x54c29
leaq 0x148(%rsp), %rdi
callq 0x6988
leaq 0x270(%rsp), %rdi
callq 0x556d0
jmp 0x54c48
leaq 0x2b0(%rsp), %rdi
callq 0x55b20
leaq 0x2e0(%rsp), %rdi
callq 0x55da0
jmp 0x5459a
leaq 0x2b0(%rsp), %rdi
callq 0x55b20
jmp 0x54c8a
movb 0x387(%rsp), %al
movb %al, 0xf(%rsp)
leaq 0x388(%rsp), %rdi
callq 0xa2c0
leaq 0x3a0(%rsp), %rdi
callq 0x55dc0
movb 0xf(%rsp), %al
andb $0x1, %al
addq $0x3c8, %rsp            # imm = 0x3C8
retq
leaq 0x388(%rsp), %rdi
callq 0xa2c0
leaq 0x3a0(%rsp), %rdi
callq 0x55dc0
movq 0x350(%rsp), %rdi
callq 0x6850
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)