// File: nvanbenschoten[P]total-order-multicast/src/process.cc
// Function: process::Process::HandleDataMsg(std::shared_ptr<udp::Client>, char*, unsigned long)
void Process::HandleDataMsg(const udp::ClientPtr client, char* buf, size_t n) {
  auto data_msg = DataMsgFromBuf(buf, n);
  if (!data_msg || !ValidDataMsg(*data_msg, processes_.size())) {
    // If the data message was not valid, return without trying to use it.
    return;
  }
  logging::out << "Received message " << *data_msg << "\n";

  // If we have already seen this message, send back the old ack so that the
  // sequence number does not change.
  auto ack_msg = hold_back_queue_.Lookup(*data_msg);
  if (!ack_msg) {
    // We have not already seen this message, so insert it into the
    // HoldBackQueue.
    ack_msg->sender = data_msg->sender;
    ack_msg->msg_id = data_msg->msg_id;
    ack_msg->proposed_seq = NextSeqNum();
    ack_msg->proposer = id_;

    hold_back_queue_.InsertUndeliverable(*ack_msg, data_msg->data);
  }

  // Respond to the sender.
  SendAckMsg(client, *ack_msg);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rsi, -0xa0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq -0x34(%rbp), %rdi
callq 0x7400
leaq -0x34(%rbp), %rdi
callq 0xad90
testb $0x1, %al
jne 0x82ed
jmp 0x831c
leaq -0x34(%rbp), %rdi
callq 0xadb0
movq -0x98(%rbp), %rdi
movq %rax, -0xa8(%rbp)
callq 0xa090
movq -0xa8(%rbp), %rdi
movq %rax, %rsi
callq 0x7a00
testb $0x1, %al
jne 0x8321
jmp 0x84d0
leaq 0x3e2d0(%rip), %rdi     # 0x465f8
leaq 0x26f84(%rip), %rsi     # 0x2f2b3
callq 0xadd0
movq %rax, -0xb8(%rbp)
leaq -0x34(%rbp), %rdi
callq 0xadb0
movq -0xb8(%rbp), %rdi
movq %rax, %rsi
callq 0xae20
movq %rax, %rdi
leaq 0x2792d(%rip), %rsi     # 0x2fc8a
callq 0xae70
movq -0x98(%rbp), %rax
addq $0x60, %rax
movq %rax, -0xb0(%rbp)
leaq -0x34(%rbp), %rdi
callq 0xadb0
movq -0xb0(%rbp), %rsi
movq %rax, %rdx
leaq -0x4c(%rbp), %rdi
callq 0x7c20
leaq -0x4c(%rbp), %rdi
callq 0xaec0
testb $0x1, %al
jne 0x8476
leaq -0x34(%rbp), %rdi
callq 0xaee0
movl 0x4(%rax), %eax
movl %eax, -0xd8(%rbp)
leaq -0x4c(%rbp), %rdi
callq 0xaf00
movl -0xd8(%rbp), %ecx
movl %ecx, 0x4(%rax)
leaq -0x34(%rbp), %rdi
callq 0xaee0
movl 0x8(%rax), %eax
movl %eax, -0xd4(%rbp)
leaq -0x4c(%rbp), %rdi
callq 0xaf00
movl -0xd4(%rbp), %ecx
movq -0x98(%rbp), %rdi
movl %ecx, 0x8(%rax)
callq 0x8500
movl %eax, -0xd0(%rbp)
leaq -0x4c(%rbp), %rdi
callq 0xaf00
movl -0xd0(%rbp), %edx
movq %rax, %rcx
movq -0x98(%rbp), %rax
movl %edx, 0xc(%rcx)
movl 0x50(%rax), %eax
movl %eax, -0xcc(%rbp)
leaq -0x4c(%rbp), %rdi
callq 0xaf00
movl -0xcc(%rbp), %edx
movq %rax, %rcx
movq -0x98(%rbp), %rax
movl %edx, 0x10(%rcx)
addq $0x60, %rax
movq %rax, -0xc8(%rbp)
leaq -0x4c(%rbp), %rdi
callq 0xaf20
movq %rax, -0xc0(%rbp)
leaq -0x34(%rbp), %rdi
callq 0xaee0
movq -0xc8(%rbp), %rdi
movq -0xc0(%rbp), %rsi
movl 0xc(%rax), %edx
callq 0x7cf0
movq -0xa0(%rbp), %rsi
leaq -0x60(%rbp), %rdi
callq 0xaf40
leaq -0x4c(%rbp), %rdi
callq 0xaf20
movq %rax, -0xe0(%rbp)
jmp 0x8498
movq -0xe0(%rbp), %rax
movl 0x10(%rax), %ecx
movl %ecx, -0x70(%rbp)
movups (%rax), %xmm0
movaps %xmm0, -0x80(%rbp)
movl -0x70(%rbp), %ecx
movq %rsp, %rax
movl %ecx, 0x10(%rax)
movaps -0x80(%rbp), %xmm0
movups %xmm0, (%rax)
leaq -0x60(%rbp), %rdi
callq 0x7760
jmp 0x84c7
leaq -0x60(%rbp), %rdi
callq 0xa2d0
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x60(%rbp), %rdi
callq 0xa2d0
movq -0x88(%rbp), %rdi
callq 0x67a0