// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/hic.cpp
// Function: idx_hc_links(kvec_pe_hit*, ha_ug_index*, bubble_type*)
void idx_hc_links(kvec_pe_hit* hits, ha_ug_index* idx, bubble_type* bub)
{
    uint64_t k, l;
    uint32_t qn, tn;

    kv_resize(uint64_t, hits->idx, idx->ug->g->n_seq);
    hits->idx.n = idx->ug->g->n_seq;
    memset(hits->idx.a, 0, hits->idx.n*sizeof(uint64_t));

    kv_resize(uint64_t, hits->occ, idx->ug->g->n_seq);
    hits->occ.n = idx->ug->g->n_seq;
    memset(hits->occ.a, 0, hits->occ.n*sizeof(uint64_t));

    radix_sort_pe_hit_idx_an1(hits->a.a, hits->a.a + hits->a.n);
    for (k = 1, l = 0; k <= hits->a.n; ++k) 
    {   
        if (k == hits->a.n || 
            ((hits->a.a[k].s<<1)>>(64 - idx->uID_bits)) != ((hits->a.a[l].s<<1)>>(64 - idx->uID_bits))) 
        {
            if (k - l > 1) radix_sort_pe_hit_idx_an2(hits->a.a + l, hits->a.a + k);
            
            hits->idx.a[((hits->a.a[l].s<<1)>>(64 - idx->uID_bits))] 
                                                = (uint64_t)l << 32 | (k - l);

            for (; l < k; l++)
            {
                qn = ((hits->a.a[l].s<<1)>>(64 - idx->uID_bits));
                tn = ((hits->a.a[l].e<<1)>>(64 - idx->uID_bits));
                if(bub && IF_HOM(qn, *bub)) continue;
                if(bub && IF_HOM(tn, *bub)) continue;
                hits->occ.a[qn]++;
                hits->occ.a[tn]++;
            }
            
            l = k;
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
movq (%rsi), %rax
movq 0x18(%rax), %rax
movl 0x14(%rax), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
cmpq %rdx, 0x20(%rdi)
jae 0x14550c
decq %rdx
movq %rdx, %rax
shrq %rax
orq %rdx, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x10, %rax
orq %rcx, %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x20(%r15)
movq 0x28(%r15), %rdi
leaq 0x8(,%rax,8), %rsi
callq 0x2370
movq %rax, %rdi
movq %rax, 0x28(%r15)
movq (%r14), %rax
movq 0x18(%rax), %rax
movl 0x14(%rax), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
jmp 0x145510
movq 0x28(%r15), %rdi
movq %rdx, 0x18(%r15)
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x20e0
movq (%r14), %rax
movq 0x18(%rax), %rax
movl 0x14(%rax), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
cmpq %rdx, 0x38(%r15)
jae 0x14559b
decq %rdx
movq %rdx, %rax
shrq %rax
orq %rdx, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x10, %rax
orq %rcx, %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x38(%r15)
movq 0x40(%r15), %rdi
leaq 0x8(,%rax,8), %rsi
callq 0x2370
movq %rax, %rdi
movq %rax, 0x40(%r15)
movq (%r14), %rax
movq 0x18(%rax), %rax
movl 0x14(%rax), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
jmp 0x14559f
movq 0x40(%r15), %rdi
movq %rdx, 0x30(%r15)
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x20e0
movq (%r15), %rsi
movq 0x10(%r15), %rdi
shlq $0x5, %rsi
addq %rdi, %rsi
callq 0x137544
movq (%r15), %rcx
testq %rcx, %rcx
je 0x1456e8
movq 0x10(%r15), %rax
movl $0x1, %r12d
xorl %r13d, %r13d
cmpq %rcx, %r12
je 0x145613
movq %r12, %rcx
shlq $0x5, %rcx
movq (%rax,%rcx), %rdx
addq %rdx, %rdx
movb 0x18(%r14), %sil
xorl %ecx, %ecx
subb %sil, %cl
shrq %cl, %rdx
movq %r13, %rsi
shlq $0x5, %rsi
movq (%rax,%rsi), %rsi
addq %rsi, %rsi
shrq %cl, %rsi
cmpq %rsi, %rdx
je 0x1456d9
movq %r12, %rbp
subq %r13, %rbp
cmpq $0x2, %rbp
jb 0x14563c
movq %r13, %rdi
shlq $0x5, %rdi
addq %rax, %rdi
movq %r12, %rsi
shlq $0x5, %rsi
addq %rax, %rsi
callq 0x1377cd
movq 0x10(%r15), %rax
movq %r13, %rsi
shlq $0x20, %rsi
movq %r13, %rdx
shlq $0x5, %rdx
movq (%rax,%rdx), %rdi
addq %rdi, %rdi
movb 0x18(%r14), %r8b
xorl %ecx, %ecx
subb %r8b, %cl
shrq %cl, %rdi
orq %rsi, %rbp
movq 0x28(%r15), %rcx
movq %rbp, (%rcx,%rdi,8)
cmpq %r13, %r12
jbe 0x1456d6
addq %rax, %rdx
addq $0x8, %rdx
movq -0x8(%rdx), %rdi
addq %rdi, %rdi
movb 0x18(%r14), %sil
xorl %ecx, %ecx
subb %sil, %cl
shrq %cl, %rdi
movq (%rdx), %rsi
addq %rsi, %rsi
shrq %cl, %rsi
testq %rbx, %rbx
je 0x1456ba
movq (%rbx), %r9
movq 0x80(%rbx), %r8
movl %edi, %ecx
movl (%r9,%rcx,4), %edi
incq %r8
cmpq %rdi, %r8
jb 0x1456ca
movl %esi, %esi
movl (%r9,%rsi,4), %edi
cmpq %rdi, %r8
jae 0x1456be
jmp 0x1456ca
movl %edi, %ecx
movl %esi, %esi
movq 0x40(%r15), %rdi
incq (%rdi,%rcx,8)
incq (%rdi,%rsi,8)
incq %r13
addq $0x20, %rdx
cmpq %r13, %r12
jne 0x145674
movq %r12, %r13
incq %r12
movq (%r15), %rcx
cmpq %rcx, %r12
jbe 0x1455da
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq