// File: GAStudyGroup[P]GPX2/src/cross/gpx/sources/GPX2Support.cpp
// Function: GPX2Support::partialDistance(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, 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*>>>, Partition*)
int GPX2Support::partialDistance(string entry, string exit, GPX2Structs::NodeMap father, Partition* partitionPtr)
{ // Distancia do SubTour da partição no pai
    //fazer uma busca em profundidade dentro da partição
    string now;
    vector<string> alreadyVisited;
    deque<string> nextToVisit;
    vector<string> partition = partitionPtr->getNodes();
    bool notAlreadyVisited{ false };
    bool notToVisit{ false };
    bool isInPartition{ false };

    int totalDistance{ 0 };

    nextToVisit.push_back(entry);

    while (!nextToVisit.empty()) {

        now = nextToVisit.back();
        nextToVisit.pop_back();
        alreadyVisited.push_back(now);
        vector<Node::node> edges = father[now]->getEdges();

        for (Node::node cn : edges) {

            notAlreadyVisited = (find(alreadyVisited.begin(), alreadyVisited.end(), cn.first) == alreadyVisited.end());
            notToVisit = (find(nextToVisit.begin(), nextToVisit.end(), cn.first) == nextToVisit.end());
            isInPartition = (find(partition.begin(), partition.end(), cn.first) != partition.end());

            if (notAlreadyVisited && notToVisit && isInPartition) {
                totalDistance += cn.second;
                nextToVisit.push_back(cn.first);
            }
        }
    }
    return (totalDistance);
}

