// File: 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:
subq $0x1c8, %rsp            # imm = 0x1C8
movq %rdi, 0x1c0(%rsp)
movq 0x1c0(%rsp), %rax
movq %rax, 0x50(%rsp)
leaq 0x190(%rsp), %rdi
callq 0x49c40
leaq 0x178(%rsp), %rdi
callq 0x1e3e0
movq 0x50(%rsp), %rax
addq $0xd8, %rax
movq %rax, 0x170(%rsp)
movq 0x170(%rsp), %rdi
callq 0x60ba0
movq %rax, 0x168(%rsp)
movq 0x170(%rsp), %rdi
callq 0x60bd0
movq %rax, 0x160(%rsp)
leaq 0x168(%rsp), %rdi
leaq 0x160(%rsp), %rsi
callq 0x60c00
testb $0x1, %al
jne 0x5e381
jmp 0x5e54b
leaq 0x168(%rsp), %rdi
callq 0x60c20
movq %rax, 0x158(%rsp)
movq 0x158(%rsp), %rsi
leaq 0x138(%rsp), %rdi
callq 0x6200
jmp 0x5e3ad
movl $0x0, 0x128(%rsp)
cmpl $0x2, 0x128(%rsp)
jae 0x5e4f3
movq 0x158(%rsp), %rax
movq 0x20(%rax), %rdi
callq 0x661c0
movq %rax, 0x48(%rsp)
jmp 0x5e3de
movq 0x48(%rsp), %rdi
movl 0x128(%rsp), %eax
movl %eax, %esi
callq 0x60c40
movq %rax, %rsi
leaq 0x190(%rsp), %rdi
callq 0x49cf0
movb %dl, 0x3f(%rsp)
movq %rax, 0x40(%rsp)
jmp 0x5e40c
movq 0x50(%rsp), %rdi
movb 0x3f(%rsp), %al
movq 0x40(%rsp), %rcx
movq %rcx, 0x118(%rsp)
movb %al, 0x120(%rsp)
addq $0x108, %rdi            # imm = 0x108
leaq 0x138(%rsp), %rsi
callq 0x60c60
movq %rax, 0x30(%rsp)
jmp 0x5e444
movq 0x30(%rsp), %rax
movq (%rax), %rdi
callq 0x661c0
movq %rax, 0x28(%rsp)
jmp 0x5e458
movq 0x28(%rsp), %rdi
movl 0x128(%rsp), %eax
movl %eax, %esi
callq 0x60c40
movq %rax, %rsi
leaq 0x190(%rsp), %rdi
callq 0x49cf0
movb %dl, 0x1f(%rsp)
movq %rax, 0x20(%rsp)
jmp 0x5e486
movb 0x1f(%rsp), %al
movq 0x20(%rsp), %rcx
movq %rcx, 0x108(%rsp)
movb %al, 0x110(%rsp)
movl 0x128(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x128(%rsp)
jmp 0x5e3b8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x130(%rsp)
movl %eax, 0x12c(%rsp)
jmp 0x5e821
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x130(%rsp)
movl %eax, 0x12c(%rsp)
leaq 0x138(%rsp), %rdi
callq 0x6988
jmp 0x5e821
leaq 0x190(%rsp), %rdi
callq 0x60d50
cmpq $0x4, %rax
jne 0x5e51f
leaq 0x178(%rsp), %rdi
leaq 0x138(%rsp), %rsi
callq 0x37210
jmp 0x5e51d
jmp 0x5e51f
leaq 0x190(%rsp), %rdi
callq 0x60d60
leaq 0x138(%rsp), %rdi
callq 0x6988
leaq 0x168(%rsp), %rdi
callq 0x60d70
jmp 0x5e363
leaq 0x178(%rsp), %rax
movq %rax, 0x100(%rsp)
movq 0x100(%rsp), %rdi
callq 0x1e310
movq %rax, 0xf8(%rsp)
movq 0x100(%rsp), %rdi
callq 0x1e340
movq %rax, 0xf0(%rsp)
leaq 0xf8(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
callq 0x1e370
testb $0x1, %al
jne 0x5e5a3
jmp 0x5e7ff
leaq 0xf8(%rsp), %rdi
callq 0x1e3b0
movq %rax, %rsi
leaq 0xd0(%rsp), %rdi
callq 0x6200
jmp 0x5e5c2
leaq 0x3f83f(%rip), %rdx     # 0x9de08
leaq 0xb0(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
callq 0xfa90
jmp 0x5e5e0
movl $0x40, %edi
callq 0x64b0
movq %rax, 0x10(%rsp)
jmp 0x5e5f1
movb $0x1, 0x87(%rsp)
leaq 0x88(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x6200
jmp 0x5e610
movq 0x10(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x66160
jmp 0x5e624
movb $0x0, 0x87(%rsp)
leaq 0x88(%rsp), %rdi
callq 0x6988
movq 0x10(%rsp), %rax
movq 0x50(%rsp), %rsi
movq %rax, 0xa8(%rsp)
addq $0xd8, %rsi
movq 0xa8(%rsp), %rdx
leaq 0xd0(%rsp), %rdi
callq 0x6d420
jmp 0x5e669
movl $0x40, %edi
callq 0x64b0
movq %rax, 0x8(%rsp)
jmp 0x5e67a
movb $0x1, 0x5f(%rsp)
leaq 0x60(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x6200
jmp 0x5e693
movq 0x8(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x66160
jmp 0x5e6a4
movq 0x8(%rsp), %rax
movb $0x0, 0x5f(%rsp)
movq %rax, 0xa8(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x6988
movq 0x50(%rsp), %rsi
addq $0x108, %rsi            # imm = 0x108
movq 0xa8(%rsp), %rdx
leaq 0xd0(%rsp), %rdi
callq 0x6d420
jmp 0x5e6e3
leaq 0xb0(%rsp), %rdi
callq 0x6988
leaq 0xd0(%rsp), %rdi
callq 0x6988
leaq 0xf8(%rsp), %rdi
callq 0x1e3c0
jmp 0x5e585
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x130(%rsp)
movl %eax, 0x12c(%rsp)
jmp 0x5e7f0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x130(%rsp)
movl %eax, 0x12c(%rsp)
jmp 0x5e7e3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x130(%rsp)
movl %eax, 0x12c(%rsp)
jmp 0x5e778
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x130(%rsp)
movl %eax, 0x12c(%rsp)
leaq 0x88(%rsp), %rdi
callq 0x6988
testb $0x1, 0x87(%rsp)
jne 0x5e784
jmp 0x5e793
movq 0x10(%rsp), %rdi
movl $0x40, %esi
callq 0x64c0
jmp 0x5e7e3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x130(%rsp)
movl %eax, 0x12c(%rsp)
jmp 0x5e7c9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x130(%rsp)
movl %eax, 0x12c(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x6988
testb $0x1, 0x5f(%rsp)
jne 0x5e7d2
jmp 0x5e7e1
movq 0x8(%rsp), %rdi
movl $0x40, %esi
callq 0x64c0
jmp 0x5e7e3
leaq 0xb0(%rsp), %rdi
callq 0x6988
leaq 0xd0(%rsp), %rdi
callq 0x6988
jmp 0x5e821
leaq 0x178(%rsp), %rdi
callq 0xa2c0
leaq 0x190(%rsp), %rdi
callq 0x49e20
addq $0x1c8, %rsp            # imm = 0x1C8
retq
leaq 0x178(%rsp), %rdi
callq 0xa2c0
leaq 0x190(%rsp), %rdi
callq 0x49e20
movq 0x130(%rsp), %rdi
callq 0x6850
nopl (%rax,%rax)