// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/external/tre/lib/tre-parse.c
// Function: tre_parse_bracket
static reg_errcode_t
tre_parse_bracket(tre_parse_ctx_t *ctx, tre_ast_node_t **result)
{
  tre_ast_node_t *node = NULL;
  int negate = 0;
  reg_errcode_t status = REG_OK;
  tre_ast_node_t **items, *u, *n;
  int i = 0, j, max_i = 32, curr_max, curr_min;
  tre_ctype_t neg_classes[MAX_NEG_CLASSES];
  int num_neg_classes = 0;

  /* Start off with an array of `max_i' elements. */
  items = xmalloc(sizeof(*items) * max_i);
  if (items == NULL)
    return REG_ESPACE;

  if (*ctx->re == CHAR_CARET)
    {
      DPRINT(("tre_parse_bracket: negate: '%.*" STRF "'\n", REST(ctx->re)));
      negate = 1;
      ctx->re++;
    }

  status = tre_parse_bracket_items(ctx, negate, neg_classes, &num_neg_classes,
				   &items, &i, &max_i);

  if (status != REG_OK)
    goto parse_bracket_done;

  /* Sort the array if we need to negate it. */
  if (negate)
    qsort(items, (unsigned)i, sizeof(*items), tre_compare_items);

  curr_max = curr_min = 0;
  /* Build a union of the items in the array, negated if necessary. */
  for (j = 0; j < i && status == REG_OK; j++)
    {
      int min, max;
      tre_literal_t *l = items[j]->obj;
      min = l->code_min;
      max = l->code_max;

      DPRINT(("item: %d - %d, class %ld, curr_max = %d\n",
	      (int)l->code_min, (int)l->code_max, (GtWord)l->u.class, curr_max));

      if (negate)
	{
	  if (min < curr_max)
	    {
	      /* Overlap. */
	      curr_max = MAX(max + 1, curr_max);
	      DPRINT(("overlap, curr_max = %d\n", curr_max));
	      l = NULL;
	    }
	  else
	    {
	      /* No overlap. */
	      curr_max = min - 1;
	      if (curr_max >= curr_min)
		{
		  DPRINT(("no overlap\n"));
		  l->code_min = curr_min;
		  l->code_max = curr_max;
		}
	      else
		{
		  DPRINT(("no overlap, zero room\n"));
		  l = NULL;
		}
	      curr_min = curr_max = max + 1;
	    }
	}

      if (l != NULL)
	{
	  int k;
	  DPRINT(("creating %d - %d\n", (int)l->code_min, (int)l->code_max));
	  l->position = ctx->position;
	  if (num_neg_classes > 0)
	    {
	      l->neg_classes = tre_mem_alloc(ctx->mem,
					     (sizeof(l->neg_classes)
					      * (num_neg_classes + 1)));
	      if (l->neg_classes == NULL)
		{
		  status = REG_ESPACE;
		  break;
		}
	      for (k = 0; k < num_neg_classes; k++)
		l->neg_classes[k] = neg_classes[k];
	      l->neg_classes[k] = (tre_ctype_t)0;
	    }
	  else
	    l->neg_classes = NULL;
	  if (node == NULL)
	    node = items[j];
	  else
	    {
	      u = tre_ast_new_union(ctx->mem, node, items[j]);
	      if (u == NULL)
		status = REG_ESPACE;
	      node = u;
	    }
	}
    }

  if (status != REG_OK)
    goto parse_bracket_done;

  if (negate)
    {
      int k;
      DPRINT(("final: creating %d - %d\n", curr_min, (int)TRE_CHAR_MAX));
      n = tre_ast_new_literal(ctx->mem, curr_min, TRE_CHAR_MAX, ctx->position);
      if (n == NULL)
	status = REG_ESPACE;
      else
	{
	  tre_literal_t *l = n->obj;
	  if (num_neg_classes > 0)
	    {
	      l->neg_classes = tre_mem_alloc(ctx->mem,
					     (sizeof(l->neg_classes)
					      * (num_neg_classes + 1)));
	      if (l->neg_classes == NULL)
		{
		  status = REG_ESPACE;
		  goto parse_bracket_done;
		}
	      for (k = 0; k < num_neg_classes; k++)
		l->neg_classes[k] = neg_classes[k];
	      l->neg_classes[k] = (tre_ctype_t)0;
	    }
	  else
	    l->neg_classes = NULL;
	  if (node == NULL)
	    node = n;
	  else
	    {
	      u = tre_ast_new_union(ctx->mem, node, n);
	      if (u == NULL)
		status = REG_ESPACE;
	      node = u;
	    }
	}
    }

  if (status != REG_OK)
    goto parse_bracket_done;

#ifdef TRE_DEBUG
  tre_ast_print(node);
#endif /* TRE_DEBUG */

 parse_bracket_done:
  xfree(items);
  ctx->position++;
  *result = node;
  return status;
}

