// File: matthewarcus[P]mmps/utils.cpp
// Function: CmdSpec::ReadOpt(int&, char**&)
int CmdSpec::ReadOpt(int &argc, char** &argv) {
  if (strcmp(argv[0], optstring) != 0) {
    return 0;
  } else {
    vector<string>cmd;
    // Skip the initial '-'
    assert(*argv[0] == '-');
    cmd.push_back(argv[0]+1);
    for (int i = 0; i < nargs; i++){
      argc--;argv++;
      if (argc == 0) {
	fprintf(stderr,"Need %d parameter for %s\n", nargs, optstring);
	return -1;
      } else {
	cmd.push_back(argv[0]);
      }
    }
    cmdlist.push_back(cmd);
    return 1;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x20(%rbp), %rcx
movq (%rcx), %rcx
movq (%rcx), %rdi
movq 0x8(%rax), %rsi
callq 0x5350
cmpl $0x0, %eax
je 0x10456
movl $0x0, -0x4(%rbp)
jmp 0x1068c
leaq -0x38(%rbp), %rdi
callq 0x10730
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x10473
jmp 0x10492
leaq 0x53c6(%rip), %rdi      # 0x15840
leaq 0x53cf(%rip), %rsi      # 0x15850
movl $0x80, %edx
leaq 0x53cd(%rip), %rcx      # 0x1585a
callq 0x5190
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rax
incq %rax
movq %rax, -0xb8(%rbp)
leaq -0x59(%rbp), %rdi
movq %rdi, -0xb0(%rbp)
callq 0x5430
movq -0xb8(%rbp), %rsi
movq -0xb0(%rbp), %rdx
leaq -0x58(%rbp), %rdi
callq 0x10780
jmp 0x104cf
leaq -0x38(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x10750
jmp 0x104de
leaq -0x58(%rbp), %rdi
callq 0x5180
leaq -0x59(%rbp), %rdi
callq 0x52e0
movl $0x0, -0x70(%rbp)
movq -0xa8(%rbp), %rcx
movl -0x70(%rbp), %eax
cmpl 0x10(%rcx), %eax
jge 0x10646
movq -0x18(%rbp), %rax
movl (%rax), %ecx
addl $-0x1, %ecx
movl %ecx, (%rax)
movq -0x20(%rbp), %rax
movq (%rax), %rcx
addq $0x8, %rcx
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x10596
movq -0xa8(%rbp), %rax
movq 0xcaa6(%rip), %rcx      # 0x1cfe0
movq (%rcx), %rdi
movl 0x10(%rax), %edx
movq 0x8(%rax), %rcx
leaq 0x533d(%rip), %rsi      # 0x15888
movb $0x0, %al
callq 0x5370
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x74(%rbp)
jmp 0x10676
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x10588
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x5180
leaq -0x59(%rbp), %rdi
callq 0x52e0
jmp 0x10681
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq %rax, -0xc8(%rbp)
leaq -0x99(%rbp), %rdi
movq %rdi, -0xc0(%rbp)
callq 0x5430
movq -0xc8(%rbp), %rsi
movq -0xc0(%rbp), %rdx
leaq -0x98(%rbp), %rdi
callq 0x10780
jmp 0x105d6
leaq -0x38(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x10750
jmp 0x105e8
leaq -0x98(%rbp), %rdi
callq 0x5180
leaq -0x99(%rbp), %rdi
callq 0x52e0
jmp 0x10636
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x10628
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x5180
leaq -0x99(%rbp), %rdi
callq 0x52e0
jmp 0x10681
jmp 0x10638
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0x104f7
leaq 0xccc3(%rip), %rdi      # 0x1d310
leaq -0x38(%rbp), %rsi
callq 0x10830
jmp 0x10658
movl $0x1, -0x4(%rbp)
movl $0x1, -0x74(%rbp)
jmp 0x10676
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x10681
leaq -0x38(%rbp), %rdi
callq 0x108a0
jmp 0x1068c
leaq -0x38(%rbp), %rdi
callq 0x108a0
jmp 0x10698
movl -0x4(%rbp), %eax
addq $0xd0, %rsp
popq %rbp
retq
movq -0x68(%rbp), %rdi
callq 0x5420
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)