// File: /workspace/github_c_makefile_star2_O1/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, %r13
movq %r8, %rbx
movq %rcx, %rbp
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %r12
movq $0x1, 0x28(%rsp)
pcmpeqd %xmm0, %xmm0
movdqa %xmm0, 0x30(%rsp)
testq %r9, %r9
je 0xa8a79
movq %r13, %rdi
callq 0x3566a
testb %al, %al
jne 0xa8f89
testq %r12, %r12
je 0xa8f84
testq %r14, %r14
je 0xa8f84
testq %r15, %r15
je 0xa8f84
movq %r15, %rdi
callq 0x3c434
testq %rax, %rax
je 0xa8f84
cmpb $0x1, 0x1b(%r12)
jne 0xa8af6
cmpq $0x0, 0x40(%r12)
jne 0xa8f8e
subq %rbp, %rbx
incq %rbx
leaq 0x52e68(%rip), %rdx     # 0xfb92e
movl $0x1, %esi
movq %rbx, %rdi
movl $0xe5, %ecx
callq 0x3601f
movq %rax, (%r14)
movq 0x48(%r12), %rcx
leaq (%rcx,%rbp), %rsi
decq %rsi
movq %rax, %rdi
movq %rbx, %rdx
callq 0xb2d0
xorl %ebp, %ebp
jmp 0xa8b12
movq %rbp, 0x10(%rsp)
movq %r12, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0xa8fbb
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testl %eax, %eax
je 0xa8b23
movl %ebp, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rdi
callq 0x3c40b
movq %rax, %rdi
callq 0x7a678
testb %al, %al
je 0xa8b6b
movq 0x38(%r12), %rdi
movq 0x28(%rsp), %rax
movq 0x10(%rsp), %rdx
subq %rax, %rdx
subq %rax, %rbx
movq %r14, %rsi
movq %rbx, %rcx
movq %r15, %r8
movq %r13, %r9
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xd7b59
movb 0x19(%r12), %cl
cmpb $0x1, %cl
jne 0xa8b81
cmpq $0x0, 0x40(%r12)
je 0xa8f93
movq 0x20(%r12), %rax
testq %rax, %rax
jne 0xa8b97
cmpq $0x0, 0x38(%r12)
je 0xa8f9d
testb %cl, %cl
je 0xa8c2a
movq 0x40(%r12), %rbp
testq %rbp, %rbp
je 0xa8f98
leaq 0x30(%rsp), %rcx
movq 0x10(%rsp), %rax
movq %rax, (%rcx)
movq %rbx, 0x8(%rcx)
movq %r15, %rdi
callq 0x3c40b
movq %r13, (%rsp)
leaq 0x18(%rsp), %rcx
leaq 0x40(%rsp), %r8
leaq 0x28(%rsp), %r9
movq %rbp, %rdi
movq %rax, %rsi
leaq 0x30(%rsp), %rdx
callq 0xa9f05
movl %eax, %ebp
testl %eax, %eax
je 0xa8d0a
testl %ebp, %ebp
jne 0xa8b12
movq 0x38(%r12), %rdi
movq 0x40(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq 0x28(%rsp), %rax
movq 0x10(%rsp), %rcx
subq %rax, %rcx
subq %rax, %rbx
movq %rbx, %r8
callq 0xd7c1f
movq %rax, (%r14)
jmp 0xa8b12
cmpb $0x1, 0x18(%r12)
jne 0xa8c76
cmpq $0x0, 0x40(%r12)
jne 0xa8fa2
movq 0x38(%r12), %rdi
testq %rdi, %rdi
movq 0x10(%rsp), %rdx
je 0xa8fa7
decq %rdx
decq %rbx
movq %r14, %rsi
movq %rbx, %rcx
movq %r15, %r8
movq %r13, %r9
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xd7ac1
cmpb $0x1, 0x1c(%r12)
jne 0xa8d8c
movq $-0x1, 0x18(%rsp)
cmpq $0x0, 0x30(%r12)
je 0xa8fac
movq %r15, %rdi
callq 0x3c40b
leaq 0x52ed7(%rip), %rsi     # 0xfbb7d
leaq 0x18(%rsp), %rdx
movq %rax, %rdi
xorl %eax, %eax
callq 0xb680
cmpl $0x1, %eax
je 0xa8cda
movq %r15, %rdi
movl %eax, %ebp
callq 0x3c40b
leaq 0x52eb9(%rip), %rsi     # 0xfbb84
movq %r13, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x3559f
movl %ebp, %eax
cmpl $0x1, %eax
setne %dl
movq 0x18(%rsp), %rsi
cmpq $-0x1, %rsi
setne %cl
orb %dl, %cl
je 0xa8fb1
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpl $0x1, %eax
je 0xa8e5c
xorl %r15d, %r15d
jmp 0xa8f25
movq 0x38(%rsp), %rax
xorl %ebp, %ebp
cmpq $-0x1, %rax
je 0xa8bf3
cmpq $-0x1, 0x30(%rsp)
je 0xa8bf3
movq 0x38(%r12), %rdi
movq 0x40(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq %rax, 0x20(%rsp)
callq 0xd7c59
addq 0x28(%rsp), %rax
cmpq %rax, 0x20(%rsp)
jb 0xa8bf3
movq %r15, %rdi
callq 0x3c40b
movq 0x30(%rsp), %r9
movq 0x38(%rsp), %rcx
movq %rcx, (%rsp)
leaq 0x52d4d(%rip), %rsi     # 0xfbaba
movq %r13, %rdi
movq 0x10(%rsp), %rdx
movq %rbx, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x3559f
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0xa8bf3
cmpb $0x1, 0x1b(%r12)
jne 0xa8dd8
cmpq $0x0, 0x40(%r12)
jne 0xa8fb6
movq 0x10(%rsp), %r15
subq %r15, %rbx
incq %rbx
leaq 0x52b7c(%rip), %rdx     # 0xfb92e
movl $0x1, %esi
movq %rbx, %rdi
movl $0x142, %ecx            # imm = 0x142
callq 0x3601f
movq %rax, (%r14)
movq 0x48(%r12), %rcx
leaq (%rcx,%r15), %rsi
decq %rsi
jmp 0xa8ae7
testq %rax, %rax
je 0xa8eff
movq 0x38(%r12), %rdi
xorl %ebp, %ebp
xorl %esi, %esi
xorl %edx, %edx
callq 0xd7c59
cmpq 0x10(%rsp), %rax
setae %dl
cmpq %rbx, %rax
setae %cl
andb %dl, %cl
jne 0xa8e36
movq %r15, %rdi
movl %ecx, %ebp
movq %rax, %r15
callq 0x3c40b
leaq 0x52e3e(%rip), %rsi     # 0xfbc55
movq %r13, %rdi
movq 0x10(%rsp), %rdx
movq %rbx, %rcx
movq %rax, %r8
movq %r15, %r9
xorl %eax, %eax
callq 0x3559f
movl %ebp, %ecx
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testb %cl, %cl
je 0xa8b12
movq 0x38(%r12), %rdi
movq 0x28(%rsp), %rax
movq 0x10(%rsp), %rcx
subq %rax, %rcx
subq %rax, %rbx
xorl %esi, %esi
xorl %edx, %edx
jmp 0xa8c1a
movq 0x30(%r12), %rdi
movq %rsi, 0x20(%rsp)
callq 0xbef6c
cmpq %rax, 0x20(%rsp)
jae 0xa8ecd
movq 0x30(%r12), %rdi
movq 0x18(%rsp), %rsi
callq 0xc2d57
movq 0x10(%rsp), %rsi
cmpq %rsi, %rax
setae %dl
cmpq %rbx, %rax
setae %cl
testb %cl, %dl
jne 0xa8f20
movq %r15, %rdi
movq %rax, 0x20(%rsp)
callq 0x3c40b
leaq 0x52da7(%rip), %rsi     # 0xfbc55
xorl %r15d, %r15d
movq %r13, %rdi
movq 0x10(%rsp), %rdx
movq %rbx, %rcx
movq %rax, %r8
movq 0x20(%rsp), %r9
xorl %eax, %eax
callq 0x3559f
jmp 0xa8f25
movq 0x18(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x30(%r12), %rdi
callq 0xbef6c
leaq 0x52d1d(%rip), %rsi     # 0xfbc05
xorl %r15d, %r15d
movq %r13, %rdi
movq 0x20(%rsp), %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x3559f
jmp 0xa8f25
movq %r15, %rdi
callq 0x3c40b
leaq 0x52e03(%rip), %rsi     # 0xfbd11
movq %r13, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x3559f
jmp 0xa8b12
xorl %ebp, %ebp
movb $0x1, %r15b
testb %r15b, %r15b
je 0xa8b12
movq %rbx, %rdi
movq 0x10(%rsp), %r15
subq %r15, %rdi
incq %rdi
leaq 0x529eb(%rip), %rdx     # 0xfb92e
movl $0x1, %esi
movl $0x13b, %ecx            # imm = 0x13B
callq 0x3601f
movq %rax, (%r14)
movq 0x30(%r12), %rdi
movq 0x18(%rsp), %rsi
callq 0xc2a64
movq 0x30(%r12), %rdi
movq (%r14), %rsi
leaq (%r15,%rax), %rdx
decq %rdx
leaq (%rbx,%rax), %rcx
decq %rcx
callq 0xc05ff
jmp 0xa8b12
callq 0x23f59
callq 0x23d1f
callq 0x23f20
callq 0x23ee7
callq 0x23e75
callq 0x23eae
callq 0x23e03
callq 0x23e3c
callq 0x23dca
callq 0x23d91
callq 0x23d58