// File: /workspace/github_c_makefile_star2_O2/jrrk[P]cbzone/c_parseopts.c
// Function: parseopt
void parseopt(argc, argv, status)
     int argc;
     char* argv[];
     Bool status;
{
  int i;
  Bool early_exit = False;

  static char* optionnames[] = {
    "-xrm", "-delay", "-blocks", "-landers", "-tanks", "-missiles",
    "-salvos", "-coptersonly", "-quiet", "-scores", "-original",
    "-version", "-help", "-nooutput", "-mono", "-cursor",
    "-defaultcolormap", "-nofullscreen"};

#ifdef WIN32
  // Eric Fogelin: Fixed options (original game, in mono color, quiet)
  opt->mono = True;
  opt->loud = False;

  opt->mblocks = 8;
  opt->mlanders = 1;
  opt->mtanks = 1;
  opt->practice = True;

#else //X11
  for (argc--, argv++; argc>0; argc--, argv++) {
    for (i=0; i<MAXOPTIONS; i++)
      if (!strncmp(*argv,optionnames[i],strlen(*argv)))
        break;
    if (i < OPTIONINT) {
      argc--; argv++;
    }
    switch(i) {
    case 0:                     /* xrm */
      break;
    case 1:                     /* delay */
      opt->delay = getoptionint(*argv);
      break;
    case 2:                     /* blocks*/
      opt->mblocks = getoptionint(*argv);
      break;
    case 3:                     /* landers */
      opt->mlanders = getoptionint(*argv);
      break;
    case 4:                     /* tanks */
      opt->mtanks = getoptionint(*argv);
      break;
    case 5:                     /* missiles */
      opt->mmissiles = getoptionint(*argv);
      break;
    case 6:                     /* salvos */
      opt->msalvos = getoptionint(*argv);
      break;
    case 7:                     /* copter practice */
      opt->copters = True;
      break;
    case 8:                     /* quiet mode */
      opt->loud = False;
      break;
    case 9:                     /* scores only */
      opt->scores = True;
      break;
    case 10:                    /* original */
      opt->original = True;
      break;
    case 11:                    /* version */
      opt->version = True;
      break;
    case 12:                    /* help */
      opt->help = True;
      break;
    case 13:                    /* nooutput */
      opt->output = False;
      break;
    case 14:                    /* monocolor */
      opt->mono = True;
      break;
    case 15:                    /* cursor */
      opt->cursor = True;
      break;
    case 16:                    /* default colormap */
      opt->defaultcolormap = True;
      break;
    case 17:                    /* fullscreen */
      opt->fullscreen = False;
      break;
    }
  }
#endif //X11

  if (opt->scores || opt->help || opt->version)
    early_exit = True;

  if (opt->output) {
    pager("cbzone.motd");

    if (opt->scores)
      scores(-1);

    if (opt->version)
      printf("\nVersion \"%s\"\n", VERSION);

    if (opt->help && pager("cbzone.help"))
      printf("Sorry help information not available.\n");
  }

  if (early_exit)
#ifdef WIN32
     return;
#else //X11
    exit(0);
#endif

  if (!status)
    return;

#if 0 // Eric Fogelin: Allow copters and tanks
  if (opt->copters)
    opt->mtanks = 0;

  if (opt->original) {
    opt->mblocks = 8;
    opt->copters = False;
    opt->mlanders = 1;
    opt->mmissiles = 1;
    opt->mtanks = 1;
    opt->practice = True;
    opt->msalvos = 1;
  }
#endif

  opt->menemies = (opt->mtanks > opt->mmissiles ?
                   opt->mtanks : opt->mmissiles);
  if (!opt->menemies) {
    printf("Must have at least one missile or tank.\n");
#ifdef WIN32
     return;
#else //X11
     exit(1);
#endif
  }

  if (opt->msalvos == -1)
    opt->msalvos = opt->menemies;
  opt->mobjects = opt->mblocks + opt->mlanders + 2*opt->menemies +
    opt->msalvos + 1;
  opt->estart = 1;
  opt->lstart = opt->estart + opt->menemies;
  opt->sstart = opt->lstart + opt->mlanders;
  opt->bstart = opt->sstart + opt->menemies + opt->msalvos;

  if (opt->mmissiles == MMISSILES &&
      opt->mtanks == MTANKS &&
      opt->mlanders == MLANDERS &&
      opt->mblocks == MBLOCKS &&
      opt->delay <= DELAY &&
      opt->msalvos == opt->menemies)
    opt->practice = False;
  else
    opt->practice = True;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, 0xc(%rsp)
movl %edi, %ebx
leaq 0x1c8f(%rip), %r13      # 0xde30
leaq 0x73e8(%rip), %r15      # 0x13590
cmpl $0x2, %ebx
jl 0xc38d
movl %ebx, 0x8(%rsp)
movq %rsi, 0x10(%rsp)
leaq 0x8(%rsi), %rax
movq %rax, %r14
movq (%rax), %r15
movq %r15, %rdi
callq 0x4280
movq %rax, %r12
movq %r13, %rbx
xorl %ebp, %ebp
cmpq $0x10, %rbp
je 0xc1f8
movslq (%rbx), %rsi
addq %r13, %rsi
movq %r15, %rdi
movq %r12, %rdx
callq 0x4180
testl %eax, %eax
je 0xc217
incq %rbp
addq $0x4, %rbx
jmp 0xc1d4
movl 0x8(%rsp), %ebx
decl %ebx
leaq 0x738b(%rip), %r15      # 0x13590
movq (%r15), %rax
movl $0x1, 0x144(%rax)
movq %r14, %rsi
jmp 0xc1a8
movq 0x10(%rsp), %rax
addq $0x10, %rax
cmpq $0x7, %rbp
cmovbq %rax, %r14
pushq $-0x1
popq %rcx
sbbl $0x0, %ecx
movl 0x8(%rsp), %ebx
addl %ecx, %ebx
decl %ebp
movq %r14, %rsi
cmpl $0x10, %ebp
leaq 0x734d(%rip), %r15      # 0x13590
ja 0xc1a8
leaq 0x1b9c(%rip), %rdx      # 0xddec
movslq (%rdx,%rbp,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movq (%rax), %rdi
callq 0xc139
movq (%r15), %rcx
movl %eax, (%rcx)
movq %r14, %rsi
jmp 0xc1a8
movq (%r15), %rax
andl $0x0, 0x140(%rax)
movq %r14, %rsi
jmp 0xc1a8
movq (%r15), %rax
movl $0x1, 0x13c(%rax)
movq %r14, %rsi
jmp 0xc1a8
movq (%r15), %rax
movl $0x1, 0x44(%rax)
movq %r14, %rsi
jmp 0xc1a8
movq (%rax), %rdi
callq 0xc139
movq (%r15), %rcx
movl %eax, 0x14(%rcx)
movq %r14, %rsi
jmp 0xc1a8
movq (%r15), %rax
movl $0x1, 0x48(%rax)
movq %r14, %rsi
jmp 0xc1a8
movq (%r15), %rax
movl $0x1, 0x40(%rax)
movq %r14, %rsi
jmp 0xc1a8
movq (%rax), %rdi
callq 0xc139
movq (%r15), %rcx
movl %eax, 0x4(%rcx)
movq %r14, %rsi
jmp 0xc1a8
movq (%r15), %rax
movl $0x1, 0x50(%rax)
movq %r14, %rsi
jmp 0xc1a8
movq (%rax), %rdi
callq 0xc139
movq (%r15), %rcx
movl %eax, 0x8(%rcx)
movq %r14, %rsi
jmp 0xc1a8
movq (%r15), %rax
movl $0x1, 0x30(%rax)
movq %r14, %rsi
jmp 0xc1a8
movq (%rax), %rdi
callq 0xc139
movq (%r15), %rcx
movl %eax, 0xc(%rcx)
movq %r14, %rsi
jmp 0xc1a8
movq (%r15), %rax
andl $0x0, 0x3c(%rax)
movq %r14, %rsi
jmp 0xc1a8
movq (%rax), %rdi
callq 0xc139
movq (%r15), %rcx
movl %eax, 0x10(%rcx)
movq %r14, %rsi
jmp 0xc1a8
movq (%r15), %rax
movl $0x1, 0x4c(%rax)
movq %r14, %rsi
jmp 0xc1a8
movq (%r15), %rax
andl $0x0, 0x34(%rax)
movq %r14, %rsi
jmp 0xc1a8
movq (%r15), %rax
cmpl $0x0, 0x40(%rax)
jne 0xc3a6
cmpl $0x0, 0x48(%rax)
jne 0xc3a6
cmpl $0x0, 0x44(%rax)
je 0xc4c1
xorl %ebx, %ebx
cmpl $0x0, 0x3c(%rax)
je 0xc410
leaq 0x1b63(%rip), %rdi      # 0xdf18
callq 0xc050
movq (%r15), %rax
cmpl $0x0, 0x40(%rax)
je 0xc3d0
pushq $-0x1
popq %rdi
xorl %eax, %eax
callq 0xc548
movq (%r15), %rax
cmpl $0x0, 0x44(%rax)
je 0xc3ee
leaq 0x1b47(%rip), %rdi      # 0xdf24
leaq 0x1b4f(%rip), %rsi      # 0xdf33
xorl %eax, %eax
callq 0x4050
movq (%r15), %rax
cmpl $0x0, 0x48(%rax)
je 0xc410
leaq 0x1b55(%rip), %rdi      # 0xdf50
callq 0xc050
testl %eax, %eax
je 0xc410
leaq 0x1b51(%rip), %rdi      # 0xdf5c
callq 0x40c0
testb %bl, %bl
je 0xc4c8
cmpl $0x0, 0xc(%rsp)
je 0xc4b2
movq (%r15), %rax
movl 0xc(%rax), %edi
movl 0x14(%rax), %esi
cmpl %edi, %esi
movl %edi, %ecx
cmovgl %esi, %ecx
movl %ecx, 0x18(%rax)
testl %ecx, %ecx
je 0xc4cf
movl 0x10(%rax), %edx
cmpl $-0x1, %edx
jne 0xc44b
movl %ecx, 0x10(%rax)
movl %ecx, %edx
movl 0x4(%rax), %r8d
movl 0x8(%rax), %r9d
leal (%r8,%rcx,2), %r10d
addl %r9d, %r10d
addl %edx, %r10d
incl %r10d
movl %r10d, 0x1c(%rax)
movl $0x1, 0x20(%rax)
leal 0x1(%rcx), %r10d
movl %r10d, 0x24(%rax)
leal (%r9,%rcx), %r10d
incl %r10d
movl %r10d, 0x28(%rax)
leal (%rcx,%rdx), %r11d
addl %r10d, %r11d
movl %r11d, 0x2c(%rax)
xorl $0x1, %edi
xorl $0x1, %esi
orl %edi, %esi
xorl $0x4, %r9d
orl %esi, %r9d
xorl $0x8, %r8d
orl %r9d, %r8d
jne 0xc4ac
cmpl $0x5, (%rax)
jg 0xc4ac
xorl %esi, %esi
cmpl %ecx, %edx
je 0xc4af
pushq $0x1
popq %rsi
movl %esi, 0x38(%rax)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x1, %bl
jmp 0xc3a8
xorl %edi, %edi
callq 0x4110
leaq 0x1aac(%rip), %rdi      # 0xdf82
callq 0x40c0
pushq $0x1
popq %rdi
callq 0x4110
nop