// File: 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
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movq 0x58(%rbp), %rax
movq 0x50(%rbp), %rax
movq 0x48(%rbp), %rax
movl 0x40(%rbp), %eax
movl 0x38(%rbp), %eax
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x30(%rbp)
movq %rsi, -0x38(%rbp)
movq %rdx, -0x40(%rbp)
movq %rcx, -0x48(%rbp)
movq %r8, -0x50(%rbp)
movq %r9, -0x58(%rbp)
movq -0x30(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
shll %eax
movl %eax, -0x60(%rbp)
leaq -0xf0(%rbp), %rdi
xorl %esi, %esi
movl $0x68, %edx
callq 0x2100
movq 0x50(%rbp), %rdi
movq -0x30(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %edx
xorl %esi, %esi
callq 0x2100
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
cmpl -0x60(%rbp), %eax
jae 0x180d2b
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x5c(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movzbl 0x4(%rax,%rcx,8), %eax
cmpl $0x1, %eax
je 0x180bd8
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x5c(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
jne 0x180bd8
movq 0x50(%rbp), %rax
movl -0x5c(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
cmpb $0x0, (%rax,%rcx)
je 0x180bdd
jmp 0x180d1d
movq -0x30(%rbp), %rdi
movl -0x5c(%rbp), %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x166b50
cmpl $0x1, %eax
je 0x180bf7
jmp 0x180d1d
movq -0x30(%rbp), %rdi
movl -0x5c(%rbp), %esi
xorl $0x1, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x166b50
cmpl $0x0, %eax
je 0x180c14
jmp 0x180d1d
movl -0x5c(%rbp), %eax
movl %eax, -0x64(%rbp)
movq $0x0, -0xb8(%rbp)
movq -0x30(%rbp), %rdi
movl -0x64(%rbp), %edx
xorl %eax, %eax
movl %eax, %esi
leaq -0x68(%rbp), %rcx
leaq -0x70(%rbp), %r8
leaq -0x78(%rbp), %r9
leaq -0x80(%rbp), %r11
leaq -0x88(%rbp), %r10
leaq -0xf0(%rbp), %rax
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movl $0x1, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x166c30
cmpl $0x7, %eax
jne 0x180c73
jmp 0x180d1d
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x48(%rbp), %r8
movq -0x50(%rbp), %r9
movq -0x58(%rbp), %rax
movq 0x10(%rbp), %rcx
movq %rcx, -0x108(%rbp)
movq 0x18(%rbp), %rcx
movq %rcx, -0x100(%rbp)
movq 0x20(%rbp), %r13
movq 0x28(%rbp), %r12
movq 0x30(%rbp), %r15
movl 0x38(%rbp), %r14d
movl 0x40(%rbp), %ebx
movq 0x48(%rbp), %r11
movq 0x50(%rbp), %r10
movq 0x58(%rbp), %rcx
movq %rcx, -0xf8(%rbp)
leaq -0xf0(%rbp), %rcx
movq %rax, (%rsp)
movq -0x108(%rbp), %rax
movq %rax, 0x8(%rsp)
movq -0x100(%rbp), %rax
movq %rax, 0x10(%rsp)
movq -0xf8(%rbp), %rax
movq %r13, 0x18(%rsp)
movq %r12, 0x20(%rsp)
movq %r15, 0x28(%rsp)
movl %r14d, 0x30(%rsp)
movl %ebx, 0x38(%rsp)
movq %r11, 0x40(%rsp)
movq %r10, 0x48(%rsp)
movq %rax, 0x50(%rsp)
callq 0x17f110
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x180b88
movq -0xa8(%rbp), %rdi
callq 0x2210
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)