// File: /workspace/github_cpp_makefile_star2_O3/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, %r12
movq %r8, 0x20(%rsp)
movq %rcx, 0x18(%rsp)
movq %rdx, 0x10(%rsp)
movq %rsi, %r13
movq %rdi, %rbp
movq 0x130(%rsp), %rbx
movl 0x14(%rdi), %edx
leal (%rdx,%rdx), %r15d
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
xorl %r14d, %r14d
movq %rbx, %rdi
xorl %esi, %esi
callq 0x20e0
testl %r15d, %r15d
je 0x115826
movq %r12, 0x8(%rsp)
movl %r15d, %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 0x1156be
cmpl $0x0, (%rcx,%rax,8)
js 0x1156be
cmpb $0x0, (%rbx,%rax)
je 0x1156cb
incq %r14
cmpq %r15, %r14
jne 0x1156a2
jmp 0x11581e
movq 0x28(%rbp), %rcx
movq (%rcx,%r14,8), %rdx
movq %rdx, %rsi
andq %r12, %rsi
je 0x1156be
movq 0x8(%rbp), %rax
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %rdx
leaq (%rax,%rdx,8), %rdx
addq $0xc, %rdx
shlq $0x3, %rsi
leaq (%rsi,%rsi,2), %rsi
xorl %edi, %edi
xorl %r8d, %r8d
movl (%rdx,%rdi), %r9d
notl %r9d
shrl $0x1f, %r9d
addl %r9d, %r8d
addq $0x18, %rdi
cmpq %rdi, %rsi
jne 0x1156fc
cmpl $0x1, %r8d
jne 0x1156be
movl %r14d, %edx
xorq $0x1, %rdx
movq (%rcx,%rdx,8), %rdx
movq %rdx, %rcx
andq %r12, %rcx
je 0x115763
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %rdx
leaq (%rax,%rdx,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 0x115748
testl %esi, %esi
jne 0x1156be
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 0x1053a7
addq $0x20, %rsp
cmpl $0x7, %eax
je 0x1156be
subq $0x8, %rsp
movq %rbp, %rdi
movq %r13, %rsi
movq 0x18(%rsp), %rdx
leaq 0x58(%rsp), %rcx
movq 0x20(%rsp), %r8
movq 0x28(%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 0x60(%rsp)
callq 0x1145ac
addq $0x60, %rsp
jmp 0x1156be
movq 0x98(%rsp), %r14
movq %r14, %rdi
callq 0x2220
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq