// File: /workspace/github_c_makefile_star2_O1/genometools[P]genometools/src/core/encseq_col.c
// Function: gt_encseq_col_do_grep_desc
static int gt_encseq_col_do_grep_desc(GtEncseqCol *esc, GtUword *filenum,
                                      GtUword *seqnum, GtStr *seqid,
                                      GtError *err)
{
  GtUword j, num_matches = 0;
  const GtSeqInfo *seq_info_ptr;
  GtSeqInfo seq_info;
  GtStr *pattern, *escaped;
  bool match = false;
  int had_err = 0;
  gt_error_check(err);

  gt_assert(esc && filenum && seqnum && seqid);
  gt_assert(esc->encseq && gt_encseq_has_description_support(esc->encseq));

  /* create cache */
  if (!esc->grep_cache)
    esc->grep_cache = gt_seq_info_cache_new();
  /* try to read from cache */
  seq_info_ptr = gt_seq_info_cache_get(esc->grep_cache, gt_str_get(seqid));
  if (seq_info_ptr) {
    if (esc->duplicates && gt_hashmap_get(esc->duplicates, gt_str_get(seqid))) {
      gt_error_set(err, "query seqid '%s' could match more than one "
                        "sequence description", gt_str_get(seqid));
      return -1;
    }
    *filenum = seq_info_ptr->filenum;
    *seqnum = seq_info_ptr->seqnum;
    return 0;
  }
  pattern = gt_str_new();
  escaped = gt_str_new();
  gt_grep_escape_extended(escaped, gt_str_get(seqid), gt_str_length(seqid));
  if (esc->matchstart)
    gt_str_append_cstr(pattern, "^");
  gt_str_append_str(pattern, escaped);
  if (esc->matchstart)
    gt_str_append_cstr(pattern, "([[:space:]]|$)");
  for (j = 0; !had_err && j < gt_encseq_num_of_sequences(esc->encseq); j++) {
    const char *desc;
    GtUword desc_len;
    desc = gt_encseq_description(esc->encseq, &desc_len, j);
    gt_assert(desc);
    had_err = gt_grep_nt(&match, gt_str_get(pattern), desc, desc_len, err);
    if (!had_err && match) {
      num_matches++;
      if (num_matches > 1) {
        gt_error_set(err, "query seqid '%s' could match more than one "
                          "sequence description", gt_str_get(seqid));
        had_err = -1;
        break;
      }
      *filenum = seq_info.filenum =
                       gt_encseq_filenum(esc->encseq,
                                         gt_encseq_seqstartpos(esc->encseq, j));
      *seqnum = seq_info.seqnum =
                      j - gt_encseq_filenum_first_seqnum(esc->encseq, *filenum);
      gt_seq_info_cache_add(esc->grep_cache, gt_str_get(seqid), &seq_info);
    }
  }
  gt_str_delete(pattern);
  gt_str_delete(escaped);
  if (!had_err && num_matches == 0) {
    gt_error_set(err, "no description matched sequence ID '%s'",
                 gt_str_get(seqid));
    had_err = -1;
  }
  return had_err;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r8, %rbx
movq %rcx, %r12
movq %rdx, %rbp
movq %rsi, %r14
movq %rdi, %r13
movb $0x0, 0xf(%rsp)
testq %r8, %r8
je 0xd3c8e
movq %rbx, %rdi
callq 0x3566a
testb %al, %al
jne 0xd3f5d
testq %r14, %r14
je 0xd3f58
testq %rbp, %rbp
je 0xd3f58
movq 0x8(%r13), %rdi
testq %rdi, %rdi
je 0xd3f53
callq 0xc38e9
testb %al, %al
je 0xd3f53
movq %r14, 0x28(%rsp)
movq %rbx, 0x18(%rsp)
cmpq $0x0, 0x18(%r13)
jne 0xd3cd4
callq 0xd7c78
movq %rax, 0x18(%r13)
movq 0x18(%r13), %r14
movq %r12, %rdi
callq 0x3c40b
movq %r14, %rdi
movq %rax, %rsi
callq 0xd7cd5
testq %rax, %rax
je 0xd3d48
movq %rax, %r14
movq 0x20(%r13), %r15
testq %r15, %r15
je 0xd3d2d
movq %r12, %rdi
callq 0x3c40b
movq %r15, %rdi
movq %rax, %rsi
callq 0x77109
testq %rax, %rax
je 0xd3d2d
movq %r12, %rdi
callq 0x3c40b
leaq 0x2df87(%rip), %rsi     # 0x101caa
movq 0x18(%rsp), %rdi
jmp 0xd3f2c
movq (%r14), %rax
movq 0x28(%rsp), %rcx
movq %rax, (%rcx)
movq 0x8(%r14), %rax
movq %rax, (%rbp)
xorl %r12d, %r12d
jmp 0xd3f3c
movq %rbp, 0x38(%rsp)
callq 0x3bfe0
movq %rax, %rbp
callq 0x3bfe0
movq %rax, %rbx
movq %r12, %rdi
callq 0x3c40b
movq %rax, %r14
movq %r12, %rdi
callq 0x3c434
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x762f0
cmpb $0x1, 0x28(%r13)
jne 0xd3d94
leaq 0x2df5e(%rip), %rsi     # 0x101cea
movq %rbp, %rdi
callq 0x3c067
movq %r12, 0x10(%rsp)
movq %rbp, %rdi
movq %rbx, 0x30(%rsp)
movq %rbx, %rsi
callq 0x3c12b
cmpb $0x1, 0x28(%r13)
movq 0x18(%rsp), %r14
jne 0xd3dc4
leaq 0x2df30(%rip), %rsi     # 0x101cec
movq %rbp, %rdi
callq 0x3c067
xorl %r15d, %r15d
movq $0x0, 0x20(%rsp)
movq 0x8(%r13), %rdi
callq 0xbef6c
cmpq %rax, %r15
jae 0xd3eed
movq 0x8(%r13), %rdi
leaq 0x40(%rsp), %rsi
movq %r15, %rdx
callq 0xc3523
testq %rax, %rax
je 0xd3f4e
movq %rax, %r12
movq %rbp, %rdi
callq 0x3c40b
movq 0x40(%rsp), %rcx
leaq 0xf(%rsp), %rdi
movq %rax, %rsi
movq %r12, %rdx
movq %r14, %r8
callq 0x7637f
movl %eax, %r12d
movb $0x1, %bl
testl %eax, %eax
jne 0xd3edb
cmpb $0x1, 0xf(%rsp)
jne 0xd3edb
movq 0x20(%rsp), %rcx
incq %rcx
movq %rcx, 0x20(%rsp)
cmpq $0x2, %rcx
jb 0xd3e72
movq 0x10(%rsp), %rdi
callq 0x3c40b
xorl %ebx, %ebx
movq %r14, %rdi
leaq 0x2de4a(%rip), %rsi     # 0x101caa
movq %rax, %rdx
xorl %eax, %eax
callq 0x3559f
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
jmp 0xd3edb
movq 0x8(%r13), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0xc2a64
movq %r14, %rdi
movq %rax, %rsi
callq 0xcd8d3
movq %rax, 0x48(%rsp)
movq 0x28(%rsp), %rcx
movq %rax, (%rcx)
movq 0x8(%r13), %rdi
movq %rax, %rsi
callq 0xcd955
movq %r15, %rcx
subq %rax, %rcx
movq %rcx, 0x50(%rsp)
movq 0x38(%rsp), %rax
movq %rcx, (%rax)
movq 0x18(%r13), %r14
movq 0x10(%rsp), %rdi
callq 0x3c40b
movq %r14, %rdi
movq 0x18(%rsp), %r14
movq %rax, %rsi
leaq 0x48(%rsp), %rdx
callq 0xd7ce8
testb %bl, %bl
je 0xd3ef0
incq %r15
testl %r12d, %r12d
je 0xd3dd0
jmp 0xd3ef0
xorl %r12d, %r12d
movq %rbp, %rdi
callq 0x3d1eb
movq 0x30(%rsp), %rdi
callq 0x3d1eb
testl %r12d, %r12d
sete %al
cmpq $0x0, 0x20(%rsp)
sete %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0xd3f3c
movq 0x10(%rsp), %rdi
callq 0x3c40b
leaq 0x2ddd3(%rip), %rsi     # 0x101cfc
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x3559f
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movl %r12d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x30ca0
callq 0x30cd7
callq 0x30c69
callq 0x30c32
nop