// File: /workspace/github_c_makefile_star2_O2/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
subq $0x18, %rsp
movl %ecx, 0xc(%rsp)
movl %edx, %ebp
movq %rsi, %r12
movq %rdi, %rbx
movq %rsi, 0x10(%rsp)
movl %ebp, %r14d
xorl %eax, %eax
testl %ebp, %ebp
sete %al
movl %eax, 0x8(%rsp)
movq 0x38(%rbx), %rax
movb (%rax,%r12), %cl
testb $0x10, %cl
jne 0x1779df
orb $0x10, %cl
movb %cl, (%rax,%r12)
movq 0x18(%rbx,%r14,8), %rax
movzwl (%rax,%r12,8), %r13d
movq %rbx, %rdi
movq %r12, %rsi
movl %ebp, %edx
cmpq $0x1, %r13
je 0x17796a
callq 0x1777ca
decl %r13d
cmpq %r13, %rax
jne 0x1779df
cmpb $0x0, 0xc(%rsp)
je 0x17794e
movq %rax, %r15
movq %rbx, %rdi
movq %r12, %rsi
movl 0x8(%rsp), %edx
callq 0x1777ca
cmpq %r15, %rax
jne 0x1779df
movq %rbx, %rdi
movq %r12, %rsi
movl %ebp, %edx
callq 0x17781a
movq 0x18(%rbx,%r14,8), %rax
cmpw $0x1, (%rax,%r12,8)
je 0x1778eb
jmp 0x1779ca
callq 0x1773b5
movq 0x38(%rbx), %rcx
movb (%rcx,%r12), %dl
testl %ebp, %ebp
je 0x17799a
orb $-0x80, %dl
movb %dl, (%rcx,%r12)
cmpl $0x1, %ebp
jne 0x1779df
movq 0x38(%rbx), %rcx
movl (%rax), %r12d
cmpb $0x0, (%rcx,%r12)
jns 0x1779b3
jmp 0x177a33
orb $0x40, %dl
movb %dl, (%rcx,%r12)
movq 0x38(%rbx), %rcx
movl (%rax), %r12d
testb $0x40, (%rcx,%r12)
jne 0x177a38
testl %ebp, %ebp
setne %cl
movb 0x7(%rax), %al
andb $0x20, %al
shrb $0x5, %al
xorb %cl, %al
movzbl %al, %ebp
jmp 0x1778dd
testl %ebp, %ebp
pushq $0x40
popq %rax
movl $0x80, %ecx
cmovel %eax, %ecx
movq 0x38(%rbx), %rax
orb %cl, (%rax,%r12)
movq 0x10(%rsp), %rsi
movq 0x38(%rbx), %rax
movb (%rax,%rsi), %cl
testb $0x10, %cl
je 0x177a24
andb $-0x11, %cl
movb %cl, (%rax,%rsi)
movl %ebp, %eax
movq 0x18(%rbx,%rax,8), %rax
cmpw $0x1, (%rax,%rsi,8)
jne 0x177a24
movq %rbx, %rdi
movl %ebp, %edx
callq 0x1773b5
movl (%rax), %esi
testl %ebp, %ebp
setne %cl
movb 0x7(%rax), %al
andb $0x20, %al
shrb $0x5, %al
xorb %cl, %al
movzbl %al, %ebp
jmp 0x1779e4
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x1
popq %rbp
jmp 0x1779df
xorl %ebp, %ebp
jmp 0x1779df