// File: /workspace/github_cpp_makefile_star2_O2/nvanbenschoten[P]byzantine-agreement/src/general.cc
// Function: generals::Lieutenant::InitNewRound()
void Lieutenant::InitNewRound() {
  ClearSenders();
  IncrementRound();

  // Determine the set of messages to forward in the next round.
  std::unordered_map<unsigned int, std::vector<msg::Message>> toSend;
  for (msg::Message msg : msgs_this_round_) {
    if (msg.round != round_ - 1) {
      throw std::logic_error(
          "message in msgs_this_round_ not from current round");
    }

    // Update the messages round number to the current round.
    msg.round = round_;

    // Add this process in at the end of the message id list.
    msg.ids.push_back(id_);

    // Determine which processes we need to send this message to.
    for (unsigned int pid = 0; pid < processes_.size(); ++pid) {
      // Only send to processes not already in this message.
      bool inMsg = false;
      for (auto const& id : msg.ids) {
        if (id == pid) {
          inMsg = true;
          break;
        }
      }
      if (!inMsg) {
        if (ShouldSendMsg()) {
          logging::out << "Sending  " << msg << " to p" << pid << "\n";
          toSend[pid].push_back(msg);
        }
      }
    }
  }

  // For each process that we have messages to send to...
  for (auto const& batch : toSend) {
    sender_threads_this_round_.AddThread([this, batch] {
      // Send each message to the process serially in a new thread.
      unsigned int pid = batch.first;
      udp::ClientPtr client = ClientForId(pid);
      for (auto const& msg : batch.second) {
        MaybeDelaySend();
        SendMessage(client, msg);
      }
    });
  }

  // Clear round-specific containers and reset round start timestamp.
  ids_this_round_.clear();
  msgs_this_round_.clear();
  round_start_ts_ = std::chrono::steady_clock::now();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdi, %rbx
callq 0xf5e8
movq %rbx, %rdi
callq 0x1018e
leaq 0x80(%rsp), %rax
movq %rax, -0x30(%rax)
movq $0x1, -0x28(%rax)
xorps %xmm0, %xmm0
movups %xmm0, -0x20(%rax)
movl $0x3f800000, -0x10(%rax) # imm = 0x3F800000
movups %xmm0, -0x8(%rax)
movq 0xc0(%rbx), %rcx
leaq 0xb0(%rbx), %rax
movq %rax, 0x48(%rsp)
leaq 0x58(%rbx), %rax
movq %rax, 0x40(%rsp)
leaq 0x18(%rsp), %r13
pushq $0x28
popq %r12
leaq 0x8(%rsp), %rbp
leaq 0x50(%rsp), %r15
cmpq 0x48(%rsp), %rcx
je 0xf77f
movq %rcx, %r14
leaq 0x20(%rcx), %rsi
movq %r13, %rdi
callq 0xff2a
movl 0x64(%rbx), %eax
leal -0x1(%rax), %ecx
cmpl %ecx, 0x18(%rsp)
jne 0xf86f
movl %eax, 0x18(%rsp)
leaq 0x20(%rsp), %rdi
movq 0x40(%rsp), %rsi
callq 0x101c4
xorl %ecx, %ecx
movl %ecx, 0x8(%rsp)
movl %ecx, %esi
movq 0x10(%rbx), %rax
subq 0x8(%rbx), %rax
cqto
idivq %r12
cmpq %rsi, %rax
jbe 0xf765
movq 0x20(%rsp), %rdx
movq 0x28(%rsp), %rax
cmpq %rax, %rdx
je 0xf6f1
leaq 0x4(%rdx), %rsi
cmpl %ecx, (%rdx)
movq %rsi, %rdx
jne 0xf6df
jmp 0xf75a
movq %rbx, %rdi
callq 0xf04a
testb %al, %al
je 0xf75a
leaq 0xfe8c(%rip), %rdi      # 0x1f590
leaq 0x4fe1(%rip), %rsi      # 0x146ec
callq 0x10066
movq %rax, %rdi
movq %r13, %rsi
callq 0x1007e
movq %rax, %rdi
leaq 0x4fd1(%rip), %rsi      # 0x146f6
callq 0x10096
movq %rax, %rdi
movq %rbp, %rsi
callq 0x100ae
movq %rax, %rdi
leaq 0x441b(%rip), %rsi      # 0x13b5a
callq 0x100c8
movq %r15, %rdi
movq %rbp, %rsi
callq 0x121e4
movq %rax, %rdi
movq %r13, %rsi
callq 0x101e2
movl 0x8(%rsp), %ecx
incl %ecx
jmp 0xf6b9
leaq 0x20(%rsp), %rdi
callq 0x1096c
movq %r14, %rdi
callq 0x53a0
movq %rax, %rcx
jmp 0xf67a
movq 0x60(%rsp), %r14
leaq 0x20(%rsp), %r15
leaq 0x108(%rbx), %r12
leaq 0x10(%rsp), %rbp
testq %r14, %r14
je 0xf82c
leaq 0x8(%r14), %rsi
movq %rbx, 0x18(%rsp)
movq %r15, %rdi
callq 0x1020e
andq $0x0, 0x10(%rsp)
pushq $0x30
popq %rdi
callq 0x5330
movq %rax, %r13
leaq 0xf549(%rip), %rax      # 0x1ed10
movq %rax, (%r13)
movq 0x18(%rsp), %rax
movq %rax, 0x8(%r13)
movq %r13, %rdi
addq $0x10, %rdi
movq %r15, %rsi
callq 0x1020e
movq %r13, 0x8(%rsp)
movq %rbp, %rdi
leaq 0x8(%rsp), %rsi
xorl %edx, %edx
callq 0x5310
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0xf807
movq (%rdi), %rax
callq *0x8(%rax)
movq %r12, %rdi
movq %rbp, %rsi
callq 0x118f4
movq %rbp, %rdi
callq 0x104a0
leaq 0x28(%rsp), %rdi
callq 0x10702
movq (%r14), %r14
jmp 0xf795
leaq 0xa8(%rbx), %r14
leaq 0xd8(%rbx), %rdi
callq 0x126de
movq %r14, %rdi
callq 0x1270c
callq 0x5450
movq %rax, 0xa0(%rbx)
leaq 0x50(%rsp), %rdi
callq 0x10724
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x10
popq %rdi
callq 0x51c0
movq %rax, %r14
leaq 0x4e8d(%rip), %rsi      # 0x1470e
movq %rax, %rdi
callq 0x54a0
movq 0xf730(%rip), %rsi      # 0x1efc0
movq 0xf6e9(%rip), %rdx      # 0x1ef80
movq %r14, %rdi
callq 0x55c0
jmp 0xf902
movq %rax, %rbx
movq %r14, %rdi
callq 0x5270
jmp 0xf905
movq %rax, %rbx
jmp 0xf8ed
movq %rax, %rbx
movq %r13, %rdi
callq 0x5190
pushq $0x30
popq %rsi
movq %r13, %rdi
callq 0x5340
jmp 0xf8ed
movq %rax, %rbx
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0xf8ed
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0xf8ed
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x104a0
leaq 0x28(%rsp), %rdi
callq 0x10702
jmp 0xf90f
jmp 0xf8fd
jmp 0xf902
movq %rax, %rbx
jmp 0xf90f
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x1096c
leaq 0x50(%rsp), %rdi
callq 0x10724
movq %rbx, %rdi
callq 0x55e0
nop