// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x208, %rsp            # imm = 0x208
movq %rsi, 0x40(%rsp)
xorps %xmm0, %xmm0
leaq 0x70(%rsp), %rbx
movaps %xmm0, (%rbx)
andq $0x0, 0x10(%rbx)
movaps %xmm0, 0x20(%rsp)
andq $0x0, 0x30(%rsp)
movq 0x18(%rdi), %r15
movq %rdi, (%rsp)
leaq 0x8(%rdi), %rax
movq %rax, 0x10(%rsp)
leaq 0x48(%rsp), %r14
leaq 0x170(%rsp), %r13
cmpq 0x10(%rsp), %r15
je 0x1d394
movq 0x28(%r15), %rdi
callq 0x223ae
movq %r15, 0x18(%rsp)
leaq 0x20(%r15), %rbp
movq (%rax), %r15
movq 0x8(%rax), %r12
cmpq %r12, %r15
je 0x1d385
movq %r14, %rdi
movq %r15, %rsi
callq 0x54a0
movq %r13, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x1db02
movq %rbx, %rdi
movq %r13, %rsi
callq 0x1ed76
movq %r13, %rdi
callq 0x56f8
movq %r14, %rdi
callq 0x56f8
addq $0x20, %r15
jmp 0x1d346
movq 0x18(%rsp), %rdi
callq 0x52a0
movq %rax, %r15
jmp 0x1d326
movq 0x70(%rsp), %r12
movq 0x78(%rsp), %rax
movq %rax, 0x18(%rsp)
movl $0x0, 0x10(%rsp)
leaq 0x48(%rsp), %rbp
cmpq 0x18(%rsp), %r12
je 0x1d66f
movq %rbp, %rdi
movq %r12, %rsi
callq 0x1d96e
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq %rbp, %rdx
callq 0x1abd1
cmpq 0x28(%rsp), %rax
jne 0x1d65e
leaq 0x20(%rsp), %rdi
movq %rbp, %rsi
callq 0x14efa
leaq 0x1b8(%rsp), %r15
movq %r15, %rdi
movq %rbp, %rsi
callq 0x54a0
leaq 0xb0(%rsp), %rdi
movq %r15, %rsi
movq (%rsp), %rdx
movq 0x40(%rsp), %rcx
callq 0x2379e
movq %r15, %rdi
callq 0x56f8
movq 0xc0(%rsp), %rsi
addq $-0x20, %rsi
leaq 0x150(%rsp), %rdi
callq 0x54a0
leaq 0x1d8(%rsp), %rbx
movq %rbx, %rdi
movq (%rsp), %rsi
callq 0x1db20
leaq 0x150(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x23d18
movl %eax, %r13d
movq %rbx, %rdi
callq 0x1dd56
movq %r15, %rdi
callq 0x56f8
movq (%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x1d860
movq (%rax), %rdi
callq 0x223d0
movq %rax, %r15
leaq 0xf0(%rsp), %rdi
movq %rbp, %rsi
callq 0x54a0
movq 0xc0(%rsp), %rsi
addq $-0x20, %rsi
leaq 0x130(%rsp), %rbx
movq %rbx, %rdi
callq 0x54a0
leaq 0x170(%rsp), %r14
movq %r14, %rdi
movl %r13d, %esi
leaq 0xf0(%rsp), %rdx
movq %rbx, %rcx
callq 0x1d98c
movq %r15, %rdi
movq %r14, %rsi
callq 0x1ef7a
movq %r14, %rdi
callq 0x1d846
leaq 0x130(%rsp), %rdi
callq 0x56f8
leaq 0xf0(%rsp), %rdi
callq 0x56f8
movq (%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x1d860
movq (%rax), %rdi
callq 0x223d0
movq 0x8(%rax), %rax
movl -0x48(%rax), %eax
movl %eax, 0xc(%rsp)
movq (%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x1d860
movq (%rax), %rdi
callq 0x223d0
movq 0x8(%rax), %rsi
addq $-0x20, %rsi
leaq 0x90(%rsp), %rdi
callq 0x54a0
cmpl $-0x1, 0xc(%rsp)
je 0x1d609
movq (%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x1d860
movq (%rax), %rdi
callq 0x223d0
movq %rax, %rbx
movl 0x68(%rsp), %r15d
leaq 0xd0(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x54a0
leaq 0x110(%rsp), %r13
movq %r13, %rdi
movq %rbp, %rsi
callq 0x54a0
leaq 0x170(%rsp), %r14
movq %r14, %rdi
movl %r15d, %esi
leaq 0xd0(%rsp), %rdx
movq %r13, %rcx
callq 0x1d98c
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1ef7a
movq %r14, %rdi
callq 0x1d846
leaq 0x110(%rsp), %rdi
callq 0x56f8
leaq 0xd0(%rsp), %rdi
callq 0x56f8
movb $0x1, %al
movl %eax, 0x10(%rsp)
leaq 0x20(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x14efa
jmp 0x1d644
movq (%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x1d860
movq (%rax), %rdi
callq 0x223d0
movq %rax, %r15
movq (%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x1d860
movq (%rax), %rdi
callq 0x223d0
movq 0x8(%rax), %rsi
movq %r15, %rdi
callq 0x1d8ae
leaq 0x90(%rsp), %rdi
callq 0x56f8
leaq 0xb8(%rsp), %rdi
callq 0x709c
movq %rbp, %rdi
callq 0x56f8
addq $0x28, %r12
jmp 0x1d3b0
leaq 0x20(%rsp), %rdi
callq 0x709c
leaq 0x70(%rsp), %rdi
callq 0x1d9d0
movl 0x10(%rsp), %eax
andb $0x1, %al
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x170(%rsp), %rdi
callq 0x1d846
jmp 0x1d6b0
movq %rax, %rbx
leaq 0x110(%rsp), %rdi
callq 0x56f8
jmp 0x1d6c2
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
callq 0x56f8
jmp 0x1d743
jmp 0x1d740
movq %rax, %rbx
leaq 0x1b8(%rsp), %rdi
jmp 0x1d781
movq %rax, %rbx
jmp 0x1d732
jmp 0x1d771
jmp 0x1d75a
movq %rax, %rbx
leaq 0x1d8(%rsp), %rdi
callq 0x1dd56
jmp 0x1d718
jmp 0x1d771
movq %rax, %rbx
leaq 0x170(%rsp), %rdi
callq 0x1d846
jmp 0x1d725
movq %rax, %rbx
leaq 0x150(%rsp), %rdi
jmp 0x1d74b
movq %rax, %rbx
leaq 0x130(%rsp), %rdi
callq 0x56f8
leaq 0xf0(%rsp), %rdi
jmp 0x1d74b
jmp 0x1d740
jmp 0x1d75a
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x56f8
jmp 0x1d75d
jmp 0x1d76c
jmp 0x1d771
jmp 0x1d76c
jmp 0x1d75a
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
callq 0x709c
jmp 0x1d786
movq %rax, %rbx
jmp 0x1d790
movq %rax, %rbx
jmp 0x1d786
movq %rax, %rbx
leaq 0x170(%rsp), %rdi
callq 0x56f8
leaq 0x48(%rsp), %rdi
callq 0x56f8
leaq 0x20(%rsp), %rdi
callq 0x709c
leaq 0x70(%rsp), %rdi
callq 0x1d9d0
movq %rbx, %rdi
callq 0x5610