// File: /workspace/github_c_makefile_star2_O2/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 0x89112
movq %r12, %rdi
callq 0xc103
testb %al, %al
jne 0x89590
testq %r13, %r13
je 0x89562
testq %r15, %r15
je 0x89562
testq %rbp, %rbp
je 0x89562
movq %rbp, %rdi
callq 0x14461
testq %rax, %rax
je 0x89562
cmpb $0x1, 0x1b(%r13)
jne 0x8918b
cmpq $0x0, 0x40(%r13)
jne 0x895be
subq %r14, %rbx
incq %rbx
leaq 0x5ba51(%rip), %rdx     # 0xe4bae
pushq $0x1
popq %rsi
movq %rbx, %rdi
movl $0xe5, %ecx
callq 0xce9a
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 0x891a6
movq %r14, 0x10(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x89778
pushq $-0x1
popq %r14
testl %eax, %eax
je 0x891b8
movl %r14d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbp, %rdi
callq 0x143d2
movq %rax, %rdi
callq 0x59a50
testb %al, %al
je 0x891fa
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 0xbfcdb
movb 0x19(%r13), %cl
cmpb $0x1, %cl
jne 0x8920e
cmpq $0x0, 0x40(%r13)
je 0x895f6
movq 0x20(%r13), %rax
testq %rax, %rax
jne 0x89222
cmpq $0x0, 0x38(%r13)
je 0x89652
testb %cl, %cl
je 0x892f8
movq 0x40(%r13), %r14
testq %r14, %r14
je 0x89624
leaq 0x18(%rsp), %rcx
movq 0x10(%rsp), %rax
movq %rax, (%rcx)
movq %rbx, 0x8(%rcx)
movq %rbp, %rdi
callq 0x143d2
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 0x8abc8
movl %eax, %r14d
testl %eax, %eax
jne 0x891a6
movq 0x20(%rsp), %r14
cmpq $-0x1, %r14
je 0x89414
cmpq $-0x1, 0x18(%rsp)
je 0x89414
movq 0x38(%r13), %rdi
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
callq 0xbff73
movq 0x28(%rsp), %r8
addq %r8, %rax
cmpq %rax, %r14
jb 0x89419
movq %rbp, %rdi
callq 0x143d2
movq 0x18(%rsp), %r9
movq 0x20(%rsp), %rcx
movq %rcx, (%rsp)
leaq 0x5ba60(%rip), %rsi     # 0xe4d3a
movq %r12, %rdi
movq 0x10(%rsp), %rdx
movq %rbx, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0xc007
pushq $-0x1
popq %r14
jmp 0x891a6
cmpb $0x1, 0x18(%r13)
jne 0x89341
cmpq $0x0, 0x40(%r13)
jne 0x89683
movq 0x38(%r13), %rdi
testq %rdi, %rdi
movq 0x10(%rsp), %rdx
je 0x896b4
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 0xbfb7f
cmpb $0x1, 0x1c(%r13)
jne 0x893e0
orq $-0x1, 0x18(%rsp)
cmpq $0x0, 0x30(%r13)
je 0x896e5
movq %rbp, %rdi
callq 0x143d2
leaq 0x5ba91(%rip), %rsi     # 0xe4dfd
leaq 0x18(%rsp), %rdx
movq %rax, %rdi
xorl %eax, %eax
callq 0xb680
cmpl $0x1, %eax
jne 0x894a3
movq 0x18(%rsp), %rax
movq %rax, 0x40(%rsp)
cmpq $-0x1, %rax
je 0x89747
movq 0x30(%r13), %rdi
callq 0xa1f8d
cmpq %rax, 0x40(%rsp)
jae 0x894b4
movq 0x30(%r13), %rdi
movq 0x18(%rsp), %rsi
callq 0xa6b5f
movq 0x10(%rsp), %rdx
cmpq %rdx, %rax
setae %sil
cmpq %rbx, %rax
setae %cl
testb %cl, %sil
jne 0x89512
movq %rbp, %rdi
movq %rdx, %r15
jmp 0x89479
cmpb $0x1, 0x1b(%r13)
jne 0x89442
cmpq $0x0, 0x40(%r13)
jne 0x89716
movq 0x10(%rsp), %r14
subq %r14, %rbx
incq %rbx
leaq 0x5b7aa(%rip), %rdx     # 0xe4bae
pushq $0x1
popq %rsi
movq %rbx, %rdi
movl $0x142, %ecx            # imm = 0x142
jmp 0x89168
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 0xbfed3
movq %rax, (%r15)
jmp 0x89186
testq %rax, %rax
je 0x894de
movq 0x38(%r13), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xbff73
movq 0x10(%rsp), %rcx
cmpq %rcx, %rax
setae %sil
cmpq %rbx, %rax
setae %dl
testb %dl, %sil
jne 0x894ff
movq %rbp, %rdi
movq %rcx, %r15
movq %rax, %r13
callq 0x143d2
leaq 0x5ba4d(%rip), %rsi     # 0xe4ed5
movq %r12, %rdi
movq %r15, %rdx
movq %rbx, %rcx
movq %rax, %r8
movq %r13, %r9
xorl %eax, %eax
callq 0xc007
jmp 0x891a6
movq %rbp, %rdi
callq 0x143d2
leaq 0x5b952(%rip), %rsi     # 0xe4e04
jmp 0x894ed
movq 0x18(%rsp), %rbx
movq 0x30(%r13), %rdi
callq 0xa1f8d
leaq 0x5b9bc(%rip), %rsi     # 0xe4e85
movq %r12, %rdi
movq %rbx, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0xc007
jmp 0x891a6
movq %rbp, %rdi
callq 0x143d2
leaq 0x5baa4(%rip), %rsi     # 0xe4f91
movq %r12, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xc007
jmp 0x891a6
movq 0x38(%r13), %rdi
decq %rcx
decq %rbx
xorl %esi, %esi
xorl %edx, %edx
jmp 0x89432
movq %rbx, %rdi
subq %rdx, %rdi
incq %rdi
movq %rdx, %r14
leaq 0x5b689(%rip), %rdx     # 0xe4bae
pushq $0x1
popq %rsi
movl $0x13b, %ecx            # imm = 0x13B
callq 0xce9a
movq %rax, (%r15)
movq 0x30(%r13), %rdi
movq 0x18(%rsp), %rsi
callq 0xa6788
movq 0x30(%r13), %rdi
movq (%r15), %rsi
leaq (%r14,%rax), %rdx
decq %rdx
leaq (%rbx,%rax), %rcx
decq %rcx
callq 0xa3d89
jmp 0x89186
movq 0xa4a4f(%rip), %rax     # 0x12dfb8
movq (%rax), %rdi
leaq 0x40af3(%rip), %rsi     # 0xca066
leaq 0x5b733(%rip), %rdx     # 0xe4cad
leaq 0x5b70d(%rip), %rcx     # 0xe4c8e
leaq 0x5b626(%rip), %r8      # 0xe4bae
movl $0xe0, %r9d
jmp 0x895ea
movq 0xa4a21(%rip), %rax     # 0x12dfb8
movq (%rax), %rdi
leaq 0x40ac5(%rip), %rsi     # 0xca066
leaq 0x410b1(%rip), %rdx     # 0xca659
leaq 0x5b6df(%rip), %rcx     # 0xe4c8e
leaq 0x5b5f8(%rip), %r8      # 0xe4bae
movl $0xdf, %r9d
jmp 0x895ea
movq 0xa49f3(%rip), %rax     # 0x12dfb8
movq (%rax), %rdi
leaq 0x40a97(%rip), %rsi     # 0xca066
leaq 0x5b706(%rip), %rdx     # 0xe4cdc
leaq 0x5b6b1(%rip), %rcx     # 0xe4c8e
leaq 0x5b5ca(%rip), %r8      # 0xe4bae
movl $0xe4, %r9d
xorl %eax, %eax
callq 0xb8c0
callq 0xb300
movq 0xa49bb(%rip), %rax     # 0x12dfb8
movq (%rax), %rdi
leaq 0x40a5f(%rip), %rsi     # 0xca066
leaq 0x5b6e8(%rip), %rdx     # 0xe4cf6
leaq 0x5b679(%rip), %rcx     # 0xe4c8e
leaq 0x5b592(%rip), %r8      # 0xe4bae
movl $0xf8, %r9d
jmp 0x895ea
movq 0xa498d(%rip), %rax     # 0x12dfb8
movq (%rax), %rdi
leaq 0x40a31(%rip), %rsi     # 0xca066
leaq 0x5b6ca(%rip), %rdx     # 0xe4d06
leaq 0x5b64b(%rip), %rcx     # 0xe4c8e
leaq 0x5b564(%rip), %r8      # 0xe4bae
movl $0xfc, %r9d
jmp 0x895ea
movq 0xa495f(%rip), %rax     # 0x12dfb8
movq (%rax), %rdi
leaq 0x40a03(%rip), %rsi     # 0xca066
leaq 0x5b6b5(%rip), %rdx     # 0xe4d1f
leaq 0x5b61d(%rip), %rcx     # 0xe4c8e
leaq 0x5b536(%rip), %r8      # 0xe4bae
movl $0xf9, %r9d
jmp 0x895ea
movq 0xa492e(%rip), %rax     # 0x12dfb8
movq (%rax), %rdi
leaq 0x409d2(%rip), %rsi     # 0xca066
leaq 0x5b641(%rip), %rdx     # 0xe4cdc
leaq 0x5b5ec(%rip), %rcx     # 0xe4c8e
leaq 0x5b505(%rip), %r8      # 0xe4bae
movl $0x117, %r9d            # imm = 0x117
jmp 0x895ea
movq 0xa48fd(%rip), %rax     # 0x12dfb8
movq (%rax), %rdi
leaq 0x409a1(%rip), %rsi     # 0xca066
leaq 0x5b662(%rip), %rdx     # 0xe4d2e
leaq 0x5b5bb(%rip), %rcx     # 0xe4c8e
leaq 0x5b4d4(%rip), %r8      # 0xe4bae
movl $0x118, %r9d            # imm = 0x118
jmp 0x895ea
movq 0xa48cc(%rip), %rax     # 0x12dfb8
movq (%rax), %rdi
leaq 0x40970(%rip), %rsi     # 0xca066
leaq 0x5b6f5(%rip), %rdx     # 0xe4df2
leaq 0x5b58a(%rip), %rcx     # 0xe4c8e
leaq 0x5b4a3(%rip), %r8      # 0xe4bae
movl $0x11f, %r9d            # imm = 0x11F
jmp 0x895ea
movq 0xa489b(%rip), %rax     # 0x12dfb8
movq (%rax), %rdi
leaq 0x4093f(%rip), %rsi     # 0xca066
leaq 0x5b5ae(%rip), %rdx     # 0xe4cdc
leaq 0x5b559(%rip), %rcx     # 0xe4c8e
leaq 0x5b472(%rip), %r8      # 0xe4bae
movl $0x141, %r9d            # imm = 0x141
jmp 0x895ea
movq 0xa486a(%rip), %rax     # 0x12dfb8
movq (%rax), %rdi
leaq 0x4090e(%rip), %rsi     # 0xca066
leaq 0x5b703(%rip), %rdx     # 0xe4e62
leaq 0x5b528(%rip), %rcx     # 0xe4c8e
leaq 0x5b441(%rip), %r8      # 0xe4bae
movl $0x126, %r9d            # imm = 0x126
jmp 0x895ea