// File: /workspace/github_c_makefile_star2_O3/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 $0x48, %rsp
movq %r8, %rbx
movq %rcx, %r14
movq %rdx, %rbp
movq %rsi, 0x18(%rsp)
movq %rdi, %r13
movb $0x0, 0xf(%rsp)
testq %r8, %r8
je 0xd4a58
movq %rbx, %rdi
callq 0x34fea
testb %al, %al
jne 0xd4d06
cmpq $0x0, 0x18(%rsp)
je 0xd4d01
testq %rbp, %rbp
je 0xd4d01
movq 0x8(%r13), %rdi
testq %rdi, %rdi
je 0xd4cfc
callq 0xc4931
testb %al, %al
je 0xd4cfc
movq 0x18(%r13), %r15
testq %r15, %r15
jne 0xd4a9c
callq 0xd8380
movq %rax, %r15
movq %rax, 0x18(%r13)
movq %r14, %rdi
callq 0x3bb5d
movq %r15, %rdi
movq %rax, %rsi
callq 0xd83dd
testq %rax, %rax
je 0xd4b07
movq %rax, %r15
movq 0x20(%r13), %r12
testq %r12, %r12
je 0xd4aec
movq %r14, %rdi
callq 0x3bb5d
movq %r12, %rdi
movq %rax, %rsi
callq 0x775ed
testq %rax, %rax
je 0xd4aec
movq %r14, %rdi
callq 0x3bb5d
leaq 0x2d137(%rip), %rsi     # 0x101c1e
jmp 0xd4ca9
movq (%r15), %rax
movq 0x18(%rsp), %rcx
movq %rax, (%rcx)
movq 0x8(%r15), %rax
movq %rax, (%rbp)
xorl %r12d, %r12d
jmp 0xd4cbc
movq %rbp, 0x28(%rsp)
callq 0x3b728
movq %rax, %rbp
callq 0x3b728
movq %rax, %r12
movq %r14, %rdi
callq 0x3bb5d
movq %rax, %r15
movq %r14, %rdi
callq 0x3bb86
movq %r12, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x76800
cmpb $0x1, 0x28(%r13)
jne 0xd4b53
leaq 0x2d113(%rip), %rsi     # 0x101c5e
movq %rbp, %rdi
callq 0x3b7af
movq %rbp, %rdi
movq %r12, %rsi
callq 0x3b87d
cmpb $0x1, 0x28(%r13)
jne 0xd4b74
leaq 0x2d0f4(%rip), %rsi     # 0x101c60
movq %rbp, %rdi
callq 0x3b7af
movq %r14, 0x10(%rsp)
movq 0x8(%r13), %rdi
callq 0xbff74
testq %rax, %rax
movq %r12, 0x20(%rsp)
je 0xd4c6a
xorl %r14d, %r14d
xorl %r15d, %r15d
movq 0x8(%r13), %rdi
leaq 0x30(%rsp), %rsi
movq %r15, %rdx
callq 0xc4566
testq %rax, %rax
je 0xd4cf7
movq %rax, %r12
movq %rbp, %rdi
callq 0x3bb5d
movq 0x30(%rsp), %rcx
leaq 0xf(%rsp), %rdi
movq %rax, %rsi
movq %r12, %rdx
movq %rbx, %r8
callq 0x76893
testl %eax, %eax
jne 0xd4c72
cmpb $0x1, 0xf(%rsp)
jne 0xd4c53
incq %r14
cmpq $0x1, %r14
ja 0xd4cce
movq 0x8(%r13), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0xc3ab6
movq %r12, %rdi
movq %rax, %rsi
callq 0xce800
movq %rax, 0x38(%rsp)
movq 0x18(%rsp), %rcx
movq %rax, (%rcx)
movq 0x8(%r13), %rdi
movq %rax, %rsi
callq 0xce880
movq %r15, %rcx
subq %rax, %rcx
movq %rcx, 0x40(%rsp)
movq 0x28(%rsp), %rax
movq %rcx, (%rax)
movq 0x18(%r13), %r12
movq 0x10(%rsp), %rdi
callq 0x3bb5d
movq %r12, %rdi
movq %rax, %rsi
leaq 0x38(%rsp), %rdx
callq 0xd83f0
incq %r15
movq 0x8(%r13), %rdi
callq 0xbff74
cmpq %rax, %r15
jb 0xd4b96
jmp 0xd4c6d
xorl %r14d, %r14d
xorl %r12d, %r12d
jmp 0xd4c75
movl %eax, %r12d
testq %r14, %r14
sete %r14b
movq %rbp, %rdi
callq 0x3c87b
movq 0x20(%rsp), %rdi
callq 0x3c87b
testl %r12d, %r12d
jne 0xd4cbc
testb %r14b, %r14b
je 0xd4cbc
movq 0x10(%rsp), %rdi
callq 0x3bb5d
leaq 0x2cfc7(%rip), %rsi     # 0x101c70
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x34f1f
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movl %r12d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%rsp), %rdi
callq 0x3bb5d
leaq 0x2cf3f(%rip), %rsi     # 0x101c1e
xorl %r14d, %r14d
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x34f1f
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
jmp 0xd4c7c
callq 0x306a3
callq 0x306da
callq 0x3066c
callq 0x30635
nop