// File: /workspace/github_c_makefile_star2_O2/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, %r15
movl %ecx, %ebx
movq %rdx, 0x30(%rsp)
movq %rsi, %r13
movq %rdi, 0x20(%rsp)
movq 0x90(%rsp), %rbp
testq %rbp, %rbp
je 0x87ec9
movq %rbp, %rdi
callq 0xc103
testb %al, %al
jne 0x882c3
callq 0x18a80
movq %rax, %rdi
movq %r13, %rsi
callq 0x1c1ec
testq %rax, %rax
je 0x88296
movq %rax, %r14
testq %r15, %r15
je 0x87efd
movq %r13, %rdi
callq 0x1c31a
movq %r15, %rdi
movq %rax, %rsi
callq 0x13eeb
testq %r12, %r12
je 0x87f44
leaq 0x4887b(%rip), %rsi     # 0xd0784
movq %r14, %rdi
callq 0x18818
testq %rax, %rax
je 0x87f44
movq %rbp, 0x8(%rsp)
andl $0x0, (%rsp)
leaq 0x4fbb9(%rip), %r9      # 0xd7adf
movq %rax, %rdi
xorl %esi, %esi
movq %r12, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x1ef1a
testl %eax, %eax
je 0x87f44
movl %eax, %r15d
jmp 0x88132
testb %bl, %bl
je 0x88120
xorl %r15d, %r15d
leaq 0x13(%rsp), %rax
movb %r15b, (%rax)
leaq 0x12(%rsp), %rax
movb %r15b, (%rax)
movq %r13, %rdi
callq 0x18df7
movq %rax, %rdi
callq 0x1ba16
movq %rax, %rbp
movb $0x1, %r14b
pushq $0x3
popq %rax
leaq 0x48805(%rip), %r13     # 0xd0784
movl %eax, 0x14(%rsp)
movq $0x0, 0x28(%rsp)
testl %r15d, %r15d
jne 0x8813a
movq %rbp, %rdi
callq 0x1bb1e
testq %rax, %rax
je 0x8813a
movq %rax, %rbx
testq %r12, %r12
sete %al
notb %r14b
orb %al, %r14b
testb $0x1, %r14b
jne 0x8800a
movq %rbx, %rdi
movq %r13, %rsi
callq 0x18818
testq %rax, %rax
je 0x8800a
movq %rax, %r15
movq %r12, %rdi
callq 0x157b1
andl $0x0, (%rsp)
movq 0x90(%rsp), %rax
movq %rax, 0x8(%rsp)
xorl %r14d, %r14d
movq %r15, %rdi
xorl %esi, %esi
movq %r12, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
leaq 0x4fae1(%rip), %r9      # 0xd7adf
callq 0x1ef1a
movl %eax, %r15d
testl %eax, %eax
jne 0x87f8c
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x88024
callq 0xc103
testb %al, %al
jne 0x88348
movq %rbx, %rdi
callq 0x18df7
testq %rax, %rax
je 0x882f0
movq %rax, %r15
movq %rax, %rdi
movq 0x30(%rsp), %rsi
callq 0x1987b
testb %al, %al
je 0x88101
movq %r15, %rdi
callq 0x18f89
leaq 0x13(%rsp), %rcx
cmpl $0x1, %eax
je 0x88072
cmpb $0x0, 0x12(%rsp)
leaq 0x12(%rsp), %rcx
pushq $0x3
popq %rax
movl %eax, 0x14(%rsp)
jne 0x88081
movb $0x1, (%rcx)
movq %r15, %rdi
callq 0x19d90
movl %eax, 0x14(%rsp)
movq %rbx, %rdi
callq 0x1c3c4
movq %rax, %r15
movq %rdx, %r14
movq %rax, 0x38(%rsp)
movq %rdx, 0x40(%rsp)
movq %rbx, %rdi
callq 0x1c31a
movq 0x88(%rsp), %rdi
leaq 0x18(%rsp), %rsi
movq %rax, %rdx
movq %r15, %rcx
movq %r14, %r8
movq 0x90(%rsp), %r9
callq 0x890d4
testl %eax, %eax
je 0x880ce
pushq $-0x1
popq %r15
jmp 0x88104
movq 0x18(%rsp), %rbx
leaq 0x38(%rsp), %rdi
callq 0x5d05e
movq 0x20(%rsp), %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x13f76
movq 0x18(%rsp), %rdi
leaq 0x5c8b3(%rip), %rsi     # 0xe49ac
pushq $0x3e
popq %rdx
callq 0xd249
xorl %r15d, %r15d
movl 0x14(%rsp), %ecx
cmpl $0x3, %ecx
movq 0x28(%rsp), %rax
cmovnel %ecx, %eax
movq %rax, 0x28(%rsp)
xorl %r14d, %r14d
jmp 0x87f8c
movq %r14, %rdi
callq 0x19528
cmpq 0x30(%rsp), %rax
je 0x881a9
xorl %r15d, %r15d
xorl %r12d, %r12d
jmp 0x8826f
movq %rbp, %rdi
callq 0x1bbe1
movq 0x28(%rsp), %r12
cmpl $0x4, %r12d
jae 0x8831a
testl %r15d, %r15d
movq 0x90(%rsp), %r14
jne 0x8826f
movq 0x20(%rsp), %rdi
callq 0x14461
xorl %r15d, %r15d
testq %rax, %rax
je 0x8826f
cmpb $0x1, 0x13(%rsp)
jne 0x8826f
movq 0x20(%rsp), %r15
movq %r15, %rdi
callq 0x143d2
movq %rax, %rbx
movq %r15, %rdi
callq 0x14461
movq %rbx, %rdi
movq %rax, %rsi
movq %r14, %rdx
jmp 0x88267
movq %r14, %rdi
callq 0x19d90
xorl %r12d, %r12d
cmpl $0x3, %eax
cmovnel %eax, %r12d
movq %r13, %rdi
callq 0x1c3c4
movq %rax, 0x38(%rsp)
movq %rdx, 0x40(%rsp)
testq %rax, %rax
je 0x8837e
movq %rax, %rbx
movq %rdx, %r15
movq %r13, %rdi
callq 0x1c31a
leaq 0x18(%rsp), %rsi
movq 0x88(%rsp), %rdi
movq %rax, %rdx
movq %rbx, %rcx
movq %r15, %r8
movq %rbp, %r9
callq 0x890d4
testl %eax, %eax
jne 0x8826c
movq 0x18(%rsp), %rbx
leaq 0x38(%rsp), %rdi
callq 0x5d05e
movq 0x20(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x13f76
movq 0x18(%rsp), %rdi
leaq 0x5c778(%rip), %rsi     # 0xe49ac
movl $0x98, %edx
callq 0xd249
movq %r14, %rdi
callq 0x18f89
cmpl $0x1, %eax
jne 0x88291
movq %r15, %rdi
callq 0x143d2
movq %rax, %rbx
movq %r15, %rdi
callq 0x14461
movq %rbx, %rdi
movq %rax, %rsi
movq %rbp, %rdx
callq 0x8a514
movl %eax, %r15d
movq 0x80(%rsp), %rax
testq %rax, %rax
je 0x8827f
movl %r12d, (%rax)
movl %r15d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r15d, %r15d
jmp 0x8826f
movq 0xa5d1b(%rip), %rax     # 0x12dfb8
movq (%rax), %rdi
leaq 0x41dbf(%rip), %rsi     # 0xca066
leaq 0x553f8(%rip), %rdx     # 0xdd6a6
leaq 0x5c71f(%rip), %rcx     # 0xe49d4
leaq 0x5c6f0(%rip), %r8      # 0xe49ac
pushq $0x55
jmp 0x88370
movq 0xa5cee(%rip), %rax     # 0x12dfb8
movq (%rax), %rdi
leaq 0x41d92(%rip), %rsi     # 0xca066
leaq 0x4237e(%rip), %rdx     # 0xca659
leaq 0x5c6f2(%rip), %rcx     # 0xe49d4
leaq 0x5c6c3(%rip), %r8      # 0xe49ac
pushq $0x53
jmp 0x88370
movq 0xa5cc1(%rip), %rax     # 0x12dfb8
movq (%rax), %rdi
leaq 0x41d65(%rip), %rsi     # 0xca066
leaq 0x5539e(%rip), %rdx     # 0xdd6a6
leaq 0x5c718(%rip), %rcx     # 0xe4a27
leaq 0x5c696(%rip), %r8      # 0xe49ac
pushq $0x2c
jmp 0x88370
movq 0xa5c97(%rip), %rax     # 0x12dfb8
movq (%rax), %rdi
leaq 0x41d3b(%rip), %rsi     # 0xca066
leaq 0x5c6c3(%rip), %rdx     # 0xe49f5
leaq 0x5c69b(%rip), %rcx     # 0xe49d4
leaq 0x5c66c(%rip), %r8      # 0xe49ac
movl $0x83, %r9d
jmp 0x88372
movq 0xa5c69(%rip), %rax     # 0x12dfb8
movq (%rax), %rdi
leaq 0x41d0d(%rip), %rsi     # 0xca066
leaq 0x422f9(%rip), %rdx     # 0xca659
leaq 0x5c6c0(%rip), %rcx     # 0xe4a27
leaq 0x5c63e(%rip), %r8      # 0xe49ac
pushq $0x2a
popq %r9
xorl %eax, %eax
callq 0xb8c0
callq 0xb300
movq 0xa5c33(%rip), %rax     # 0x12dfb8
movq (%rax), %rdi
leaq 0x41cd7(%rip), %rsi     # 0xca066
leaq 0x5d4ef(%rip), %rdx     # 0xe5885
leaq 0x5c637(%rip), %rcx     # 0xe49d4
leaq 0x5c608(%rip), %r8      # 0xe49ac
movl $0x92, %r9d
jmp 0x88372