// File: /workspace/github_cpp_makefile_star2_O3/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 0x11f82
incl 0x64(%rbx)
leaq 0xe569(%rip), %rdi      # 0x20578
leaq 0x5781(%rip), %rsi      # 0x17797
callq 0x1321c
movq %rax, %r14
movb 0x8(%rax), %al
testb $0x1, %al
je 0x12030
movq (%r14), %rdi
movl 0x64(%rbx), %esi
callq 0x5220
leaq 0x4b1e(%rip), %rsi      # 0x16b55
movq %r14, %rdi
callq 0x12f16
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), %r14
leaq 0xb0(%rbx), %rax
movq %rax, 0x48(%rsp)
cmpq %rax, %r14
je 0x122c7
leaq 0x58(%rbx), %rax
movq %rax, 0x40(%rsp)
leaq 0x10(%rsp), %r15
leaq 0x8(%rsp), %r12
movabsq $-0x3333333333333333, %rbp # imm = 0xCCCCCCCCCCCCCCCD
movq 0x20(%r14), %rax
movq %rax, 0x10(%rsp)
leaq 0x28(%r14), %rsi
leaq 0x18(%rsp), %rdi
callq 0x12e2e
movl 0x64(%rbx), %eax
leal -0x1(%rax), %ecx
cmpl %ecx, 0x10(%rsp)
jne 0x1230a
movl %eax, 0x10(%rsp)
movq 0x20(%rsp), %rsi
cmpq 0x28(%rsp), %rsi
je 0x120e9
movq 0x40(%rsp), %rax
movl (%rax), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x20(%rsp)
jmp 0x120f8
leaq 0x18(%rsp), %rdi
movq 0x40(%rsp), %rdx
callq 0x14c5e
movl $0x0, 0x8(%rsp)
movq 0x10(%rbx), %rax
cmpq 0x8(%rbx), %rax
je 0x121d2
xorl %eax, %eax
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %rdx
cmpq %rdx, %rcx
je 0x1212d
cmpl %eax, (%rcx)
je 0x121af
addq $0x4, %rcx
jmp 0x1211a
movq %rbx, %rdi
callq 0x11818
testb %al, %al
je 0x121af
leaq 0xe438(%rip), %rdi      # 0x20578
leaq 0x55ed(%rip), %rsi      # 0x17734
callq 0x12eae
movq %rax, %r13
movb 0x8(%rax), %al
testb $0x1, %al
je 0x12162
movq (%r13), %rdi
movq %r15, %rsi
callq 0x11055
movq %r13, %rdi
leaq 0x55d2(%rip), %rsi      # 0x1773e
callq 0x12ee2
movq %rax, %r13
movb 0x8(%rax), %al
testb $0x1, %al
je 0x12188
movq (%r13), %rdi
movl 0x8(%rsp), %esi
callq 0x5220
movq %r13, %rdi
leaq 0x49c3(%rip), %rsi      # 0x16b55
callq 0x12f16
leaq 0x50(%rsp), %rdi
movq %r12, %rsi
callq 0x14d3a
movq %rax, %rdi
movq %r15, %rsi
callq 0x12f7e
movl 0x8(%rsp), %eax
incl %eax
movl %eax, 0x8(%rsp)
movq 0x10(%rbx), %rcx
subq 0x8(%rbx), %rcx
sarq $0x3, %rcx
imulq %rbp, %rcx
cmpq %rax, %rcx
ja 0x12110
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x121e9
movq 0x28(%rsp), %rsi
subq %rdi, %rsi
callq 0x5340
movq %r14, %rdi
callq 0x53d0
movq %rax, %r14
cmpq 0x48(%rsp), %rax
jne 0x1209e
movq 0x60(%rsp), %r13
testq %r13, %r13
je 0x122c7
leaq 0x20(%rsp), %r14
leaq 0x108(%rbx), %r15
leaq 0x38(%rsp), %r12
movq %rbx, 0x10(%rsp)
movl 0x8(%r13), %eax
movl %eax, 0x18(%rsp)
leaq 0x10(%r13), %rsi
movq %r14, %rdi
callq 0x13250
movq $0x0, 0x38(%rsp)
movl $0x30, %edi
callq 0x5330
movq %rax, %rbp
leaq 0xdab4(%rip), %rax      # 0x1fd08
movq %rax, (%rbp)
movq 0x10(%rsp), %rax
movq %rax, 0x8(%rbp)
movl 0x18(%rsp), %eax
movl %eax, 0x10(%rbp)
movq %rbp, %rdi
addq $0x18, %rdi
movq %r14, %rsi
callq 0x13250
movq %rbp, 0x8(%rsp)
movq %r12, %rdi
leaq 0x8(%rsp), %rsi
xorl %edx, %edx
callq 0x5300
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x1229b
movq (%rdi), %rax
callq *0x8(%rax)
movq %r15, %rdi
movq %r12, %rsi
callq 0x145b2
cmpq $0x0, 0x38(%rsp)
jne 0x1235e
movq %r14, %rdi
callq 0x133ac
movq (%r13), %r13
testq %r13, %r13
jne 0x1221e
leaq 0xa8(%rbx), %r14
leaq 0xd8(%rbx), %rdi
callq 0x151b0
movq %r14, %rdi
callq 0x151de
callq 0x5460
movq %rax, 0xa0(%rbx)
leaq 0x50(%rsp), %rdi
callq 0x13400
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x10, %edi
callq 0x51a0
movq %rax, %r14
leaq 0x5438(%rip), %rsi      # 0x17756
movq %rax, %rdi
callq 0x54c0
movq 0xdc93(%rip), %rsi      # 0x1ffc0
movq 0xdc54(%rip), %rdx      # 0x1ff88
movq %r14, %rdi
callq 0x55d0
jmp 0x1239f
jmp 0x1239f
movq %rax, %rbx
movq %r14, %rdi
callq 0x5270
jmp 0x123a2
jmp 0x12359
jmp 0x1239a
cmpq $0x0, 0x38(%rsp)
jne 0x1235e
movq %rax, %rbx
jmp 0x12390
callq 0x50e0
movq %rax, %rbx
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x12390
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x12390
movq %rax, %rbx
movq %rbp, %rdi
callq 0x5190
movl $0x30, %esi
movq %rbp, %rdi
callq 0x5340
movq %r14, %rdi
callq 0x133ac
jmp 0x123b9
movq %rax, %rbx
jmp 0x123b9
movq %rax, %rbx
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x123b9
movq 0x28(%rsp), %rsi
subq %rdi, %rsi
callq 0x5340
leaq 0x50(%rsp), %rdi
callq 0x13400
movq %rbx, %rdi
callq 0x5600
nop