// File: cpearce[P]OggIndex/src/Options.cpp
// Function: Options::DoParse(int, char**, char const**)
bool Options::DoParse(int argc, char** argv, const char** error) {

  for (ogg_int32_t argIndex=1; argIndex < argc; argIndex++) {
    const char* arg = argv[argIndex];

    if (strcmp(arg, "-v") == 0) {
      mVerifyIndex = true;
      continue;
    }

    if (strcmp(arg, "-d") == 0) {
      if (mDumpKeyPackets) {
        *error = "ERROR: You can't use -d and -k at the same time.";
        return false;
      }
      mDumpPackets = true;
      continue;
    }

    if (strcmp(arg, "-k") == 0) {
      if (mDumpPackets) {
        *error = "ERROR: You can't use -d and -k at the same time.";
        return false;
      }
      mDumpKeyPackets = true;
      continue;
    }

    if (strcmp(arg, "-p") == 0) {
      mDumpPages = true;
      continue;
    }

    if (strcmp(arg, "-m") == 0) {
      mDumpMerge = true;
      continue;
    }

    if (strcmp(arg, "-o") == 0) {
      if (argIndex+1 == argc || IsArgument(argv[argIndex+1])) {
        *error = "ERROR: You must specify an output filename with '-o' argument";
        return false;
      }
      mOutputFilename = argv[argIndex+1];
      argIndex++;
      continue;
    }
    
    if (strcmp(arg, "-i") == 0) {
      ogg_int32_t interval = 0;
      if (argIndex+1 == argc || IsArgument(argv[argIndex+1]) ||  (interval = atoi(argv[argIndex+1])) == 0) {
        *error = "ERROR: You must specify an integer interval in ms with '-i' argument";
        return false;
      }
      mKeyPointInterval = interval;
      argIndex++;
      continue;
    }

    if (!mInputFilename.empty()) {
      *error = "ERROR: You cannot specify more than one input file";
      return false;
    }

    // Assume argument is input filename.
    if (!FileExists(argv[argIndex])) {
      *error = "ERROR: Input file does not exist";
      return false;
    }

    mInputFilename = argv[argIndex];
  }

  if (mOutputFilename.empty()) {
    // No output filename specified, use input.indexed.extension.
    mOutputFilename = OutputFilename(mInputFilename);
  }

  if (mInputFilename.compare(mOutputFilename) == 0) {
    *error = "ERROR: output filename must be different from the input filename";
    return false;
  }

  if (mInputFilename.empty()) {
    *error = "ERROR: specify input filename";
    return false;
  }

  return true;
}

