// File: /workspace/github_cpp_makefile_star2_O3/nvanbenschoten[P]byzantine-agreement/src/general.cc
// Function: generals::Lieutenant::ValidMessage(msg::Message const&, net::Address const&) const
bool Lieutenant::ValidMessage(const msg::Message& msg,
                              const net::Address& from) const {
  // Invalid if the message is from a later round.
  if (msg.round > round_) {
    return false;
  }
  // Invalid if the message has an incorrect number of ids.
  if (msg.round + 1 != msg.ids.size()) {
    return false;
  }
  // Invalid if the first message is not from the General (pid 0);
  if (msg.ids.at(0) != 0) {
    return false;
  }
  // Invalid if not all ids are unique.
  std::set<unsigned int> idset;
  for (auto const& id : msg.ids) {
    // Invalid if any id is out of bounds.
    if (id >= processes_.size()) {
      return false;
    }
    // Invalid if any id is our id.
    if (id == id_) {
      return false;
    }
    idset.insert(id);
  }
  if (idset.size() < msg.ids.size()) {
    return false;
  }
  // Invalid if the last id does not match the sender. This check will not
  // be complete for processes on the same host, because we can not know the
  // sending port of the process, only its receiving port.
  if (processes_.at(msg.ids.back()).hostname() != from.hostname()) {
    return false;
  }
  return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdx, %rcx
movl (%rsi), %edx
cmpl 0x64(%rdi), %edx
ja 0x12410
movq %rsi, %r15
incl %edx
movq 0x8(%rsi), %r12
movq 0x10(%rsi), %rbx
movq %rbx, %rax
subq %r12, %rax
sarq $0x2, %rax
cmpq %rdx, %rax
jne 0x12410
cmpq %r12, %rbx
je 0x12511
cmpl $0x0, (%r12)
je 0x12423
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdi, %r14
movq %rcx, (%rsp)
leaq 0x10(%rsp), %rax
movl $0x0, (%rax)
xorl %ecx, %ecx
movq %rcx, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
movq %rcx, 0x20(%rax)
leaq 0x8(%rsp), %r13
xorl %ebp, %ebp
movl (%r12), %eax
movq 0x10(%r14), %rcx
subq 0x8(%r14), %rcx
sarq $0x3, %rcx
movabsq $-0x3333333333333333, %rdx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rdx, %rcx
cmpq %rax, %rcx
jbe 0x12502
cmpl 0x58(%r14), %eax
je 0x12502
movq %r13, %rdi
movq %r12, %rsi
callq 0x1520c
addq $0x4, %r12
cmpq %rbx, %r12
jne 0x1244e
movq 0x10(%r15), %rax
movq %rax, %rcx
subq 0x8(%r15), %rcx
sarq $0x2, %rcx
cmpq %rcx, 0x30(%rsp)
jb 0x12500
movl -0x4(%rax), %esi
movq 0x8(%r14), %rax
movq 0x10(%r14), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movabsq $-0x3333333333333333, %rcx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rcx, %rdx
cmpq %rsi, %rdx
jbe 0x12521
leaq (%rsi,%rsi,4), %rcx
movq 0x8(%rax,%rcx,8), %rdx
movq (%rsp), %rsi
cmpq 0x8(%rsi), %rdx
jne 0x12500
movb $0x1, %bpl
testq %rdx, %rdx
je 0x12502
leaq (%rax,%rcx,8), %rax
movq (%rsp), %rcx
movq (%rcx), %rsi
movq (%rax), %rdi
callq 0x5360
testl %eax, %eax
je 0x12502
xorl %ebp, %ebp
leaq 0x8(%rsp), %rdi
callq 0x1349a
jmp 0x12412
leaq 0x490e(%rip), %rdi      # 0x16e26
xorl %esi, %esi
xorl %eax, %eax
callq 0x5520
leaq 0x48fe(%rip), %rdi      # 0x16e26
xorl %eax, %eax
callq 0x5520
jmp 0x12531
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x1349a
movq %rbx, %rdi
callq 0x5600