// File: /workspace/github_cpp_makefile_star2_O1/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
movl (%rsi), %eax
cmpl 0x64(%rdi), %eax
ja 0x12576
movq %rdx, %rcx
movq %rsi, %r15
incl %eax
movq 0x8(%rsi), %r12
movq 0x10(%rsi), %rbx
movq %rbx, %rdx
subq %r12, %rdx
sarq $0x2, %rdx
cmpq %rax, %rdx
jne 0x12576
cmpq %r12, %rbx
je 0x1267b
cmpl $0x0, (%r12)
je 0x12589
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)
cmpq %rbx, %r12
je 0x125fb
movabsq $-0x3333333333333333, %r13 # imm = 0xCCCCCCCCCCCCCCCD
xorl %ebp, %ebp
movl (%r12), %eax
movq 0x10(%r14), %rcx
subq 0x8(%r14), %rcx
sarq $0x3, %rcx
imulq %r13, %rcx
cmpq %rax, %rcx
jbe 0x12667
cmpl 0x58(%r14), %eax
je 0x12667
leaq 0x8(%rsp), %rdi
movq %r12, %rsi
callq 0x153ea
addq $0x4, %r12
cmpq %rbx, %r12
jne 0x125be
movq 0x10(%r15), %rax
movq %rax, %rcx
subq 0x8(%r15), %rcx
sarq $0x2, %rcx
cmpq %rcx, 0x30(%rsp)
jb 0x12665
movl -0x4(%rax), %esi
movq 0x8(%r14), %rax
movq 0x10(%r14), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
movabsq $-0x3333333333333333, %rdx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rcx, %rdx
cmpq %rsi, %rdx
jbe 0x1268b
leaq (%rsi,%rsi,4), %rcx
movq 0x8(%rax,%rcx,8), %rdx
movq (%rsp), %rsi
cmpq 0x8(%rsi), %rdx
jne 0x12665
testq %rdx, %rdx
je 0x12676
leaq (%rax,%rcx,8), %rax
movq (%rsi), %rsi
movq (%rax), %rdi
callq 0x5360
testl %eax, %eax
sete %bpl
jmp 0x12667
xorl %ebp, %ebp
leaq 0x8(%rsp), %rdi
callq 0x134ee
jmp 0x12578
movb $0x1, %bpl
jmp 0x12667
leaq 0x47a4(%rip), %rdi      # 0x16e26
xorl %esi, %esi
xorl %eax, %eax
callq 0x5520
leaq 0x4794(%rip), %rdi      # 0x16e26
xorl %eax, %eax
callq 0x5520
jmp 0x1269b
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x134ee
movq %rbx, %rdi
callq 0x5600