// Assembly:
subq $0xa8, %rsp
movq %rdi, 0x98(%rsp)
movl %esi, 0x94(%rsp)
movq %rdx, 0x88(%rsp)
movq %rcx, 0x80(%rsp)
movq 0x98(%rsp), %rax
movq %rax, 0x10(%rsp)
movl $0x1, 0x7c(%rsp)
movl 0x7c(%rsp), %eax
cmpl 0x94(%rsp), %eax
jge 0x10fff
movq 0x88(%rsp), %rax
movslq 0x7c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x70(%rsp)
movq 0x70(%rsp), %rdi
leaq 0xd12f(%rip), %rsi      # 0x1de4d
callq 0x55c0
cmpl $0x0, %eax
jne 0x10d36
movq 0x10(%rsp), %rax
movb $0x1, 0x4(%rax)
jmp 0x10fef
movq 0x70(%rsp), %rdi
leaq 0xd10e(%rip), %rsi      # 0x1de50
callq 0x55c0
cmpl $0x0, %eax
jne 0x10d83
movq 0x10(%rsp), %rax
testb $0x1, 0x1(%rax)
je 0x10d76
movq 0x80(%rsp), %rax
leaq 0xd0ed(%rip), %rcx      # 0x1de53
movq %rcx, (%rax)
movb $0x0, 0xa7(%rsp)
jmp 0x110ed
movq 0x10(%rsp), %rax
movb $0x1, (%rax)
jmp 0x10fef
movq 0x70(%rsp), %rdi
leaq 0xd0f5(%rip), %rsi      # 0x1de84
callq 0x55c0
cmpl $0x0, %eax
jne 0x10dd0
movq 0x10(%rsp), %rax
testb $0x1, (%rax)
je 0x10dc2
movq 0x80(%rsp), %rax
leaq 0xd0a1(%rip), %rcx      # 0x1de53
movq %rcx, (%rax)
movb $0x0, 0xa7(%rsp)
jmp 0x110ed
movq 0x10(%rsp), %rax
movb $0x1, 0x1(%rax)
jmp 0x10fef
movq 0x70(%rsp), %rdi
leaq 0xd0ab(%rip), %rsi      # 0x1de87
callq 0x55c0
cmpl $0x0, %eax
jne 0x10df4
movq 0x10(%rsp), %rax
movb $0x1, 0x2(%rax)
jmp 0x10fef
movq 0x70(%rsp), %rdi
leaq 0xd08a(%rip), %rsi      # 0x1de8a
callq 0x55c0
cmpl $0x0, %eax
jne 0x10e18
movq 0x10(%rsp), %rax
movb $0x1, 0x3(%rax)
jmp 0x10fef
movq 0x70(%rsp), %rdi
leaq 0xd069(%rip), %rsi      # 0x1de8d
callq 0x55c0
cmpl $0x0, %eax
jne 0x10eb6
movl 0x7c(%rsp), %eax
addl $0x1, %eax
cmpl 0x94(%rsp), %eax
je 0x10e63
movq 0x88(%rsp), %rax
movl 0x7c(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x11110
testb $0x1, %al
jne 0x10e63
jmp 0x10e82
movq 0x80(%rsp), %rax
leaq 0xd01e(%rip), %rcx      # 0x1de90
movq %rcx, (%rax)
movb $0x0, 0xa7(%rsp)
jmp 0x110ed
movq 0x10(%rsp), %rdi
movq 0x88(%rsp), %rax
movl 0x7c(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rsi
addq $0x28, %rdi
callq 0x5580
movl 0x7c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x7c(%rsp)
jmp 0x10fef
movq 0x70(%rsp), %rdi
leaq 0xd00c(%rip), %rsi      # 0x1dece
callq 0x55c0
cmpl $0x0, %eax
jne 0x10f66
movl $0x0, 0x6c(%rsp)
movl 0x7c(%rsp), %eax
addl $0x1, %eax
cmpl 0x94(%rsp), %eax
je 0x10f2b
movq 0x88(%rsp), %rax
movl 0x7c(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x11110
testb $0x1, %al
jne 0x10f2b
movq 0x88(%rsp), %rax
movl 0x7c(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x56a0
movl %eax, 0x6c(%rsp)
cmpl $0x0, %eax
jne 0x10f4a
movq 0x80(%rsp), %rax
leaq 0xcf97(%rip), %rcx      # 0x1ded1
movq %rcx, (%rax)
movb $0x0, 0xa7(%rsp)
jmp 0x110ed
movq 0x10(%rsp), %rax
movl 0x6c(%rsp), %ecx
movl %ecx, 0x48(%rax)
movl 0x7c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x7c(%rsp)
jmp 0x10fef
movq 0x10(%rsp), %rdi
addq $0x8, %rdi
callq 0x5730
testb $0x1, %al
jne 0x10f97
movq 0x80(%rsp), %rax
leaq 0xcf8f(%rip), %rcx      # 0x1df16
movq %rcx, (%rax)
movb $0x0, 0xa7(%rsp)
jmp 0x110ed
movq 0x88(%rsp), %rax
movslq 0x7c(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x11200
testb $0x1, %al
jne 0x10fd0
movq 0x80(%rsp), %rax
leaq 0xcf89(%rip), %rcx      # 0x1df49
movq %rcx, (%rax)
movb $0x0, 0xa7(%rsp)
jmp 0x110ed
movq 0x10(%rsp), %rdi
movq 0x88(%rsp), %rax
movslq 0x7c(%rsp), %rcx
movq (%rax,%rcx,8), %rsi
addq $0x8, %rdi
callq 0x5580
movl 0x7c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x7c(%rsp)
jmp 0x10ceb
movq 0x10(%rsp), %rdi
addq $0x28, %rdi
callq 0x5730
testb $0x1, %al
jne 0x11013
jmp 0x1107f
movq 0x10(%rsp), %rsi
addq $0x8, %rsi
leaq 0x28(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x5190
movq 0x8(%rsp), %rsi
leaq 0x48(%rsp), %rdi
callq 0x11230
jmp 0x1103c
movq 0x10(%rsp), %rdi
addq $0x28, %rdi
leaq 0x48(%rsp), %rsi
callq 0x54e0
leaq 0x48(%rsp), %rdi
callq 0x5260
leaq 0x28(%rsp), %rdi
callq 0x5260
jmp 0x1107f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x20(%rsp)
movl %eax, 0x1c(%rsp)
leaq 0x28(%rsp), %rdi
callq 0x5260
jmp 0x110fe
movq 0x10(%rsp), %rsi
movq %rsi, %rdi
addq $0x8, %rdi
addq $0x28, %rsi
callq 0x5040
cmpl $0x0, %eax
jne 0x110b5
movq 0x80(%rsp), %rax
leaq 0xcec2(%rip), %rcx      # 0x1df6a
movq %rcx, (%rax)
movb $0x0, 0xa7(%rsp)
jmp 0x110ed
movq 0x10(%rsp), %rdi
addq $0x8, %rdi
callq 0x5730
testb $0x1, %al
jne 0x110c9
jmp 0x110e5
movq 0x80(%rsp), %rax
leaq 0xced3(%rip), %rcx      # 0x1dfab
movq %rcx, (%rax)
movb $0x0, 0xa7(%rsp)
jmp 0x110ed
movb $0x1, 0xa7(%rsp)
movb 0xa7(%rsp), %al
andb $0x1, %al
addq $0xa8, %rsp
retq
movq 0x20(%rsp), %rdi
callq 0x57d0
nopl (%rax,%rax)