// File: 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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
callq 0x1b7ca0
movsd %xmm0, -0x30(%rbp)
movq -0x8(%rbp), %rcx
movl $0x40, %eax
subq 0x18(%rcx), %rax
movq %rax, -0x48(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x1d113d
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x38(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rax
shlq %rax
movq -0x48(%rbp), %rcx
shrq %cl, %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x38(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
shlq %rax
movq -0x48(%rbp), %rcx
shrq %cl, %rax
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x58(%rbp), %rax
jne 0x1d1098
jmp 0x1d112c
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0x50(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x20(%rbp), %rcx
movq 0x80(%rcx), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jbe 0x1d10bc
jmp 0x1d112c
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0x58(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x20(%rbp), %rcx
movq 0x80(%rcx), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jbe 0x1d10e0
jmp 0x1d112c
movq $-0x1, -0x60(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
imulq $0x30, -0x50(%rbp), %rax
addq %rax, %rdi
movq -0x58(%rbp), %rsi
xorps %xmm0, %xmm0
xorl %edx, %edx
leaq -0x60(%rbp), %rcx
callq 0x1cb380
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
imulq $0x30, -0x58(%rbp), %rax
addq %rax, %rdi
movq -0x50(%rbp), %rsi
xorps %xmm0, %xmm0
xorl %edx, %edx
leaq -0x60(%rbp), %rcx
callq 0x1cb380
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x1d102f
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rdi
callq 0x10b830
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rsi
addq $0x138, %rsi            # imm = 0x138
callq 0x1ceb40
movq -0x68(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x1cc270
movq -0x68(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x20(%rbp), %rcx
callq 0x1cdcc0
movq -0x68(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rsi
addq $0x138, %rsi            # imm = 0x138
movq -0x18(%rbp), %rdx
callq 0x1d0b60
movq -0x68(%rbp), %rdi
callq 0xcd170
movq 0x1f2e25(%rip), %rax    # 0x3c3fe0
movq (%rax), %rax
movq %rax, -0x70(%rbp)
callq 0x1b7ca0
movq -0x70(%rbp), %rdi
subsd -0x30(%rbp), %xmm0
leaq 0x1bb1a0(%rip), %rsi    # 0x38c377
leaq 0x1bb1cc(%rip), %rdx    # 0x38c3aa
movb $0x1, %al
callq 0x22a0
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)