// File: /workspace/github_c_makefile_star2_O2/zpole[P]IICV/vl/getopt_long.c
// Function: getopt_long
VL_EXPORT int
getopt_long(int argc, char *const argv[],
            const char *optstring,
            const struct option * longopts,
            int *longindex)
{
  static char *place = EMSG;	/* option letter processing */
  static int   optbegin  = 0 ;
  static int   optend    = 0 ;
  char        *oli;		/* option letter list index */
  int          has_colon = 0 ;
  int          ret_val   = 0 ;

  /*
     A semicolon at the beginning of optstring has a special meaning.
     If we find one, we annote and remove it.
  */
  has_colon = optstring && optstring[0] == ':' ;
  if (has_colon) ++ optstring ;

  /*
   Here we are either processing a short option sequence or
   we start processing a new option. This is indicated by optreset.
  */

  if (optreset || *place == '\0') {

    /* ---------------------------------------------------------------
     *                                 Look for next short/long option
     * ------------------------------------------------------------ */
    optreset = 0 ;

    /* no more arguments ? */
    if (optind >= argc) {
      place = EMSG ;
      return -1 ;
    }

    /* next argument that may hold an option */
    optbegin = optind ;

    /* ---------------------------------------------------------------
     *                                     Look for an option to parse
     * ------------------------------------------------------------ */

  parse_option_at_optbegin :

    /* place points to the candidate option */
    place = argv [optbegin] ;

    /* an option is introduced by '-' */
    if (place [0] != '-') {
      /* this argument is not an option: try next argument */
      ++ optbegin ;
      if (optbegin >= argc) {
        /* no more arguments to look for options */
        place = EMSG ;
        return -1 ;
      }
      goto parse_option_at_optbegin ;
    }

    /* consume leading `-' */
    ++ place ;

    /* assume the option is composed of one argument only */
    optend = optbegin + 1 ;

    /* assume no argument */
    optarg = 0 ;

    /* ---------------------------------------------------------------
     *                                                     option `--'
     * ------------------------------------------------------------ */

    /* this special option (void long option) ends the option processing */
    if (place[0]        &&
        place[0] == '-' &&
        place[1] == '\0') {

      optind  = optend ;
      place   = EMSG ;
      ret_val = -1 ;
      goto done_option ;
    }

    /* ---------------------------------------------------------------
     *                                                     long option
     * ------------------------------------------------------------ */

    if (place[0]        &&
        place[0] == '-' &&
        place[1] ) {

      size_t namelen ;
      int i ;

      /* consume second `-' */
      ++ place ;

      /* count characters before `=' */
      namelen = strcspn(place, "=") ;

      /* scan longopts for this option */
      for (i = 0 ; longopts[i].name != NULL ; ++ i) {

        if (strlen  (       longopts[i].name) == namelen &&
            strncmp (place, longopts[i].name, namelen) == 0 ) {

          /* save back long option index */
          if (longindex) *longindex = i ;

          /* process long option argument */
          if (longopts[i].has_arg == required_argument ||
              longopts[i].has_arg == optional_argument) {

            /* --option=value style */
            if (place[namelen] == '=') {
              optarg = place + namelen + 1 ;
            }

            /* --option value style (only required_argument) */
            else if (longopts[i].has_arg == required_argument) {
              /* missing argument ? */
              if (optbegin >= argc - 1) {
                if (! has_colon && opterr)
                  fprintf(stderr,
                          "%s: option requires an argument -- %s\n",
                          argv[0], place);
                place   = EMSG ;
                ret_val = has_colon ? BADARG : BADCH ;
                goto done_option ;
              }
              optarg = argv [optend] ;
              ++ optend ;
            }
          }

          /* determine return value */
          if (longopts[i].flag == NULL) {
            ret_val = longopts[i].val ;
          }
          else {
            *longopts[i].flag = longopts[i].val;
            ret_val = 0 ;
          }

          /* mark sequence closed */
          place = EMSG ;
          goto done_option ;
        } /* if match */

      } /* scan longoptions */

      /* no matching option found */
      if (! has_colon && opterr)
        fprintf(stderr,
                "%s: illegal option -- %s\n", argv[0], place) ;
      place   = EMSG ;
      ret_val = BADCH ;
      goto done_option ;
    }
  } /* end new option */

  /* -----------------------------------------------------------------
   *                                      Finish short option sequence
   * -------------------------------------------------------------- */
  optopt = (int) *place++ ;

  /* search charcater in option list */
  oli = strchr(optstring, optopt);

  /* short option not found */
  if (!oli) {

    if (! has_colon && opterr)
      fprintf(stderr,
              "%s: illegal option -- %c\n",
              argv[0], optopt);

    if (*place) {
      /* more short options in the list */
      return BADCH ;
    }

    else {
      /* error occured as last option in the list */
      place   = EMSG ;
      ret_val = BADCH ;
      goto done_option ;
    }
  } /* end short option not found */

  if (oli[1] != ':') {
    /* short option with no argument */

    if (*place) {
      /* more short options in the list */
      return optopt ;
    }
    else {
      /* last option in the list */
      place   = EMSG ;
      ret_val = optopt ;
      goto done_option ;
    }

  } else {
    /* short option with argument */

    /* -ovalue style */
    if (*place) {
      optarg  = place ;
      place   = EMSG ;
      ret_val = optopt ;
      goto done_option ;
    }
    /* -o value style: missing argument */
    else if (optbegin >= argc - 1) {
      if (! has_colon && opterr)
        fprintf(stderr,
                "%s: option requires an argument -- %c\n",
                argv[0], optopt);
      place   = EMSG ;
      ret_val = has_colon ? BADARG : BADCH ;
      goto done_option ;
    }

    /* -o value style: process argument */
    optarg = argv [optend] ;
    ++ optend ;
    place   = EMSG ;
    ret_val = optopt ;
    goto done_option ;
  } /* short with argument */

 done_option :
  {
    int pos = optend - optbegin ;  /* n of circular shifts */
    int c   = pos ;

    while (c --) {
      int i ;
      char *tmp = argv [optend - 1] ;
      for (i = optend - 1 ; i > optind ; -- i) {
        ((char**)argv) [i] = argv [i-1] ;
      }
      ((char**)argv) [optind] = tmp ;
    }
    optind += pos ;
  }

  return ret_val ;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, %r14
movq %rsi, %rbx
movl %edi, %r9d
xorl %r13d, %r13d
testq %rdx, %rdx
je 0x1029a
cmpb $0x3a, (%rdx)
sete %r13b
movq %r13, %rdi
addq %rdx, %rdi
jmp 0x1029c
xorl %edi, %edi
movq 0x26c8d(%rip), %rax     # 0x36f30
cmpl $0x0, (%rax)
je 0x102fe
andl $0x0, (%rax)
movq 0x26cde(%rip), %rax     # 0x36f90
movl (%rax), %ecx
cmpl %r9d, %ecx
jge 0x102e7
movslq %ecx, %rbp
movl %ecx, 0x27476(%rip)     # 0x37738
movslq %r9d, %rcx
movq (%rbx,%rbp,8), %r12
cmpb $0x2d, (%r12)
je 0x10312
leal 0x1(%rbp), %edx
movq %rbp, %rsi
incq %rsi
movl %edx, 0x27459(%rip)     # 0x37738
movq %rsi, %rbp
cmpq %rcx, %rsi
jl 0x102c5
leaq 0x1d4da(%rip), %rax     # 0x2d7c8
movq %rax, 0x27343(%rip)     # 0x37638
pushq $-0x1
popq %r14
jmp 0x105e1
movq 0x27333(%rip), %r15     # 0x37638
movb (%r15), %cl
testb %cl, %cl
jne 0x103cf
jmp 0x102a8
leaq 0x1(%r12), %r15
movq %r15, 0x2731a(%rip)     # 0x37638
movq 0x26ccb(%rip), %rcx     # 0x36ff0
andq $0x0, (%rcx)
leal 0x1(%rbp), %edx
movl %edx, 0x2740a(%rip)     # 0x3773c
movb 0x1(%r12), %cl
cmpb $0x2d, %cl
jne 0x103cf
cmpb $0x0, 0x2(%r12)
je 0x1049b
movl %edx, 0x8(%rsp)
movq %r8, 0x20(%rsp)
movl %r9d, 0xc(%rsp)
movq %r13, 0x10(%rsp)
addq $0x2, %r12
movq %r12, 0x272ce(%rip)     # 0x37638
leaq 0x1d0a4(%rip), %rsi     # 0x2d415
movq %r12, %rdi
callq 0x9490
movq %rax, %r8
addq $0x18, %r14
xorl %r13d, %r13d
movq -0x18(%r14), %r15
testq %r15, %r15
je 0x10443
movq %r14, 0x18(%rsp)
movq %r15, %rdi
movq %r8, %r14
callq 0x9320
movq %r14, %r8
cmpq %r14, %rax
jne 0x103c1
movq %r12, %rdi
movq %r15, %rsi
movq %r8, %rdx
callq 0x90e0
movq %r14, %r8
testl %eax, %eax
je 0x104b4
incl %r13d
movq 0x18(%rsp), %r14
addq $0x20, %r14
jmp 0x10383
movl %r9d, %ebp
incq %r15
movq %r15, 0x2725c(%rip)     # 0x37638
movsbl %cl, %r14d
movq 0x26bb9(%rip), %rax     # 0x36fa0
movl %r14d, (%rax)
movl %r14d, %esi
callq 0x9390
testq %rax, %rax
je 0x10413
cmpb $0x3a, 0x1(%rax)
movb (%r15), %al
jne 0x10436
testb %al, %al
je 0x1046f
movq 0x26be5(%rip), %rax     # 0x36ff0
movq %r15, (%rax)
jmp 0x1058b
movq 0x26b2e(%rip), %rax     # 0x36f48
cmpl $0x0, (%rax)
sete %al
orb %al, %r13b
je 0x1052b
cmpb $0x0, (%r15)
je 0x1045d
pushq $0x3f
jmp 0x102f7
testb %al, %al
jne 0x105e1
jmp 0x1058b
movq 0x26afe(%rip), %rax     # 0x36f48
cmpl $0x0, (%rax)
sete %al
movq 0x10(%rsp), %rcx
orb %al, %cl
je 0x105f3
leaq 0x1d364(%rip), %rax     # 0x2d7c8
movq %rax, 0x271cd(%rip)     # 0x37638
pushq $0x3f
jmp 0x104ad
decl %ebp
cmpl %ebp, 0x272c1(%rip)     # 0x37738
jge 0x104f5
movslq 0x272bc(%rip), %rax     # 0x3773c
movq (%rbx,%rax,8), %rcx
movq 0x26b65(%rip), %rdx     # 0x36ff0
movq %rcx, (%rdx)
incl %eax
movl %eax, 0x272a6(%rip)     # 0x3773c
jmp 0x1058b
movl %edx, (%rax)
leaq 0x1d324(%rip), %rax     # 0x2d7c8
movq %rax, 0x2718d(%rip)     # 0x37638
pushq $-0x1
popq %r14
jmp 0x10599
movq 0x20(%rsp), %rax
testq %rax, %rax
je 0x104c1
movl %r13d, (%rax)
movq 0x18(%rsp), %rsi
movl -0x10(%rsi), %eax
leal -0x1(%rax), %ecx
cmpl $0x1, %ecx
movl 0xc(%rsp), %ecx
movq 0x26b16(%rip), %rdx     # 0x36ff0
ja 0x10579
cmpb $0x3d, (%r12,%r8)
jne 0x10555
addq %r8, %r12
incq %r12
movq %r12, (%rdx)
jmp 0x10579
movq 0x26a4c(%rip), %rax     # 0x36f48
cmpl $0x0, (%rax)
sete %al
orb %r13b, %al
je 0x10648
leaq 0x1d2b6(%rip), %rax     # 0x2d7c8
movq %rax, 0x2711f(%rip)     # 0x37638
xorb $0x1, %r13b
movzbl %r13b, %eax
leal (%rax,%rax,4), %r14d
addl $0x3a, %r14d
jmp 0x10599
movq 0x26ac6(%rip), %rax     # 0x36ff8
movq (%rax), %rdi
movq (%rbx), %rdx
leaq 0x1cf19(%rip), %rsi     # 0x2d458
movl %r14d, %ecx
xorl %eax, %eax
callq 0x9580
movq 0x270e8(%rip), %r15     # 0x37638
jmp 0x10429
cmpl $0x1, %eax
jne 0x10579
decl %ecx
cmpl %ebp, %ecx
jle 0x10616
movslq 0x8(%rsp), %rax
movq (%rbx,%rax,8), %rax
movq %rax, (%rdx)
leal 0x2(%rbp), %eax
movl %eax, 0x271c3(%rip)     # 0x3773c
movq -0x8(%rsi), %rax
movl (%rsi), %r14d
testq %rax, %rax
je 0x1058b
movl %r14d, (%rax)
xorl %r14d, %r14d
leaq 0x1d236(%rip), %rax     # 0x2d7c8
movq %rax, 0x2709f(%rip)     # 0x37638
movl 0x2719d(%rip), %ecx     # 0x3773c
movl %ecx, %eax
subl 0x27191(%rip), %eax     # 0x37738
decl %ecx
movslq %ecx, %rsi
movq 0x269dd(%rip), %rcx     # 0x36f90
movslq (%rcx), %rdx
movl %eax, %edi
subl $0x1, %edi
jb 0x105dd
movq (%rbx,%rsi,8), %r8
movq %rsi, %r9
cmpq %rdx, %r9
jle 0x105d7
movq -0x8(%rbx,%r9,8), %r10
movq %r10, (%rbx,%r9,8)
decq %r9
jmp 0x105c4
movq %r8, (%rbx,%rdx,8)
jmp 0x105b8
addl %eax, %edx
movl %edx, (%rcx)
movl %r14d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x269fe(%rip), %rax     # 0x36ff8
movq (%rax), %rdi
movq (%rbx), %rdx
leaq 0x1ce37(%rip), %rsi     # 0x2d43e
movq %r12, %rcx
xorl %eax, %eax
callq 0x9580
jmp 0x1045d
movq 0x2692b(%rip), %rax     # 0x36f48
cmpl $0x0, (%rax)
sete %al
movq 0x10(%rsp), %r14
orb %r14b, %al
je 0x1066b
leaq 0x1d194(%rip), %rax     # 0x2d7c8
movq %rax, 0x26ffd(%rip)     # 0x37638
xorb $0x1, %r14b
movzbl %r14b, %eax
jmp 0x10521
movq 0x269a9(%rip), %rax     # 0x36ff8
movq (%rax), %rdi
movq (%rbx), %rdx
leaq 0x1ce16(%rip), %rsi     # 0x2d472
movl %r14d, %ecx
xorl %eax, %eax
callq 0x9580
jmp 0x1050b
movq 0x26986(%rip), %rax     # 0x36ff8
movq (%rax), %rdi
movq (%rbx), %rdx
leaq 0x1cd98(%rip), %rsi     # 0x2d417
movq %r12, %rcx
xorl %eax, %eax
callq 0x9580
jmp 0x1062d
nop