// Assembly:
subq $0x298, %rsp            # imm = 0x298
movq %rdi, 0x288(%rsp)
movq %rsi, 0x280(%rsp)
movq $0x0, 0x278(%rsp)
movl $0x0, 0x274(%rsp)
movl $0x0, 0x270(%rsp)
movl $0x0, 0x254(%rsp)
movl $0x20, 0x24c(%rsp)
movl $0x0, 0x3c(%rsp)
movslq 0x24c(%rsp), %rdi
shlq $0x3, %rdi
callq 0xbcb8
movq %rax, 0x268(%rsp)
cmpq $0x0, 0x268(%rsp)
jne 0xc658b
movl $0xc, 0x294(%rsp)
jmp 0xc6af7
movq 0x288(%rsp), %rax
movq 0x18(%rax), %rax
movzbl (%rax), %eax
cmpl $0x5e, %eax
jne 0xc65c2
jmp 0xc65a1
jmp 0xc65a3
movl $0x1, 0x274(%rsp)
movq 0x288(%rsp), %rax
movq 0x18(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x18(%rax)
movq 0x288(%rsp), %rdi
movl 0x274(%rsp), %esi
leaq 0x40(%rsp), %rdx
leaq 0x3c(%rsp), %rcx
leaq 0x268(%rsp), %r8
leaq 0x254(%rsp), %r9
leaq 0x24c(%rsp), %rax
movq %rax, (%rsp)
callq 0xc6cf0
movl %eax, 0x270(%rsp)
cmpl $0x0, 0x270(%rsp)
je 0xc6612
jmp 0xc6ab8
cmpl $0x0, 0x274(%rsp)
je 0xc663e
movq 0x268(%rsp), %rdi
movl 0x254(%rsp), %eax
movl %eax, %esi
movl $0x8, %edx
leaq 0xef7(%rip), %rcx       # 0xc7530
callq 0xbc40
movl $0x0, 0x244(%rsp)
movl $0x0, 0x248(%rsp)
movl $0x0, 0x250(%rsp)
movl 0x250(%rsp), %ecx
xorl %eax, %eax
cmpl 0x254(%rsp), %ecx
movb %al, 0x17(%rsp)
jge 0xc6684
cmpl $0x0, 0x270(%rsp)
sete %al
movb %al, 0x17(%rsp)
movb 0x17(%rsp), %al
testb $0x1, %al
jne 0xc6691
jmp 0xc6906
movq 0x268(%rsp), %rax
movslq 0x250(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x8(%rax), %rax
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rax
movq (%rax), %rax
movl %eax, 0x38(%rsp)
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rax
movl %eax, 0x34(%rsp)
jmp 0xc66c9
cmpl $0x0, 0x274(%rsp)
je 0xc678d
movl 0x38(%rsp), %eax
cmpl 0x248(%rsp), %eax
jge 0xc6724
movl 0x34(%rsp), %eax
addl $0x1, %eax
cmpl 0x248(%rsp), %eax
jl 0xc6701
movl 0x34(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x10(%rsp)
jmp 0xc670c
movl 0x248(%rsp), %eax
movl %eax, 0x10(%rsp)
movl 0x10(%rsp), %eax
movl %eax, 0x248(%rsp)
jmp 0xc6719
movq $0x0, 0x28(%rsp)
jmp 0xc678b
movl 0x38(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x248(%rsp)
movl 0x248(%rsp), %eax
cmpl 0x244(%rsp), %eax
jl 0xc6769
jmp 0xc6744
jmp 0xc6746
movslq 0x244(%rsp), %rcx
movq 0x28(%rsp), %rax
movq %rcx, (%rax)
movslq 0x248(%rsp), %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x8(%rax)
jmp 0xc6776
jmp 0xc676b
jmp 0xc676d
movq $0x0, 0x28(%rsp)
movl 0x34(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x248(%rsp)
movl %eax, 0x244(%rsp)
jmp 0xc678d
cmpq $0x0, 0x28(%rsp)
je 0xc68ee
jmp 0xc679b
jmp 0xc679d
movq 0x288(%rsp), %rax
movl 0x38(%rax), %ecx
movq 0x28(%rsp), %rax
movl %ecx, 0x10(%rax)
cmpl $0x0, 0x3c(%rsp)
jle 0xc685c
movq 0x288(%rsp), %rax
movq (%rax), %rdi
movl 0x3c(%rsp), %eax
addl $0x1, %eax
movslq %eax, %r8
shlq $0x3, %r8
xorl %ecx, %ecx
xorl %eax, %eax
movl %eax, %edx
movl %ecx, %esi
callq 0xc3270
movq %rax, %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x20(%rax)
movq 0x28(%rsp), %rax
cmpq $0x0, 0x20(%rax)
jne 0xc6809
movl $0xc, 0x270(%rsp)
jmp 0xc6906
movl $0x0, 0x24(%rsp)
movl 0x24(%rsp), %eax
cmpl 0x3c(%rsp), %eax
jge 0xc6844
movslq 0x24(%rsp), %rax
movq 0x40(%rsp,%rax,8), %rdx
movq 0x28(%rsp), %rax
movq 0x20(%rax), %rax
movslq 0x24(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0xc6811
movq 0x28(%rsp), %rax
movq 0x20(%rax), %rax
movslq 0x24(%rsp), %rcx
movq $0x0, (%rax,%rcx,8)
jmp 0xc6869
movq 0x28(%rsp), %rax
movq $0x0, 0x20(%rax)
cmpq $0x0, 0x278(%rsp)
jne 0xc6892
movq 0x268(%rsp), %rax
movslq 0x250(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x278(%rsp)
jmp 0xc68ec
movq 0x288(%rsp), %rax
movq (%rax), %rdi
movq 0x278(%rsp), %rsi
movq 0x268(%rsp), %rax
movslq 0x250(%rsp), %rcx
movq (%rax,%rcx,8), %rdx
callq 0xfc2f0
movq %rax, 0x260(%rsp)
cmpq $0x0, 0x260(%rsp)
jne 0xc68dc
movl $0xc, 0x270(%rsp)
movq 0x260(%rsp), %rax
movq %rax, 0x278(%rsp)
jmp 0xc68ee
jmp 0xc68f0
movl 0x250(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x250(%rsp)
jmp 0xc665f
cmpl $0x0, 0x270(%rsp)
je 0xc6915
jmp 0xc6ab8
cmpl $0x0, 0x274(%rsp)
je 0xc6aaa
jmp 0xc6925
jmp 0xc6927
movq 0x288(%rsp), %rax
movq (%rax), %rdi
movl 0x244(%rsp), %esi
movq 0x288(%rsp), %rax
movl 0x38(%rax), %ecx
movl $0xff, %edx
callq 0xfc1a0
movq %rax, 0x258(%rsp)
cmpq $0x0, 0x258(%rsp)
jne 0xc6971
movl $0xc, 0x270(%rsp)
jmp 0xc6aa8
movq 0x258(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x18(%rsp)
cmpl $0x0, 0x3c(%rsp)
jle 0xc6a2e
movq 0x288(%rsp), %rax
movq (%rax), %rdi
movl 0x3c(%rsp), %eax
addl $0x1, %eax
movslq %eax, %r8
shlq $0x3, %r8
xorl %ecx, %ecx
xorl %eax, %eax
movl %eax, %edx
movl %ecx, %esi
callq 0xc3270
movq %rax, %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x20(%rax)
movq 0x18(%rsp), %rax
cmpq $0x0, 0x20(%rax)
jne 0xc69db
movl $0xc, 0x270(%rsp)
jmp 0xc6ab8
movl $0x0, 0x20(%rsp)
movl 0x20(%rsp), %eax
cmpl 0x3c(%rsp), %eax
jge 0xc6a16
movslq 0x20(%rsp), %rax
movq 0x40(%rsp,%rax,8), %rdx
movq 0x18(%rsp), %rax
movq 0x20(%rax), %rax
movslq 0x20(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movl 0x20(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x20(%rsp)
jmp 0xc69e3
movq 0x18(%rsp), %rax
movq 0x20(%rax), %rax
movslq 0x20(%rsp), %rcx
movq $0x0, (%rax,%rcx,8)
jmp 0xc6a3b
movq 0x18(%rsp), %rax
movq $0x0, 0x20(%rax)
cmpq $0x0, 0x278(%rsp)
jne 0xc6a58
movq 0x258(%rsp), %rax
movq %rax, 0x278(%rsp)
jmp 0xc6aa6
movq 0x288(%rsp), %rax
movq (%rax), %rdi
movq 0x278(%rsp), %rsi
movq 0x258(%rsp), %rdx
callq 0xfc2f0
movq %rax, 0x260(%rsp)
cmpq $0x0, 0x260(%rsp)
jne 0xc6a96
movl $0xc, 0x270(%rsp)
movq 0x260(%rsp), %rax
movq %rax, 0x278(%rsp)
jmp 0xc6aa8
jmp 0xc6aaa
cmpl $0x0, 0x270(%rsp)
je 0xc6ab6
jmp 0xc6ab8
jmp 0xc6ab8
movq 0x268(%rsp), %rdi
callq 0xb760
movq 0x288(%rsp), %rax
movl 0x38(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x38(%rax)
movq 0x278(%rsp), %rcx
movq 0x280(%rsp), %rax
movq %rcx, (%rax)
movl 0x270(%rsp), %eax
movl %eax, 0x294(%rsp)
movl 0x294(%rsp), %eax
addq $0x298, %rsp            # imm = 0x298
retq
nopw %cs:(%rax,%rax)