// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/extended/cds_check_visitor.c
// Function: check_cds_phases
static int check_cds_phases(GtArray *cds_features, GtCDSCheckVisitor *v,
                            bool is_multi, bool second_pass, GtError *err)
{
  GtPhase correct_phase = GT_PHASE_ZERO;
  GtFeatureNode *fn;
  GtStrand strand;
  bool first = true;
  GtUword i,
          total_length = 0;
  int had_err = 0;
  gt_error_check(err);
  gt_assert(cds_features);
  gt_assert(gt_array_size(cds_features));
  fn = *(GtFeatureNode**) gt_array_get_first(cds_features);
  strand = gt_feature_node_get_strand(fn);
  if (strand == GT_STRAND_REVERSE)
    gt_array_reverse(cds_features);
  for (i = 0; !had_err && i < gt_array_size(cds_features); i++) {
    fn = *(GtFeatureNode**) gt_array_get(cds_features, i);
    /* the first phase can be anything (except being undefined), because the
       GFF3 spec says:

       NOTE 4 - CDS features MUST have have a defined phase field. Otherwise it
       is not possible to infer the correct polypeptides corresponding to
       partially annotated genes. */
    if ((!i && gt_feature_node_get_phase(fn) == GT_PHASE_UNDEFINED) ||
        (i && gt_feature_node_get_phase(fn) != correct_phase)) {
      if (gt_hashmap_get(v->cds_features, fn)) {
        if (v->tidy && !is_multi && !gt_feature_node_has_children(fn)) {
          /* we can split the feature */
          gt_warning("%s feature on line %u in file \"%s\" has multiple "
                     "parents which require different phases; split feature",
                     gt_ft_CDS,
                     gt_genome_node_get_line_number((GtGenomeNode*) fn),
                     gt_genome_node_get_filename((GtGenomeNode*) fn));
          gt_hashmap_add(v->cds_features_to_split, fn, fn);
          v->splitting_is_necessary = true; /* split later */
        }
        else {
          gt_error_set(err, "%s feature on line %u in file \"%s\" has multiple "
                       "parents which require different phases",
                       gt_ft_CDS,
                       gt_genome_node_get_line_number((GtGenomeNode*) fn),
                       gt_genome_node_get_filename((GtGenomeNode*) fn));
          had_err = -1;
        }
      }
      else {
        if (v->tidy) {
          if (!second_pass) {
            gt_warning("%s feature on line %u in file \"%s\" has the wrong "
                       "phase %c -> correcting it to %c", gt_ft_CDS,
                       gt_genome_node_get_line_number((GtGenomeNode*) fn),
                       gt_genome_node_get_filename((GtGenomeNode*) fn),
                       GT_PHASE_CHARS[gt_feature_node_get_phase(fn)],
                       GT_PHASE_CHARS[correct_phase]);
          }
          gt_feature_node_set_phase(fn, correct_phase);
        }
        else {
          gt_error_set(err, "%s feature on line %u in file \"%s\" has the "
                       "wrong phase %c (should be %c)", gt_ft_CDS,
                       gt_genome_node_get_line_number((GtGenomeNode*) fn),
                       gt_genome_node_get_filename((GtGenomeNode*) fn),
                       GT_PHASE_CHARS[gt_feature_node_get_phase(fn)],
                       GT_PHASE_CHARS[correct_phase]);
          had_err = -1;
        }
      }
    }
    if (!had_err) {
      GtUword current_length = gt_genome_node_get_length((GtGenomeNode*) fn);
      if (first) {
        /* this handles the case of 5' partial genes, where CDS might not start
           on codon boundaries */
        GtUword current_phase = (GtUword) gt_feature_node_get_phase(fn);
        if (current_length >= current_phase) {
          /* we simply skip the amount of bases defined by phase */
          current_length -= current_phase;
          first = false;
          total_length = current_length;
          correct_phase = (3 - (total_length) % 3) % 3;
        } else {
          /* corner case: first CDS is single base */
          gt_assert(current_length == 1 && current_phase == 2);
          correct_phase = 1;
        }
      } else {
        total_length += current_length;
        correct_phase = (3 - (total_length) % 3) % 3;
      }
      gt_hashmap_add(v->cds_features, fn, fn); /* record CDS feature */
    }
  }
  return had_err;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rcx, %rbx
movl %edx, 0x2c(%rsp)
movq %rsi, %r15
movq %rdi, %r12
testq %rcx, %rcx
je 0x63d5c
movq %rbx, %rdi
callq 0xc103
testb %al, %al
jne 0x64073
movq %r12, %rdi
callq 0x4b988
testq %rax, %rax
je 0x64049
movq %rbx, 0x30(%rsp)
movq %r12, %rdi
callq 0x4b4dc
movq (%rax), %rdi
callq 0x18f89
cmpl $0x1, %eax
jne 0x63d8f
movq %r12, %rdi
callq 0x4b6dd
movb $0x1, %al
movq %rax, 0x18(%rsp)
xorl %r13d, %r13d
movq $0x0, 0x20(%rsp)
xorl %eax, %eax
xorl %ebx, %ebx
movq %r12, 0x10(%rsp)
movq %r15, 0x8(%rsp)
testl %eax, %eax
jne 0x64009
movq %r12, %rdi
callq 0x4b988
cmpq %rax, %r13
jae 0x6400e
movq %r12, %rdi
movq %r13, %rsi
callq 0x4b48e
movq (%rax), %rbp
movq %rbp, %rdi
callq 0x19d90
testq %r13, %r13
je 0x63ded
cmpl %ebx, %eax
jne 0x63df6
jmp 0x63f4a
cmpl $0x3, %eax
jne 0x63f4a
movq 0x10(%r15), %rdi
movq %rbp, %rsi
callq 0x55ef6
movb 0x20(%r15), %r15b
testq %rax, %rax
je 0x63e66
xorb $0x1, %r15b
orb 0x2c(%rsp), %r15b
jne 0x63e26
movq %rbp, %rdi
callq 0x194d0
testb %al, %al
je 0x63f05
movq %rbp, %rdi
callq 0x1c2d8
movl %eax, %r14d
movq %rbp, %rdi
callq 0x1c285
movq 0x30(%rsp), %rdi
leaq 0x7959e(%rip), %rsi     # 0xdd3e3
leaq 0x6a383(%rip), %rdx     # 0xce1cf
movl %r14d, %ecx
movq %rax, %r8
xorl %eax, %eax
callq 0xc007
pushq $-0x1
popq %rax
movq 0x8(%rsp), %r15
jmp 0x63fdc
movq %rbp, %rdi
callq 0x1c2d8
movl %eax, %r14d
movq %rbp, %rdi
callq 0x1c285
movq %rax, %r12
movq %rbp, %rdi
callq 0x19d90
movl %eax, %eax
leaq 0x67d63(%rip), %rdx     # 0xcbbf0
movsbl (%rax,%rdx), %eax
movl %ebx, %ecx
movsbl (%rcx,%rdx), %r9d
testb %r15b, %r15b
je 0x63ecc
leaq 0x79596(%rip), %rdi     # 0xdd43a
leaq 0x6a324(%rip), %rsi     # 0xce1cf
movl %r14d, %edx
movq %r12, %rcx
movl %eax, %r8d
xorl %eax, %eax
callq 0x161b0
movq %rbp, %rdi
movl %ebx, %esi
callq 0x18944
movq 0x8(%rsp), %r15
jmp 0x63f4a
movl %r9d, (%rsp)
movq 0x30(%rsp), %rdi
leaq 0x795af(%rip), %rsi     # 0xdd48b
leaq 0x6a2ec(%rip), %rdx     # 0xce1cf
movl %r14d, %ecx
movq %r12, %r8
movl %eax, %r9d
xorl %eax, %eax
callq 0xc007
pushq $-0x1
popq %rax
movq 0x8(%rsp), %r15
movq 0x10(%rsp), %r12
jmp 0x63fdc
movq %rbp, %rdi
callq 0x1c2d8
movl %eax, %ebx
movq %rbp, %rdi
callq 0x1c285
leaq 0x7945f(%rip), %rdi     # 0xdd37d
leaq 0x6a2aa(%rip), %rsi     # 0xce1cf
movl %ebx, %edx
movq %rax, %rcx
xorl %eax, %eax
callq 0x161b0
movq 0x8(%rsp), %r15
movq 0x18(%r15), %rdi
movq %rbp, %rsi
movq %rbp, %rdx
callq 0x55f31
movb $0x1, 0x21(%r15)
movq %rbp, %rdi
callq 0x1c420
movq %rax, %r12
testb $0x1, 0x18(%rsp)
je 0x63f96
movq %rbp, %rdi
callq 0x19d90
movl %eax, %eax
movq %r12, %r14
subq %rax, %r14
jae 0x63fe4
cmpq $0x1, %r12
movq 0x10(%rsp), %r12
jne 0x6401f
movb $0x1, %cl
movq %rcx, 0x18(%rsp)
movq 0x20(%rsp), %r14
pushq $0x1
popq %rbx
cmpl $0x2, %eax
je 0x63fc6
jmp 0x6401f
addq 0x20(%rsp), %r12
movq $0x0, 0x18(%rsp)
movq %r12, %rax
xorl %edx, %edx
pushq $0x3
popq %rcx
divq %rcx
movl $0x0, %ebx
testq %rdx, %rdx
je 0x63fbe
xorl $0x3, %edx
movl %edx, %ebx
movq %r12, %r14
movq 0x10(%rsp), %r12
movq 0x10(%r15), %rdi
movq %rbp, %rsi
movq %rbp, %rdx
callq 0x55f31
xorl %eax, %eax
movq %r14, 0x20(%rsp)
incq %r13
jmp 0x63db0
movq $0x0, 0x18(%rsp)
movq %r14, %rax
xorl %edx, %edx
pushq $0x3
popq %rcx
divq %rcx
movl $0x0, %ebx
testq %rdx, %rdx
je 0x63fc1
xorl $0x3, %edx
movl %edx, %ebx
jmp 0x63fc1
pushq $-0x1
popq %rax
jmp 0x64010
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xc9f92(%rip), %rax     # 0x12dfb8
movq (%rax), %rdi
leaq 0x66036(%rip), %rsi     # 0xca066
leaq 0x7949d(%rip), %rdx     # 0xdd4d4
leaq 0x7932e(%rip), %rcx     # 0xdd36c
leaq 0x792c1(%rip), %r8      # 0xdd306
pushq $0x7b
jmp 0x6409b
movq 0xc9f68(%rip), %rax     # 0x12dfb8
movq (%rax), %rdi
leaq 0x6600c(%rip), %rsi     # 0xca066
leaq 0x904c2(%rip), %rdx     # 0xf4523
leaq 0x79304(%rip), %rcx     # 0xdd36c
leaq 0x79297(%rip), %r8      # 0xdd306
pushq $0x33
jmp 0x6409b
movq 0xc9f3e(%rip), %rax     # 0x12dfb8
movq (%rax), %rdi
leaq 0x65fe2(%rip), %rsi     # 0xca066
leaq 0x665ce(%rip), %rdx     # 0xca659
leaq 0x792da(%rip), %rcx     # 0xdd36c
leaq 0x7926d(%rip), %r8      # 0xdd306
pushq $0x31
popq %r9
xorl %eax, %eax
callq 0xb8c0
callq 0xb300