// File: tomfunkhouser[P]gaps/apps/img2pd/img2pd.cpp
// Function: ParseArgs(int, char**)
static int 
ParseArgs(int argc, char **argv)
{
  // Parse arguments
  argc--; argv++;
  while (argc > 0) {
    if ((*argv)[0] == '-') {
      if (!strcmp(*argv, "-v")) {
        print_verbose = 1;
      }
      else if (!strcmp(*argv, "-debug")) {
        print_debug = 1;
      }
      else if (!strcmp(*argv, "-list")) {
        argc--; argv++; input_list_filenames.Insert(*argv);
      }
      else if (!strcmp(*argv, "-image")) {
        argc--; argv++; input_image_filenames.Insert(*argv);
      }
      else if (!strcmp(*argv, "-directory")) {
        argc--; argv++; input_image_directories.Insert(*argv);
      }
      else {
        RNFail("Invalid program argument: %s", *argv);
        exit(1);
      }
      argv++; argc--;
    }
    else {
      if (strstr(*argv, ".pd")) output_pixel_database_filename = *argv;
      else if (strstr(*argv, ".png")) input_image_filenames.Insert(*argv);
      else if (strstr(*argv, ".PNG")) input_image_filenames.Insert(*argv);
      else if (strstr(*argv, ".jpeg")) input_image_filenames.Insert(*argv);
      else if (strstr(*argv, ".JPEG")) input_image_filenames.Insert(*argv);
      else if (strstr(*argv, ".jpg")) input_image_filenames.Insert(*argv);
      else if (strstr(*argv, ".JPG")) input_image_filenames.Insert(*argv);
      else if (strstr(*argv, ".txt")) input_list_filenames.Insert(*argv);
      else input_image_directories.Insert(*argv);
      argv++; argc--;
    }
  }

  // Check inputs
  RNBoolean input_found = FALSE;
  if (!input_image_filenames.IsEmpty()) input_found = TRUE;
  if (!input_list_filenames.IsEmpty()) input_found = TRUE;
  if (!input_image_directories.IsEmpty()) input_found = TRUE;
  
  // Check program arguments
  if (!output_pixel_database_filename || !input_found) {
    RNFail("Usage: img2pd output.pd [inputoptions].\n");
    return 0;
  }

  // Return OK status 
  return 1;
}

