// File: /workspace/github_cpp_makefile_star2_O1/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 0x120c4
incl 0x64(%rbx)
leaq 0xe42b(%rip), %rdi      # 0x20578
leaq 0x55fb(%rip), %rsi      # 0x1774f
callq 0x13276
movq %rax, %r14
movb 0x8(%rax), %al
testb $0x1, %al
je 0x1216e
movq (%r14), %rdi
movl 0x64(%rbx), %esi
callq 0x5220
leaq 0x49e0(%rip), %rsi      # 0x16b55
movq %r14, %rdi
callq 0x12f76
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 0x1235b
leaq 0x58(%rbx), %rax
movq %rax, 0x40(%rsp)
leaq 0x10(%rsp), %r15
movabsq $-0x3333333333333333, %rbp # imm = 0xCCCCCCCCCCCCCCCD
movl $0x1, %r12d
movq 0x20(%r14), %rax
movq %rax, 0x10(%rsp)
leaq 0x28(%r14), %rsi
leaq 0x18(%rsp), %rdi
callq 0x12e8e
movl 0x64(%rbx), %eax
leal -0x1(%rax), %ecx
cmpl %ecx, 0x10(%rsp)
jne 0x12466
movl %eax, 0x10(%rsp)
movq 0x20(%rsp), %rsi
cmpq 0x28(%rsp), %rsi
je 0x12228
movq 0x40(%rsp), %rax
movl (%rax), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x20(%rsp)
jmp 0x12237
leaq 0x18(%rsp), %rdi
movq 0x40(%rsp), %rdx
callq 0x14dc0
movl $0x0, 0x8(%rsp)
movq 0x10(%rbx), %rax
cmpq 0x8(%rbx), %rax
je 0x1232e
xorl %eax, %eax
movq 0x18(%rsp), %rdx
movq 0x20(%rsp), %rcx
cmpq %rcx, %rdx
je 0x12287
addq $0x4, %rdx
xorl %esi, %esi
movzbl %sil, %esi
cmpl %eax, -0x4(%rdx)
cmovel %r12d, %esi
je 0x1227d
leaq 0x4(%rdx), %rdi
cmpq %rcx, %rdx
movq %rdi, %rdx
jne 0x12264
testb $0x1, %sil
jne 0x1230b
movq %rbx, %rdi
callq 0x1192e
testb %al, %al
je 0x1230b
leaq 0xe2de(%rip), %rdi      # 0x20578
leaq 0x544b(%rip), %rsi      # 0x176ec
callq 0x12f0e
movq %rax, %r13
movb 0x8(%rax), %al
testb $0x1, %al
je 0x122bc
movq (%r13), %rdi
movq %r15, %rsi
callq 0x11271
movq %r13, %rdi
leaq 0x5430(%rip), %rsi      # 0x176f6
callq 0x12f42
movq %rax, %r13
movb 0x8(%rax), %al
testb $0x1, %al
je 0x122e2
movq (%r13), %rdi
movl 0x8(%rsp), %esi
callq 0x5220
movq %r13, %rdi
leaq 0x4869(%rip), %rsi      # 0x16b55
callq 0x12f76
leaq 0x50(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x14e9c
movq %rax, %rdi
movq %r15, %rsi
callq 0x12fde
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 0x1224f
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x12345
movq 0x28(%rsp), %rsi
subq %rdi, %rsi
callq 0x5340
movq %r14, %rdi
callq 0x53d0
movq %rax, %r14
cmpq 0x48(%rsp), %rax
jne 0x121dd
movq 0x60(%rsp), %r13
testq %r13, %r13
je 0x12423
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 0x132aa
movq $0x0, 0x38(%rsp)
movl $0x30, %edi
callq 0x5330
movq %rax, %rbp
leaq 0xd958(%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 0x132aa
movq %rbp, 0x8(%rsp)
movq %r12, %rdi
leaq 0x8(%rsp), %rsi
xorl %edx, %edx
callq 0x5300
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x123f7
movq (%rdi), %rax
callq *0x8(%rax)
movq %r15, %rdi
movq %r12, %rsi
callq 0x1461a
cmpq $0x0, 0x38(%rsp)
jne 0x124bf
movq %r14, %rdi
callq 0x13406
movq (%r13), %r13
testq %r13, %r13
jne 0x1237a
leaq 0xa8(%rbx), %r14
leaq 0xd8(%rbx), %rdi
callq 0x1538e
movq %r14, %rdi
callq 0x153bc
callq 0x5460
movq %rax, 0xa0(%rbx)
leaq 0x50(%rsp), %rdi
callq 0x13454
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 0x5294(%rip), %rsi      # 0x1770e
movq %rax, %rdi
callq 0x54c0
movq 0xdb37(%rip), %rsi      # 0x1ffc0
movq 0xdaf8(%rip), %rdx      # 0x1ff88
movq %r14, %rdi
callq 0x55d0
jmp 0x12506
jmp 0x12506
movq %rax, %rbx
movq %r14, %rdi
callq 0x5270
jmp 0x12509
jmp 0x124ad
jmp 0x124ba
movq %rax, %rbx
jmp 0x12520
cmpq $0x0, 0x38(%rsp)
jne 0x124bf
movq %rax, %rbx
jmp 0x124fa
callq 0x50e0
movq %rax, %rbx
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x124d7
movq (%rdi), %rax
callq *0x8(%rax)
movq $0x0, 0x8(%rsp)
jmp 0x124fa
movq %rax, %rbx
movq %rbp, %rdi
callq 0x5190
movl $0x30, %esi
movq %rbp, %rdi
callq 0x5340
leaq 0x20(%rsp), %rdi
callq 0x13406
jmp 0x12520
movq %rax, %rbx
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x12520
movq 0x28(%rsp), %rsi
subq %rdi, %rsi
callq 0x5340
leaq 0x50(%rsp), %rdi
callq 0x13454
movq %rbx, %rdi
callq 0x5600