// File: /workspace/github_c_makefile_star2_O1/genometools[P]genometools/src/match/rdj-contigs-graph.c
// Function: gt_contigs_graph_simplify_from_contig
void gt_contigs_graph_simplify_from_contig(GtContigsGraph *cg,
    GtUword cnum, unsigned int incoming, bool restrict_rm_optionals)
{
  GtUword src = cnum;
  while (true)
  {
    GtContigsGraphSpmEdge *edge;
    if (cg->v_m[cnum].visited)
      break;
    cg->v_m[cnum].visited = true;
    if (cg->v_spm[incoming][cnum].deg == (uint64_t)1)
    {
      edge = gt_contigs_graph_find_only_spm_edge(cg, cnum, incoming);
      GT_CONTIGS_GRAPH_SET_DIR_MARK(cg, cnum, incoming);
      if (GT_CONTIGS_GRAPH_DIR_MARK_IS_UNSET(cg, edge->dest, incoming))
      {
        cnum = (GtUword)edge->dest;
        incoming = GT_CONTIGS_GRAPH_VALID_PATH_DIR(incoming, edge->reverse);
        /*gt_log_log("... continue from contig "GT_WU" (incoming=%u, deg=%u)",
                   cnum, incoming, cg->v_spm[incoming][cnum].deg);*/
      }
      else
      {
        break;
      }
    }
    else
    {
      if (gt_contigs_graph_nof_optional_neighbours(cg, cnum, incoming) ==
          cg->v_spm[incoming][cnum].deg - 1U)
      {
        if (restrict_rm_optionals && gt_contigs_graph_nof_optional_neighbours(
              cg, cnum, GT_CONTIGS_GRAPH_OTHER_DIR(incoming)) != cg->v_spm[
            incoming][cnum].deg - 1U)
        {
          break;
        }
        gt_contigs_graph_rm_optional_neighbours(cg, cnum, incoming);
        if (cg->v_spm[incoming][cnum].deg != (uint64_t)1)
        {
          GT_CONTIGS_GRAPH_SET_DIR_MARK(cg, cnum, incoming);
          break;
        }
        /*gt_log_log("... repeat contig "GT_WU" (incoming=%u, deg=%u)", cnum,
            incoming, cg->v_spm[incoming][cnum].deg);*/
      }
      else
      {
        break;
      }
    }
  }
  /* reset visited mark */
  cnum = src;
  while (true)
  {
    GtContigsGraphSpmEdge *edge;
    if (!cg->v_m[cnum].visited)
      break;
    cg->v_m[cnum].visited = false;
    if (cg->v_spm[incoming][cnum].deg != (uint64_t)1)
      break;
    edge = gt_contigs_graph_find_only_spm_edge(cg, cnum, incoming);
    cnum = (GtUword)edge->dest;
    incoming = GT_CONTIGS_GRAPH_VALID_PATH_DIR(incoming, edge->reverse);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %ecx, 0x4(%rsp)
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
movq %rsi, %r12
movq 0x38(%rbx), %rax
movb (%rax,%r12), %cl
testb $0x10, %cl
jne 0x1d063f
orb $0x10, %cl
movb %cl, (%rax,%r12)
movl %ebp, %r13d
movq 0x18(%rbx,%r13,8), %rax
movzwl (%rax,%r12,8), %r15d
movq %rbx, %rdi
movq %r12, %rsi
movl %ebp, %edx
cmpq $0x1, %r15
jne 0x1d05e0
callq 0x1d0158
testl %ebp, %ebp
movq 0x38(%rbx), %rcx
movl $0x80, %edx
movl $0x40, %esi
cmovel %esi, %edx
orb %dl, (%rcx,%r12)
testl %ebp, %ebp
jne 0x1d05b2
movq 0x38(%rbx), %rcx
movl (%rax), %edx
testb $0x40, (%rcx,%rdx)
je 0x1d05c7
cmpl $0x1, %ebp
jne 0x1d063f
movq 0x38(%rbx), %rcx
movl (%rax), %edx
cmpb $0x0, (%rcx,%rdx)
js 0x1d063f
movl (%rax), %r12d
testl %ebp, %ebp
setne %cl
movb 0x7(%rax), %al
andb $0x20, %al
shrb $0x5, %al
xorb %cl, %al
movzbl %al, %ebp
movb $0x1, %al
jmp 0x1d0641
callq 0x1d042f
decl %r15d
cmpq %r15, %rax
jne 0x1d063f
cmpb $0x0, 0x4(%rsp)
je 0x1d060b
xorl %edx, %edx
testl %ebp, %ebp
sete %dl
movq %rbx, %rdi
movq %r12, %rsi
callq 0x1d042f
cmpq %r15, %rax
jne 0x1d063f
movq %rbx, %rdi
movq %r12, %rsi
movl %ebp, %edx
callq 0x1d0485
movq 0x18(%rbx,%r13,8), %rcx
movb $0x1, %al
cmpw $0x1, (%rcx,%r12,8)
je 0x1d0641
movq 0x38(%rbx), %rax
movb (%rax,%r12), %cl
testl %ebp, %ebp
je 0x1d0638
orb $-0x80, %cl
jmp 0x1d063b
orb $0x40, %cl
movb %cl, (%rax,%r12)
xorl %eax, %eax
testb %al, %al
jne 0x1d0553
movq 0x38(%rbx), %rax
movb (%rax,%r14), %cl
testb $0x10, %cl
je 0x1d0692
andb $-0x11, %cl
movb %cl, (%rax,%r14)
movl %ebp, %eax
movq 0x18(%rbx,%rax,8), %rax
cmpw $0x1, (%rax,%r14,8)
jne 0x1d0692
movq %rbx, %rdi
movq %r14, %rsi
movl %ebp, %edx
callq 0x1d0158
movl (%rax), %r14d
testl %ebp, %ebp
setne %cl
movb 0x7(%rax), %al
andb $0x20, %al
shrb $0x5, %al
xorb %cl, %al
movzbl %al, %ebp
movb $0x1, %al
jmp 0x1d0694
xorl %eax, %eax
testb %al, %al
jne 0x1d0649
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq