// File: tonymuu[P]distributed-kv-store/MP2Node.cpp
// Function: MP2Node::checkMessages()
void MP2Node::checkMessages() {
	char * data;
	int size;

	// dequeue all messages and handle them
	while ( !memberNode->mp2q.empty() ) {
	    // Pop a message from the queue
		data = (char *)memberNode->mp2q.front().elt;
		size = memberNode->mp2q.front().size;
		memberNode->mp2q.pop();

		string strMsg(data, data + size);
		Message msg(strMsg);

		// Handle the message types here
        switch (msg.type) {
            case CREATE:
                handleCreateMessage(msg);
                break;
            case UPDATE:
                handleUpdateMessage(msg);
                break;
            case READ:
                handleReadMessage(msg);
                break;
            case DELETE:
                handleDeleteMessage(msg);
                break;
            case REPLY:
            case READREPLY:
                handleReplyMessage(msg);
                break;
            default:
                break;
        }
	}

	/*
	* This function should also ensure all READ and UPDATE operation
	* get QUORUM replies
	*/
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x370, %rsp            # imm = 0x370
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x348(%rbp)
movq -0x348(%rbp), %rax
movq 0x50(%rax), %rdi
addq $0x98, %rdi
callq 0x72a0
xorb $-0x1, %al
testb $0x1, %al
jne 0x2040c
jmp 0x2074f
movq -0x348(%rbp), %rax
movq 0x50(%rax), %rdi
addq $0x98, %rdi
callq 0x72c0
movq %rax, %rcx
movq -0x348(%rbp), %rax
movq (%rcx), %rcx
movq %rcx, -0x10(%rbp)
movq 0x50(%rax), %rdi
addq $0x98, %rdi
callq 0x72c0
movq %rax, %rcx
movq -0x348(%rbp), %rax
movl 0x8(%rcx), %ecx
movl %ecx, -0x14(%rbp)
movq 0x50(%rax), %rdi
addq $0x98, %rdi
callq 0x72e0
movq -0x10(%rbp), %rax
movq %rax, -0x360(%rbp)
movslq -0x14(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x358(%rbp)
leaq -0x39(%rbp), %rdi
movq %rdi, -0x350(%rbp)
callq 0x45c0
movq -0x360(%rbp), %rsi
movq -0x358(%rbp), %rdx
movq -0x350(%rbp), %rcx
leaq -0x38(%rbp), %rdi
callq 0x22030
jmp 0x204ad
leaq -0x39(%rbp), %rdi
callq 0x43b0
leaq -0xe8(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x4160
jmp 0x204c8
leaq -0xc8(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0x29f40
jmp 0x204dd
leaq -0xe8(%rbp), %rdi
callq 0x4200
movl -0xc8(%rbp), %eax
movq %rax, -0x368(%rbp)
subq $0x5, %rax
ja 0x2071c
movq -0x368(%rbp), %rax
leaq 0xc79a(%rip), %rcx      # 0x2cca8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x39(%rbp), %rdi
callq 0x43b0
jmp 0x20758
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x20744
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0x4200
jmp 0x20744
leaq -0x160(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x2a530
jmp 0x20574
movq -0x348(%rbp), %rdi
leaq -0x160(%rbp), %rsi
callq 0x20770
jmp 0x20589
leaq -0x160(%rbp), %rdi
callq 0x21f90
jmp 0x2071e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x20738
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x160(%rbp), %rdi
callq 0x21f90
jmp 0x20738
leaq -0x1d8(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x2a530
jmp 0x205dd
movq -0x348(%rbp), %rdi
leaq -0x1d8(%rbp), %rsi
callq 0x20be0
jmp 0x205f2
leaq -0x1d8(%rbp), %rdi
callq 0x21f90
jmp 0x2071e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x1d8(%rbp), %rdi
callq 0x21f90
jmp 0x20738
leaq -0x250(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x2a530
jmp 0x20635
movq -0x348(%rbp), %rdi
leaq -0x250(%rbp), %rsi
callq 0x21050
jmp 0x2064a
leaq -0x250(%rbp), %rdi
callq 0x21f90
jmp 0x2071e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x250(%rbp), %rdi
callq 0x21f90
jmp 0x20738
leaq -0x2c8(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x2a530
jmp 0x2068d
movq -0x348(%rbp), %rdi
leaq -0x2c8(%rbp), %rsi
callq 0x21400
jmp 0x206a2
leaq -0x2c8(%rbp), %rdi
callq 0x21f90
jmp 0x2071e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x2c8(%rbp), %rdi
callq 0x21f90
jmp 0x20738
leaq -0x340(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x2a530
jmp 0x206df
movq -0x348(%rbp), %rdi
leaq -0x340(%rbp), %rsi
callq 0x21780
jmp 0x206f4
leaq -0x340(%rbp), %rdi
callq 0x21f90
jmp 0x2071e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x340(%rbp), %rdi
callq 0x21f90
jmp 0x20738
jmp 0x2071e
leaq -0xc8(%rbp), %rdi
callq 0x21f90
leaq -0x38(%rbp), %rdi
callq 0x4200
jmp 0x203ea
leaq -0xc8(%rbp), %rdi
callq 0x21f90
leaq -0x38(%rbp), %rdi
callq 0x4200
jmp 0x20758
addq $0x370, %rsp            # imm = 0x370
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x45b0
nopw %cs:(%rax,%rax)