// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/extended/extract_feature_sequence.c
// Function: extract_feature_sequence_generic
static int extract_feature_sequence_generic(GtStr *sequence, GtGenomeNode *gn,
                                            const char *type, bool join,
                                            GtStr *seqid,
                                            GtStrArray *target_ids,
                                            unsigned int *out_phase_offset,
                                            GtRegionMapping *region_mapping,
                                            GtError *err)
{
  GtFeatureNode *fn;
  GtRange range;
  unsigned int phase_offset = 0;
  char *outsequence;
  const char *target;
  int had_err = 0;

  gt_error_check(err);
  fn = gt_genome_node_cast(gt_feature_node_class(), gn);
  gt_assert(fn);

  if (seqid)
    gt_str_append_str(seqid, gt_genome_node_get_seqid(gn));
  if (target_ids &&
      (target = gt_feature_node_get_attribute(fn, GT_GFF_TARGET))) {
    had_err = gt_gff3_parser_parse_all_target_attributes(target, false,
                                                         target_ids, NULL,
                                                         NULL, "", 0, err);
  }
  if (!had_err) {
    if (join) {
      GtFeatureNodeIterator *fni;
      GtFeatureNode *child;
      bool reverse_strand = false,
           first_child = true,
           first_child_of_type_seen = false;
      GtPhase phase = GT_PHASE_UNDEFINED;
      /* in this case we have to traverse the children */
      fni = gt_feature_node_iterator_new_direct(gt_feature_node_cast(gn));
      while (!had_err && (child = gt_feature_node_iterator_next(fni))) {
        if (first_child) {
          if (target_ids &&
               (target = gt_feature_node_get_attribute(child, GT_GFF_TARGET))) {
            gt_str_array_reset(target_ids);
            had_err = gt_gff3_parser_parse_all_target_attributes(target, false,
                                                                 target_ids,
                                                                 NULL,
                                                                 NULL, "", 0,
                                                                 err);
          }
          first_child = false;
        }
        if (!had_err) {
          if (extract_join_feature((GtGenomeNode*) child, type, region_mapping,
                                   sequence, &reverse_strand,
                                   &first_child_of_type_seen,
                                   &phase, err)) {
            had_err = -1;
          }
          if (phase != GT_PHASE_UNDEFINED) {
            phase_offset = (int) phase;
          }
        }
      }
      gt_feature_node_iterator_delete(fni);
      gt_assert(phase_offset <= (unsigned int) GT_PHASE_UNDEFINED);
      if (!had_err && gt_str_length(sequence)) {
        if (reverse_strand) {
          had_err = gt_reverse_complement(gt_str_get(sequence),
                                          gt_str_length(sequence), err);
        }
      }
    }
    else if (gt_feature_node_get_type(fn) == type) {
      GtPhase phase = gt_feature_node_get_phase(fn);
      gt_assert(!had_err);
      if (phase != GT_PHASE_UNDEFINED)
        phase_offset = (unsigned int) phase;
      /* otherwise we only have to look at this feature */
      range = gt_genome_node_get_range(gn);
      gt_assert(range.start); /* 1-based coordinates */
      had_err = gt_region_mapping_get_sequence(region_mapping, &outsequence,
                                               gt_genome_node_get_seqid(gn),
                                               range.start, range.end, err);
      if (!had_err) {
        gt_str_append_cstr_nt(sequence, outsequence, gt_range_length(&range));
        gt_free(outsequence);
        if (gt_feature_node_get_strand(fn) == GT_STRAND_REVERSE) {
          had_err = gt_reverse_complement(gt_str_get(sequence),
                                          gt_str_length(sequence), err);
        }
      }
    }
  }
  if (out_phase_offset && phase_offset != GT_PHASE_UNDEFINED) {
    *out_phase_offset = phase_offset;
  }
  return had_err;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r9, %r12
movq %r8, %rbx
movl %ecx, %r15d
movq %rdx, 0x20(%rsp)
movq %rsi, %r13
movq %rdi, 0x10(%rsp)
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0xa734a
callq 0x34fea
testb %al, %al
jne 0xa76fb
callq 0x3f04a
movq %rax, %rdi
movq %r13, %rsi
callq 0x4153f
testq %rax, %rax
je 0xa76f6
movq %rax, %r14
testq %rbx, %rbx
je 0xa737e
movq %r13, %rdi
callq 0x415a1
movq %rbx, %rdi
movq %rax, %rsi
callq 0x3b87d
testq %r12, %r12
je 0xa73c7
leaq 0x4040a(%rip), %rsi     # 0xe7794
movq %r14, %rdi
callq 0x3eedc
testq %rax, %rax
je 0xa73c7
leaq 0x47799(%rip), %r9      # 0xeeb37
xorl %ebp, %ebp
movq %rax, %rdi
xorl %esi, %esi
movq %r12, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
pushq 0x80(%rsp)
pushq $0x0
callq 0x4354d
addq $0x10, %rsp
testl %eax, %eax
jne 0xa76a4
testb %r15b, %r15b
je 0xa75c6
xorl %ebp, %ebp
movb %bpl, 0x7(%rsp)
movb %bpl, 0x6(%rsp)
movq %r13, %rdi
callq 0x3f369
movq %rax, %rdi
callq 0x40fcd
movq %rax, 0x18(%rsp)
movq %rax, %rdi
callq 0x41076
testq %rax, %rax
movq 0x80(%rsp), %r15
je 0xa757d
movq %rax, %r14
xorl %ebp, %ebp
movb $0x1, %al
movl $0x3, %r13d
testq %r12, %r12
sete %cl
notb %al
orb %cl, %al
testb $0x1, %al
jne 0xa746d
movq %r14, %rdi
leaq 0x40365(%rip), %rsi     # 0xe7794
callq 0x3eedc
testq %rax, %rax
je 0xa746d
movq %rax, %rbx
movq %r12, %rdi
callq 0x3cbdb
movq %rbx, %rdi
xorl %esi, %esi
movq %r12, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
leaq 0x476df(%rip), %r9      # 0xeeb37
pushq %r15
pushq $0x0
callq 0x4354d
addq $0x10, %rsp
testl %eax, %eax
jne 0xa76d2
testq %r15, %r15
je 0xa7482
movq %r15, %rdi
callq 0x34fea
testb %al, %al
jne 0xa76f1
movq %r14, %rdi
callq 0x3f369
testq %rax, %rax
je 0xa76ec
movq %rax, %rbx
movq %rax, %rdi
movq 0x20(%rsp), %rsi
callq 0x3faa4
testb %al, %al
je 0xa755d
movq %rbx, %rdi
callq 0x3f462
leaq 0x7(%rsp), %rcx
cmpl $0x1, %eax
je 0xa74cf
movl $0x3, %r13d
cmpb $0x0, 0x6(%rsp)
leaq 0x6(%rsp), %rcx
jne 0xa74dd
movb $0x1, (%rcx)
movq %rbx, %rdi
callq 0x3fcc6
movl %eax, %r13d
movq %r14, %rdi
callq 0x415e5
movq %rax, %rbx
movq %rdx, %r15
movq %rax, 0x28(%rsp)
movq %rdx, 0x30(%rsp)
movq %r14, %rdi
callq 0x415a1
movq 0x78(%rsp), %rdi
leaq 0x8(%rsp), %rsi
movq %rax, %rdx
movq %rbx, %rcx
movq %r15, %r8
movq 0x80(%rsp), %r15
movq %r15, %r9
callq 0xa8075
testl %eax, %eax
jne 0xa76c3
movq 0x8(%rsp), %rbx
leaq 0x28(%rsp), %rdi
callq 0x7e19f
movq 0x10(%rsp), %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x3b8d7
movq 0x8(%rsp), %rdi
leaq 0x54149(%rip), %rsi     # 0xfb69c
movl $0x3e, %edx
callq 0x35c27
cmpl $0x3, %r13d
cmovnel %r13d, %ebp
movq 0x18(%rsp), %rdi
callq 0x41076
movq %rax, %r14
xorl %eax, %eax
testq %r14, %r14
jne 0xa7417
movq 0x18(%rsp), %rdi
callq 0x41108
cmpl $0x4, %ebp
jae 0xa76e3
movq 0x10(%rsp), %r14
movq %r14, %rdi
callq 0x3bb86
xorl %ebx, %ebx
testq %rax, %rax
je 0xa76a6
cmpb $0x1, 0x7(%rsp)
jne 0xa76a6
movq %r14, %rdi
callq 0x3bb5d
movq %rax, %rbx
movq %r14, %rdi
jmp 0xa7691
movq %r14, %rdi
callq 0x3f914
cmpq 0x20(%rsp), %rax
je 0xa75de
xorl %ebx, %ebx
xorl %ebp, %ebp
jmp 0xa76a6
movq %r14, %rdi
callq 0x3fcc6
xorl %ebp, %ebp
cmpl $0x3, %eax
cmovnel %eax, %ebp
movq %r13, %rdi
callq 0x415e5
movq %rax, 0x28(%rsp)
movq %rdx, 0x30(%rsp)
testq %rax, %rax
je 0xa7700
movq %rax, %rbx
movq %rdx, %r15
movq %r13, %rdi
callq 0x415a1
leaq 0x8(%rsp), %rsi
movq 0x78(%rsp), %rdi
movq %rax, %rdx
movq %rbx, %rcx
movq %r15, %r8
movq 0x80(%rsp), %r15
movq %r15, %r9
callq 0xa8075
testl %eax, %eax
jne 0xa76a4
movq 0x8(%rsp), %rbx
leaq 0x28(%rsp), %rdi
callq 0x7e19f
movq 0x10(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x3b8d7
movq 0x8(%rsp), %rdi
leaq 0x54030(%rip), %rsi     # 0xfb69c
movl $0x98, %edx
callq 0x35c27
movq %r14, %rdi
callq 0x3f462
cmpl $0x1, %eax
jne 0xa76e8
movq %r12, %rdi
callq 0x3bb5d
movq %rax, %rbx
movq %r12, %rdi
callq 0x3bb86
movq %rbx, %rdi
movq %rax, %rsi
movq %r15, %rdx
callq 0xa8efc
movl %eax, %ebx
movq 0x70(%rsp), %rax
testq %rax, %rax
je 0xa76b2
movl %ebp, (%rax)
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x3, %r13d
cmovnel %r13d, %ebp
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0xa76d4
movl %eax, %ebx
movq 0x18(%rsp), %rdi
callq 0x41108
cmpl $0x4, %ebp
jb 0xa76a6
callq 0x236dc
xorl %ebx, %ebx
jmp 0xa76a6
callq 0x236a5
callq 0x2366e
callq 0x23715
callq 0x235fe
callq 0x23635