// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Purge_Dups.cpp
// Function: link_unitigs(asg_t*, ma_ug_t*, hap_overlaps_list*, R_to_U*, ma_hit_t_alloc*, ma_sub_t*, asg_t*, unsigned long*, kvec_asg_arc_t_offset*, kvec_t_i32_warp*, kvec_t_i32_warp*, int, int, kvec_asg_arc_t_warp*, unsigned char*, hap_cov_t*)
void link_unitigs(asg_t *purge_g, ma_ug_t *ug, hap_overlaps_list* all_ovlp,
R_to_U* ruIndex, ma_hit_t_alloc* reverse_sources, ma_sub_t *coverage_cut, asg_t *read_g, 
uint64_t* position_index, kvec_asg_arc_t_offset* u_buffer, kvec_t_i32_warp* tailIndex, 
kvec_t_i32_warp* prevIndex, int max_hang, int min_ovlp, kvec_asg_arc_t_warp* edge, uint8_t* visit,
hap_cov_t *cov)
{
    uint32_t v, n_vtx = purge_g->n_seq * 2, beg, end;
    long long nodeLen, baseLen, max_stop_nodeLen, max_stop_baseLen;
    buf_t b_0;
    memset(&b_0, 0, sizeof(buf_t));
    memset(visit, 0, purge_g->n_seq);
    for (v = 0; v < n_vtx; ++v) 
    {
        if(purge_g->seq[v>>1].c == ALTER_LABLE || purge_g->seq[v>>1].del || visit[v>>1]) continue;
        if(get_real_length(purge_g, v, NULL) != 1) continue;
        if(get_real_length(purge_g, v^1, NULL) != 0) continue;

        beg = v;
        b_0.b.n = 0;
        if(get_unitig(purge_g, NULL, beg, &end, &nodeLen, &baseLen, &max_stop_nodeLen, 
                    &max_stop_baseLen, 1, &b_0) == LOOP)
        {
            continue;
        }

        ///if(cov->link) collect_reverse_unitigs_purge(&b_0, cov->link, ug, all_ovlp);
        purge_merge(purge_g, ug, all_ovlp, &b_0, ruIndex, reverse_sources, coverage_cut, 
        read_g, position_index, u_buffer, tailIndex, prevIndex,max_hang, min_ovlp, edge, visit, cov);
    }
    free(b_0.b.a);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %r9, 0x20(%rsp)
movq %r8, 0x18(%rsp)
movq %rcx, 0x10(%rsp)
movq %rdx, 0x8(%rsp)
movq %rsi, %r13
movq %rdi, %rbp
movq 0x130(%rsp), %rbx
movl 0x14(%rdi), %edx
leal (%rdx,%rdx), %r14d
xorps %xmm0, %xmm0
movaps %xmm0, 0xa0(%rsp)
movaps %xmm0, 0x90(%rsp)
movaps %xmm0, 0x80(%rsp)
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movq $0x0, 0xb0(%rsp)
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movq %rbx, %rdi
xorl %esi, %esi
callq 0x20e0
testl %r14d, %r14d
je 0x110104
movl %r14d, %r15d
xorl %r14d, %r14d
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movq 0x20(%rbp), %rcx
movl %r14d, %eax
shrl %eax
cmpb $0x1, 0x4(%rcx,%rax,8)
je 0x10ffa2
cmpl $0x0, (%rcx,%rax,8)
js 0x10ffa2
cmpb $0x0, (%rbx,%rax)
je 0x10ffaf
incq %r14
cmpq %r15, %r14
jne 0x10ff86
jmp 0x110104
movq 0x28(%rbp), %rax
movq (%rax,%r14,8), %rcx
movq %rcx, %rdx
andq %r12, %rdx
je 0x10ffa2
movq 0x8(%rbp), %rsi
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rsi,%rcx,8), %rcx
addq $0xc, %rcx
shlq $0x3, %rdx
leaq (%rdx,%rdx,2), %rdx
xorl %esi, %esi
xorl %edi, %edi
movl (%rcx,%rsi), %r8d
notl %r8d
shrl $0x1f, %r8d
addl %r8d, %edi
addq $0x18, %rsi
cmpq %rsi, %rdx
jne 0x10ffdf
cmpl $0x1, %edi
jne 0x10ffa2
movl %r14d, %ecx
xorq $0x1, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, %rcx
andq %r12, %rcx
je 0x110049
movq 0x8(%rbp), %rdx
shrq $0x20, %rax
leaq (%rax,%rax,2), %rax
leaq (%rdx,%rax,8), %rax
addq $0xc, %rax
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rcx
xorl %edx, %edx
xorl %esi, %esi
movl (%rax,%rdx), %edi
notl %edi
shrl $0x1f, %edi
addl %edi, %esi
addq $0x18, %rdx
cmpq %rdx, %rcx
jne 0x11002e
testl %esi, %esi
jne 0x10ffa2
movq $0x0, 0x88(%rsp)
movq %rbp, %rdi
xorl %esi, %esi
movl %r14d, %edx
leaq 0x2c(%rsp), %rcx
leaq 0x48(%rsp), %r8
leaq 0x40(%rsp), %r9
leaq 0x50(%rsp), %rax
pushq %rax
pushq $0x1
leaq 0x40(%rsp), %rax
pushq %rax
leaq 0x50(%rsp), %rax
pushq %rax
callq 0x10109f
addq $0x20, %rsp
cmpl $0x7, %eax
je 0x10ffa2
subq $0x8, %rsp
movq %rbp, %rdi
movq %r13, %rsi
movq 0x10(%rsp), %rdx
leaq 0x58(%rsp), %rcx
movq 0x18(%rsp), %r8
movq 0x20(%rsp), %r9
pushq 0x140(%rsp)
pushq %rbx
pushq 0x140(%rsp)
movl 0x140(%rsp), %eax
pushq %rax
movl 0x140(%rsp), %eax
pushq %rax
pushq 0x140(%rsp)
pushq 0x140(%rsp)
pushq 0x140(%rsp)
pushq 0x140(%rsp)
pushq 0x140(%rsp)
pushq 0x78(%rsp)
callq 0x10efd7
addq $0x60, %rsp
jmp 0x10ffa2
movq 0x98(%rsp), %rdi
callq 0x2220
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq