// File: GAStudyGroup[P]GPX2/src/cross/gpx/sources/GPX2Support.cpp
// Function: GPX2Support::cleanInsideAccess(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*>>>&)
void GPX2Support::cleanInsideAccess(GPX2Structs::PartitionMap &partitions, GPX2Structs::NodeMap &unitedGraph)
{//Removes de Acess flags from the vertices that connects the partition to itself

    //Goes through the partition
    for (auto& p : partitions) {
        //accessNodesAV - already visited
        vector<string> testedAccessNodes,accessNodesAV;

        vector<string> accessNodes = p.second->getAccessNodes();

        for (string node : accessNodes) {
            //If the node doenst have been visited already
            if(find(accessNodesAV.begin(),accessNodesAV.end(),node)==accessNodesAV.end()){
                //check if node is connected to another partition
                pair<GPX2Structs::SearchResult, vector<string>> result = DFS_outside(node, partitions, unitedGraph);

                if (result.first == GPX2Structs::SearchResult::CONNECTED_TO_PARTITION) {
                    testedAccessNodes.push_back(node);
                    accessNodesAV.push_back(node);
                } else {
                    //put the distance value in the edges of the nodes that are inserted in the partition 
                    for(string node : result.second){
                        for(auto &edge : unitedGraph[node]->getEdges()){
                            edge.second = distance(node, edge.first);
                        }
                    }

                    accessNodesAV.push_back(result.second.front());
                    accessNodesAV.push_back(result.second.back());

                    result.second.erase(result.second.begin());
                    result.second.erase(result.second.end());
                    
                    

                    p.second->getNodes().insert(p.second->getNodes().end(),result.second.begin(), result.second.end());
                }
            }
        }
        p.second->setAccessNodes(testedAccessNodes);
    }
}

// Assembly:
subq $0x288, %rsp            # imm = 0x288
movq %rdi, 0x280(%rsp)
movq %rsi, 0x278(%rsp)
movq 0x280(%rsp), %rax
movq %rax, 0x270(%rsp)
movq 0x270(%rsp), %rdi
callq 0x54cc0
movq %rax, 0x268(%rsp)
movq 0x270(%rsp), %rdi
callq 0x54d10
movq %rax, 0x260(%rsp)
leaq 0x268(%rsp), %rdi
leaq 0x260(%rsp), %rsi
callq 0x54cf0
testb $0x1, %al
jne 0x6b73f
jmp 0x6be4a
leaq 0x268(%rsp), %rdi
callq 0x54d40
movq %rax, 0x258(%rsp)
leaq 0x240(%rsp), %rdi
callq 0x1e3e0
leaq 0x228(%rsp), %rdi
callq 0x1e3e0
movq 0x258(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x67e80
movq %rax, 0x70(%rsp)
jmp 0x6b786
movq 0x70(%rsp), %rsi
leaq 0x210(%rsp), %rdi
callq 0x305f0
jmp 0x6b79a
leaq 0x210(%rsp), %rax
movq %rax, 0x1f8(%rsp)
movq 0x1f8(%rsp), %rdi
callq 0x1e310
movq %rax, 0x1f0(%rsp)
movq 0x1f8(%rsp), %rdi
callq 0x1e340
movq %rax, 0x1e8(%rsp)
leaq 0x1f0(%rsp), %rdi
leaq 0x1e8(%rsp), %rsi
callq 0x1e370
testb $0x1, %al
jne 0x6b7f2
jmp 0x6bdcd
leaq 0x1f0(%rsp), %rdi
callq 0x1e3b0
movq %rax, %rsi
leaq 0x1c8(%rsp), %rdi
callq 0x6200
jmp 0x6b811
leaq 0x228(%rsp), %rdi
movq %rdi, 0x60(%rsp)
callq 0x1e310
movq 0x60(%rsp), %rdi
movq %rax, 0x1b8(%rsp)
callq 0x1e340
movq %rax, 0x1b0(%rsp)
movq 0x1b8(%rsp), %rdi
movq 0x1b0(%rsp), %rsi
leaq 0x1c8(%rsp), %rdx
callq 0x49c90
movq %rax, 0x68(%rsp)
jmp 0x6b861
movq 0x68(%rsp), %rax
movq %rax, 0x1c0(%rsp)
leaq 0x228(%rsp), %rdi
callq 0x1e340
movq %rax, 0x1a8(%rsp)
leaq 0x1c0(%rsp), %rdi
leaq 0x1a8(%rsp), %rsi
callq 0x55c20
testb $0x1, %al
jne 0x6b8a1
jmp 0x6bd9f
leaq 0x168(%rsp), %rdi
leaq 0x1c8(%rsp), %rsi
callq 0x6200
jmp 0x6b8b8
movq 0x280(%rsp), %rdx
movq 0x278(%rsp), %rcx
leaq 0x188(%rsp), %rdi
leaq 0x168(%rsp), %rsi
callq 0x6be60
jmp 0x6b8df
leaq 0x168(%rsp), %rdi
callq 0x6988
cmpl $0x0, 0x188(%rsp)
jne 0x6b9b7
leaq 0x240(%rsp), %rdi
leaq 0x1c8(%rsp), %rsi
callq 0x37210
jmp 0x6b911
leaq 0x228(%rsp), %rdi
leaq 0x1c8(%rsp), %rsi
callq 0x37210
jmp 0x6b928
jmp 0x6bd81
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x208(%rsp)
movl %eax, 0x204(%rsp)
jmp 0x6be2e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x208(%rsp)
movl %eax, 0x204(%rsp)
jmp 0x6be21
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x208(%rsp)
movl %eax, 0x204(%rsp)
jmp 0x6bdbe
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x208(%rsp)
movl %eax, 0x204(%rsp)
leaq 0x168(%rsp), %rdi
callq 0x6988
jmp 0x6bdbe
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x208(%rsp)
movl %eax, 0x204(%rsp)
jmp 0x6bd90
leaq 0x188(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x160(%rsp)
movq 0x160(%rsp), %rdi
callq 0x1e310
movq %rax, 0x158(%rsp)
movq 0x160(%rsp), %rdi
callq 0x1e340
movq %rax, 0x150(%rsp)
leaq 0x158(%rsp), %rdi
leaq 0x150(%rsp), %rsi
callq 0x1e370
testb $0x1, %al
jne 0x6ba13
jmp 0x6bbe3
leaq 0x158(%rsp), %rdi
callq 0x1e3b0
movq %rax, %rsi
leaq 0x130(%rsp), %rdi
callq 0x6200
jmp 0x6ba32
movq 0x278(%rsp), %rdi
leaq 0x130(%rsp), %rsi
callq 0x60c60
movq %rax, 0x58(%rsp)
jmp 0x6ba4e
movq 0x58(%rsp), %rax
movq (%rax), %rdi
callq 0x661c0
movq %rax, 0x50(%rsp)
jmp 0x6ba62
movq 0x50(%rsp), %rax
movq %rax, 0x128(%rsp)
movq 0x128(%rsp), %rdi
callq 0x60f80
movq %rax, 0x120(%rsp)
movq 0x128(%rsp), %rdi
callq 0x60fb0
movq %rax, 0x118(%rsp)
leaq 0x120(%rsp), %rdi
leaq 0x118(%rsp), %rsi
callq 0x60fe0
testb $0x1, %al
jne 0x6bab7
jmp 0x6bbb2
leaq 0x120(%rsp), %rdi
callq 0x61020
movq %rax, 0x110(%rsp)
leaq 0xf0(%rsp), %rdi
leaq 0x130(%rsp), %rsi
callq 0x6200
jmp 0x6bae3
movq 0x110(%rsp), %rsi
leaq 0xd0(%rsp), %rdi
callq 0x6200
jmp 0x6bafa
leaq 0xf0(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
callq 0x1b4c0
movl %eax, 0x4c(%rsp)
jmp 0x6bb15
movl 0x4c(%rsp), %eax
cvtsi2sd %eax, %xmm0
movq 0x110(%rsp), %rax
movsd %xmm0, 0x20(%rax)
leaq 0xd0(%rsp), %rdi
callq 0x6988
leaq 0xf0(%rsp), %rdi
callq 0x6988
leaq 0x120(%rsp), %rdi
callq 0x610c0
jmp 0x6ba99
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x208(%rsp)
movl %eax, 0x204(%rsp)
jmp 0x6bbd1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x208(%rsp)
movl %eax, 0x204(%rsp)
jmp 0x6bba3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x208(%rsp)
movl %eax, 0x204(%rsp)
leaq 0xd0(%rsp), %rdi
callq 0x6988
leaq 0xf0(%rsp), %rdi
callq 0x6988
jmp 0x6bbd1
leaq 0x130(%rsp), %rdi
callq 0x6988
leaq 0x158(%rsp), %rdi
callq 0x1e3c0
jmp 0x6b9f5
leaq 0x130(%rsp), %rdi
callq 0x6988
jmp 0x6bd90
leaq 0x190(%rsp), %rdi
callq 0x61140
movq %rax, %rsi
leaq 0x228(%rsp), %rdi
callq 0x37210
jmp 0x6bc02
leaq 0x190(%rsp), %rdi
callq 0x47710
movq %rax, %rsi
leaq 0x228(%rsp), %rdi
callq 0x37210
jmp 0x6bc21
leaq 0x190(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0x1e310
movq %rax, 0xc0(%rsp)
leaq 0xc8(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x555d0
movq 0x38(%rsp), %rdi
movq 0xc8(%rsp), %rsi
callq 0x55560
movq %rax, 0x40(%rsp)
jmp 0x6bc69
movq 0x40(%rsp), %rax
movq %rax, 0xb8(%rsp)
leaq 0x190(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x1e340
movq %rax, 0xa8(%rsp)
leaq 0xb0(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x555d0
movq 0x28(%rsp), %rdi
movq 0xb0(%rsp), %rsi
callq 0x55560
movq %rax, 0x30(%rsp)
jmp 0x6bcbe
movq 0x30(%rsp), %rax
movq %rax, 0xa0(%rsp)
movq 0x258(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x67e70
movq %rax, 0x20(%rsp)
jmp 0x6bce3
movq 0x258(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x67e70
movq %rax, 0x18(%rsp)
jmp 0x6bcfb
movq 0x18(%rsp), %rdi
callq 0x1e340
movq %rax, 0x90(%rsp)
leaq 0x98(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x555d0
leaq 0x190(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x1e310
movq 0x8(%rsp), %rdi
movq %rax, 0x88(%rsp)
callq 0x1e340
movq 0x20(%rsp), %rdi
movq %rax, 0x80(%rsp)
movq 0x98(%rsp), %rsi
movq 0x88(%rsp), %rdx
movq 0x80(%rsp), %rcx
callq 0x55610
movq %rax, 0x10(%rsp)
jmp 0x6bd77
movq 0x10(%rsp), %rax
movq %rax, 0x78(%rsp)
leaq 0x188(%rsp), %rdi
callq 0x556d0
jmp 0x6bd9f
leaq 0x188(%rsp), %rdi
callq 0x556d0
jmp 0x6bdbe
leaq 0x1c8(%rsp), %rdi
callq 0x6988
leaq 0x1f0(%rsp), %rdi
callq 0x1e3c0
jmp 0x6b7d4
leaq 0x1c8(%rsp), %rdi
callq 0x6988
jmp 0x6be21
movq 0x258(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x240(%rsp), %rsi
callq 0x67f40
jmp 0x6bde8
leaq 0x210(%rsp), %rdi
callq 0xa2c0
leaq 0x228(%rsp), %rdi
callq 0xa2c0
leaq 0x240(%rsp), %rdi
callq 0xa2c0
leaq 0x268(%rsp), %rdi
callq 0x552a0
jmp 0x6b721
leaq 0x210(%rsp), %rdi
callq 0xa2c0
leaq 0x228(%rsp), %rdi
callq 0xa2c0
leaq 0x240(%rsp), %rdi
callq 0xa2c0
jmp 0x6be52
addq $0x288, %rsp            # imm = 0x288
retq
movq 0x208(%rsp), %rdi
callq 0x6850
nop