// File: 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
movq %rsp, %rbp
subq $0x270, %rsp            # imm = 0x270
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x258(%rbp)
movq 0x48(%rax), %rdi
addq $0x8, %rdi
callq 0x10a20
movq %rax, -0x10(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x10620
movq -0x258(%rbp), %rax
movq 0x48(%rax), %rdi
addq $0x8, %rdi
callq 0x10a80
movq %rax, -0x48(%rbp)
leaq -0x10(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x10a50
testb $0x1, %al
jne 0x1a3a2
jmp 0x1a6d1
leaq -0x10(%rbp), %rdi
callq 0x10ab0
movq %rax, %rsi
leaq -0x68(%rbp), %rdi
callq 0x4150
jmp 0x1a3b9
leaq -0x10(%rbp), %rdi
callq 0x10ab0
movq %rax, %rsi
addq $0x20, %rsi
leaq -0x98(%rbp), %rdi
callq 0x4150
jmp 0x1a3d7
leaq -0xd0(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x4150
jmp 0x1a3e9
movq -0x258(%rbp), %rsi
addq $0x30, %rsi
leaq -0xe8(%rbp), %rdi
callq 0x1ee50
jmp 0x1a402
movq -0x258(%rbp), %rsi
leaq -0xb0(%rbp), %rdi
leaq -0xd0(%rbp), %rdx
leaq -0xe8(%rbp), %rcx
callq 0x1dfb0
jmp 0x1a425
leaq -0xe8(%rbp), %rdi
callq 0x10c60
leaq -0xd0(%rbp), %rdi
callq 0x41e0
leaq -0x120(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x4150
jmp 0x1a44f
movq -0x258(%rbp), %rsi
addq $0x70, %rsi
leaq -0x138(%rbp), %rdi
callq 0x1ee50
jmp 0x1a468
movq -0x258(%rbp), %rsi
leaq -0x100(%rbp), %rdi
leaq -0x120(%rbp), %rdx
leaq -0x138(%rbp), %rcx
callq 0x1dfb0
jmp 0x1a48b
leaq -0x138(%rbp), %rdi
callq 0x10c60
leaq -0x120(%rbp), %rdi
callq 0x41e0
leaq -0x150(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x1ee50
jmp 0x1a4b8
leaq -0x168(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x1ee50
jmp 0x1a4cd
leaq -0x150(%rbp), %rdi
leaq -0x168(%rbp), %rsi
callq 0x1e480
movb %al, -0x259(%rbp)
leaq -0x168(%rbp), %rdi
callq 0x10c60
leaq -0x150(%rbp), %rdi
callq 0x10c60
movb -0x259(%rbp), %al
testb $0x1, %al
jne 0x1a50d
jmp 0x1a664
leaq -0x1a8(%rbp), %rdi
leaq -0x68(%rbp), %rsi
leaq -0x98(%rbp), %rdx
callq 0x1ef80
jmp 0x1a526
leaq -0x40(%rbp), %rdi
leaq -0x1a8(%rbp), %rsi
callq 0x1ef40
movb %dl, -0x269(%rbp)
movq %rax, -0x268(%rbp)
jmp 0x1a545
movb -0x269(%rbp), %al
movq -0x268(%rbp), %rcx
movq %rcx, -0x1b8(%rbp)
movb %al, -0x1b0(%rbp)
leaq -0x1a8(%rbp), %rdi
callq 0x1efc0
jmp 0x1a664
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x1a86e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x1a6c3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x1a6b7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x1a5c9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0x10c60
leaq -0xd0(%rbp), %rdi
callq 0x41e0
jmp 0x1a6b7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x1a6ab
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x1a611
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x138(%rbp), %rdi
callq 0x10c60
leaq -0x120(%rbp), %rdi
callq 0x41e0
jmp 0x1a6ab
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x1a69f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x150(%rbp), %rdi
callq 0x10c60
jmp 0x1a69f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x1a8(%rbp), %rdi
callq 0x1efc0
jmp 0x1a69f
leaq -0x10(%rbp), %rdi
callq 0x10ad0
leaq -0x100(%rbp), %rdi
callq 0x10c60
leaq -0xb0(%rbp), %rdi
callq 0x10c60
leaq -0x98(%rbp), %rdi
callq 0x41e0
leaq -0x68(%rbp), %rdi
callq 0x41e0
jmp 0x1a374
leaq -0x100(%rbp), %rdi
callq 0x10c60
leaq -0xb0(%rbp), %rdi
callq 0x10c60
leaq -0x98(%rbp), %rdi
callq 0x41e0
leaq -0x68(%rbp), %rdi
callq 0x41e0
jmp 0x1a86e
movq -0x258(%rbp), %rdi
movq %rdi, %rsi
addq $0x70, %rsi
addq $0x30, %rdi
callq 0x1e640
jmp 0x1a6ea
leaq -0x40(%rbp), %rdi
callq 0x10a20
movq %rax, -0x1c0(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x10a80
movq %rax, -0x1c8(%rbp)
leaq -0x1c0(%rbp), %rdi
leaq -0x1c8(%rbp), %rsi
callq 0x10a50
testb $0x1, %al
jne 0x1a726
jmp 0x1a85c
leaq -0x1c0(%rbp), %rdi
callq 0x10ab0
movq %rax, %rsi
leaq -0x1e8(%rbp), %rdi
callq 0x4150
jmp 0x1a743
leaq -0x1c0(%rbp), %rdi
callq 0x10ab0
movq %rax, %rsi
addq $0x20, %rsi
leaq -0x208(%rbp), %rdi
callq 0x4150
jmp 0x1a764
leaq -0x228(%rbp), %rdi
leaq -0x1e8(%rbp), %rsi
callq 0x4150
jmp 0x1a779
leaq -0x248(%rbp), %rdi
leaq -0x208(%rbp), %rsi
callq 0x4150
jmp 0x1a78e
movq -0x258(%rbp), %rdi
leaq -0x228(%rbp), %rsi
leaq -0x248(%rbp), %rdx
callq 0x1bd10
jmp 0x1a7aa
leaq -0x248(%rbp), %rdi
callq 0x41e0
leaq -0x228(%rbp), %rdi
callq 0x41e0
leaq -0x1c0(%rbp), %rdi
xorl %esi, %esi
callq 0x10b00
movq %rax, -0x250(%rbp)
leaq -0x208(%rbp), %rdi
callq 0x41e0
leaq -0x1e8(%rbp), %rdi
callq 0x41e0
jmp 0x1a6fa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x1a84e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x1a842
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x1a836
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x248(%rbp), %rdi
callq 0x41e0
leaq -0x228(%rbp), %rdi
callq 0x41e0
leaq -0x208(%rbp), %rdi
callq 0x41e0
leaq -0x1e8(%rbp), %rdi
callq 0x41e0
jmp 0x1a86e
leaq -0x40(%rbp), %rdi
callq 0x10750
addq $0x270, %rsp            # imm = 0x270
popq %rbp
retq
leaq -0x40(%rbp), %rdi
callq 0x10750
movq -0x70(%rbp), %rdi
callq 0x4550