// File: /workspace/github_c_makefile_star2_O1/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 $0x48, %rsp
movq %r9, %r12
movq %r8, %rbx
movl %ecx, %ebp
movq %rdx, 0x38(%rsp)
movq %rsi, %r15
movq %rdi, 0x20(%rsp)
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0xa7c8d
callq 0x3566a
testb %al, %al
jne 0xa80ad
callq 0x3f9be
movq %rax, %rdi
movq %r15, %rsi
callq 0x41edd
testq %rax, %rax
je 0xa80a3
movq %rax, %r14
testq %rbx, %rbx
je 0xa7cc1
movq %r15, %rdi
callq 0x41f3f
movq %rbx, %rdi
movq %rax, %rsi
callq 0x3c12b
xorl %ebx, %ebx
movl $0x0, %r13d
testq %r12, %r12
je 0xa7d11
leaq 0x3fb11(%rip), %rsi     # 0xe77e6
movq %r14, %rdi
callq 0x3f850
movl $0x0, %r13d
testq %rax, %rax
je 0xa7d11
leaq 0x46e90(%rip), %r9      # 0xeeb7f
movq %rax, %rdi
xorl %esi, %esi
movq %r12, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
pushq 0x90(%rsp)
pushq $0x0
callq 0x43ef6
addq $0x10, %rsp
movl %eax, %r13d
testl %r13d, %r13d
je 0xa7d37
movq 0x80(%rsp), %rax
testq %rax, %rax
je 0xa7d25
movl %ebx, (%rax)
movl %r13d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testb %bpl, %bpl
je 0xa7f50
movq %r15, %rdi
callq 0x3fcd9
movq %rax, %rdi
callq 0x41959
movq %rax, 0x40(%rsp)
movq %rax, %rdi
callq 0x41a02
testq %rax, %rax
je 0xa7f69
movq %rax, %r15
movb $0x1, %r14b
movl $0x3, 0x8(%rsp)
movl $0x0, 0x1c(%rsp)
movl $0x0, 0x4(%rsp)
movl $0x0, 0xc(%rsp)
movq 0x90(%rsp), %rbp
testq %r12, %r12
sete %cl
movzbl %r14b, %eax
notb %r14b
testb $0x1, %al
movl $0x0, %edx
cmovnel %edx, %eax
orb %cl, %r14b
testb $0x1, %r14b
jne 0xa7dfb
movq %r15, %rdi
leaq 0x3fa28(%rip), %rsi     # 0xe77e6
callq 0x3f850
testq %rax, %rax
je 0xa7e00
movq %rax, %rbx
movq %r12, %rdi
callq 0x3d54e
xorl %r14d, %r14d
movq %rbx, %rdi
xorl %esi, %esi
movq %r12, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
leaq 0x46d95(%rip), %r9      # 0xeeb7f
pushq %rbp
pushq $0x0
callq 0x43ef6
addq $0x10, %rsp
movl %eax, %r13d
jmp 0xa7e06
movl %eax, %r14d
jmp 0xa7e03
xorl %r14d, %r14d
xorl %r13d, %r13d
testl %r13d, %r13d
jne 0xa7f26
testq %rbp, %rbp
je 0xa7e24
movq %rbp, %rdi
callq 0x3566a
testb %al, %al
jne 0xa80b2
movq %r15, %rdi
callq 0x3fcd9
testq %rax, %rax
je 0xa80a8
movq %rax, %rbx
movq %rax, %rdi
movq 0x38(%rsp), %rsi
callq 0x40409
xorl %r13d, %r13d
testb %al, %al
je 0xa7f14
movq %rbx, %rdi
callq 0x3fdd2
cmpl $0x1, %eax
jne 0xa7e6b
movb $0x1, %al
movl %eax, 0x1c(%rsp)
movl 0x4(%rsp), %eax
movl %eax, %ebp
jmp 0xa7e7d
movb $0x1, %bpl
movl $0x3, 0x8(%rsp)
testb $0x1, 0x4(%rsp)
jne 0xa7e8f
movq %rbx, %rdi
callq 0x4062b
movl %eax, 0x8(%rsp)
movl %ebp, %eax
movl %eax, 0x4(%rsp)
movq %r15, %rdi
callq 0x41f83
movq %rax, 0x28(%rsp)
movq %rdx, 0x30(%rsp)
movq %r15, %rdi
callq 0x41f3f
movq 0x28(%rsp), %rcx
movq 0x30(%rsp), %r8
movq 0x88(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movq %rax, %rdx
movq 0x90(%rsp), %rbp
movq %rbp, %r9
callq 0xa8a31
testl %eax, %eax
je 0xa7edf
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
jmp 0xa7f14
movq 0x10(%rsp), %rbx
leaq 0x28(%rsp), %rdi
callq 0x7e05b
movq 0x20(%rsp), %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x3c185
movq 0x10(%rsp), %rdi
leaq 0x53822(%rip), %rsi     # 0xfb72c
movl $0x3e, %edx
callq 0x362a0
movl 0x8(%rsp), %ecx
cmpl $0x3, %ecx
movl 0xc(%rsp), %eax
cmovnel %ecx, %eax
movl %eax, 0xc(%rsp)
testl %r13d, %r13d
sete %bl
jne 0xa7f44
movq 0x40(%rsp), %rdi
callq 0x41a02
movq %rax, %r15
testq %rax, %rax
jne 0xa7d94
movl 0xc(%rsp), %r14d
movl 0x1c(%rsp), %r15d
jmp 0xa7f74
movq %r14, %rdi
callq 0x40276
cmpq 0x38(%rsp), %rax
je 0xa7fbe
xorl %r13d, %r13d
xorl %ebx, %ebx
jmp 0xa7d16
movb $0x1, %bl
xorl %r15d, %r15d
xorl %r13d, %r13d
xorl %r14d, %r14d
movq 0x40(%rsp), %rdi
callq 0x41a94
cmpl $0x4, %r14d
jae 0xa80b7
movl %r14d, %ebp
testb %bl, %bl
je 0xa809c
movq 0x20(%rsp), %rdi
callq 0x3c434
xorl %r13d, %r13d
testq %rax, %rax
movl %ebp, %ebx
je 0xa7d16
xorb $0x1, %r15b
testb $0x1, %r15b
je 0xa8062
jmp 0xa7d16
movq %r14, %rdi
callq 0x4062b
xorl %ebx, %ebx
cmpl $0x3, %eax
cmovnel %eax, %ebx
movq %r15, %rdi
callq 0x41f83
movq %rax, 0x28(%rsp)
movq %rdx, 0x30(%rsp)
testq %rax, %rax
je 0xa80bc
movq %r15, %rdi
callq 0x41f3f
movq 0x28(%rsp), %rcx
movq 0x30(%rsp), %r8
leaq 0x10(%rsp), %rsi
movq 0x88(%rsp), %rdi
movq %rax, %rdx
movq 0x90(%rsp), %r9
callq 0xa8a31
testl %eax, %eax
jne 0xa8091
movl %ebx, %ebp
movq 0x10(%rsp), %rbx
leaq 0x28(%rsp), %rdi
callq 0x7e05b
movq 0x20(%rsp), %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x3c185
movq 0x10(%rsp), %rdi
leaq 0x536e3(%rip), %rsi     # 0xfb72c
movl $0x98, %edx
callq 0x362a0
movq %r14, %rdi
callq 0x3fdd2
cmpl $0x1, %eax
jne 0xa8099
movl %ebp, %ebx
movq 0x20(%rsp), %r14
movq %r14, %rdi
callq 0x3c40b
movl %ebx, %ebp
movq %rax, %rbx
movq %r14, %rdi
callq 0x3c434
movq %rbx, %rdi
movl %ebp, %ebx
movq %rax, %rsi
movq 0x90(%rsp), %rdx
callq 0xa99bc
movl %eax, %r13d
jmp 0xa7d16
xorl %r13d, %r13d
movl %ebp, %ebx
jmp 0xa7d16
callq 0x237ed
callq 0x2377d
callq 0x236d6
callq 0x23746
callq 0x237b4
callq 0x2370d