// File: /workspace/github_cpp_makefile_star2_O1/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, 0x28(%rsp)
movq %rcx, 0x18(%rsp)
movq %rdx, 0x8(%rsp)
movq %rsi, %r13
movq %rdi, 0x10(%rsp)
callq 0x1303c7
movsd %xmm0, 0x30(%rsp)
cmpq $0x0, (%r13)
je 0x162bb
pushq $0x40
popq %rbp
movq 0x10(%rsp), %rax
subq 0x18(%rax), %rbp
pushq $0x8
popq %rbx
xorl %r15d, %r15d
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 0x162aa
movq 0x18(%rsp), %rax
movq (%rax), %rcx
movq 0x80(%rax), %rax
movl (%rcx,%r14,4), %edx
incq %rax
cmpq %rdx, %rax
jb 0x162aa
movl (%rcx,%r12,4), %ecx
cmpq %rcx, %rax
jb 0x162aa
orq $-0x1, 0x20(%rsp)
imulq $0x30, %r14, %rdi
movq 0x8(%rsp), %rax
addq 0x10(%rax), %rdi
xorpd %xmm0, %xmm0
movq %r12, %rsi
xorl %edx, %edx
leaq 0x20(%rsp), %rcx
callq 0x13b8bb
imulq $0x30, %r12, %rdi
movq 0x8(%rsp), %rax
addq 0x10(%rax), %rdi
xorpd %xmm0, %xmm0
movq %r14, %rsi
xorl %edx, %edx
leaq 0x20(%rsp), %rcx
callq 0x13b8bb
incq %r15
addq $0x20, %rbx
cmpq (%r13), %r15
jb 0x16220
movq 0x10(%rsp), %r15
movq (%r15), %rax
movq 0x18(%rax), %rdi
callq 0xc802c
movq %rax, %r14
movl $0x138, %r12d           # imm = 0x138
movq 0x10(%r15), %rsi
addq %r12, %rsi
movq %rax, %rdi
callq 0x13d54c
movq %r14, %rdi
movq 0x8(%rsp), %rbx
movq %rbx, %rsi
movq 0x28(%rsp), %r13
movq %r13, %rdx
callq 0x13bfb1
movq %r14, %rdi
movq %rbx, %rsi
movq %r13, %rdx
movq 0x18(%rsp), %rcx
callq 0x13ce8f
addq 0x10(%r15), %r12
movq %r14, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x13e644
movq %r14, %rdi
callq 0x9fcdb
movq 0x273cb0(%rip), %rax    # 0x289fe0
movq (%rax), %rbx
callq 0x1303c7
subsd 0x30(%rsp), %xmm0
leaq 0x2191c5(%rip), %rsi    # 0x22f50a
leaq 0x2191f1(%rip), %rdx    # 0x22f53d
movq %rbx, %rdi
movb $0x1, %al
callq 0x22b0
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq