// File: nvanbenschoten[P]byzantine-agreement/src/main.cc
// Function: ValidateOrder(args::ValueFlag<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, args::ValueReader<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>&, bool)
std::experimental::optional<msg::Order> ValidateOrder(StringFlag& order,
                                                      bool is_commander) {
  if (is_commander) {
    if (!order) {
      throw args::UsageError("the commander must specify an order");
    }

    try {
      auto order_val = args::get(order);
      return msg::StringToOrder(order_val);
    } catch (std::invalid_argument e) {
      throw args::ValidationError(e.what());
    }
  } else {
    if (order) {
      throw args::ValidationError(
          "only the commander process can specify an order");
    }
    return {};
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movq %rdi, -0x108(%rbp)
movb %dl, %al
movq %rdi, %rcx
movq %rcx, -0x100(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
andb $0x1, %al
movb %al, -0x11(%rbp)
testb $0x1, -0x11(%rbp)
je 0x8822
movq -0x10(%rbp), %rdi
callq 0xcd40
testb $0x1, %al
jne 0x862e
movb $0x1, -0x4d(%rbp)
movl $0x10, %edi
callq 0x6240
movq %rax, -0x118(%rbp)
leaq -0x39(%rbp), %rdi
movq %rdi, -0x110(%rbp)
callq 0x6760
movq -0x110(%rbp), %rdx
leaq 0x2e43a(%rip), %rsi     # 0x369e3
leaq -0x38(%rbp), %rdi
callq 0xc850
jmp 0x85b4
movq -0x118(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0xca20
jmp 0x85c6
movq -0x118(%rbp), %rdi
movb $0x0, -0x4d(%rbp)
leaq 0x49dc8(%rip), %rsi     # 0x523a0
leaq 0x4481(%rip), %rdx      # 0xca60
callq 0x6730
jmp 0x8941
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x860c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x6878
leaq -0x39(%rbp), %rdi
callq 0x6460
testb $0x1, -0x4d(%rbp)
jne 0x861d
jmp 0x8629
movq -0x118(%rbp), %rdi
callq 0x6300
jmp 0x8930
movq -0x10(%rbp), %rdi
callq 0xcd60
movq %rax, -0x120(%rbp)
jmp 0x8640
movq -0x120(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0x61d0
jmp 0x8652
leaq -0x98(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x61d0
jmp 0x8664
leaq -0x98(%rbp), %rdi
callq 0x24cd0
movl %eax, -0x124(%rbp)
jmp 0x8678
movq -0x108(%rbp), %rdi
movl -0x124(%rbp), %eax
movl %eax, -0x74(%rbp)
leaq -0x74(%rbp), %rsi
callq 0xcd80
jmp 0x8693
leaq -0x98(%rbp), %rdi
callq 0x6878
leaq -0x70(%rbp), %rdi
callq 0x6878
jmp 0x8920
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x86ea
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x86e1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x6878
leaq -0x70(%rbp), %rdi
callq 0x6878
movl -0x4c(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x8930
movq -0x48(%rbp), %rdi
movq %rdi, -0x150(%rbp)
callq 0x6510
movq %rax, %rsi
leaq -0xa8(%rbp), %rdi
movq %rdi, -0x148(%rbp)
callq 0xc9e0
movq -0x150(%rbp), %rdi
callq 0x61a0
movb $0x1, -0xca(%rbp)
movl $0x10, %edi
callq 0x6240
movq -0x148(%rbp), %rdi
movq %rax, -0x140(%rbp)
callq 0x6640
movq %rax, -0x138(%rbp)
leaq -0xc9(%rbp), %rdi
movq %rdi, -0x130(%rbp)
callq 0x6760
movq -0x138(%rbp), %rsi
movq -0x130(%rbp), %rdx
leaq -0xc8(%rbp), %rdi
callq 0xc850
jmp 0x8786
movq -0x140(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0xcb20
jmp 0x879b
movq -0x140(%rbp), %rdi
movb $0x0, -0xca(%rbp)
leaq 0x49c08(%rip), %rsi     # 0x523b8
leaq 0x43a9(%rip), %rdx      # 0xcb60
callq 0x6730
jmp 0x8941
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x87e7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x6878
leaq -0xc9(%rbp), %rdi
callq 0x6460
testb $0x1, -0xca(%rbp)
jne 0x87fe
jmp 0x880a
movq -0x140(%rbp), %rdi
callq 0x6300
leaq -0xa8(%rbp), %rdi
callq 0x6880
callq 0x66c0
jmp 0x881d
jmp 0x8930
movq -0x10(%rbp), %rdi
callq 0xcd40
testb $0x1, %al
jne 0x8834
jmp 0x8901
movb $0x1, -0xf2(%rbp)
movl $0x10, %edi
callq 0x6240
movq %rax, -0x160(%rbp)
leaq -0xf1(%rbp), %rdi
movq %rdi, -0x158(%rbp)
callq 0x6760
movq -0x158(%rbp), %rdx
leaq 0x2e19a(%rip), %rsi     # 0x36a07
leaq -0xf0(%rbp), %rdi
callq 0xc850
jmp 0x887b
movq -0x160(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0xcb20
jmp 0x8890
movq -0x160(%rbp), %rdi
movb $0x0, -0xf2(%rbp)
leaq 0x49b13(%rip), %rsi     # 0x523b8
leaq 0x42b4(%rip), %rdx      # 0xcb60
callq 0x6730
jmp 0x8941
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x88dc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x6878
leaq -0xf1(%rbp), %rdi
callq 0x6460
testb $0x1, -0xf2(%rbp)
jne 0x88f3
jmp 0x88ff
movq -0x160(%rbp), %rdi
callq 0x6300
jmp 0x8930
movq -0x108(%rbp), %rdi
xorl %esi, %esi
movl $0x8, %edx
callq 0x6270
movq -0x108(%rbp), %rdi
callq 0xcdb0
movq -0x100(%rbp), %rax
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x6750
movq %rax, %rdi
callq 0xca80
nopw %cs:(%rax,%rax)