// File: nvanbenschoten[P]byzantine-agreement/src/general.cc
// Function: generals::Commander::Decide()
msg::Order Commander::Decide() {
  // Send in parallel so that some Lieutenants don't end up far ahead of
  // others.
  threadutil::ThreadGroup senders;
  auto ids = std::vector<unsigned int>{0};
  for (unsigned int pid = 1; pid < processes_.size(); ++pid) {
    if (ShouldSendMsg()) {
      msg::Message msg{round_, OrderForMsg(), ids};
      logging::out << "Sending  " << msg << " to p" << pid << "\n";

      udp::ClientPtr client = ClientForId(pid);
      senders.AddThread([this, client, msg] {
        MaybeDelaySend();
        SendMessage(client, msg);
      });
    }
  }
  senders.JoinAll();
  return order_;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xd8(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x21b10
movl $0x0, -0x4c(%rbp)
leaq -0x4c(%rbp), %rax
movq %rax, -0x48(%rbp)
movq $0x1, -0x40(%rbp)
leaq -0x4d(%rbp), %rdi
movq %rdi, -0xd0(%rbp)
callq 0x29440
movq -0xd0(%rbp), %rcx
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
leaq -0x38(%rbp), %rdi
callq 0x29460
jmp 0x26394
leaq -0x4d(%rbp), %rdi
callq 0x294e0
movl $0x1, -0x60(%rbp)
movq -0xd8(%rbp), %rdi
movl -0x60(%rbp), %eax
movq %rax, -0xe0(%rbp)
addq $0x8, %rdi
callq 0xcaf0
movq %rax, %rcx
movq -0xe0(%rbp), %rax
cmpq %rcx, %rax
jae 0x265d2
movq -0xd8(%rbp), %rdi
callq 0x26140
movb %al, -0xe1(%rbp)
jmp 0x263e5
movb -0xe1(%rbp), %al
testb $0x1, %al
jne 0x263f4
jmp 0x265c2
movq -0xd8(%rbp), %rdi
movl 0x64(%rdi), %eax
movl %eax, -0x80(%rbp)
leaq -0x7c(%rbp), %rax
movq %rax, -0xf0(%rbp)
callq 0x26630
movl %eax, -0xe8(%rbp)
jmp 0x26419
movq -0xf0(%rbp), %rax
movl -0xe8(%rbp), %ecx
movl %ecx, (%rax)
leaq -0x78(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x29500
jmp 0x26437
leaq 0x2d232(%rip), %rdi     # 0x53670
leaq 0x112bf(%rip), %rsi     # 0x37704
callq 0x295f0
movq %rax, -0xf8(%rbp)
jmp 0x26453
movq -0xf8(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x29640
movq %rax, -0x100(%rbp)
jmp 0x2646c
movq -0x100(%rbp), %rdi
leaq 0x11294(%rip), %rsi     # 0x3770e
callq 0x29690
movq %rax, -0x108(%rbp)
jmp 0x26488
movq -0x108(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x296e0
movq %rax, -0x110(%rbp)
jmp 0x264a1
movq -0x110(%rbp), %rdi
leaq 0x106a3(%rip), %rsi     # 0x36b52
callq 0x29730
jmp 0x264b6
movq -0xd8(%rbp), %rsi
movl -0x60(%rbp), %edx
leaq -0x90(%rbp), %rdi
callq 0x29780
jmp 0x264ce
movq -0xd8(%rbp), %rax
movq %rax, -0xc8(%rbp)
leaq -0xc0(%rbp), %rdi
movq %rdi, -0x118(%rbp)
leaq -0x90(%rbp), %rsi
callq 0x297e0
leaq -0xb0(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x29020
jmp 0x26508
leaq -0x20(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x26710
jmp 0x2651a
leaq -0xc8(%rbp), %rdi
callq 0x26780
leaq -0x90(%rbp), %rdi
callq 0x21160
leaq -0x80(%rbp), %rdi
callq 0x28fb0
jmp 0x265c2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x4d(%rbp), %rdi
callq 0x294e0
jmp 0x26617
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x2660e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x265b7
movq -0x118(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
callq 0x21160
jmp 0x265ab
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x26780
leaq -0x90(%rbp), %rdi
callq 0x21160
leaq -0x80(%rbp), %rdi
callq 0x28fb0
jmp 0x2660e
jmp 0x265c4
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x263a4
leaq -0x20(%rbp), %rdi
callq 0x29810
jmp 0x265dd
movq -0xd8(%rbp), %rax
movl 0x68(%rax), %eax
movl %eax, -0x11c(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x29890
leaq -0x20(%rbp), %rdi
callq 0x298f0
movl -0x11c(%rbp), %eax
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
leaq -0x38(%rbp), %rdi
callq 0x29890
leaq -0x20(%rbp), %rdi
callq 0x298f0
movq -0x58(%rbp), %rdi
callq 0x6750
nopl (%rax)