// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/extended/region_mapping.c
// Function: gt_region_mapping_get_sequence
int gt_region_mapping_get_sequence(GtRegionMapping *rm, char **seq,
                                   GtStr *seqid, GtUword start,
                                   GtUword end, GtError *err)
{
  int had_err = 0;
  GtUword offset = 1;
  GtRange range = {GT_UNDEF_UWORD, GT_UNDEF_UWORD};
  gt_error_check(err);
  gt_assert(rm && seq && seqid && gt_str_length(seqid) > 0);

  /* handle rawseq access first  */
  if (rm->userawseq) {
    gt_assert(!rm->seqid2seqnum_mapping);
    *seq = gt_calloc(end - start + 1, sizeof (char));
    strncpy(*seq, rm->rawseq + start - 1, (end - start + 1) * sizeof (char));
    return 0;
  }

  /* make sure that correct sequence is loaded */
  had_err = update_seq_col_if_necessary(rm, seqid, err);

  /* MD5 sequence id */
  if (!had_err) {
    if (gt_md5_seqid_has_prefix(gt_str_get(seqid))) {
      had_err = gt_seq_col_md5_to_seq(rm->seq_col, seq, start - offset,
                                      end - offset, seqid, err);
      return had_err;
    }
  }

  /* ``regular'' sequence ID */
  if (!had_err) {
    gt_assert(!rm->usedesc || rm->seqid2seqnum_mapping);
    gt_assert(rm->mapping || rm->seq_col);
    if (rm->usedesc) {
      GtUword seqnum, filenum;
      gt_assert(rm->seqid2seqnum_mapping);
      range.start = start;
      range.end = end;
      had_err = gt_seqid2seqnum_mapping_map(rm->seqid2seqnum_mapping,
                                            gt_str_get(seqid), &range, &seqnum,
                                            &filenum, &offset, err);

      if (!had_err) {
        if (range.end != GT_UNDEF_UWORD && range.start != GT_UNDEF_UWORD &&
              range.end >= gt_seq_col_get_sequence_length(rm->seq_col, filenum,
                                                          seqnum)
              + offset) {
          gt_error_set(err, "trying to extract range " GT_WU "-" GT_WU " on "
                       "sequence ``%s'' which is not covered by that sequence "
                       "(with boundaries " GT_WU "-" GT_WU "). Has the "
                       "sequence-region to sequence mapping been defined "
                       "correctly?",
                       start, end, gt_str_get(seqid),
                       range.start, range.end);
          had_err = -1;
        }
      }
      if (!had_err) {
        *seq = gt_seq_col_get_sequence(rm->seq_col, filenum, seqnum,
                                       start - offset, end - offset);
      }
    } else if (rm->matchdesc) {
      gt_assert(!rm->seqid2seqnum_mapping);
      gt_assert(rm->seq_col);
      if (!had_err) {
        had_err = gt_seq_col_grep_desc(rm->seq_col, seq, start - 1, end - 1,
                                       seqid, err);
      }
    } else if (rm->useseqno) {
      GtUword seqno = GT_UNDEF_UWORD;
      gt_assert(rm->encseq);
      if (1 != sscanf(gt_str_get(seqid), "seq"GT_WU"", &seqno)) {
        gt_error_set(err, "seqid '%s' does not have the form 'seqX' "
                          "where X is a sequence number in the encoded "
                          "sequence", gt_str_get(seqid));
        had_err = -1;
      }
      gt_assert(had_err || seqno != GT_UNDEF_UWORD);
      if (!had_err && seqno >= gt_encseq_num_of_sequences(rm->encseq)) {
          gt_error_set(err, "trying to access sequence "GT_WU", but encoded "
                            "sequence contains only "GT_WU" sequences",
                            seqno, gt_encseq_num_of_sequences(rm->encseq));
          had_err = -1;
      }
      if (!had_err) {
        GtUword seqlength = gt_encseq_seqlength(rm->encseq, seqno);
        if (start > seqlength || end > seqlength) {
          gt_error_set(err, "trying to extract range " GT_WU "-" GT_WU " on "
                       "sequence ``%s'' which is not covered by that sequence "
                       "(only " GT_WU " characters in size). Has the "
                       "sequence-region to sequence mapping been defined "
                       "correctly?",
                       start, end, gt_str_get(seqid), seqlength);
          had_err = -1;
        }
      }
      if (!had_err) {
        GtUword seqstartpos;
        *seq = gt_calloc(end - start + 1, sizeof (char));
        seqstartpos = gt_encseq_seqstartpos(rm->encseq, seqno);
        gt_encseq_extract_decoded(rm->encseq, *seq, seqstartpos + start - 1,
                                  seqstartpos + end - 1);
      }
    } else if (rm->userawseq) {
      gt_assert(!rm->seqid2seqnum_mapping);
      *seq = gt_calloc(end - start + 1, sizeof (char));
      strncpy(*seq, rm->rawseq + start - 1, (end - start + 1) * sizeof (char));
    } else if (rm->mapping) {
      if (!had_err) {
        GtUword seqlength = gt_seq_col_get_sequence_length(rm->seq_col,
                                                                 0, 0);
        if (start > seqlength || end > seqlength) {
          had_err = -1;
          gt_error_set(err, "trying to extract range " GT_WU "-" GT_WU " on "
                       "sequence ``%s'' which is not covered by that sequence "
                       "(only " GT_WU " characters in size). Has the "
                       "sequence-region to sequence mapping been defined "
                       "correctly?",
                       start, end, gt_str_get(seqid), seqlength);
        }
        if (!had_err) {
          *seq = gt_seq_col_get_sequence(rm->seq_col, 0, 0, start - offset,
                                         end - offset);
        }
      }
    } else {
      gt_assert(!rm->usedesc && !rm->matchdesc);
      gt_error_set(err, "no mapping rule given and no MD5 tags "
                        "present in the query seqid \"%s\" -- no mapping can "
                        "be defined", 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 %r9, %r12
movq %r8, %rbx
movq %rcx, %r14
movq %rdx, %rbp
movq %rsi, %r15
movq %rdi, %r13
movq $0x1, 0x28(%rsp)
testq %r9, %r9
je 0xa80b3
movq %r12, %rdi
callq 0x34fea
testb %al, %al
jne 0xa8515
testq %r13, %r13
je 0xa8510
testq %r15, %r15
je 0xa8510
testq %rbp, %rbp
je 0xa8510
movq %rbp, %rdi
callq 0x3bb86
testq %rax, %rax
je 0xa8510
cmpb $0x1, 0x1b(%r13)
jne 0xa812e
cmpq $0x0, 0x40(%r13)
jne 0xa851a
subq %r14, %rbx
incq %rbx
leaq 0x537a0(%rip), %rdx     # 0xfb89e
movl $0x1, %esi
movq %rbx, %rdi
movl $0xe5, %ecx
callq 0x359a6
movq %rax, (%r15)
movq 0x48(%r13), %rcx
leaq (%rcx,%r14), %rsi
decq %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xb2d0
xorl %r14d, %r14d
jmp 0xa814b
movq %r14, 0x10(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0xa8547
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
testl %eax, %eax
je 0xa815d
movl %r14d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbp, %rdi
callq 0x3bb5d
movq %rax, %rdi
callq 0x7aa64
testb %al, %al
je 0xa819f
movq 0x38(%r13), %rdi
movq 0x10(%rsp), %rdx
decq %rdx
decq %rbx
movq %r15, %rsi
movq %rbx, %rcx
movq %rbp, %r8
movq %r12, %r9
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xd8261
movb 0x19(%r13), %cl
cmpb $0x1, %cl
jne 0xa81b3
cmpq $0x0, 0x40(%r13)
je 0xa851f
movq 0x20(%r13), %rax
testq %rax, %rax
jne 0xa81c7
cmpq $0x0, 0x38(%r13)
je 0xa8529
testb %cl, %cl
je 0xa829f
movq 0x40(%r13), %r14
testq %r14, %r14
je 0xa8524
leaq 0x18(%rsp), %rcx
movq 0x10(%rsp), %rax
movq %rax, (%rcx)
movq %rbx, 0x8(%rcx)
movq %rbp, %rdi
callq 0x3bb5d
movq %r12, (%rsp)
leaq 0x38(%rsp), %rcx
leaq 0x30(%rsp), %r8
leaq 0x28(%rsp), %r9
movq %r14, %rdi
movq %rax, %rsi
leaq 0x18(%rsp), %rdx
callq 0xa944a
movl %eax, %r14d
testl %eax, %eax
jne 0xa814b
movq 0x20(%rsp), %r14
cmpq $-0x1, %r14
je 0xa83c0
cmpq $-0x1, 0x18(%rsp)
je 0xa83c0
movq 0x38(%r13), %rdi
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
callq 0xd8361
movq 0x28(%rsp), %r8
addq %r8, %rax
cmpq %rax, %r14
jb 0xa83c5
movq %rbp, %rdi
callq 0x3bb5d
movq 0x18(%rsp), %r9
movq 0x20(%rsp), %rcx
movq %rcx, (%rsp)
leaq 0x537ab(%rip), %rsi     # 0xfba2a
movq %r12, %rdi
movq 0x10(%rsp), %rdx
movq %rbx, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x34f1f
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
jmp 0xa814b
cmpb $0x1, 0x18(%r13)
jne 0xa82e8
cmpq $0x0, 0x40(%r13)
jne 0xa852e
movq 0x38(%r13), %rdi
testq %rdi, %rdi
movq 0x10(%rsp), %rdx
je 0xa8533
decq %rdx
decq %rbx
movq %r15, %rsi
movq %rbx, %rcx
movq %rbp, %r8
movq %r12, %r9
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xd81c9
cmpb $0x1, 0x1c(%r13)
jne 0xa838a
movq $-0x1, 0x18(%rsp)
cmpq $0x0, 0x30(%r13)
je 0xa8538
movq %rbp, %rdi
callq 0x3bb5d
leaq 0x537d7(%rip), %rsi     # 0xfbaed
leaq 0x18(%rsp), %rdx
movq %rax, %rdi
xorl %eax, %eax
callq 0xb680
cmpl $0x1, %eax
jne 0xa844f
movq 0x18(%rsp), %rax
movq %rax, 0x40(%rsp)
cmpq $-0x1, %rax
je 0xa8542
movq 0x30(%r13), %rdi
callq 0xbff74
cmpq %rax, 0x40(%rsp)
jae 0xa8460
movq 0x30(%r13), %rdi
movq 0x18(%rsp), %rsi
callq 0xc3d9a
movq 0x10(%rsp), %rdx
cmpq %rdx, %rax
setae %sil
cmpq %rbx, %rax
setae %cl
testb %cl, %sil
jne 0xa84be
movq %rbp, %rdi
movq %rdx, %r15
jmp 0xa8425
cmpb $0x1, 0x1b(%r13)
jne 0xa83ee
cmpq $0x0, 0x40(%r13)
jne 0xa853d
movq 0x10(%rsp), %r14
subq %r14, %rbx
incq %rbx
leaq 0x534f0(%rip), %rdx     # 0xfb89e
movl $0x1, %esi
movq %rbx, %rdi
movl $0x142, %ecx            # imm = 0x142
jmp 0xa810b
movq 0x28(%rsp), %r8
movq 0x38(%r13), %rdi
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq 0x10(%rsp), %rcx
subq %r8, %rcx
subq %r8, %rbx
movq %rbx, %r8
callq 0xd8327
movq %rax, (%r15)
jmp 0xa8129
testq %rax, %rax
je 0xa848a
movq 0x38(%r13), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xd8361
movq 0x10(%rsp), %rcx
cmpq %rcx, %rax
setae %sil
cmpq %rbx, %rax
setae %dl
testb %dl, %sil
jne 0xa84ab
movq %rbp, %rdi
movq %rcx, %r15
movq %rax, %r13
callq 0x3bb5d
leaq 0x53791(%rip), %rsi     # 0xfbbc5
movq %r12, %rdi
movq %r15, %rdx
movq %rbx, %rcx
movq %rax, %r8
movq %r13, %r9
xorl %eax, %eax
callq 0x34f1f
jmp 0xa814b
movq %rbp, %rdi
callq 0x3bb5d
leaq 0x53696(%rip), %rsi     # 0xfbaf4
jmp 0xa8499
movq 0x18(%rsp), %rbx
movq 0x30(%r13), %rdi
callq 0xbff74
leaq 0x53700(%rip), %rsi     # 0xfbb75
movq %r12, %rdi
movq %rbx, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x34f1f
jmp 0xa814b
movq %rbp, %rdi
callq 0x3bb5d
leaq 0x537e8(%rip), %rsi     # 0xfbc81
movq %r12, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x34f1f
jmp 0xa814b
movq 0x38(%r13), %rdi
decq %rcx
decq %rbx
xorl %esi, %esi
xorl %edx, %edx
jmp 0xa83de
movq %rbx, %rdi
subq %rdx, %rdi
incq %rdi
movq %rdx, %r14
leaq 0x533cd(%rip), %rdx     # 0xfb89e
movl $0x1, %esi
movl $0x13b, %ecx            # imm = 0x13B
callq 0x359a6
movq %rax, (%r15)
movq 0x30(%r13), %rdi
movq 0x18(%rsp), %rsi
callq 0xc3ab6
movq 0x30(%r13), %rdi
movq (%r15), %rsi
leaq (%r14,%rax), %rdx
decq %rdx
leaq (%rbx,%rax), %rcx
decq %rcx
callq 0xc1686
jmp 0xa8129
callq 0x23e81
callq 0x23c47
callq 0x23e48
callq 0x23e0f
callq 0x23d9d
callq 0x23dd6
callq 0x23d2b
callq 0x23d64
callq 0x23cf2
callq 0x23c80
callq 0x23cb9