// Assembly:
subq $0x18, %rsp
movl %edi, 0x10(%rsp)
movq %rsi, 0x8(%rsp)
movl 0x10(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x10(%rsp)
movq 0x8(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x8(%rsp)
cmpl $0x0, 0x10(%rsp)
jle 0x6e00
movq 0x8(%rsp), %rax
movq (%rax), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x6c36
movq 0x8(%rsp), %rax
movq (%rax), %rdi
leaq 0x995bd(%rip), %rsi     # 0xa0091
callq 0x5550
cmpl $0x0, %eax
jne 0x6aed
movl $0x1, 0xb89b0(%rip)     # 0xbf498
jmp 0x6c18
movq 0x8(%rsp), %rax
movq (%rax), %rdi
leaq 0x99598(%rip), %rsi     # 0xa0094
callq 0x5550
cmpl $0x0, %eax
jne 0x6b15
movl $0x1, 0xb899c(%rip)     # 0xbf4ac
jmp 0x6c16
movq 0x8(%rsp), %rax
movq (%rax), %rdi
leaq 0x99577(%rip), %rsi     # 0xa009b
callq 0x5550
cmpl $0x0, %eax
jne 0x6b60
movl 0x10(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x10(%rsp)
movq 0x8(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rax
movq (%rax), %rsi
leaq 0xb8922(%rip), %rdi     # 0xbf478
callq 0x7200
jmp 0x6c14
movq 0x8(%rsp), %rax
movq (%rax), %rdi
leaq 0x99532(%rip), %rsi     # 0xa00a1
callq 0x5550
cmpl $0x0, %eax
jne 0x6ba8
movl 0x10(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x10(%rsp)
movq 0x8(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rax
movq (%rax), %rsi
leaq 0xb88c7(%rip), %rdi     # 0xbf468
callq 0x7200
jmp 0x6c12
movq 0x8(%rsp), %rax
movq (%rax), %rdi
leaq 0x994f1(%rip), %rsi     # 0xa00a8
callq 0x5550
cmpl $0x0, %eax
jne 0x6bf0
movl 0x10(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x10(%rsp)
movq 0x8(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rax
movq (%rax), %rsi
leaq 0xb889f(%rip), %rdi     # 0xbf488
callq 0x7200
jmp 0x6c10
movq 0x8(%rsp), %rax
movq (%rax), %rsi
leaq 0x994b4(%rip), %rdi     # 0xa00b3
movb $0x0, %al
callq 0x424c0
movl $0x1, %edi
callq 0x5470
jmp 0x6c12
jmp 0x6c14
jmp 0x6c16
jmp 0x6c18
movq 0x8(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x8(%rsp)
movl 0x10(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x10(%rsp)
jmp 0x6dfb
movq 0x8(%rsp), %rax
movq (%rax), %rdi
leaq 0x9948b(%rip), %rsi     # 0xa00d0
callq 0x50e0
cmpq $0x0, %rax
je 0x6c64
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq %rax, 0xb8841(%rip)     # 0xbf4a0
jmp 0x6de2
movq 0x8(%rsp), %rax
movq (%rax), %rdi
leaq 0x99461(%rip), %rsi     # 0xa00d4
callq 0x50e0
cmpq $0x0, %rax
je 0x6c97
movq 0x8(%rsp), %rax
movq (%rax), %rsi
leaq 0xb87db(%rip), %rdi     # 0xbf468
callq 0x7200
jmp 0x6de0
movq 0x8(%rsp), %rax
movq (%rax), %rdi
leaq 0x99433(%rip), %rsi     # 0xa00d9
callq 0x50e0
cmpq $0x0, %rax
je 0x6cca
movq 0x8(%rsp), %rax
movq (%rax), %rsi
leaq 0xb87a8(%rip), %rdi     # 0xbf468
callq 0x7200
jmp 0x6dde
movq 0x8(%rsp), %rax
movq (%rax), %rdi
leaq 0x99405(%rip), %rsi     # 0xa00de
callq 0x50e0
cmpq $0x0, %rax
je 0x6cfd
movq 0x8(%rsp), %rax
movq (%rax), %rsi
leaq 0xb8775(%rip), %rdi     # 0xbf468
callq 0x7200
jmp 0x6ddc
movq 0x8(%rsp), %rax
movq (%rax), %rdi
leaq 0x993d8(%rip), %rsi     # 0xa00e4
callq 0x50e0
cmpq $0x0, %rax
je 0x6d30
movq 0x8(%rsp), %rax
movq (%rax), %rsi
leaq 0xb8742(%rip), %rdi     # 0xbf468
callq 0x7200
jmp 0x6dda
movq 0x8(%rsp), %rax
movq (%rax), %rdi
leaq 0x993ab(%rip), %rsi     # 0xa00ea
callq 0x50e0
cmpq $0x0, %rax
je 0x6d60
movq 0x8(%rsp), %rax
movq (%rax), %rsi
leaq 0xb870f(%rip), %rdi     # 0xbf468
callq 0x7200
jmp 0x6dd8
movq 0x8(%rsp), %rax
movq (%rax), %rdi
leaq 0x99380(%rip), %rsi     # 0xa00ef
callq 0x50e0
cmpq $0x0, %rax
je 0x6d90
movq 0x8(%rsp), %rax
movq (%rax), %rsi
leaq 0xb86df(%rip), %rdi     # 0xbf468
callq 0x7200
jmp 0x6dd6
movq 0x8(%rsp), %rax
movq (%rax), %rdi
leaq 0x99355(%rip), %rsi     # 0xa00f4
callq 0x50e0
cmpq $0x0, %rax
je 0x6dc0
movq 0x8(%rsp), %rax
movq (%rax), %rsi
leaq 0xb86bf(%rip), %rdi     # 0xbf478
callq 0x7200
jmp 0x6dd4
movq 0x8(%rsp), %rax
movq (%rax), %rsi
leaq 0xb86b9(%rip), %rdi     # 0xbf488
callq 0x7200
jmp 0x6dd6
jmp 0x6dd8
jmp 0x6dda
jmp 0x6ddc
jmp 0x6dde
jmp 0x6de0
jmp 0x6de2
movq 0x8(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x8(%rsp)
movl 0x10(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x10(%rsp)
jmp 0x6aa6
movl $0x0, 0x4(%rsp)
leaq 0xb8659(%rip), %rdi     # 0xbf468
callq 0x7230
cmpl $0x0, %eax
jne 0x6e21
movl $0x1, 0x4(%rsp)
leaq 0xb8650(%rip), %rdi     # 0xbf478
callq 0x7230
cmpl $0x0, %eax
jne 0x6e3a
movl $0x1, 0x4(%rsp)
leaq 0xb8647(%rip), %rdi     # 0xbf488
callq 0x7230
cmpl $0x0, %eax
jne 0x6e53
movl $0x1, 0x4(%rsp)
cmpq $0x0, 0xb8645(%rip)     # 0xbf4a0
je 0x6e64
cmpl $0x0, 0x4(%rsp)
jne 0x6e7c
leaq 0x9928e(%rip), %rdi     # 0xa00f9
movb $0x0, %al
callq 0x424c0
movl $0x0, 0x14(%rsp)
jmp 0x6e84
movl $0x1, 0x14(%rsp)
movl 0x14(%rsp), %eax
addq $0x18, %rsp
retq
nopl (%rax)