// File: /workspace/github_c_makefile_star2_O3/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)
cmpl $0x2, %edi
jl 0xd214
movq %rsi, %r14
movl %edi, %ebp
leaq 0x8(%r14), %rax
movq %rax, 0x10(%rsp)
movq 0x8(%r14), %r15
movq %r15, %rdi
callq 0x4280
movq %rax, %r12
leaq 0x1e63(%rip), %r13      # 0xee70
xorl %ebx, %ebx
movslq (%r13), %rsi
leaq 0x1e56(%rip), %rax      # 0xee70
addq %rax, %rsi
movq %r15, %rdi
movq %r12, %rdx
callq 0x4180
testl %eax, %eax
je 0xd068
incq %rbx
addq $0x4, %r13
cmpq $0x10, %rbx
jne 0xd00f
decl %ebp
movl %ebp, %r15d
movq 0x10(%rsp), %r12
leaq 0x7536(%rip), %rax      # 0x14580
movq (%rax), %rax
movl $0x1, 0x144(%rax)
movl %r15d, %ebp
movq %r12, %r14
cmpl $0x1, %r15d
jg 0xcfee
jmp 0xd214
addq $0x10, %r14
cmpq $0x7, %rbx
movq 0x10(%rsp), %r12
cmovbq %r14, %r12
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
sbbl $0x0, %r15d
addl %ebp, %r15d
decl %ebx
cmpl $0x10, %ebx
ja 0xd057
leaq 0x1d98(%rip), %rcx      # 0xee2c
movslq (%rcx,%rbx,4), %rax
addq %rcx, %rax
jmpq *%rax
movq (%r14), %rdi
callq 0xcf81
leaq 0x74d4(%rip), %rcx      # 0x14580
movq (%rcx), %rcx
movl %eax, (%rcx)
jmp 0xd057
leaq 0x74c6(%rip), %rax      # 0x14580
movq (%rax), %rax
movl $0x0, 0x140(%rax)
jmp 0xd057
leaq 0x74b0(%rip), %rax      # 0x14580
movq (%rax), %rax
movl $0x1, 0x50(%rax)
jmp 0xd057
leaq 0x749a(%rip), %rax      # 0x14580
movq (%rax), %rax
movl $0x1, 0x48(%rax)
jmp 0xd057
movq (%r14), %rdi
callq 0xcf81
leaq 0x747c(%rip), %rcx      # 0x14580
movq (%rcx), %rcx
movl %eax, 0xc(%rcx)
jmp 0xd057
leaq 0x746a(%rip), %rax      # 0x14580
movq (%rax), %rax
movl $0x0, 0x3c(%rax)
jmp 0xd057
leaq 0x7454(%rip), %rax      # 0x14580
movq (%rax), %rax
movl $0x1, 0x4c(%rax)
jmp 0xd057
movq (%r14), %rdi
callq 0xcf81
leaq 0x7436(%rip), %rcx      # 0x14580
movq (%rcx), %rcx
movl %eax, 0x8(%rcx)
jmp 0xd057
movq (%r14), %rdi
callq 0xcf81
leaq 0x741c(%rip), %rcx      # 0x14580
movq (%rcx), %rcx
movl %eax, 0x14(%rcx)
jmp 0xd057
leaq 0x740a(%rip), %rax      # 0x14580
movq (%rax), %rax
movl $0x0, 0x34(%rax)
jmp 0xd057
movq (%r14), %rdi
callq 0xcf81
leaq 0x73ec(%rip), %rcx      # 0x14580
movq (%rcx), %rcx
movl %eax, 0x4(%rcx)
jmp 0xd057
movq (%r14), %rdi
callq 0xcf81
leaq 0x73d2(%rip), %rcx      # 0x14580
movq (%rcx), %rcx
movl %eax, 0x10(%rcx)
jmp 0xd057
leaq 0x73c0(%rip), %rax      # 0x14580
movq (%rax), %rax
movl $0x1, 0x13c(%rax)
jmp 0xd057
leaq 0x73a7(%rip), %rax      # 0x14580
movq (%rax), %rax
movl $0x1, 0x30(%rax)
jmp 0xd057
leaq 0x7391(%rip), %rax      # 0x14580
movq (%rax), %rax
movl $0x1, 0x44(%rax)
jmp 0xd057
leaq 0x737b(%rip), %rax      # 0x14580
movq (%rax), %rax
movl $0x1, 0x40(%rax)
jmp 0xd057
leaq 0x7365(%rip), %rbx      # 0x14580
movq (%rbx), %rax
cmpl $0x0, 0x40(%rax)
jne 0xd234
cmpl $0x0, 0x48(%rax)
jne 0xd234
cmpl $0x0, 0x44(%rax)
je 0xd354
xorl %ebp, %ebp
cmpl $0x0, 0x3c(%rax)
je 0xd2a0
leaq 0x1d15(%rip), %rdi      # 0xef58
callq 0xcec8
movq (%rbx), %rax
cmpl $0x0, 0x40(%rax)
je 0xd260
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
xorl %eax, %eax
callq 0xd41d
movq (%rbx), %rax
cmpl $0x0, 0x44(%rax)
je 0xd27e
leaq 0x1cf7(%rip), %rdi      # 0xef64
leaq 0x1cff(%rip), %rsi      # 0xef73
xorl %eax, %eax
callq 0x4050
movq (%rbx), %rax
cmpl $0x0, 0x48(%rax)
je 0xd2a0
leaq 0x1d05(%rip), %rdi      # 0xef90
callq 0xcec8
testl %eax, %eax
je 0xd2a0
leaq 0x1d01(%rip), %rdi      # 0xef9c
callq 0x40c0
testb %bpl, %bpl
je 0xd35c
cmpl $0x0, 0xc(%rsp)
je 0xd345
movq (%rbx), %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 0xd363
movl 0x10(%rax), %edx
cmpl $-0x1, %edx
jne 0xd2dc
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 0xd33d
cmpl $0x5, (%rax)
jg 0xd33d
xorl %esi, %esi
cmpl %ecx, %edx
je 0xd342
movl $0x1, %esi
movl %esi, 0x38(%rax)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x1, %bpl
jmp 0xd236
xorl %edi, %edi
callq 0x4110
leaq 0x1c58(%rip), %rdi      # 0xefc2
callq 0x40c0
movl $0x1, %edi
callq 0x4110
nopl (%rax)