// File: /workspace/github_c_makefile_star2_O3/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, %r14
movq %rdi, %rbx
movq 0x38(%rdi), %rax
movb (%rax,%rsi), %cl
testb $0x10, %cl
jne 0x1c73f0
addq %r14, %rax
movq %r14, %r12
orb $0x10, %cl
movb %cl, (%rax)
movl %ebp, %ecx
movq 0x18(%rbx,%rcx,8), %rax
movzwl (%rax,%r12,8), %r15d
cmpq $0x1, %r15
jne 0x1c732d
movq %rbx, %rdi
movq %r12, %rsi
movl %ebp, %edx
callq 0x1c6ebb
movq 0x38(%rbx), %rcx
movb (%rcx,%r12), %dl
testl %ebp, %ebp
je 0x1c7391
orb $-0x80, %dl
movb %dl, (%rcx,%r12)
cmpl $0x1, %ebp
jne 0x1c73f0
movq 0x38(%rbx), %rcx
movl (%rax), %r12d
cmpb $0x0, (%rcx,%r12)
jns 0x1c73a6
jmp 0x1c73e7
movq %rcx, 0x10(%rsp)
movq %rbx, %rdi
movq %r12, %rsi
movl %ebp, %edx
callq 0x1c71a0
decl %r15d
cmpq %r15, %rax
jne 0x1c73f0
cmpb $0x0, 0xc(%rsp)
je 0x1c7370
movq %rax, %r13
xorl %edx, %edx
testl %ebp, %ebp
sete %dl
movq %rbx, %rdi
movq %r12, %rsi
callq 0x1c71a0
cmpq %r13, %rax
jne 0x1c73f0
movq %rbx, %rdi
movq %r12, %rsi
movl %ebp, %edx
callq 0x1c71f6
movq 0x10(%rsp), %rax
movq 0x18(%rbx,%rax,8), %rax
cmpw $0x1, (%rax,%r12,8)
je 0x1c73b8
jmp 0x1c73ce
orb $0x40, %dl
movb %dl, (%rcx,%r12)
movq 0x38(%rbx), %rcx
movl (%rax), %r12d
testb $0x40, (%rcx,%r12)
jne 0x1c73ee
testl %ebp, %ebp
setne %cl
movb 0x7(%rax), %al
andb $0x20, %al
shrb $0x5, %al
xorb %cl, %al
movzbl %al, %ebp
movq 0x38(%rbx), %rax
movb (%rax,%r12), %cl
addq %r12, %rax
testb $0x10, %cl
je 0x1c72d6
jmp 0x1c73f0
testl %ebp, %ebp
movl $0x40, %eax
movl $0x80, %ecx
cmovel %eax, %ecx
movq 0x38(%rbx), %rax
orb %cl, (%rax,%r12)
jmp 0x1c73f0
movl $0x1, %ebp
jmp 0x1c73f0
xorl %ebp, %ebp
movq 0x38(%rbx), %rax
movb (%rax,%r14), %cl
testb $0x10, %cl
je 0x1c7446
addq %r14, %rax
andb $-0x11, %cl
movb %cl, (%rax)
movl %ebp, %eax
movq 0x18(%rbx,%rax,8), %rax
cmpw $0x1, (%rax,%r14,8)
jne 0x1c7446
movq %rbx, %rdi
movq %r14, %rsi
movl %ebp, %edx
callq 0x1c6ebb
movl (%rax), %r14d
testl %ebp, %ebp
setne %cl
movb 0x7(%rax), %al
andb $0x20, %al
shrb $0x5, %al
xorb %cl, %al
movzbl %al, %ebp
movq 0x38(%rbx), %rax
movb (%rax,%r14), %cl
addq %r14, %rax
testb $0x10, %cl
jne 0x1c7400
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq