// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/external/tre/lib/tre-compile.c
// Function: tre_ast_to_tnfa
static reg_errcode_t
tre_ast_to_tnfa(tre_ast_node_t *node, tre_tnfa_transition_t *transitions,
		int *counts, int *offs)
{
  tre_union_t *uni;
  tre_catenation_t *cat;
  tre_iteration_t *iter;
  reg_errcode_t errcode = REG_OK;

  /* XXX - recurse using a stack!. */
  switch (node->type)
    {
    case LITERAL:
      break;
    case UNION:
      uni = (tre_union_t *)node->obj;
      errcode = tre_ast_to_tnfa(uni->left, transitions, counts, offs);
      if (errcode != REG_OK)
	return errcode;
      errcode = tre_ast_to_tnfa(uni->right, transitions, counts, offs);
      break;

    case CATENATION:
      cat = (tre_catenation_t *)node->obj;
      /* Add a transition from each position in cat->left->lastpos
	 to each position in cat->right->firstpos. */
      errcode = tre_make_trans(cat->left->lastpos, cat->right->firstpos,
			       transitions, counts, offs);
      if (errcode != REG_OK)
	return errcode;
      errcode = tre_ast_to_tnfa(cat->left, transitions, counts, offs);
      if (errcode != REG_OK)
	return errcode;
      errcode = tre_ast_to_tnfa(cat->right, transitions, counts, offs);
      break;

    case ITERATION:
      iter = (tre_iteration_t *)node->obj;
      assert(iter->max == -1 || iter->max == 1);

      if (iter->max == -1)
	{
	  assert(iter->min == 0 || iter->min == 1);
	  /* Add a transition from each last position in the iterated
	     expression to each first position. */
	  errcode = tre_make_trans(iter->arg->lastpos, iter->arg->firstpos,
				   transitions, counts, offs);
	  if (errcode != REG_OK)
	    return errcode;
	}
      errcode = tre_ast_to_tnfa(iter->arg, transitions, counts, offs);
      break;
    }
  return errcode;
}

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x48(%rsp)
movq %rsi, 0x40(%rsp)
movq %rdx, 0x38(%rsp)
movq %rcx, 0x30(%rsp)
movl $0x0, 0x14(%rsp)
movq 0x48(%rsp), %rax
movl (%rax), %eax
movq %rax, 0x8(%rsp)
subq $0x3, %rax
ja 0xbd68f
movq 0x8(%rsp), %rax
leaq 0xb7cf6(%rip), %rcx     # 0x175178
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
jmp 0xbd68f
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rax
movq (%rax), %rdi
movq 0x40(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq 0x30(%rsp), %rcx
callq 0xbd440
movl %eax, 0x14(%rsp)
cmpl $0x0, 0x14(%rsp)
je 0xbd4d2
movl 0x14(%rsp), %eax
movl %eax, 0x54(%rsp)
jmp 0xbd697
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rdi
movq 0x40(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq 0x30(%rsp), %rcx
callq 0xbd440
movl %eax, 0x14(%rsp)
jmp 0xbd68f
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq 0x28(%rax), %rdi
movq 0x20(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x20(%rax), %rsi
movq 0x40(%rsp), %rdx
movq 0x38(%rsp), %rcx
movq 0x30(%rsp), %r8
callq 0xbf310
movl %eax, 0x14(%rsp)
cmpl $0x0, 0x14(%rsp)
je 0xbd54b
movl 0x14(%rsp), %eax
movl %eax, 0x54(%rsp)
jmp 0xbd697
movq 0x20(%rsp), %rax
movq (%rax), %rdi
movq 0x40(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq 0x30(%rsp), %rcx
callq 0xbd440
movl %eax, 0x14(%rsp)
cmpl $0x0, 0x14(%rsp)
je 0xbd57f
movl 0x14(%rsp), %eax
movl %eax, 0x54(%rsp)
jmp 0xbd697
movq 0x20(%rsp), %rax
movq 0x8(%rax), %rdi
movq 0x40(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq 0x30(%rsp), %rcx
callq 0xbd440
movl %eax, 0x14(%rsp)
jmp 0xbd68f
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rax
cmpl $-0x1, 0xc(%rax)
je 0xbd5c9
movq 0x18(%rsp), %rax
cmpl $0x1, 0xc(%rax)
jne 0xbd5cb
jmp 0xbd5ea
leaq 0xb7ed5(%rip), %rdi     # 0x1754a7
leaq 0xb7c32(%rip), %rsi     # 0x17520b
movl $0x721, %edx            # imm = 0x721
leaq 0xb7ee4(%rip), %rcx     # 0x1754c9
callq 0xb3e0
movq 0x18(%rsp), %rax
cmpl $-0x1, 0xc(%rax)
jne 0xbd66f
movq 0x18(%rsp), %rax
cmpl $0x0, 0x8(%rax)
je 0xbd60b
movq 0x18(%rsp), %rax
cmpl $0x1, 0x8(%rax)
jne 0xbd60d
jmp 0xbd62c
leaq 0xb7f0c(%rip), %rdi     # 0x175520
leaq 0xb7bf0(%rip), %rsi     # 0x17520b
movl $0x725, %edx            # imm = 0x725
leaq 0xb7ea2(%rip), %rcx     # 0x1754c9
callq 0xb3e0
movq 0x18(%rsp), %rax
movq (%rax), %rax
movq 0x28(%rax), %rdi
movq 0x18(%rsp), %rax
movq (%rax), %rax
movq 0x20(%rax), %rsi
movq 0x40(%rsp), %rdx
movq 0x38(%rsp), %rcx
movq 0x30(%rsp), %r8
callq 0xbf310
movl %eax, 0x14(%rsp)
cmpl $0x0, 0x14(%rsp)
je 0xbd66d
movl 0x14(%rsp), %eax
movl %eax, 0x54(%rsp)
jmp 0xbd697
jmp 0xbd66f
movq 0x18(%rsp), %rax
movq (%rax), %rdi
movq 0x40(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq 0x30(%rsp), %rcx
callq 0xbd440
movl %eax, 0x14(%rsp)
movl 0x14(%rsp), %eax
movl %eax, 0x54(%rsp)
movl 0x54(%rsp), %eax
addq $0x58, %rsp
retq