// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/external/tre/lib/tre-parse.c
// Function: tre_parse_bracket_items
static reg_errcode_t
tre_parse_bracket_items(tre_parse_ctx_t *ctx, int negate,
			tre_ctype_t neg_classes[], int *num_neg_classes,
			tre_ast_node_t ***items, int *num_items,
			int *items_size)
{
  const tre_char_t *re = ctx->re;
  reg_errcode_t status = REG_OK;
  tre_ctype_t class = (tre_ctype_t)0;
  int i = *num_items;
  int max_i = *items_size;
  int skip;

  /* Build an array of the items in the bracket expression. */
  while (status == REG_OK)
    {
      skip = 0;
      if (re == ctx->re_end)
	{
	  status = REG_EBRACK;
	}
      else if (*re == CHAR_RBRACKET && re > ctx->re)
	{
	  DPRINT(("tre_parse_bracket:	done: '%.*" STRF "'\n", REST(re)));
	  re++;
	  break;
	}
      else
	{
	  tre_cint_t min = 0, max = 0;

	  class = (tre_ctype_t)0;
	  if (re + 2 < ctx->re_end
	      && *(re + 1) == CHAR_MINUS && *(re + 2) != CHAR_RBRACKET)
	    {
	      DPRINT(("tre_parse_bracket:  range: '%.*" STRF "'\n", REST(re)));
	      min = *re;
	      max = *(re + 2);
	      re += 3;
	      /* XXX - Should use collation order instead of encoding values
		 in character ranges. */
	      if (min > max)
		status = REG_ERANGE;
	    }
	  else if (re + 1 < ctx->re_end
		   && *re == CHAR_LBRACKET && *(re + 1) == CHAR_PERIOD)
	    status = REG_ECOLLATE;
	  else if (re + 1 < ctx->re_end
		   && *re == CHAR_LBRACKET && *(re + 1) == CHAR_EQUAL)
	    status = REG_ECOLLATE;
	  else if (re + 1 < ctx->re_end
		   && *re == CHAR_LBRACKET && *(re + 1) == CHAR_COLON)
	    {
	      char tmp_str[64];
	      const tre_char_t *endptr = re + 2;
	      int len;
	      DPRINT(("tre_parse_bracket:  class: '%.*" STRF "'\n", REST(re)));
	      while (endptr < ctx->re_end && *endptr != CHAR_COLON)
		endptr++;
	      if (endptr != ctx->re_end)
		{
		  len = MIN(endptr - re - 2, 63);
#ifdef TRE_WCHAR
		  {
		    tre_char_t tmp_wcs[64];
		    wcsncpy(tmp_wcs, re + 2, (size_t)len);
		    tmp_wcs[len] = L'\0';
#if defined HAVE_WCSRTOMBS
		    {
		      mbstate_t state;
		      const tre_char_t *src = tmp_wcs;
		      memset(&state, '\0', sizeof(state));
		      len = wcsrtombs(tmp_str, &src, sizeof(tmp_str), &state);
		    }
#elif defined HAVE_WCSTOMBS
		    len = wcstombs(tmp_str, tmp_wcs, 63);
#endif /* defined HAVE_WCSTOMBS */
		  }
#else /* !TRE_WCHAR */
		  strncpy(tmp_str, (const char*)re + 2, len);
#endif /* !TRE_WCHAR */
		  tmp_str[len] = '\0';
		  DPRINT(("  class name: %s\n", tmp_str));
		  class = tre_ctype(tmp_str);
		  if (!class)
		    status = REG_ECTYPE;
		  /* Optimize character classes for 8 bit character sets. */
		  if (status == REG_OK && TRE_MB_CUR_MAX == 1)
		    {
		      status = tre_expand_ctype(ctx->mem, class, items,
						&i, &max_i, ctx->cflags);
		      class = (tre_ctype_t)0;
		      skip = 1;
		    }
		  re = endptr + 2;
		}
	      else
		status = REG_ECTYPE;
	      min = 0;
	      max = TRE_CHAR_MAX;
	    }
	  else
	    {
	      DPRINT(("tre_parse_bracket:   char: '%.*" STRF "'\n", REST(re)));
	      if (*re == CHAR_MINUS && *(re + 1) != CHAR_RBRACKET
		  && ctx->re != re)
		/* Two ranges are not allowed to share and endpoint. */
		status = REG_ERANGE;
	      min = max = *re++;
	    }

	  if (status != REG_OK)
	    break;

	  if (class && negate)
	    if (*num_neg_classes >= MAX_NEG_CLASSES)
	      status = REG_ESPACE;
	    else
	      neg_classes[(*num_neg_classes)++] = class;
	  else if (!skip)
	    {
	      status = tre_new_item(ctx->mem, min, max, &i, &max_i, items);
	      if (status != REG_OK)
		break;
	      ((tre_literal_t*)((*items)[i-1])->obj)->u.class = class;
	    }

	  /* Add opposite-case counterpoints if REG_ICASE is present.
	     This is broken if there are more than two "same" characters. */
	  if (ctx->cflags & REG_ICASE && !class && status == REG_OK && !skip)
	    {
	      tre_cint_t cmin, ccurr;

	      DPRINT(("adding opposite-case counterpoints\n"));
	      while (min <= max)
		{
		  if (tre_islower(min))
		    {
		      cmin = ccurr = tre_toupper(min++);
		      while (tre_islower(min) && tre_toupper(min) == ccurr + 1
			     && min <= max)
			ccurr = tre_toupper(min++);
		      status = tre_new_item(ctx->mem, cmin, ccurr,
					    &i, &max_i, items);
		    }
		  else if (tre_isupper(min))
		    {
		      cmin = ccurr = tre_tolower(min++);
		      while (tre_isupper(min) && tre_tolower(min) == ccurr + 1
			     && min <= max)
			ccurr = tre_tolower(min++);
		      status = tre_new_item(ctx->mem, cmin, ccurr,
					    &i, &max_i, items);
		    }
		  else min++;
		  if (status != REG_OK)
		    break;
		}
	      if (status != REG_OK)
		break;
	    }
	}
    }
  *num_items = i;
  *items_size = max_i;
  ctx->re = re;
  return status;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rsi, %rbp
movq %rdi, %r14
movq 0x18(%rdi), %r12
movq %rdx, 0x30(%rsp)
movl (%rdx), %eax
movq %rsp, %rdx
movl %eax, (%rdx)
movq %rcx, 0x38(%rsp)
movl (%rcx), %eax
leaq 0x4(%rsp), %rcx
movl %eax, (%rcx)
movq %rdi, 0x18(%rsp)
movq %rsi, 0x10(%rsp)
movq 0x28(%r14), %r15
cmpq %r15, %r12
je 0x96f28
movzbl (%r12), %ebx
cmpw $0x5d, %bx
jne 0x96bd4
cmpq 0x18(%r14), %r12
ja 0x96f2f
leaq 0x2(%r12), %rsi
cmpq %r15, %rsi
movq %r12, 0x8(%rsp)
jae 0x96bfa
cmpb $0x2d, 0x1(%r12)
jne 0x96bfa
movzbl (%rsi), %r13d
cmpw $0x5d, %r13w
jne 0x96edf
incq %r12
cmpq %r15, %r12
setae %al
cmpb $0x5b, %bl
setne %cl
orb %al, %cl
jne 0x96c33
movzbl (%r12), %ecx
cmpl $0x3a, %ecx
je 0x96da2
movl $0x3, %eax
cmpl $0x2e, %ecx
je 0x96f42
cmpl $0x3d, %ecx
jne 0x96c4e
jmp 0x96f42
cmpb $0x2d, %bl
jne 0x96c4e
cmpb $0x5d, (%r12)
je 0x96c4e
movq 0x8(%rsp), %rax
cmpq %rax, 0x18(%r14)
jne 0x96f36
movl %ebx, %r13d
movq (%r14), %rdi
movzwl %bx, %esi
movzwl %r13w, %edx
movq %rsp, %rcx
leaq 0x4(%rsp), %r8
movq %rbp, %r9
callq 0x96f9d
testl %eax, %eax
jne 0x96f52
movq (%rbp), %rax
movslq (%rsp), %rcx
movq -0x8(%rax,%rcx,8), %rax
movq 0x8(%rax), %rax
movq $0x0, 0x18(%rax)
testb $0x2, 0x44(%r14)
je 0x96f0a
movq %r15, 0x20(%rsp)
cmpw %r13w, %bx
jg 0x96f05
movswl %bx, %ebx
callq 0xb6e0
movq (%rax), %r14
movslq %ebx, %r15
movzwl (%r14,%r15,2), %eax
btl $0x9, %eax
jb 0x96cd3
btl $0x8, %eax
jb 0x96d25
incl %ebx
xorl %eax, %eax
movq 0x18(%rsp), %r14
jmp 0x96d95
movl %r15d, %edi
callq 0xbbf0
movl %eax, %ebp
leal 0x1(%r15), %ebx
testb $0x2, 0x3(%r14,%r15,2)
movl %eax, %r15d
je 0x96d71
movl %ebp, %r15d
movl %ebx, %edi
callq 0xbbf0
cmpw %r13w, %bx
jg 0x96d71
cwtl
movswl %r15w, %ecx
incl %ecx
cmpl %ecx, %eax
jne 0x96d71
movl %ebx, %edi
callq 0xbbf0
movl %eax, %r15d
incl %ebx
movswq %bx, %rax
testb $0x2, 0x1(%r14,%rax,2)
jne 0x96cf3
jmp 0x96d71
movl %r15d, %edi
callq 0xb900
movl %eax, %ebp
leal 0x1(%r15), %ebx
testb $0x1, 0x3(%r14,%r15,2)
movl %eax, %r15d
je 0x96d71
movl %ebp, %r15d
movl %ebx, %edi
callq 0xb900
cmpw %r13w, %bx
jg 0x96d71
cwtl
movswl %r15w, %ecx
incl %ecx
cmpl %ecx, %eax
jne 0x96d71
movl %ebx, %edi
callq 0xb900
movl %eax, %r15d
incl %ebx
movswq %bx, %rax
testb $0x1, 0x1(%r14,%rax,2)
jne 0x96d41
movq 0x18(%rsp), %r14
movq (%r14), %rdi
movswl %bp, %esi
movswl %r15w, %edx
movq %rsp, %rcx
leaq 0x4(%rsp), %r8
movq 0x10(%rsp), %rbp
movq %rbp, %r9
callq 0x96f9d
testl %eax, %eax
je 0x96c9c
jmp 0x96f52
movq %rsi, %r12
cmpq %r15, %rsi
jae 0x96dcb
movq %r15, %rax
subq 0x8(%rsp), %rax
addq $-0x2, %rax
movq %rsi, %r12
cmpb $0x3a, (%r12)
je 0x96dcb
incq %r12
decq %rax
jne 0x96db9
movq %r15, %r12
cmpq %r15, %r12
je 0x96f3d
movq %r15, 0x20(%rsp)
movq %r12, %rax
subq 0x8(%rsp), %rax
leal -0x2(%rax), %ecx
cmpq $0x42, %rax
movslq %ecx, %rbx
movl $0x3f, %eax
cmovgeq %rax, %rbx
leaq 0x40(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rdx
callq 0xb2d0
movb $0x0, 0x40(%rsp,%rbx)
movq %r15, %rdi
callq 0x952b0
testq %rax, %rax
je 0x96f49
movq %rax, %rbx
movq (%r14), %rax
movq %rax, 0x28(%rsp)
movl 0x44(%r14), %r14d
xorl %ebp, %ebp
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
xorl %r13d, %r13d
movswl %bp, %edi
callq *%rbx
testl %eax, %eax
je 0x96e5b
testl %r15d, %r15d
cmovsl %ebp, %r15d
xorl %eax, %eax
movl %ebp, %r13d
cmpq $0xfe, %rbp
ja 0x96eaf
incq %rbp
testl %eax, %eax
je 0x96e34
jmp 0x96eaf
testb $0x2, %r14b
jne 0x96e8d
xorl %eax, %eax
testl %r15d, %r15d
js 0x96e49
movq 0x28(%rsp), %rdi
movl %r15d, %esi
movl %r13d, %edx
movq %rsp, %rcx
leaq 0x4(%rsp), %r8
movq 0x10(%rsp), %r9
callq 0x96f9d
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
jmp 0x96e49
movl %ebp, %edi
callq 0xb900
movswl %ax, %edi
callq *%rbx
testl %eax, %eax
jne 0x96e3d
movl %ebp, %edi
callq 0xbbf0
movswl %ax, %edi
callq *%rbx
testl %eax, %eax
jne 0x96e3d
jmp 0x96e61
testl %r15d, %r15d
js 0x96eee
testl %eax, %eax
movq 0x18(%rsp), %r14
movq 0x10(%rsp), %rbp
jne 0x96ef8
movq 0x28(%rsp), %rdi
movl %r15d, %esi
movl %r13d, %edx
movq %rsp, %rcx
leaq 0x4(%rsp), %r8
movq %rbp, %r9
callq 0x96f9d
jmp 0x96ef8
addq $0x3, %r12
cmpb %r13b, %bl
jbe 0x96c51
jmp 0x96f36
movq 0x18(%rsp), %r14
movq 0x10(%rsp), %rbp
addq $0x2, %r12
testl %eax, %eax
jne 0x96f52
testq %rbx, %rbx
je 0x96f17
movq 0x20(%rsp), %r15
cmpq %r15, 0x8(%rsp)
jne 0x96bb2
jmp 0x96f32
movw $0xff, %r13w
xorl %ebx, %ebx
movq 0x20(%rsp), %r15
jmp 0x96c51
movl $0x7, %eax
jmp 0x96f52
incq %r12
xorl %eax, %eax
jmp 0x96f52
movl $0xb, %eax
jmp 0x96f52
movl $0x4, %eax
movq 0x8(%rsp), %r12
jmp 0x96f52
addq $0x2, %r12
movl $0x4, %eax
movl (%rsp), %ecx
movq 0x30(%rsp), %rdx
movl %ecx, (%rdx)
movl 0x4(%rsp), %ecx
movq 0x38(%rsp), %rdx
movl %ecx, (%rdx)
movq %r12, 0x18(%r14)
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq