// File: /workspace/github_cpp_makefile_star2_O2/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 $0x1e8, %rsp            # imm = 0x1E8
movq 0x48(%rdi), %rax
movq 0x20(%rax), %r14
leaq 0xd8(%rsp), %rcx
andl $0x0, (%rcx)
andq $0x0, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
andq $0x0, 0x20(%rcx)
leaq 0x30(%rdi), %rcx
movq %rcx, 0x18(%rsp)
movq %rdi, 0x20(%rsp)
leaq 0x70(%rdi), %rcx
movq %rcx, 0x10(%rsp)
leaq 0xb0(%rsp), %r13
leaq 0x120(%rsp), %rbp
leaq 0x138(%rsp), %rbx
leaq 0x58(%rsp), %r12
addq $0x10, %rax
cmpq %rax, %r14
je 0xc433
leaq 0x20(%r14), %rsi
movq %r13, %rdi
callq 0x3340
leaq 0x40(%r14), %rsi
leaq 0x90(%rsp), %rdi
callq 0x3340
leaq 0x70(%rsp), %rdi
movq %r13, %rsi
callq 0x3340
movq %rbp, %rdi
movq 0x18(%rsp), %rsi
callq 0xe7cc
movq %rbx, %rdi
leaq 0x70(%rsp), %rdx
movq %rbp, %rcx
callq 0xe330
movq %rbp, %rdi
callq 0x894c
leaq 0x70(%rsp), %rdi
callq 0x3110
leaq 0x100(%rsp), %rdi
movq %r13, %rsi
callq 0x3340
movq %r12, %rdi
movq 0x10(%rsp), %rsi
callq 0xe7cc
movq %r12, %r15
leaq 0x28(%rsp), %rdi
leaq 0x100(%rsp), %r12
movq %r12, %rdx
movq %r15, %rcx
callq 0xe330
movq %r15, %rdi
callq 0x894c
movq %r12, %rdi
callq 0x3110
leaq 0x40(%rsp), %rdi
movq %rbx, %rsi
callq 0xe7cc
leaq 0x1d0(%rsp), %r12
movq %r12, %rdi
leaq 0x28(%rsp), %rsi
callq 0xe7cc
leaq 0x40(%rsp), %r15
movq %r15, %rdi
movq %r12, %rsi
callq 0xe527
movb %al, 0xf(%rsp)
movq %r12, %rdi
callq 0x894c
movq %r15, %rdi
callq 0x894c
cmpb $0x0, 0xf(%rsp)
leaq 0x58(%rsp), %r12
je 0xc3f3
leaq 0x190(%rsp), %r15
movq %r15, %rdi
movq %r13, %rsi
leaq 0x90(%rsp), %rdx
callq 0xe88e
leaq 0xd0(%rsp), %rdi
movq %r15, %rsi
callq 0xf968
movq %r15, %rdi
callq 0xe820
movq %r14, %rdi
callq 0x31a0
movq %rax, %r14
leaq 0x28(%rsp), %rdi
callq 0x894c
movq %rbx, %rdi
callq 0x894c
leaq 0x90(%rsp), %rdi
callq 0x3110
movq %r13, %rdi
callq 0x3110
movq 0x20(%rsp), %rax
movq 0x48(%rax), %rax
jmp 0xc2c0
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0xe560
movq 0xe8(%rsp), %r12
leaq 0x190(%rsp), %rbx
leaq 0xb0(%rsp), %r14
leaq 0x170(%rsp), %r15
leaq 0x150(%rsp), %r13
leaq 0xd8(%rsp), %rbp
cmpq %rbp, %r12
je 0xc4e4
leaq 0x20(%r12), %rsi
movq %rbx, %rdi
callq 0x3340
leaq 0x40(%r12), %rsi
movq %r14, %rdi
callq 0x3340
movq %r15, %rdi
movq %rbx, %rsi
callq 0x3340
movq %r13, %rdi
movq %r14, %rsi
callq 0x3340
movq 0x20(%rsp), %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0xd094
movq %r13, %rdi
callq 0x3110
movq %r15, %rdi
callq 0x3110
movq %r12, %rdi
callq 0x31a0
movq %rax, %r12
movq %r14, %rdi
callq 0x3110
movq %rbx, %rdi
callq 0x3110
jmp 0xc472
leaq 0xd0(%rsp), %rdi
callq 0x8c66
addq $0x1e8, %rsp            # imm = 0x1E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xc575
jmp 0xc570
movq %rax, %rbx
leaq 0x190(%rsp), %rdi
callq 0xe820
jmp 0xc58a
movq %rax, %rbx
jmp 0xc552
movq %rax, %rbx
jmp 0xc545
movq %rax, %rbx
jmp 0xc538
movq %rax, %rbx
leaq 0x150(%rsp), %rdi
callq 0x3110
leaq 0x170(%rsp), %rdi
callq 0x3110
leaq 0xb0(%rsp), %rdi
callq 0x3110
leaq 0x190(%rsp), %rdi
jmp 0xc5f8
jmp 0xc575
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x894c
jmp 0xc5c9
movq %rax, %rbx
jmp 0xc58a
movq %rax, %rbx
jmp 0xc5fd
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x894c
leaq 0x28(%rsp), %rdi
callq 0x894c
jmp 0xc5d6
movq %rax, %rbx
jmp 0xc5f0
movq %rax, %rbx
jmp 0xc5e3
movq %rax, %rbx
jmp 0xc5b5
movq %rax, %rbx
leaq 0x120(%rsp), %rdi
callq 0x894c
leaq 0x70(%rsp), %rdi
callq 0x3110
jmp 0xc5e3
movq %rax, %rbx
jmp 0xc5d6
movq %rax, %rbx
leaq 0x100(%rsp), %rdi
callq 0x3110
leaq 0x138(%rsp), %rdi
callq 0x894c
leaq 0x90(%rsp), %rdi
callq 0x3110
leaq 0xb0(%rsp), %rdi
callq 0x3110
leaq 0xd0(%rsp), %rdi
callq 0x8c66
movq %rbx, %rdi
callq 0x3420