// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/hic.cpp
// Function: filter_disconnect_edges(ha_ug_index*, kvec_pe_hit*, hc_links*, bubble_type*, unsigned int, double)
void filter_disconnect_edges(ha_ug_index* idx, kvec_pe_hit *hits, hc_links *link, bubble_type *bub, uint32_t thres, double rate)
{
    uint32_t k, l, i, m, h_occ, *occ = NULL;
    uint64_t shif = 64 - idx->uID_bits, qn, tn, u_dis;
    pe_hit *h_a = NULL;
    hc_linkeage *t = NULL;
    u_trans_t *p = NULL;
    hc_edge *e = NULL;
    kv_u_trans_t k_trans; 
    kv_init(k_trans);
    
    if(hits->idx.n == 0) idx_hc_links(hits, idx, bub);
    CALLOC(occ, hits->idx.n);
    for (qn = 0; qn < hits->idx.n; qn++)
    {
        if(IF_HOM(qn, *bub)) continue;
        h_a = hits->a.a + (hits->idx.a[qn]>>32);
        h_occ = (uint32_t)(hits->idx.a[qn]);

        for (k = 1, l = 0; k <= h_occ; ++k) ///same qn
        {
            if (k == h_occ || ((h_a[k].e<<1)>>shif) != ((h_a[l].e<<1)>>shif)) //same qn and tn
            {
                tn = ((h_a[l].e<<1)>>shif);
                if(!IF_HOM(tn, *bub) && tn != qn)
                {
                    t = &(link->a.a[qn]);
                    for (i = 0, u_dis = (uint64_t)-1; i < t->e.n; i++)
                    {
                        if(t->e.a[i].del || t->e.a[i].uID != tn) continue;
                        u_dis = (t->e.a[i].dis ==(uint64_t)-1? (uint64_t)-1 : t->e.a[i].dis>>3);
                        break;
                    }
                    
                    if(u_dis == (uint64_t)-1)
                    {
                        kv_pushp(u_trans_t, k_trans, &p);
                        p->qn = qn; p->tn = tn; p->occ = (k-l);
                        kv_pushp(u_trans_t, k_trans, &p);
                        p->qn = tn; p->tn = qn; p->occ = (k-l);
                    }
                    else
                    {
                        occ[qn] += (k-l); occ[tn] += (k-l);
                    }
                }
                l = k;
            }
        }
    }


    radix_sort_u_trans_m(k_trans.a, k_trans.a + k_trans.n);

    for (k = 1, l = 0, m = 0; k <= k_trans.n; ++k)
    {
        if (k == k_trans.n || k_trans.a[l].qn != k_trans.a[k].qn || k_trans.a[l].tn != k_trans.a[k].tn) //same qn and tn
        {
            if(k - l > 2) fprintf(stderr, "ERROR-3\n");
            for (i = l, h_occ = 0; i < k; i++)
            {
                h_occ += k_trans.a[i].occ;
            }

            k_trans.a[m] = k_trans.a[l];
            // k_trans.a[m].occ = ((uint32_t)-1) - h_occ;
            k_trans.a[m].occ = h_occ;

            if(h_occ > thres || h_occ >= (occ[k_trans.a[m].qn]*rate) || h_occ >= (occ[k_trans.a[m].tn]*rate))
            {
                e = get_hc_edge(link, k_trans.a[m].qn, k_trans.a[m].tn, 0);
                if(e->dis != (uint64_t)-1) fprintf(stderr, "ERROR-3-0\n");
                e->is_cc = 1;

                e = get_hc_edge(link, k_trans.a[m].tn, k_trans.a[m].qn, 0);
                if(e->dis != (uint64_t)-1) fprintf(stderr, "ERROR-3-0\n");
                e->is_cc = 1;
            }
            m++;
            l = k;
        }
    }
    k_trans.n = m;

    kv_destroy(k_trans); free(occ);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movsd %xmm0, 0x20(%rsp)
movl %r8d, 0x2c(%rsp)
movq %rcx, %r14
movq %rdx, %r13
movq %rsi, %r15
movl $0x40, %ebp
subq 0x18(%rdi), %rbp
movq 0x18(%rsi), %r12
testq %r12, %r12
je 0x144fce
movl $0x4, %esi
movq %r12, %rdi
callq 0x2120
movq %rax, 0x8(%rsp)
jmp 0x144ffe
movq %rdi, %rsi
movq %r15, %rdi
movq %r14, %rdx
callq 0x14547c
movq 0x18(%r15), %r12
movl $0x4, %esi
movq %r12, %rdi
callq 0x2120
movq %rax, %rbx
testq %r12, %r12
je 0x145456
movq %rbx, 0x8(%rsp)
xorl %r9d, %r9d
xorl %r11d, %r11d
xorl %edi, %edi
xorl %r10d, %r10d
movq %r13, 0x50(%rsp)
movq %rbp, 0x48(%rsp)
movq %r14, 0x40(%rsp)
movq %r15, 0x38(%rsp)
movq (%r14), %rax
movq 0x80(%r14), %rcx
movl (%rax,%r10,4), %eax
incq %rcx
cmpq %rax, %rcx
jb 0x14522b
movq 0x28(%r15), %rax
movq (%rax,%r10,8), %rsi
testl %esi, %esi
je 0x14522b
movq %rsi, %rax
shrq $0x1b, %rax
andq $-0x20, %rax
addq 0x10(%r15), %rax
movq %rax, 0x18(%rsp)
xorl %r12d, %r12d
movl $0x1, %ebx
movq %r10, 0x30(%rsp)
movq %rsi, 0x10(%rsp)
movl %r12d, %eax
cmpl %esi, %ebx
jne 0x14508c
shlq $0x5, %rax
movq 0x18(%rsp), %rcx
movq 0x8(%rcx,%rax), %r15
addq %r15, %r15
movl %ebp, %ecx
shrq %cl, %r15
jmp 0x1450bc
movl %ebx, %ecx
shlq $0x5, %rcx
movq 0x18(%rsp), %r8
movq 0x8(%r8,%rcx), %rdx
addq %rdx, %rdx
movl %ebp, %ecx
shrq %cl, %rdx
shlq $0x5, %rax
movq 0x8(%r8,%rax), %r15
addq %r15, %r15
shrq %cl, %r15
cmpq %r15, %rdx
je 0x1451ef
cmpq %r10, %r15
je 0x1451ec
movq (%r14), %rax
movq 0x80(%r14), %rcx
movl (%rax,%r15,4), %eax
incq %rcx
cmpq %rax, %rcx
jb 0x1451ec
movq 0x10(%r13), %rcx
leaq (%r10,%r10,2), %rdx
shlq $0x4, %rdx
movq (%rcx,%rdx), %rax
testq %rax, %rax
je 0x145127
addq %rdx, %rcx
movq 0x10(%rcx), %rcx
movl $0x1, %edx
xorl %esi, %esi
leaq (%rsi,%rsi,4), %rsi
cmpb $0x0, 0x18(%rcx,%rsi,8)
js 0x14511e
leaq (%rcx,%rsi,8), %rsi
movl 0x8(%rsi), %r8d
cmpq %r8, %r15
je 0x1451fb
movl %edx, %esi
incl %edx
cmpq %rsi, %rax
ja 0x145102
cmpq %r11, %r9
jne 0x14515d
leaq (%r9,%r9), %rbp
testq %r9, %r9
movl $0x2, %eax
cmoveq %rax, %rbp
movq %rbp, %rax
shlq $0x4, %rax
leaq (%rax,%rax,2), %rsi
movq %r9, %r13
callq 0x2370
movq %rbp, %r11
movq 0x30(%rsp), %r10
movq %r13, %r9
movq %rax, %rdi
leaq 0x1(%r9), %r13
leaq (%r9,%r9,2), %rax
shlq $0x4, %rax
movl %r10d, 0x8(%rdi,%rax)
movl %r15d, 0x14(%rdi,%rax)
movl %ebx, %ebp
subl %r12d, %ebp
movl %ebp, 0x18(%rdi,%rax)
cmpq %r11, %r13
jne 0x1451b7
leaq (%r11,%r11), %r12
testq %r11, %r11
movl $0x2, %eax
cmoveq %rax, %r12
movq %r12, %rax
shlq $0x4, %rax
leaq (%rax,%rax,2), %rsi
movq %r9, %r14
callq 0x2370
movq 0x30(%rsp), %r10
movq %r14, %r9
movq 0x40(%rsp), %r14
movq %rax, %rdi
movq %r12, %r11
movq 0x10(%rsp), %rsi
addq $0x2, %r9
leaq (,%r13,2), %rax
addq %r13, %rax
shlq $0x4, %rax
movl %r15d, 0x8(%rdi,%rax)
movl %r10d, 0x14(%rdi,%rax)
movl %ebp, 0x18(%rdi,%rax)
movl %ebx, %r12d
movq 0x50(%rsp), %r13
movq 0x48(%rsp), %rbp
jmp 0x1451ef
movl %ebx, %r12d
incl %ebx
cmpl %esi, %ebx
jbe 0x14506d
jmp 0x145222
cmpq $-0x1, 0x10(%rsi)
je 0x145127
movl %ebx, %eax
subl %r12d, %eax
movq 0x8(%rsp), %rcx
addl %eax, (%rcx,%r10,4)
addl %eax, (%rcx,%r15,4)
movl %ebx, %r12d
movq 0x10(%rsp), %rsi
jmp 0x1451ef
movq 0x38(%rsp), %r15
movq 0x18(%r15), %r12
incq %r10
cmpq %r12, %r10
jb 0x14501d
leaq (%r9,%r9,2), %rsi
shlq $0x4, %rsi
addq %rdi, %rsi
movq %rdi, %r12
movq %r9, %r14
callq 0x136a91
testq %r14, %r14
je 0x14544c
movq %r14, %r8
leaq 0x18(%r12), %rax
movq %rax, 0x10(%rsp)
xorl %ebx, %ebx
movl $0x1, %r15d
movl $0x1, %eax
xorl %ebp, %ebp
movsd 0x20(%rsp), %xmm3
movq %r12, %rdi
movq %r12, 0x18(%rsp)
movl %ebx, %r12d
cmpq %rax, %r8
je 0x1452b4
leaq (%r12,%r12,2), %rcx
shlq $0x4, %rcx
movl 0x8(%rdi,%rcx), %edx
leaq (%rax,%rax,2), %rax
shlq $0x4, %rax
cmpl 0x8(%rdi,%rax), %edx
jne 0x1452b4
addq %rdi, %rcx
addq %rdi, %rax
movl 0x14(%rcx), %ecx
cmpl 0x14(%rax), %ecx
je 0x14540e
movl %r15d, %eax
subl %ebx, %eax
cmpl $0x3, %eax
jae 0x14541f
cmpl %ebx, %r15d
jbe 0x14532d
movl %r15d, %edx
leaq (%r12,%r12,2), %rcx
shlq $0x4, %rcx
movq 0x10(%rsp), %rax
leaq (%rax,%rcx), %rsi
subq %r12, %rdx
xorl %eax, %eax
addl (%rsi), %eax
addq $0x30, %rsi
decq %rdx
jne 0x1452e0
movl %ebp, %edx
leaq (%rdx,%rdx,2), %rdx
shlq $0x4, %rdx
leaq (%rdi,%rdx), %r12
movupd (%rdi,%rcx), %xmm0
movupd 0x10(%rdi,%rcx), %xmm1
movups 0x20(%rdi,%rcx), %xmm2
movupd %xmm1, 0x10(%rdi,%rdx)
movups %xmm2, 0x20(%rdi,%rdx)
movupd %xmm0, (%rdi,%rdx)
movl %eax, 0x18(%rdi,%rdx)
cmpl 0x2c(%rsp), %eax
jbe 0x14536d
movl 0x8(%r12), %esi
jmp 0x1453b0
leaq (%r12,%r12,2), %rax
shlq $0x4, %rax
movl %ebp, %ecx
leaq (%rcx,%rcx,2), %rcx
shlq $0x4, %rcx
leaq (%rdi,%rcx), %r12
movupd (%rdi,%rax), %xmm0
movupd 0x10(%rdi,%rax), %xmm1
movups 0x20(%rdi,%rax), %xmm2
movupd %xmm1, 0x10(%rdi,%rcx)
movups %xmm2, 0x20(%rdi,%rcx)
movupd %xmm0, (%rdi,%rcx)
movl $0x0, 0x18(%rdi,%rcx)
xorl %eax, %eax
movl %eax, %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movl 0x8(%r12), %esi
movq 0x8(%rsp), %rcx
movl (%rcx,%rsi,4), %eax
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
mulsd %xmm3, %xmm1
ucomisd %xmm1, %xmm0
jae 0x1453b0
movl 0x14(%r12), %eax
movl (%rcx,%rax,4), %eax
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
mulsd %xmm3, %xmm1
ucomisd %xmm1, %xmm0
jb 0x145409
movl 0x14(%r12), %edx
movq %r13, %rdi
xorl %ecx, %ecx
callq 0x144201
movq %rax, %rbx
cmpq $-0x1, 0x10(%rax)
jne 0x145437
movb 0x18(%rbx), %al
andb $-0x80, %al
incb %al
movb %al, 0x18(%rbx)
movl 0x8(%r12), %edx
movl 0x14(%r12), %esi
movq %r13, %rdi
xorl %ecx, %ecx
callq 0x144201
movq %rax, %rbx
cmpq $-0x1, 0x10(%rax)
jne 0x14543e
movb 0x18(%rbx), %al
andb $-0x80, %al
incb %al
movb %al, 0x18(%rbx)
movsd 0x20(%rsp), %xmm3
movq 0x18(%rsp), %rdi
movq %r14, %r8
incl %ebp
movl %r15d, %ebx
incl %r15d
movq %r15, %rax
cmpq %r15, %r8
jae 0x145280
jmp 0x145445
callq 0x1c3cb
movq %r14, %r8
movq 0x18(%rsp), %rdi
movsd 0x20(%rsp), %xmm3
jmp 0x1452c2
callq 0x1c3e7
jmp 0x1453c9
callq 0x1c403
jmp 0x1453f1
movq 0x8(%rsp), %rbx
jmp 0x145461
movq 0x8(%rsp), %rbx
movq %r12, %rdi
jmp 0x145461
xorl %edi, %edi
xorl %esi, %esi
callq 0x136a91
xorl %edi, %edi
callq 0x2220
movq %rbx, %rdi
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2220