// File: jliesch[P]ofxget/clap/src/cmdline.cc
// Function: CmdLine::parse(int, char**)
void CmdLine::parse(int argc, char* argv[])
{
  CmdArg*            cmd;
  CmdArgListIterator it;

  for (int i = 1; i < argc; i++)
    {
      char* arg = argv[i];
      bool found = false;
      for (it = _cmdList.begin(); (it != _cmdList.end())&& !found; it++)
	{
	  cmd = *it;
	  char cmdWord[512], cmdChar[512];
	  sprintf(cmdWord, "-%s", cmd->getKeyword());
	  sprintf(cmdChar, "-%c", cmd->getOptChar());
	  if (!strcmp(arg, cmdWord) || !strcmp(arg, cmdChar))
	    {
	      cmd->setFound();
	      if (!cmd->getValue(&i, argc, argv))
		{
		  cout << "Error: switch -" << cmd->getKeyword()
		       << " must take an argument" << endl;
		  usage();
		}
	      else
		{
		  cmd->setValFound();
		}
	      found = true;
	    }
	}
      if (!found)
	{
	  cout << "Warning: argument \"" << arg
	       << "\" looks strange, ignoring." << endl;
	}
    }
  
  for (it = _cmdList.begin(); it != _cmdList.end(); it++)
    {
      cmd = *it;
      if (!cmd->isOpt()) // i.e required
	if (!cmd->isFound())
	  {
	    cout << "Error: the switch -" << cmd->getKeyword()
		 << " must be supplied" << endl;
	    usage();
	  }
      
      if (cmd->isFound() && !cmd->isValOpt()) // i.e need value
	if (!cmd->isValFound())
	  {
	    cout << "Error: the switch -" << cmd->getKeyword()
		 << " must take a vlue" << endl;
	    usage();
	  }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x4b0, %rsp            # imm = 0x4B0
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x478(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x3ffa0
movl $0x1, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x3fd56
movq -0x478(%rbp), %rdi
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x38(%rbp)
movb $0x0, -0x39(%rbp)
callq 0x3ffc0
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x478(%rbp), %rdi
callq 0x40020
movq %rax, -0x50(%rbp)
leaq -0x28(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x3fff0
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x479(%rbp)
jne 0x3fba7
jmp 0x3fbb2
movb -0x39(%rbp), %al
xorb $-0x1, %al
movb %al, -0x479(%rbp)
movb -0x479(%rbp), %al
testb $0x1, %al
jne 0x3fbc1
jmp 0x3fd03
leaq -0x28(%rbp), %rdi
callq 0x40050
movq (%rax), %rax
movq %rax, -0x20(%rbp)
leaq -0x250(%rbp), %rax
movq %rax, -0x490(%rbp)
movq -0x20(%rbp), %rdi
callq 0x3b4e0
movq -0x490(%rbp), %rdi
movq %rax, %rdx
leaq 0x2ab53(%rip), %rsi     # 0x6a74c
movb $0x0, %al
callq 0x7980
leaq -0x450(%rbp), %rax
movq %rax, -0x488(%rbp)
movq -0x20(%rbp), %rdi
callq 0x3b4c0
movq -0x488(%rbp), %rdi
movsbl %al, %edx
leaq 0x2ab28(%rip), %rsi     # 0x6a750
movb $0x0, %al
callq 0x7980
movq -0x38(%rbp), %rdi
leaq -0x250(%rbp), %rsi
callq 0x7790
cmpl $0x0, %eax
je 0x3fc5d
movq -0x38(%rbp), %rdi
leaq -0x450(%rbp), %rsi
callq 0x7790
cmpl $0x0, %eax
jne 0x3fcea
movq -0x20(%rbp), %rdi
callq 0x3b5e0
movq -0x20(%rbp), %rdi
movl -0xc(%rbp), %edx
movq -0x18(%rbp), %rcx
movq (%rdi), %rax
leaq -0x2c(%rbp), %rsi
callq *0x10(%rax)
testb $0x1, %al
jne 0x3fcdd
movq 0x55302(%rip), %rdi     # 0x94f88
leaq 0x2aac7(%rip), %rsi     # 0x6a754
callq 0x7580
movq %rax, -0x498(%rbp)
movq -0x20(%rbp), %rdi
callq 0x3b4e0
movq -0x498(%rbp), %rdi
movq %rax, %rsi
callq 0x7580
movq %rax, %rdi
leaq 0x2aaa9(%rip), %rsi     # 0x6a764
callq 0x7580
movq %rax, %rdi
movq 0x552fe(%rip), %rsi     # 0x94fc8
callq 0x7970
movq -0x478(%rbp), %rdi
callq 0x3f7f0
jmp 0x3fce6
movq -0x20(%rbp), %rdi
callq 0x3b620
movb $0x1, -0x39(%rbp)
jmp 0x3fcec
leaq -0x28(%rbp), %rdi
xorl %esi, %esi
callq 0x40070
movq %rax, -0x458(%rbp)
jmp 0x3fb79
testb $0x1, -0x39(%rbp)
jne 0x3fd46
movq 0x55278(%rip), %rdi     # 0x94f88
leaq 0x2aa64(%rip), %rsi     # 0x6a77b
callq 0x7580
movq %rax, %rdi
movq -0x38(%rbp), %rsi
callq 0x7580
movq %rax, %rdi
leaq 0x2aa5d(%rip), %rsi     # 0x6a78f
callq 0x7580
movq %rax, %rdi
movq 0x55287(%rip), %rsi     # 0x94fc8
callq 0x7970
jmp 0x3fd48
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x3fb41
movq -0x478(%rbp), %rdi
callq 0x3ffc0
movq %rax, -0x460(%rbp)
movq -0x460(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x478(%rbp), %rdi
callq 0x40020
movq %rax, -0x468(%rbp)
leaq -0x28(%rbp), %rdi
leaq -0x468(%rbp), %rsi
callq 0x3fff0
testb $0x1, %al
jne 0x3fda0
jmp 0x3fec8
leaq -0x28(%rbp), %rdi
callq 0x40050
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
callq 0x3b580
testb $0x1, %al
jne 0x3fe28
movq -0x20(%rbp), %rdi
callq 0x3b600
testb $0x1, %al
jne 0x3fe26
movq 0x551b7(%rip), %rdi     # 0x94f88
leaq 0x2a9d2(%rip), %rsi     # 0x6a7aa
callq 0x7580
movq %rax, -0x4a0(%rbp)
movq -0x20(%rbp), %rdi
callq 0x3b4e0
movq -0x4a0(%rbp), %rdi
movq %rax, %rsi
callq 0x7580
movq %rax, %rdi
leaq 0x2a9b8(%rip), %rsi     # 0x6a7be
callq 0x7580
movq %rax, %rdi
movq 0x551b3(%rip), %rsi     # 0x94fc8
callq 0x7970
movq -0x478(%rbp), %rdi
callq 0x3f7f0
jmp 0x3fe28
movq -0x20(%rbp), %rdi
callq 0x3b600
testb $0x1, %al
jne 0x3fe37
jmp 0x3feaf
movq -0x20(%rbp), %rdi
callq 0x3b5a0
testb $0x1, %al
jne 0x3feaf
movq -0x20(%rbp), %rdi
callq 0x3b640
testb $0x1, %al
jne 0x3fead
movq 0x55130(%rip), %rdi     # 0x94f88
leaq 0x2a94b(%rip), %rsi     # 0x6a7aa
callq 0x7580
movq %rax, -0x4a8(%rbp)
movq -0x20(%rbp), %rdi
callq 0x3b4e0
movq -0x4a8(%rbp), %rdi
movq %rax, %rsi
callq 0x7580
movq %rax, %rdi
leaq 0x2a943(%rip), %rsi     # 0x6a7d0
callq 0x7580
movq %rax, %rdi
movq 0x5512c(%rip), %rsi     # 0x94fc8
callq 0x7970
movq -0x478(%rbp), %rdi
callq 0x3f7f0
jmp 0x3feaf
jmp 0x3feb1
leaq -0x28(%rbp), %rdi
xorl %esi, %esi
callq 0x40070
movq %rax, -0x470(%rbp)
jmp 0x3fd74
addq $0x4b0, %rsp            # imm = 0x4B0
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)