// File: /workspace/github_cpp_makefile_star2_O1/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 $0x118, %rsp            # imm = 0x118
movq %rdi, %rbx
xorpd %xmm0, %xmm0
leaq 0x60(%rsp), %rdi
movapd %xmm0, 0x40(%rdi)
movapd %xmm0, 0x30(%rdi)
movapd %xmm0, 0x20(%rdi)
movapd %xmm0, 0x10(%rdi)
movapd %xmm0, (%rdi)
xorl %esi, %esi
callq 0x2f88c
leaq 0x40(%rsp), %rdi
xorpd %xmm0, %xmm0
movapd %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movq %rbx, 0x38(%rsp)
movq 0x18(%rbx), %rsi
movq 0x40(%rsi), %rbx
addq $0x20, %rsi
callq 0x1a992
movq %rbx, %rdi
callq 0x29d64
movq (%rax), %rsi
leaq 0x60(%rsp), %rdi
callq 0x2f798
movq %rbx, %rdi
callq 0x29d64
movq (%rax), %rax
xorpd %xmm0, %xmm0
addsd 0x20(%rax), %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0xc(%rsp)
leaq 0x60(%rsp), %rax
movq 0x10(%rax), %rsi
leaq 0x20(%rsp), %rbp
leaq 0x10(%rsp), %r12
leaq 0x40(%rsp), %rdi
callq 0x1a992
movq 0x70(%rsp), %rsi
movq 0x38(%rsp), %rdi
callq 0x28bca
movq (%rax), %rbx
leaq 0x60(%rsp), %rdi
callq 0x2f850
movq %rbx, 0x58(%rsp)
movq %rbx, %rdi
callq 0x29d64
movq (%rax), %r13
movq 0x8(%rax), %r15
cmpq %r15, %r13
je 0x2eb6a
movq %rbp, 0x10(%rsp)
movq (%r13), %rsi
movq 0x8(%r13), %rdx
addq %rsi, %rdx
movq %r12, %rdi
callq 0x82cc
movsd 0x20(%r13), %xmm0
movsd %xmm0, 0x30(%rsp)
movq 0x40(%rsp), %rdi
movq 0x48(%rsp), %rsi
movq %r12, %rdx
callq 0x218f9
movq %rax, %rbx
movq 0x48(%rsp), %r14
movapd 0x70(%rsp), %xmm0
movaps 0x80(%rsp), %xmm1
movaps 0x90(%rsp), %xmm2
movaps 0xa0(%rsp), %xmm3
movapd %xmm0, 0xd0(%rsp)
movaps %xmm1, 0xe0(%rsp)
movaps %xmm2, 0xb0(%rsp)
movaps %xmm3, 0xc0(%rsp)
leaq 0xf8(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
leaq 0xb0(%rsp), %rdx
movq %r12, %rcx
callq 0x2fe74
cmpq %r14, %rbx
jne 0x2eb4a
movq 0x90(%rsp), %rax
cmpq %rax, 0xf8(%rsp)
jne 0x2eb4a
leaq 0x60(%rsp), %rdi
movq %r12, %rsi
callq 0x2f798
xorps %xmm0, %xmm0
cvtsi2sdl 0xc(%rsp), %xmm0
addsd 0x30(%rsp), %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0xc(%rsp)
movq 0x10(%rsp), %rdi
cmpq %rbp, %rdi
je 0x2eb61
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x53c0
addq $0x28, %r13
jmp 0x2ea69
movq 0x70(%rsp), %rsi
cmpq %rsi, 0x90(%rsp)
jne 0x2ea2f
movq 0x58(%rsp), %rdi
callq 0x29d64
movq (%rax), %r12
movq 0x8(%rax), %r13
cmpq %r13, %r12
je 0x2ec1a
leaq 0x10(%rsp), %rbx
movq %rbp, 0x10(%rsp)
movq (%r12), %rsi
movq 0x8(%r12), %rdx
addq %rsi, %rdx
movq %rbx, %rdi
callq 0x82cc
movsd 0x20(%r12), %xmm0
movsd %xmm0, 0x30(%rsp)
movq 0x38(%rsp), %rax
movq 0x18(%rax), %rsi
addq $0x20, %rsi
movq %rbx, %rdi
callq 0x5050
testl %eax, %eax
movl 0xc(%rsp), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
addsd 0x30(%rsp), %xmm0
cvttsd2si %xmm0, %r15d
cmovnel %eax, %r15d
movq 0x10(%rsp), %rdi
cmpq %rbp, %rdi
je 0x2ec0a
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x53c0
addq $0x28, %r12
movl %r15d, 0xc(%rsp)
cmpq %r13, %r12
jne 0x2eb9c
jmp 0x2ec1f
movl 0xc(%rsp), %r15d
leaq 0x40(%rsp), %rdi
callq 0x81e0
leaq 0x60(%rsp), %rdi
callq 0x2f806
movl %r15d, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2ec58
jmp 0x2ec58
jmp 0x2ec58
jmp 0x2ec58
jmp 0x2ec5f
jmp 0x2ec58
jmp 0x2ec58
jmp 0x2ec5f
movq %rax, %rbx
jmp 0x2ec79
jmp 0x2ec5f
movq %rax, %rbx
movq 0x10(%rsp), %rdi
cmpq %rbp, %rdi
je 0x2ec79
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x53c0
leaq 0x40(%rsp), %rdi
callq 0x81e0
leaq 0x60(%rsp), %rdi
callq 0x2f806
movq %rbx, %rdi
callq 0x5670