// File: tonymuu[P]distributed-kv-store/MP1Node.cpp
// Function: MP1Node::serializeMemberList(MP1Node::MessageHdr*)
void MP1Node::serializeMemberList(MessageHdr* msg) {
    int offset = 0;
    int id = 0;
    short port = 0;
    setIdAndPortFromAddress(memberNode->addr, &id, &port);
    long currTime = par->getcurrtime();
    for(auto mle = memberNode->memberList.begin(); mle != memberNode->memberList.end(); ++mle) {
        memcpy((char *)(msg+1) + offset, &mle->id, sizeof(int));
        offset += sizeof(int);

        memcpy((char *)(msg+1) + offset, &mle->port, sizeof(short));
        offset += sizeof(short);

        memcpy((char *)(msg+1) + offset, mle->id == id ? &(memberNode->heartbeat) : &(mle->heartbeat), sizeof(long));
        offset += sizeof(long);

        memcpy((char *)(msg+1) + offset, mle->id == id ? &currTime : &(mle->timestamp), sizeof(long));
        offset += sizeof(long);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x40(%rbp)
movl $0x0, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movw $0x0, -0x1a(%rbp)
movq 0x20(%rax), %rsi
addq $0x8, %rsi
leaq -0x20(%rbp), %rdi
callq 0x18e40
movq -0x40(%rbp), %rdi
leaq -0x20(%rbp), %rsi
leaq -0x18(%rbp), %rdx
leaq -0x1a(%rbp), %rcx
callq 0x5ff0
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x18c60
movl %eax, %ecx
movq -0x40(%rbp), %rax
movslq %ecx, %rcx
movq %rcx, -0x28(%rbp)
movq 0x20(%rax), %rdi
addq $0x28, %rdi
callq 0x7380
movq %rax, -0x30(%rbp)
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rdi
addq $0x28, %rdi
callq 0x73f0
movq %rax, -0x38(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x73b0
testb $0x1, %al
jne 0x69eb
jmp 0x6b1c
movq -0x10(%rbp), %rax
movq %rax, -0x60(%rbp)
movslq -0x14(%rbp), %rax
movq %rax, -0x68(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x7420
movq -0x68(%rbp), %rcx
movq %rax, %rdx
movq -0x60(%rbp), %rax
movl (%rdx), %edx
movl %edx, 0x4(%rax,%rcx)
movslq -0x14(%rbp), %rax
addq $0x4, %rax
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x50(%rbp)
movslq -0x14(%rbp), %rax
movq %rax, -0x58(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x7420
movq -0x58(%rbp), %rcx
movq %rax, %rdx
movq -0x50(%rbp), %rax
movw 0x4(%rdx), %dx
movw %dx, 0x4(%rax,%rcx)
movslq -0x14(%rbp), %rax
addq $0x2, %rax
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rax
addq $0x4, %rax
movslq -0x14(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x7420
movl (%rax), %eax
cmpl -0x18(%rbp), %eax
jne 0x6a8d
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rax
addq $0x18, %rax
movq %rax, -0x70(%rbp)
jmp 0x6a9e
leaq -0x30(%rbp), %rdi
callq 0x7420
addq $0x8, %rax
movq %rax, -0x70(%rbp)
movq -0x48(%rbp), %rax
movq -0x70(%rbp), %rcx
movq (%rcx), %rcx
movq %rcx, (%rax)
movslq -0x14(%rbp), %rax
addq $0x8, %rax
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rax
addq $0x4, %rax
movslq -0x14(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x78(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x7420
movl (%rax), %eax
cmpl -0x18(%rbp), %eax
jne 0x6ae4
leaq -0x28(%rbp), %rax
movq %rax, -0x80(%rbp)
jmp 0x6af5
leaq -0x30(%rbp), %rdi
callq 0x7420
addq $0x10, %rax
movq %rax, -0x80(%rbp)
movq -0x78(%rbp), %rax
movq -0x80(%rbp), %rcx
movq (%rcx), %rcx
movq %rcx, (%rax)
movslq -0x14(%rbp), %rax
addq $0x8, %rax
movl %eax, -0x14(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x75c0
jmp 0x69c0
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)