// File: /workspace/github_cpp_makefile_star2_O1/tonymuu[P]distributed-kv-store/MP2Node.cpp
// Function: MP2Node::updateRing()
void MP2Node::updateRing() {
    vector<Node> curMemList;
    bool change = false;

	/*
	 *  Step 1. Get the current membership list from Membership Protocol / MP1
	 */
	curMemList = getMembershipList();

	/*
	 * Step 2: Construct the ring
	 */
	// Sort the list based on the hashCode
	sort(curMemList.begin(), curMemList.end());

	// Check if the ring has changes
	if (curMemList.size() != ring.size()) {
        // if the current membership ring and my ring doesn't have the same size, then it must have changed
	    change = true;
	} else {
	    // go through each node in the two rings and check if they the same hash
        for (int i = 0; i < ring.size(); i++) {
            if (ring.at(i).getHashCode() != curMemList.at(i).getHashCode()) {
                change = true;
            }
        }
	}

	ring = curMemList;
	/*
	 * Step 3: Run the stabilization protocol IF REQUIRED
	 */
	// Run stabilization protocol if the hash table size is greater than zero and if there has been a changed in the ring
	if (change) {
        stabilizationProtocol();
	}

	// Also update the transaction map to see if any has been successful or failed
	updateTransactionMap();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %rbx
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
leaq 0x18(%rsp), %rdi
movq %rbx, %rsi
callq 0xea80
leaq 0x30(%rsp), %rdi
xorps %xmm0, %xmm0
movaps %xmm0, (%rdi)
movaps (%rsp), %xmm0
movq 0x10(%rsp), %rax
leaq 0x18(%rsp), %r14
movups (%r14), %xmm1
movaps %xmm1, (%rsp)
movq 0x10(%r14), %rcx
movq %rcx, 0x10(%rsp)
movaps (%rdi), %xmm1
movaps %xmm0, (%rdi)
movq %rax, 0x10(%rdi)
movups %xmm1, (%r14)
movq $0x0, 0x10(%r14)
callq 0xb544
movq %r14, %rdi
callq 0xb544
movq (%rsp), %r14
movq 0x8(%rsp), %r15
cmpq %r15, %r14
je 0xe99a
movq %r15, %rax
subq %r14, %rax
sarq $0x5, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x12c07
movq %r14, %rdi
movq %r15, %rsi
callq 0x12cbd
movq 0x8(%rsp), %rax
subq (%rsp), %rax
movq 0x38(%rbx), %rcx
subq 0x30(%rbx), %rcx
movb $0x1, %bpl
cmpq %rcx, %rax
jne 0xea1d
movq 0x30(%rbx), %rdi
cmpq %rdi, 0x38(%rbx)
je 0xea1b
xorl %r12d, %r12d
movl $0x1, %r13d
xorl %r14d, %r14d
xorl %ebp, %ebp
addq %r12, %rdi
callq 0x13c66
movq (%rsp), %rdi
movq 0x8(%rsp), %rdx
subq %rdi, %rdx
sarq $0x5, %rdx
cmpq %r14, %rdx
jbe 0xea56
movq %rax, %r15
addq %r12, %rdi
callq 0x13c66
cmpq %rax, %r15
movzbl %bpl, %ebp
cmovnel %r13d, %ebp
incq %r14
movq 0x30(%rbx), %rdi
movq 0x38(%rbx), %rax
subq %rdi, %rax
sarq $0x5, %rax
addq $0x20, %r12
cmpq %r14, %rax
ja 0xe9cb
jmp 0xea1d
xorl %ebp, %ebp
leaq 0x30(%rbx), %rdi
movq %rsp, %rsi
callq 0x127c8
testb $0x1, %bpl
je 0xea37
movq %rbx, %rdi
callq 0xebe0
movq %rbx, %rdi
callq 0xefdc
movq %rsp, %rdi
callq 0xb544
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x9d11(%rip), %rdi      # 0x1876e
movq %r14, %rsi
xorl %eax, %eax
callq 0x3410
jmp 0xea6d
jmp 0xea6d
jmp 0xea6d
movq %rax, %rbx
movq %rsp, %rdi
callq 0xb544
movq %rbx, %rdi
callq 0x34b0