// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/hic.cpp
// Function: collect_hc_links(ha_ug_index const*, kvec_pe_hit*, hc_links*, bubble_type*, MT*)
void collect_hc_links(const ha_ug_index* idx, kvec_pe_hit* hits, hc_links* link, bubble_type* bub, MT* M)
{
    double index_time = yak_realtime();
    uint64_t k, i, shif = 64 - idx->uID_bits, beg, end, t_d;
    for (k = 0; k < hits->a.n; ++k) 
    {
        beg = ((hits->a.a[k].s<<1)>>shif);
        end = ((hits->a.a[k].e<<1)>>shif);

        if(beg == end) continue;
        if(IF_HOM(beg, *bub)) continue;
        if(IF_HOM(end, *bub)) continue;

        t_d = (uint64_t)-1;
        push_hc_edge(&(link->a.a[beg]), end, 0, 0, &t_d);
        push_hc_edge(&(link->a.a[end]), beg, 0, 0, &t_d);
    }
    asg_t *copy_sg = copy_read_graph(idx->ug->g);


    update_ug_by_trans(copy_sg, &(idx->t_ch->k_trans));
    all_pair_shortest_path(copy_sg, link, M);
    fill_utg_distance_multi(copy_sg, link, M, bub);
    update_containment_distance(copy_sg, &(idx->t_ch->k_trans), link);
    asg_destroy(copy_sg);

    fprintf(stderr, "[M::%s::%.3f] ==> Hi-C linkages have been counted\n", __func__, yak_realtime()-index_time);
    return;





    index_time = yak_realtime();
    for (k = 0; k < link->enzymes.n; k++)
    {
        link->enzymes.a[k] = 0;
        for (i = 0; i < (uint64_t)asm_opt.hic_enzymes->n; i++)
        {
            link->enzymes.a[k] += get_enzyme_occ(idx->ug->u.a[k].s, idx->ug->u.a[k].len, 
                                                asm_opt.hic_enzymes->a[i], asm_opt.hic_enzymes->l[i]);
        }
    }
    fprintf(stderr, "[M::%s::%.3f] ==> Enzymes have been counted\n", __func__, yak_realtime()-index_time);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r8, 0x18(%rsp)
movq %rcx, %r14
movq %rdx, 0x8(%rsp)
movq %rsi, %r13
movq %rdi, %rbx
callq 0xefea7
movq %r14, %rsi
pushq $0x40
popq %rbp
movq %rbx, 0x20(%rsp)
subq 0x18(%rbx), %rbp
movsd %xmm0, 0x28(%rsp)
pushq $0x8
popq %rbx
xorl %r15d, %r15d
movq %r14, 0x30(%rsp)
cmpq (%r13), %r15
jae 0xfcee0
movq 0x10(%r13), %rax
movq -0x8(%rax,%rbx), %r14
addq %r14, %r14
movl %ebp, %ecx
shrq %cl, %r14
movq (%rax,%rbx), %r12
addq %r12, %r12
shrq %cl, %r12
cmpq %r12, %r14
je 0xfced4
movq (%rsi), %rcx
movq 0x80(%rsi), %rax
movl (%rcx,%r14,4), %edx
incq %rax
cmpq %rdx, %rax
jb 0xfced4
movl (%rcx,%r12,4), %ecx
cmpq %rcx, %rax
jb 0xfced4
orq $-0x1, 0x10(%rsp)
imulq $0x30, %r14, %rdi
movq 0x8(%rsp), %rax
addq 0x10(%rax), %rdi
xorpd %xmm0, %xmm0
movq %r12, %rsi
xorl %edx, %edx
leaq 0x10(%rsp), %rcx
callq 0xfa2fb
imulq $0x30, %r12, %rdi
movq 0x8(%rsp), %rax
addq 0x10(%rax), %rdi
xorpd %xmm0, %xmm0
movq %r14, %rsi
xorl %edx, %edx
leaq 0x10(%rsp), %rcx
callq 0xfa2fb
movq 0x30(%rsp), %rsi
incq %r15
addq $0x20, %rbx
jmp 0xfce40
movq 0x20(%rsp), %r15
movq (%r15), %rax
movq 0x18(%rax), %rdi
movq %rsi, %r13
callq 0x8c8a9
movq %rax, %r14
movl $0x138, %r12d           # imm = 0x138
movq 0x10(%r15), %rsi
addq %r12, %rsi
movq %rax, %rdi
callq 0xfbd2b
movq %r14, %rdi
movq 0x8(%rsp), %rbx
movq %rbx, %rsi
movq 0x18(%rsp), %rbp
movq %rbp, %rdx
callq 0xfa940
movq %r14, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
movq %r13, %rcx
callq 0xfb703
addq 0x10(%r15), %r12
movq %r14, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0xfcb50
movq %r14, %rdi
callq 0x68f68
movq 0x15608a(%rip), %rax    # 0x252fe0
movq (%rax), %rbx
callq 0xefea7
subsd 0x28(%rsp), %xmm0
leaq 0xf06df(%rip), %rsi     # 0x1ed64a
leaq 0xf070b(%rip), %rdx     # 0x1ed67d
movq %rbx, %rdi
movb $0x1, %al
callq 0x22b0
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq