// File: /workspace/github_cpp_makefile_star2_O2/GAStudyGroup[P]GPX2/src/cross/gpx/sources/GPX2Support.cpp
// Function: GPX2Support::removeGhosts(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::removeGhosts(GPX2Structs::NodeMap& graph)
{
    for (auto it = graph.begin();it!=graph.end();) {
        auto index = (*it).first.find(GPX2Structs::ghostToken);
        if (index != string::npos) {
            // gets the id of the node without the ghost token
            string id = (*it).first;
            id.erase(index, GPX2Structs::ghostToken.size());

            //Gets two nodes that are connected to the original node, and also to the ghost, iterating through the edges of the original node
            vector<Node::node> edges = graph[id]->getEdges();
            unsigned edgeToDelete{ 0 };
            Node::node prev, next;
            for (unsigned i = 0; i < edges.size(); i++) {
                //If it found the edge that is connected to the ghost...
                if (!edges[i].first.compare((*it).first)) {
                    edgeToDelete = i;
                } else {
                    prev = edges[i];
                }
            }
            graph[id]->deleteEdge(edgeToDelete);

            edges = graph[(*it).first]->getEdges();

            for (unsigned i = 0; i < edges.size(); i++) {
                //Find the nodes that aren't the original in the edge list 
                if (!(!edges[i].first.compare(id))) {
                    next = edges[i];
                    break;
                }
            }

            //Connect the original node to the next
            graph[id]->addEdge(next);

            //arrange the next node edges
            edges = graph[next.first]->getEdges();
            for (unsigned i = 0; i < edges.size(); i++) {
                //Found the edge that references the ghost
                if (!edges[i].first.compare((*it).first)) {
                    edgeToDelete = i;
                    break;
                }
            }
            graph[next.first]->deleteEdge(edgeToDelete);
            graph[next.first]->addEdge(make_pair(id, next.second));

            //removes the ghost node
            delete graph[(*it).first];
            it = graph.erase(it);
        }else{
            it++;
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq %rdi, %r15
movq 0x18(%rdi), %r14
leaq 0x8(%rdi), %rax
movq %rax, 0x50(%rsp)
leaq 0xd8(%rsp), %r12
pushq $0x28
popq %rbx
movq %rdi, 0x20(%rsp)
cmpq 0x50(%rsp), %r14
je 0x253d1
leaq 0x20(%r14), %r13
movq %r13, %rdi
leaq 0x18be9(%rip), %rsi     # 0x3dcf0
xorl %edx, %edx
callq 0x56d0
movq %r14, %rdi
cmpq $-0x1, %rax
je 0x252f9
movq %rax, %r14
movq %rdi, 0x58(%rsp)
movq %r12, %rdi
movq %r13, %rsi
callq 0x54a0
movq 0x18bc3(%rip), %rdx     # 0x3dcf8
movq %r12, %rdi
movq %r14, %rsi
callq 0x50b0
movq %r15, %rdi
movq %r12, %rsi
callq 0x20910
movq (%rax), %rdi
callq 0x21c02
leaq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0x20a64
leaq 0x70(%rsp), %rax
movq %rax, 0x60(%rsp)
andq $0x0, 0x68(%rsp)
xorl %r14d, %r14d
movb %r14b, 0x70(%rsp)
andq $0x0, 0x80(%rsp)
leaq 0x38(%rsp), %rax
movq %rax, 0x28(%rsp)
andq $0x0, 0x30(%rsp)
movb %r14b, 0x38(%rsp)
andq $0x0, 0x48(%rsp)
xorl %ebp, %ebp
movl %ebp, %ecx
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rax
subq %rdi, %rax
cqto
idivq %rbx
cmpq %rcx, %rax
jbe 0x251e8
imulq $0x28, %rcx, %r15
addq %r15, %rdi
movq %r13, %rsi
callq 0x5040
movl %ebp, %ecx
testl %eax, %eax
je 0x251e1
addq 0x8(%rsp), %r15
leaq 0x60(%rsp), %rdi
movq %r15, %rsi
callq 0x21fce
movl %r14d, %ecx
incl %ebp
movl %ecx, %r14d
jmp 0x2519e
movq 0x20(%rsp), %r15
movq %r15, %rdi
movq %r12, %rsi
callq 0x20910
movq (%rax), %rdi
movl %r14d, %esi
callq 0x21c2c
movq %r15, %rdi
movq %r13, %rsi
callq 0x20910
movq (%rax), %rdi
callq 0x21c02
leaq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0x21de2
xorl %ebp, %ebp
movl %ebp, %ebp
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rax
subq %rdi, %rax
cqto
idivq %rbx
cmpq %rbp, %rax
jbe 0x25265
imulq $0x28, %rbp, %r15
addq %r15, %rdi
movq %r12, %rsi
callq 0x5040
incl %ebp
testl %eax, %eax
je 0x25225
addq 0x8(%rsp), %r15
leaq 0x28(%rsp), %rdi
movq %r15, %rsi
callq 0x21fce
movq 0x20(%rsp), %rbp
movq %rbp, %rdi
movq %r12, %rsi
callq 0x20910
movq (%rax), %r15
leaq 0xb0(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x209fc
movq %r15, %rdi
leaq 0xb0(%rsp), %r15
movq %r15, %rsi
callq 0x21c22
movq %r15, %rdi
callq 0x56f8
movq %rbp, %rdi
leaq 0x28(%rsp), %rsi
callq 0x20910
movq (%rax), %rdi
callq 0x21c02
leaq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0x21de2
xorl %ebp, %ebp
movl %ebp, %ecx
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rax
subq %rdi, %rax
cqto
idivq %rbx
cmpq %rcx, %rax
jbe 0x25309
imulq $0x28, %rcx, %rax
addq %rax, %rdi
movq %r13, %rsi
callq 0x5040
testl %eax, %eax
je 0x25306
incl %ebp
jmp 0x252c9
callq 0x52a0
movq %rax, %r14
jmp 0x250ee
movl %ebp, %r14d
movq 0x20(%rsp), %r15
movq %r15, %rdi
leaq 0x28(%rsp), %rsi
callq 0x20910
movq (%rax), %rdi
movl %r14d, %esi
callq 0x21c2c
movq %r15, %rdi
leaq 0x28(%rsp), %rsi
callq 0x20910
movq (%rax), %r14
leaq 0x88(%rsp), %rdi
movq %r12, %rsi
callq 0x54a0
movsd 0x48(%rsp), %xmm0
movsd %xmm0, 0xa8(%rsp)
movq %r14, %rdi
leaq 0x88(%rsp), %r14
movq %r14, %rsi
callq 0x21c22
movq %r14, %rdi
callq 0x56f8
movq %r15, %rdi
movq %r13, %rsi
callq 0x20910
movq (%rax), %r14
testq %r14, %r14
je 0x2538b
movq %r14, %rdi
callq 0x20a4e
movq %r14, %rdi
pushq $0x40
popq %rsi
callq 0x5390
movq %r15, %rdi
movq 0x58(%rsp), %rsi
callq 0x26650
movq %rax, %r14
leaq 0x28(%rsp), %rdi
callq 0x56f8
leaq 0x60(%rsp), %rdi
callq 0x56f8
leaq 0x8(%rsp), %rdi
callq 0x20abe
movq %r12, %rdi
callq 0x56f8
jmp 0x250ee
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x25413
jmp 0x25413
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
jmp 0x253ff
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
callq 0x56f8
jmp 0x25416
jmp 0x25408
movq %rax, %rbx
jmp 0x25434
jmp 0x25413
jmp 0x25413
jmp 0x25413
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x56f8
leaq 0x60(%rsp), %rdi
callq 0x56f8
leaq 0x8(%rsp), %rdi
callq 0x20abe
leaq 0xd8(%rsp), %rdi
callq 0x56f8
movq %rbx, %rdi
callq 0x5610