// File: /workspace/github_cpp_makefile_star2_O2/GAStudyGroup[P]GPX2/src/cross/gpx/sources/GPX2.cpp
// Function: GPX2::createGhosts()
void GPX2::createGhosts()
{
    set<string> ghosts;
    vector<string> ghostsToAdd;

    // The SET container does not allow repeated values inside himself
    for (auto& city : red) {
        string idKey = city.first;
        for (unsigned i = 0; i < 2; i++) {
            ghosts.insert(city.second->getEdges()[i].first);
            ghosts.insert(blue[idKey]->getEdges()[i].first);
        }
        if (ghosts.size() == 4) { // node with degree 4
            //mark the node to transform in ghost node
            ghostsToAdd.push_back(idKey);
        }
        ghosts.clear();
    }

    for(string id : ghostsToAdd){
        //the ghost id is created adding a token to the normal ID
        string ghostID = id+GPX2Structs::ghostToken;

        Node* ghostNode = new Node(ghostID);
        GPX2Support::insertGhost(id, red, ghostNode);

        ghostNode = new Node(ghostID);
        GPX2Support::insertGhost(id, blue, ghostNode); 
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %rdi, %rbx
leaq 0x50(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
movq %rsp, %rax
andq $0x0, 0x10(%rax)
xorps %xmm0, %xmm0
movaps %xmm0, (%rax)
leaq 0xd8(%rdi), %rax
movq %rax, 0x18(%rsp)
movq 0xf0(%rdi), %r14
leaq 0xe0(%rdi), %rbp
addq $0x108, %rbx            # imm = 0x108
leaq 0x28(%rsp), %r12
leaq 0x48(%rsp), %r13
cmpq %rbp, %r14
je 0x1f5aa
leaq 0x20(%r14), %rsi
movq %r12, %rdi
callq 0x54a0
xorl %r15d, %r15d
cmpq $0x50, %r15
je 0x1f577
movq 0x40(%r14), %rdi
callq 0x21c02
movq (%rax), %rsi
addq %r15, %rsi
movq %r13, %rdi
callq 0x1acbc
movq %rbx, %rdi
movq %r12, %rsi
callq 0x20910
movq (%rax), %rdi
callq 0x21c02
movq (%rax), %rsi
addq %r15, %rsi
movq %r13, %rdi
callq 0x1acbc
addq $0x28, %r15
jmp 0x1f533
cmpq $0x4, 0x70(%rsp)
jne 0x1f58a
movq %rsp, %rdi
movq %r12, %rsi
callq 0x14efa
movq %r13, %rdi
callq 0x211ac
movq %r12, %rdi
callq 0x56f8
movq %r14, %rdi
callq 0x52a0
movq %rax, %r14
jmp 0x1f51b
movq (%rsp), %r15
movq 0x8(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0x28(%rsp), %r12
leaq 0xb8(%rsp), %rbp
cmpq 0x20(%rsp), %r15
je 0x1f683
movq %r12, %rdi
movq %r15, %rsi
callq 0x54a0
movq %rbp, %rdi
movq %r12, %rsi
leaq 0x1e6e0(%rip), %rdx     # 0x3dcc8
callq 0x9173
pushq $0x40
popq %rdi
callq 0x5380
movq %rax, %r14
leaq 0x98(%rsp), %r13
movq %r13, %rdi
movq %rbp, %rsi
callq 0x54a0
movq %r14, %rdi
movq %r13, %rsi
callq 0x21bdc
movq %r13, %rdi
callq 0x56f8
movq %r12, %rdi
movq 0x18(%rsp), %rsi
movq %r14, %rdx
callq 0x242fb
pushq $0x40
popq %rdi
callq 0x5380
movq %rax, %r14
leaq 0x78(%rsp), %r13
movq %r13, %rdi
movq %rbp, %rsi
callq 0x54a0
movq %r14, %rdi
movq %r13, %rsi
callq 0x21bdc
movq %r13, %rdi
callq 0x56f8
movq %r12, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x242fb
movq %rbp, %rdi
callq 0x56f8
movq %r12, %rdi
callq 0x56f8
addq $0x20, %r15
jmp 0x1f5c5
movq %rsp, %rdi
callq 0x709c
leaq 0x48(%rsp), %rdi
callq 0x1a934
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1f6f2
jmp 0x1f6db
jmp 0x1f6f2
jmp 0x1f6bc
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
jmp 0x1f6c9
movq %rax, %rbx
jmp 0x1f6ce
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x56f8
pushq $0x40
popq %rsi
movq %r14, %rdi
callq 0x5390
jmp 0x1f6e3
movq %rax, %rbx
jmp 0x1f6ff
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
callq 0x56f8
jmp 0x1f6f5
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x56f8
movq %rsp, %rdi
callq 0x709c
leaq 0x48(%rsp), %rdi
callq 0x1a934
movq %rbx, %rdi
callq 0x5610
nop