// File: /workspace/github_cpp_makefile_star2_O3/zkl94[P]distributed-key-value-store/MP2Node.cpp
// Function: MP2Node::stabilizationProtocol()
void MP2Node::stabilizationProtocol() {
    // for every key in the hashtable
    // 		if vector<Node> of old hashtable is different from the new vector<Node>
    // 			find out the difference (new vector<Node> - old vector<Node>)
    // 			act as coordinator and send create request to all three of the new nodes


    std::map<string, string>::iterator it = this->ht->hashTable.begin();
    std::map<string, string> difference_map;

    while(it != this->ht->hashTable.end()) {
        string key = it->first;
        string value = it->second;
        vector<Node> old_nodes = findNodes2(key, this->ring);
        vector<Node> new_nodes = findNodes2(key, this->new_ring);

        if (vector_diff(old_nodes, new_nodes)) {
            // if there is difference for this key, create new replicas
            difference_map.emplace(std::make_pair(key, value));
        }
        ++it;
    }

    this->ring = this->new_ring;

    std::map<string, string>::iterator it2 = difference_map.begin();

    while(it2 != difference_map.end()) {
        string key = it2->first;
        string value = it2->second;

        clientCreate(key, value);
        it2++;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1d8, %rsp            # imm = 0x1D8
movq %rdi, 0x20(%rsp)
movq 0x48(%rdi), %rax
movq 0x20(%rax), %r14
leaq 0x150(%rsp), %rdx
movl $0x0, (%rdx)
xorl %ecx, %ecx
movq %rcx, 0x8(%rdx)
movq %rdx, 0x10(%rdx)
movq %rdx, 0x18(%rdx)
movq %rcx, 0x20(%rdx)
addq $0x10, %rax
cmpq %rax, %r14
je 0xf267
movq 0x20(%rsp), %rcx
leaq 0x30(%rcx), %rax
movq %rax, 0xd0(%rsp)
leaq 0x70(%rcx), %rax
movq %rax, 0xc8(%rsp)
leaq 0x1a8(%rsp), %rbp
leaq 0x1c0(%rsp), %r15
leaq 0x178(%rsp), %r12
leaq 0x190(%rsp), %r13
leaq 0x10(%rsp), %rax
movq %rax, (%rsp)
movq 0x20(%r14), %rsi
movq 0x28(%r14), %rdx
addq %rsi, %rdx
movq %rsp, %rdi
callq 0x6790
leaq 0x78(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x40(%r14), %rsi
movq 0x48(%r14), %rdx
addq %rsi, %rdx
leaq 0x68(%rsp), %rdi
callq 0x6790
leaq 0x58(%rsp), %rax
movq %rax, 0x48(%rsp)
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
addq %rsi, %rdx
leaq 0x48(%rsp), %rdi
callq 0x6790
movq %rbp, %rdi
movq 0xd0(%rsp), %rsi
callq 0x12e1c
movq %r15, %rdi
leaq 0x48(%rsp), %rdx
movq %rbp, %rcx
callq 0x1283c
movq %rbp, %rdi
callq 0xbaf6
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0xf087
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x3280
leaq 0x38(%rsp), %rax
movq %rax, 0x28(%rsp)
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
addq %rsi, %rdx
leaq 0x28(%rsp), %rdi
callq 0x6790
movq %r12, %rdi
movq 0xc8(%rsp), %rsi
callq 0x12e1c
movq %r13, %rdi
leaq 0x28(%rsp), %rdx
movq %r12, %rcx
callq 0x1283c
movq %r12, %rdi
callq 0xbaf6
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0xf0eb
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x3280
leaq 0xd8(%rsp), %rdi
movq %r15, %rsi
callq 0x12e1c
leaq 0x130(%rsp), %rdi
movq %r13, %rsi
callq 0x12e1c
movq 0x130(%rsp), %rax
movq 0x138(%rsp), %rcx
cmpq %rcx, %rax
je 0xf154
movq 0xd8(%rsp), %rdx
movq 0xe0(%rsp), %rsi
cmpq %rsi, %rdx
je 0xf14b
movq 0x10(%rax), %rdi
movq %rdx, %r8
cmpq 0x10(%r8), %rdi
je 0xf173
addq $0x20, %r8
cmpq %rsi, %r8
jne 0xf13c
addq $0x20, %rax
cmpq %rcx, %rax
jne 0xf130
leaq 0x130(%rsp), %rdi
callq 0xbaf6
leaq 0xd8(%rsp), %rdi
callq 0xbaf6
jmp 0xf1ff
leaq 0x130(%rsp), %rdi
callq 0xbaf6
leaq 0xd8(%rsp), %rdi
callq 0xbaf6
leaq 0x88(%rsp), %rbx
movq %rbx, %rdi
movq %rsp, %rsi
leaq 0x68(%rsp), %rdx
callq 0x12f2c
leaq 0x148(%rsp), %rdi
movq %rbx, %rsi
callq 0x13f2c
movq 0xa8(%rsp), %rdi
leaq 0xb8(%rsp), %rax
cmpq %rax, %rdi
je 0xf1da
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x3280
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0xf1ff
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x3280
movq %r14, %rdi
callq 0x31b0
movq %rax, %r14
movq %r13, %rdi
callq 0xbaf6
movq %r15, %rdi
callq 0xbaf6
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0xf236
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x3280
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0xf251
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3280
movq 0x20(%rsp), %rax
movq 0x48(%rax), %rax
addq $0x10, %rax
cmpq %rax, %r14
jne 0xefe8
movq 0x20(%rsp), %rax
leaq 0x70(%rax), %rsi
movq %rax, %r12
leaq 0x30(%rax), %rdi
callq 0x12b2e
movq 0x160(%rsp), %r14
leaq 0x150(%rsp), %rax
cmpq %rax, %r14
je 0xf3dc
leaq 0x120(%rsp), %r15
leaq 0x100(%rsp), %rbx
leaq 0x110(%rsp), %r13
leaq 0xf0(%rsp), %rbp
leaq 0x98(%rsp), %rax
movq %rax, 0x88(%rsp)
movq 0x20(%r14), %rsi
movq 0x28(%r14), %rdx
addq %rsi, %rdx
leaq 0x88(%rsp), %rdi
callq 0x6790
leaq 0x10(%rsp), %rax
movq %rax, (%rsp)
movq 0x40(%r14), %rsi
movq 0x48(%r14), %rdx
addq %rsi, %rdx
movq %rsp, %rdi
callq 0x6790
movq %r15, 0x110(%rsp)
movq 0x88(%rsp), %rsi
movq 0x90(%rsp), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0x6790
movq %rbx, 0xf0(%rsp)
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
addq %rsi, %rdx
movq %rbp, %rdi
callq 0x6790
movq %r12, %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x106e8
movq 0xf0(%rsp), %rdi
cmpq %rbx, %rdi
je 0xf363
movq 0x100(%rsp), %rsi
incq %rsi
callq 0x3280
movq 0x110(%rsp), %rdi
cmpq %r15, %rdi
je 0xf380
movq 0x120(%rsp), %rsi
incq %rsi
callq 0x3280
movq %r14, %rdi
callq 0x31b0
movq %rax, %r14
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0xf3a6
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3280
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0xf3cb
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x3280
leaq 0x150(%rsp), %rax
cmpq %rax, %r14
jne 0xf2b5
leaq 0x148(%rsp), %rdi
callq 0xbd46
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xf4ac
jmp 0xf52f
movq %rax, %r14
leaq 0x88(%rsp), %rdi
callq 0x12ea6
jmp 0xf544
jmp 0xf4ac
movq %rax, %r14
jmp 0xf486
movq %rax, %r14
jmp 0xf46b
movq %rax, %r14
jmp 0xf44e
movq %rax, %r14
movq 0xf0(%rsp), %rdi
cmpq %rbx, %rdi
je 0xf44e
movq 0x100(%rsp), %rsi
incq %rsi
callq 0x3280
movq 0x110(%rsp), %rdi
cmpq %r15, %rdi
je 0xf46b
movq 0x120(%rsp), %rsi
incq %rsi
callq 0x3280
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0xf486
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3280
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0xf595
movq 0x98(%rsp), %rsi
jmp 0xf58d
movq %rax, %r14
jmp 0xf595
movq %rax, %r14
jmp 0xf57a
movq %rax, %r14
jmp 0xf55e
movq %rax, %r14
jmp 0xf4d9
movq %rax, %r14
leaq 0x1a8(%rsp), %rdi
callq 0xbaf6
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0xf55e
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x3280
jmp 0xf55e
movq %rax, %r14
jmp 0xf551
movq %rax, %r14
jmp 0xf511
movq %rax, %r14
leaq 0x178(%rsp), %rdi
callq 0xbaf6
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0xf551
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x3280
jmp 0xf551
movq %rax, %r14
jmp 0xf544
movq %rax, %r14
leaq 0xd8(%rsp), %rdi
callq 0xbaf6
leaq 0x190(%rsp), %rdi
callq 0xbaf6
leaq 0x1c0(%rsp), %rdi
callq 0xbaf6
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0xf57a
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x3280
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0xf595
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3280
leaq 0x148(%rsp), %rdi
callq 0xbd46
movq %r14, %rdi
callq 0x3450