// File: /workspace/github_c_makefile_star2_O1/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, 0x8(%rsp)
cmpl $0x2, %edi
jl 0xd1cf
movq %rsi, %r14
leaq 0x1d59(%rip), %rbp      # 0xed18
movl %edi, 0xc(%rsp)
leaq 0x8(%r14), %rax
movq %rax, 0x10(%rsp)
movq 0x8(%r14), %r15
movq %r15, %rdi
callq 0x4280
movq %rax, %r12
movq %rbp, %r13
xorl %ebx, %ebx
movslq (%r13), %rsi
addq %rbp, %rsi
movq %r15, %rdi
movq %r12, %rdx
callq 0x4180
testl %eax, %eax
je 0xd008
incq %rbx
addq $0x4, %r13
cmpq $0x10, %rbx
jne 0xcfe0
movl $0x10, %ebx
addq $0x10, %r14
cmpl $0x7, %ebx
movq 0x10(%rsp), %rax
cmovbq %r14, %rax
movq %rax, %r14
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
sbbl $0x0, %r15d
decl %ebx
cmpl $0x10, %ebx
ja 0xd1bf
leaq 0x1c9d(%rip), %rcx      # 0xecd4
movslq (%rcx,%rbx,4), %rax
addq %rcx, %rax
jmpq *%rax
movq (%r14), %rdi
callq 0xcf4d
leaq 0x7541(%rip), %rcx      # 0x14590
movq (%rcx), %rcx
movl %eax, (%rcx)
jmp 0xd1bf
leaq 0x7530(%rip), %rax      # 0x14590
movq (%rax), %rax
movl $0x0, 0x140(%rax)
jmp 0xd1bf
leaq 0x7517(%rip), %rax      # 0x14590
movq (%rax), %rax
movl $0x1, 0x50(%rax)
jmp 0xd1bf
leaq 0x7501(%rip), %rax      # 0x14590
movq (%rax), %rax
movl $0x1, 0x48(%rax)
jmp 0xd1bf
movq (%r14), %rdi
callq 0xcf4d
leaq 0x74e3(%rip), %rcx      # 0x14590
movq (%rcx), %rcx
movl %eax, 0xc(%rcx)
jmp 0xd1bf
leaq 0x74d1(%rip), %rax      # 0x14590
movq (%rax), %rax
movl $0x0, 0x3c(%rax)
jmp 0xd1bf
leaq 0x74bb(%rip), %rax      # 0x14590
movq (%rax), %rax
movl $0x1, 0x4c(%rax)
jmp 0xd1bf
movq (%r14), %rdi
callq 0xcf4d
leaq 0x749d(%rip), %rcx      # 0x14590
movq (%rcx), %rcx
movl %eax, 0x8(%rcx)
jmp 0xd1bf
leaq 0x748b(%rip), %rax      # 0x14590
movq (%rax), %rax
movl $0x1, 0x144(%rax)
jmp 0xd1bf
movq (%r14), %rdi
callq 0xcf4d
leaq 0x746a(%rip), %rcx      # 0x14590
movq (%rcx), %rcx
movl %eax, 0x14(%rcx)
jmp 0xd1bf
leaq 0x7458(%rip), %rax      # 0x14590
movq (%rax), %rax
movl $0x0, 0x34(%rax)
jmp 0xd1bf
movq (%r14), %rdi
callq 0xcf4d
leaq 0x743d(%rip), %rcx      # 0x14590
movq (%rcx), %rcx
movl %eax, 0x4(%rcx)
jmp 0xd1bf
movq (%r14), %rdi
callq 0xcf4d
leaq 0x7426(%rip), %rcx      # 0x14590
movq (%rcx), %rcx
movl %eax, 0x10(%rcx)
jmp 0xd1bf
leaq 0x7417(%rip), %rax      # 0x14590
movq (%rax), %rax
movl $0x1, 0x13c(%rax)
jmp 0xd1bf
leaq 0x7401(%rip), %rax      # 0x14590
movq (%rax), %rax
movl $0x1, 0x30(%rax)
jmp 0xd1bf
leaq 0x73ee(%rip), %rax      # 0x14590
movq (%rax), %rax
movl $0x1, 0x44(%rax)
jmp 0xd1bf
leaq 0x73db(%rip), %rax      # 0x14590
movq (%rax), %rax
movl $0x1, 0x40(%rax)
movl 0xc(%rsp), %edi
addl %r15d, %edi
cmpl $0x1, %edi
jg 0xcfbf
leaq 0x73ba(%rip), %rbx      # 0x14590
movq (%rbx), %rax
cmpl $0x0, 0x40(%rax)
jne 0xd1ef
cmpl $0x0, 0x48(%rax)
jne 0xd1ef
cmpl $0x0, 0x44(%rax)
je 0xd316
xorl %ebp, %ebp
cmpl $0x0, 0x3c(%rax)
je 0xd25b
leaq 0x1c02(%rip), %rdi      # 0xee00
callq 0xce94
movq (%rbx), %rax
cmpl $0x0, 0x40(%rax)
je 0xd218
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
xorl %eax, %eax
callq 0xd3dd
movq (%rbx), %rax
cmpl $0x0, 0x44(%rax)
je 0xd236
leaq 0x1be4(%rip), %rdi      # 0xee0c
leaq 0x1bec(%rip), %rsi      # 0xee1b
xorl %eax, %eax
callq 0x4050
movq (%rbx), %rax
cmpl $0x0, 0x48(%rax)
je 0xd25b
leaq 0x1bf2(%rip), %rdi      # 0xee38
callq 0xce94
testl %eax, %eax
je 0xd25b
leaq 0x1bee(%rip), %rdi      # 0xee44
callq 0x40c0
testb %bpl, %bpl
je 0xd31e
cmpl $0x0, 0x8(%rsp)
je 0xd307
movq (%rbx), %rax
movl 0xc(%rax), %esi
movl 0x14(%rax), %edx
cmpl %esi, %edx
movl %esi, %ecx
cmovgl %edx, %ecx
movl %ecx, 0x18(%rax)
testl %ecx, %ecx
je 0xd325
cmpl $-0x1, 0x10(%rax)
jne 0xd293
movl %ecx, 0x10(%rax)
movl 0x4(%rax), %r8d
movl 0x8(%rax), %r9d
movl 0x10(%rax), %edi
leal (%r8,%rcx,2), %r10d
addl %r9d, %r10d
addl %edi, %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,%rdi), %r11d
addl %r10d, %r11d
movl %r11d, 0x2c(%rax)
xorl $0x1, %esi
xorl $0x1, %edx
orl %esi, %edx
xorl $0x4, %r9d
orl %edx, %r9d
xorl $0x8, %r8d
orl %r9d, %r8d
jne 0xd2ff
cmpl $0x6, (%rax)
setl %dl
cmpl %ecx, %edi
sete %sil
xorl %ecx, %ecx
testb %sil, %dl
jne 0xd304
movl $0x1, %ecx
movl %ecx, 0x38(%rax)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x1, %bpl
jmp 0xd1f1
xorl %edi, %edi
callq 0x4110
leaq 0x1b3e(%rip), %rdi      # 0xee6a
callq 0x40c0
movl $0x1, %edi
callq 0x4110
nop