// File: /workspace/github_cpp_makefile_star2_O2/GAStudyGroup[P]GPX2/src/cross/gpx/sources/GPX2Support.cpp
// Function: GPX2Support::totalDistance(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*>>>&)
int GPX2Support::totalDistance(GPX2Structs::NodeMap& graph) 
{ // Distancia total para percorrer o grafo
    deque<string> nextToVisit;
    vector<string> isAlreadyVisited;
    int totalDistance{ 0 };
    bool notAlreadyVisited{ false };
    bool notToVisit{ false };

    Node *city = graph.begin()->second, *last = nullptr; // Reduzir chamadas (Node dentro do map)
    isAlreadyVisited.push_back(graph.begin()->first);

    nextToVisit.push_back(city->getEdges()[0].first);
    totalDistance += city->getEdges()[0].second;

    while (!nextToVisit.empty()) {
        isAlreadyVisited.push_back(nextToVisit.front());
        city = graph[nextToVisit.front()];
        nextToVisit.pop_front();

        for (Node::node n : city->getEdges()) {

            notAlreadyVisited = find(isAlreadyVisited.begin(), isAlreadyVisited.end(), n.first) == isAlreadyVisited.end();
            notToVisit = find(nextToVisit.begin(), nextToVisit.end(), n.first) == nextToVisit.end();

            if (notAlreadyVisited && notToVisit) {
                nextToVisit.push_back(n.first);
                totalDistance += n.second;
            }
        }
        last = city;
    }
    for (Node::node n : last->getEdges()) {
        if (n.first.compare(graph.begin()->first) == 0) {
            totalDistance += n.second;
        }
    }
    return totalDistance;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %rdi, %rbx
leaq 0x28(%rsp), %rdi
callq 0x25e64
xorpd %xmm0, %xmm0
leaq 0x10(%rsp), %rdi
andq $0x0, 0x10(%rdi)
movapd %xmm0, (%rdi)
movq %rbx, 0x8(%rsp)
movq 0x18(%rbx), %rsi
movq 0x40(%rsi), %rbx
addq $0x20, %rsi
callq 0x14efa
movq %rbx, %rdi
callq 0x21c02
movq (%rax), %rsi
leaq 0x28(%rsp), %rdi
callq 0x25ce4
movq %rbx, %rdi
callq 0x21c02
movq (%rax), %rax
xorpd %xmm0, %xmm0
addsd 0x20(%rax), %xmm0
cvttsd2si %xmm0, %ebp
movq $0x0, (%rsp)
leaq 0x78(%rsp), %r12
movq 0x38(%rsp), %rsi
cmpq %rsi, 0x58(%rsp)
je 0x25653
leaq 0x10(%rsp), %rdi
callq 0x14efa
movq 0x38(%rsp), %rsi
movq 0x8(%rsp), %rdi
callq 0x20910
movq (%rax), %rbx
leaq 0x28(%rsp), %rdi
callq 0x25dba
movq %rbx, (%rsp)
movq %rbx, %rdi
callq 0x21c02
movq (%rax), %r15
movq 0x8(%rax), %r14
cmpq %r14, %r15
je 0x25547
movq %r12, %rdi
movq %r15, %rsi
callq 0x209fc
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq %r12, %rdx
callq 0x1abd1
movq %rax, %r13
movq 0x18(%rsp), %rbx
movupd 0x38(%rsp), %xmm0
movups 0x48(%rsp), %xmm1
movups 0x58(%rsp), %xmm2
movups 0x68(%rsp), %xmm3
movapd %xmm0, 0xc0(%rsp)
movaps %xmm1, 0xd0(%rsp)
movaps %xmm2, 0xa0(%rsp)
movaps %xmm3, 0xb0(%rsp)
leaq 0xe8(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
leaq 0xa0(%rsp), %rdx
movq %r12, %rcx
callq 0x25d2c
cmpq %rbx, %r13
jne 0x25642
movq 0x58(%rsp), %rax
cmpq %rax, 0xe8(%rsp)
jne 0x25642
leaq 0x28(%rsp), %rdi
movq %r12, %rsi
callq 0x25ce4
cvtsi2sd %ebp, %xmm0
addsd 0x98(%rsp), %xmm0
cvttsd2si %xmm0, %ebp
movq %r12, %rdi
callq 0x56f8
addq $0x28, %r15
jmp 0x25590
movq (%rsp), %rdi
callq 0x21c02
movq (%rax), %rbx
movq 0x8(%rax), %r15
leaq 0x78(%rsp), %r14
cmpq %r15, %rbx
je 0x256b1
movq %r14, %rdi
movq %rbx, %rsi
callq 0x209fc
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rsi
addq $0x20, %rsi
movq %r14, %rdi
callq 0x5040
testl %eax, %eax
cvtsi2sd %ebp, %xmm0
addsd 0x98(%rsp), %xmm0
cvttsd2si %xmm0, %eax
cmovel %eax, %ebp
movq %r14, %rdi
callq 0x56f8
addq $0x28, %rbx
jmp 0x25668
leaq 0x10(%rsp), %rdi
callq 0x709c
leaq 0x28(%rsp), %rdi
callq 0x25d6e
movl %ebp, %eax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x256e9
jmp 0x256e9
jmp 0x256e9
jmp 0x256e9
jmp 0x256f0
jmp 0x256e9
jmp 0x256e9
jmp 0x256f0
movq %rax, %rbx
jmp 0x256fd
jmp 0x256f0
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x56f8
leaq 0x10(%rsp), %rdi
callq 0x709c
leaq 0x28(%rsp), %rdi
callq 0x25d6e
movq %rbx, %rdi
callq 0x5610