// Assembly:
subq $0x268, %rsp            # imm = 0x268
movq %rdi, 0x68(%rsp)
movq %rdx, 0x70(%rsp)
movq %rdi, 0x260(%rsp)
movq %rsi, 0x258(%rsp)
movq %rdx, 0x250(%rsp)
movq %rcx, 0x248(%rsp)
leaq 0x228(%rsp), %rdi
callq 0x6690
leaq 0x210(%rsp), %rdi
callq 0x1e3e0
leaq 0x1c0(%rsp), %rdi
callq 0x70690
jmp 0x6df9a
movq 0x248(%rsp), %rdi
callq 0x67e70
movq %rax, 0x60(%rsp)
jmp 0x6dfae
movq 0x60(%rsp), %rsi
leaq 0x198(%rsp), %rdi
callq 0x305f0
jmp 0x6dfc2
movq 0x68(%rsp), %rsi
movb $0x0, 0x197(%rsp)
movb $0x0, 0x196(%rsp)
movb $0x0, 0x195(%rsp)
movl $0x0, 0x190(%rsp)
leaq 0x1c0(%rsp), %rdi
callq 0x706a0
jmp 0x6dff9
jmp 0x6dffb
leaq 0x1c0(%rsp), %rdi
callq 0x70700
xorb $-0x1, %al
testb $0x1, %al
jne 0x6e013
jmp 0x6e3db
leaq 0x1c0(%rsp), %rdi
callq 0x70720
movq %rax, %rsi
leaq 0x228(%rsp), %rdi
callq 0x6070
jmp 0x6e032
leaq 0x1c0(%rsp), %rdi
callq 0x70750
leaq 0x210(%rsp), %rdi
leaq 0x228(%rsp), %rsi
callq 0x37210
jmp 0x6e056
movq 0x70(%rsp), %rdi
leaq 0x228(%rsp), %rsi
callq 0x60c60
movq %rax, 0x58(%rsp)
jmp 0x6e06f
movq 0x58(%rsp), %rax
movq (%rax), %rdi
callq 0x661c0
movq %rax, 0x50(%rsp)
jmp 0x6e083
movq 0x50(%rsp), %rsi
leaq 0x178(%rsp), %rdi
callq 0x615a0
jmp 0x6e097
leaq 0x178(%rsp), %rax
movq %rax, 0x170(%rsp)
movq 0x170(%rsp), %rdi
callq 0x60f80
movq %rax, 0x168(%rsp)
movq 0x170(%rsp), %rdi
callq 0x60fb0
movq %rax, 0x160(%rsp)
leaq 0x168(%rsp), %rdi
leaq 0x160(%rsp), %rsi
callq 0x60fe0
testb $0x1, %al
jne 0x6e0ef
jmp 0x6e3ba
leaq 0x168(%rsp), %rdi
callq 0x61020
movq %rax, %rsi
leaq 0x138(%rsp), %rdi
callq 0x61030
jmp 0x6e10e
leaq 0x210(%rsp), %rdi
movq %rdi, 0x40(%rsp)
callq 0x1e310
movq 0x40(%rsp), %rdi
movq %rax, 0x128(%rsp)
callq 0x1e340
movq %rax, 0x120(%rsp)
movq 0x128(%rsp), %rdi
movq 0x120(%rsp), %rsi
leaq 0x138(%rsp), %rdx
callq 0x49c90
movq %rax, 0x48(%rsp)
jmp 0x6e15e
movq 0x48(%rsp), %rax
movq %rax, 0x130(%rsp)
leaq 0x210(%rsp), %rdi
callq 0x1e340
movq %rax, 0x118(%rsp)
leaq 0x130(%rsp), %rdi
leaq 0x118(%rsp), %rsi
callq 0x55c20
movb %al, 0x197(%rsp)
leaq 0xd8(%rsp), %rdi
movq %rdi, 0x30(%rsp)
leaq 0x1c0(%rsp), %rsi
movq %rsi, 0x28(%rsp)
callq 0x70860
movq 0x28(%rsp), %rsi
leaq 0xb8(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0x70890
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
leaq 0xf8(%rsp), %rdi
leaq 0x138(%rsp), %rcx
callq 0x707e0
jmp 0x6e1f3
leaq 0x98(%rsp), %rdi
movq %rdi, 0x10(%rsp)
leaq 0x1c0(%rsp), %rsi
callq 0x70890
movq 0x10(%rsp), %rsi
leaq 0xf8(%rsp), %rdi
callq 0x707c0
movb %al, 0x196(%rsp)
leaq 0x198(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x1e310
movq 0x18(%rsp), %rdi
movq %rax, 0x88(%rsp)
callq 0x1e340
movq %rax, 0x80(%rsp)
movq 0x88(%rsp), %rdi
movq 0x80(%rsp), %rsi
leaq 0x138(%rsp), %rdx
callq 0x49c90
movq %rax, 0x20(%rsp)
jmp 0x6e276
movq 0x20(%rsp), %rax
movq %rax, 0x90(%rsp)
leaq 0x198(%rsp), %rdi
callq 0x1e340
movq %rax, 0x78(%rsp)
leaq 0x90(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x1e370
andb $0x1, %al
movb %al, 0x195(%rsp)
testb $0x1, 0x197(%rsp)
je 0x6e39b
testb $0x1, 0x196(%rsp)
je 0x6e39b
testb $0x1, 0x195(%rsp)
je 0x6e39b
movsd 0x158(%rsp), %xmm1
cvtsi2sdl 0x190(%rsp), %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x190(%rsp)
leaq 0x1c0(%rsp), %rdi
leaq 0x138(%rsp), %rsi
callq 0x706a0
jmp 0x6e312
jmp 0x6e39b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b8(%rsp)
movl %eax, 0x1b4(%rsp)
jmp 0x6e440
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b8(%rsp)
movl %eax, 0x1b4(%rsp)
jmp 0x6e433
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b8(%rsp)
movl %eax, 0x1b4(%rsp)
jmp 0x6e426
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b8(%rsp)
movl %eax, 0x1b4(%rsp)
jmp 0x6e3cc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b8(%rsp)
movl %eax, 0x1b4(%rsp)
leaq 0x138(%rsp), %rdi
callq 0x610b0
jmp 0x6e3cc
leaq 0x138(%rsp), %rdi
callq 0x610b0
leaq 0x168(%rsp), %rdi
callq 0x610c0
jmp 0x6e0d1
leaq 0x178(%rsp), %rdi
callq 0x616a0
jmp 0x6dffb
leaq 0x178(%rsp), %rdi
callq 0x616a0
jmp 0x6e426
movl 0x190(%rsp), %eax
movl %eax, 0xc(%rsp)
leaq 0x198(%rsp), %rdi
callq 0xa2c0
leaq 0x1c0(%rsp), %rdi
callq 0x70900
leaq 0x210(%rsp), %rdi
callq 0xa2c0
leaq 0x228(%rsp), %rdi
callq 0x6988
movl 0xc(%rsp), %eax
addq $0x268, %rsp            # imm = 0x268
retq
leaq 0x198(%rsp), %rdi
callq 0xa2c0
leaq 0x1c0(%rsp), %rdi
callq 0x70900
leaq 0x210(%rsp), %rdi
callq 0xa2c0
leaq 0x228(%rsp), %rdi
callq 0x6988
movq 0x1b8(%rsp), %rdi
callq 0x6850
nopw (%rax,%rax)