// File: /workspace/github_cpp_makefile_star2_O1/tonymuu[P]distributed-kv-store/MP1Node.cpp
// Function: MP1Node::deserializeAndUpdateMemberList(char*, int)
void MP1Node::deserializeAndUpdateMemberList(char *data, int size) {
    // map of port, heartbeat, timestamp
    auto map = createMemberlistMap();

    auto currTime = par->getcurrtime();

    int mleSize = sizeof(int) + sizeof(short) + sizeof(long) + sizeof(long);
    int numEntries = (size - sizeof(MessageHdr)) / mleSize;
    int offset = sizeof(MessageHdr);

    for (int i = 0; i < numEntries; i++) {
        // get the member list
        int id = 0;
        short port = 0;
        long heartbeat = 0;
        long timestamp = 0;

        memcpy(&id, data + offset, sizeof(int));
        offset += sizeof(int);

        memcpy(&port, data + offset, sizeof(short));
        offset += sizeof(short);

        memcpy(&heartbeat, data + offset, sizeof(long));
        offset += sizeof(long);

        memcpy(&timestamp, data + offset, sizeof(long));
        offset += sizeof(long);

        // if member doesn't exist in current member list, we add it there
//        MemberListEntry* old = getNodeFromMemberListTable(id);
        if (map.count(id) == 0) {
//        if (old == nullptr) {
            MemberListEntry entry = MemberListEntry(id, port, heartbeat, currTime);
            memberNode->memberList.push_back(entry);

            // log the new mle join
            Address addr = createAddressFromIdAndPort(id, port);
            log->logNodeAdd(&memberNode->addr, &addr);
        } else {
            // update the existing member entry
            auto old = map[id];
            if (old->heartbeat < heartbeat) {
                if (failed.count(id) > 0) {
                    failed.erase(id);
                }
                old->setheartbeat(heartbeat);
                old->settimestamp(currTime);
            }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl %edx, %ebp
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x30(%rsp), %rdi
movq %r14, %rsi
callq 0x4e9c
movq %r14, 0x20(%rsp)
movq 0x18(%r14), %rdi
callq 0xc962
movl %eax, %ecx
movslq %ebp, %rax
addq $-0x4, %rax
movabsq $0x2e8ba2e8ba2e8ba3, %rdx # imm = 0x2E8BA2E8BA2E8BA3
mulq %rdx
shrq $0x2, %rdx
movq %rdx, 0x28(%rsp)
testl %edx, %edx
jle 0x4cdf
movslq %ecx, %rax
movq %rax, 0x18(%rsp)
movl $0x4, %r14d
xorl %r15d, %r15d
movl $0x0, 0xc(%rsp)
movslq %r14d, %rax
movl (%rbx,%rax), %esi
movl %esi, 0xc(%rsp)
movq 0x40(%rsp), %rcx
leaq 0x38(%rsp), %rax
testq %rcx, %rcx
je 0x4bbf
xorl %edx, %edx
cmpl %esi, 0x20(%rcx)
setl %dl
cmovgeq %rcx, %rax
movq 0x10(%rcx,%rdx,8), %rcx
jmp 0x4ba7
leaq 0x38(%rsp), %rdx
movq %rdx, %rcx
cmpq %rdx, %rax
je 0x4bd6
cmpl 0x20(%rax), %esi
cmovlq %rdx, %rax
movq %rax, %rcx
shlq $0x20, %r14
movabsq $0x600000000, %rax      # imm = 0x600000000
addq %r14, %rax
sarq $0x20, %rax
movq (%rbx,%rax), %r13
cmpq %rdx, %rcx
je 0x4c51
leaq 0x30(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x5042
movq (%rax), %rbp
cmpq %r13, 0x8(%rbp)
jge 0x4cbc
leaq 0x1c6d9(%rip), %rdi     # 0x212f0
leaq 0xc(%rsp), %rsi
callq 0x5e7a
testq %rax, %rax
je 0x4c37
leaq 0x1c6c3(%rip), %rdi     # 0x212f0
leaq 0xc(%rsp), %rsi
callq 0x61dc
movq %rbp, %rdi
movq %r13, %rsi
callq 0xca60
movq %rbp, %rdi
movq 0x18(%rsp), %rsi
callq 0xca66
jmp 0x4cbc
movabsq $0x400000000, %rax      # imm = 0x400000000
addq %r14, %rax
sarq $0x20, %rax
movq %rbx, %r12
movzwl (%rbx,%rax), %ebp
movswl %bp, %edx
leaq 0x60(%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rcx
movq 0x18(%rsp), %r8
callq 0xc9f2
movq 0x20(%rsp), %r13
movq 0x20(%r13), %rdi
addq $0x28, %rdi
movq %rbx, %rsi
callq 0x5016
movl 0xc(%rsp), %eax
movl %eax, 0x10(%rsp)
movw %bp, 0x14(%rsp)
movq 0x10(%r13), %rdi
movq 0x20(%r13), %rsi
addq $0x8, %rsi
leaq 0x10(%rsp), %rdx
callq 0xbf50
movq %r12, %rbx
movabsq $0xe00000000, %rax      # imm = 0xE00000000
addq %rax, %r14
sarq $0x20, %r14
addq $0x8, %r14
incl %r15d
cmpl 0x28(%rsp), %r15d
jne 0x4b8b
leaq 0x30(%rsp), %rdi
callq 0x563a
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4cfe
jmp 0x4cfe
jmp 0x4cfe
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x563a
movq %rbx, %rdi
callq 0x34b0
nop