// File: /workspace/github_cpp_makefile_star2_O1/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 0x48(%rdi), %rax
movq 0x20(%rax), %r14
leaq 0x150(%rsp), %rcx
movl $0x0, (%rcx)
xorl %eax, %eax
movq %rax, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq %rax, 0x20(%rcx)
movq %rdi, 0x20(%rsp)
movq 0x48(%rdi), %rax
addq $0x10, %rax
cmpq %rax, %r14
je 0xf5e5
leaq 0x10(%rsp), %rbx
movq 0x20(%rsp), %rax
leaq 0x30(%rax), %rcx
movq %rcx, 0xd0(%rsp)
addq $0x70, %rax
movq %rax, 0xc8(%rsp)
leaq 0x1c0(%rsp), %r15
leaq 0x178(%rsp), %r12
leaq 0x190(%rsp), %r13
movq %rbx, (%rsp)
movq 0x20(%r14), %rsi
movq 0x28(%r14), %rdx
addq %rsi, %rdx
movq %rsp, %rdi
callq 0x6810
leaq 0x78(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x40(%r14), %rsi
movq 0x48(%r14), %rdx
addq %rsi, %rdx
leaq 0x68(%rsp), %rdi
callq 0x6810
leaq 0x58(%rsp), %rax
movq %rax, 0x48(%rsp)
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
addq %rsi, %rdx
leaq 0x48(%rsp), %rdi
callq 0x6810
leaq 0x1a8(%rsp), %rbp
movq %rbp, %rdi
movq 0xd0(%rsp), %rsi
callq 0x130bc
movq %r15, %rdi
leaq 0x48(%rsp), %rdx
movq %rbp, %rcx
callq 0x12ade
movq %rbp, %rdi
callq 0xbc10
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0xf405
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 0x6810
movq %r12, %rdi
movq 0xc8(%rsp), %rsi
callq 0x130bc
movq %r13, %rdi
leaq 0x28(%rsp), %rdx
movq %r12, %rcx
callq 0x12ade
movq %r12, %rdi
callq 0xbc10
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0xf469
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x3280
leaq 0x118(%rsp), %rdi
movq %r15, %rsi
callq 0x130bc
leaq 0x130(%rsp), %rdi
movq %r13, %rsi
callq 0x130bc
movq 0x130(%rsp), %rax
movq 0x138(%rsp), %rcx
cmpq %rcx, %rax
setne %bl
je 0xf4ec
movq 0x118(%rsp), %rdx
movq 0x120(%rsp), %rsi
leaq 0x20(%rdx), %rdi
movb $0x1, %bl
cmpq %rsi, %rdx
je 0xf4e0
movq 0x10(%rax), %r8
cmpq 0x10(%rdx), %r8
je 0xf4ec
movq %rdi, %r10
cmpq %rsi, %r10
je 0xf4e0
movq %r10, %r9
addq $0x20, %r10
cmpq 0x10(%r9), %r8
jne 0xf4c9
cmpq %rsi, %r9
jne 0xf4ec
addq $0x20, %rax
cmpq %rcx, %rax
setne %bl
jne 0xf4b7
leaq 0x130(%rsp), %rdi
callq 0xbc10
leaq 0x118(%rsp), %rdi
callq 0xbc10
testb $0x1, %bl
leaq 0x10(%rsp), %rbx
je 0xf582
leaq 0x88(%rsp), %rbp
movq %rbp, %rdi
movq %rsp, %rsi
leaq 0x68(%rsp), %rdx
callq 0x131cc
leaq 0x148(%rsp), %rdi
movq %rbp, %rsi
callq 0x141b0
movq 0xa8(%rsp), %rdi
leaq 0xb8(%rsp), %rax
cmpq %rax, %rdi
je 0xf55d
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x3280
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0xf582
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x3280
movq %r14, %rdi
callq 0x31b0
movq %rax, %r14
movq %r13, %rdi
callq 0xbc10
movq %r15, %rdi
callq 0xbc10
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0xf5b9
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x3280
movq (%rsp), %rdi
cmpq %rbx, %rdi
je 0xf5cf
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3280
movq 0x20(%rsp), %rax
movq 0x48(%rax), %rax
addq $0x10, %rax
cmpq %rax, %r14
jne 0xf363
movq 0x20(%rsp), %rax
leaq 0x70(%rax), %rsi
leaq 0x30(%rax), %rdi
callq 0x12dfa
movq 0x160(%rsp), %r14
leaq 0x150(%rsp), %rax
cmpq %rax, %r14
je 0xf754
leaq 0x10(%rsp), %r12
leaq 0x108(%rsp), %r15
leaq 0xe8(%rsp), %rbx
leaq 0xf8(%rsp), %r13
leaq 0xd8(%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 0x6810
movq %r12, (%rsp)
movq 0x40(%r14), %rsi
movq 0x48(%r14), %rdx
addq %rsi, %rdx
movq %rsp, %rdi
callq 0x6810
movq %r15, 0xf8(%rsp)
movq 0x88(%rsp), %rsi
movq 0x90(%rsp), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0x6810
movq %rbx, 0xd8(%rsp)
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
addq %rsi, %rdx
movq %rbp, %rdi
callq 0x6810
movq 0x20(%rsp), %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x10a34
movq 0xd8(%rsp), %rdi
cmpq %rbx, %rdi
je 0xf6e0
movq 0xe8(%rsp), %rsi
incq %rsi
callq 0x3280
movq 0xf8(%rsp), %rdi
cmpq %r15, %rdi
je 0xf6fd
movq 0x108(%rsp), %rsi
incq %rsi
callq 0x3280
movq %r14, %rdi
callq 0x31b0
movq %rax, %r14
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0xf71e
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3280
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0xf743
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x3280
leaq 0x150(%rsp), %rax
cmpq %rax, %r14
jne 0xf635
leaq 0x148(%rsp), %rdi
callq 0xbe52
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xf81f
jmp 0xf8a7
movq %rax, %r14
leaq 0x88(%rsp), %rdi
callq 0x13146
jmp 0xf8bc
jmp 0xf81f
movq %rax, %r14
jmp 0xf7f9
movq %rax, %r14
jmp 0xf7c6
movq %rax, %r14
jmp 0xf7e3
movq %rax, %r14
movq 0xd8(%rsp), %rdi
cmpq %rbx, %rdi
je 0xf7c6
movq 0xe8(%rsp), %rsi
incq %rsi
callq 0x3280
movq 0xf8(%rsp), %rdi
cmpq %r15, %rdi
je 0xf7e3
movq 0x108(%rsp), %rsi
incq %rsi
callq 0x3280
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0xf7f9
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3280
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0xf90d
movq 0x98(%rsp), %rsi
jmp 0xf905
movq %rax, %r14
jmp 0xf90d
movq %rax, %r14
jmp 0xf8f7
movq %rax, %r14
jmp 0xf8db
movq %rax, %r14
jmp 0xf84c
movq %rax, %r14
leaq 0x1a8(%rsp), %rdi
callq 0xbc10
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0xf868
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x3280
leaq 0x10(%rsp), %rbx
jmp 0xf8db
movq %rax, %r14
jmp 0xf8ce
movq %rax, %r14
jmp 0xf889
movq %rax, %r14
leaq 0x178(%rsp), %rdi
callq 0xbc10
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0xf8c9
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x3280
jmp 0xf8c9
movq %rax, %r14
jmp 0xf8bc
movq %rax, %r14
leaq 0x118(%rsp), %rdi
callq 0xbc10
leaq 0x190(%rsp), %rdi
callq 0xbc10
leaq 0x10(%rsp), %rbx
leaq 0x1c0(%rsp), %rdi
callq 0xbc10
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0xf8f7
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x3280
movq (%rsp), %rdi
cmpq %rbx, %rdi
je 0xf90d
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x3280
leaq 0x148(%rsp), %rdi
callq 0xbe52
movq %r14, %rdi
callq 0x3450