// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/hic.cpp
// Function: measure_distance(ha_ug_index*, ma_ug_t const*, kvec_pe_hit*, hc_links*, bubble_type*, kv_u_trans_t*)
void measure_distance(ha_ug_index* idx, const ma_ug_t* ug, kvec_pe_hit* hits, hc_links* link, bubble_type* bub, kv_u_trans_t *ta)
{
    // double index_time = yak_realtime();
    MT M;
    init_MT(&M, ug->g->n_seq<<1);
    uint64_t uID_bits;
    for (uID_bits=1; (uint64_t)(1<<uID_bits)<(uint64_t)ug->u.n; uID_bits++);
    uint64_t k, i, shif = 64 - uID_bits, beg, end, t_d;
    if(hits)
    {
        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);
        }
    }
    else
    {
        for (k = 0; k < ug->g->n_seq; ++k)
        {
            if(IF_HOM(k, *bub)) continue;
            for (i = 0; i < ug->g->n_seq; ++i)
            {
                if(i == k || IF_HOM(i, *bub)) continue;
                t_d = (uint64_t)-1;
                push_hc_edge(&(link->a.a[i]), k, 0, 0, &t_d);
                push_hc_edge(&(link->a.a[k]), i, 0, 0, &t_d);
            }
        }
    }

    asg_t *copy_sg = copy_read_graph(ug->g);

    update_ug_by_trans(copy_sg, ta);
    // update_ug_by_tigs(copy_sg, link);
    all_pair_shortest_path(copy_sg, link, &M);
    fill_utg_distance_multi(copy_sg, link, &M, bub);
    update_containment_distance(copy_sg, ta, link);
    // update_dis_connected_gfa(copy_sg, link, &M);
    asg_destroy(copy_sg);
    destory_MT(&M);

    for (i = 0; i < link->a.n; i++)
    {
        for (k = 0; k < link->a.a[i].e.n; k++)
        {
            link->a.a[i].e.a[k].is_cc = 0;
            if(link->a.a[i].e.a[k].del) continue;
            if(link->a.a[i].e.a[k].dis == (uint64_t)-1) continue;
            link->a.a[i].e.a[k].is_cc = 1;
        }
    }

    // filter_disconnect_edges(idx, hits, link, bub, 1, 0.01);
    // fprintf(stderr, "[M::%s::%.3f] ==> Hi-C linkages have been counted\n", __func__, yak_realtime()-index_time);
    return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r9, 0x20(%rsp)
movq %r8, %r15
movq %rcx, %rbx
movq %rdx, 0x18(%rsp)
movq %rsi, %r14
movq 0x18(%rsi), %rax
movl 0x14(%rax), %esi
addl %esi, %esi
leaq 0x30(%rsp), %rdi
callq 0xfbb57
movq %r14, 0x10(%rsp)
movq (%r14), %rax
pushq $-0x40
popq %rbp
pushq $0x1
popq %rdx
leal 0x41(%rbp), %ecx
movl %edx, %esi
shll %cl, %esi
movslq %esi, %rcx
incq %rbp
cmpq %rcx, %rax
ja 0xfdf7f
movq 0x18(%rsp), %rsi
testq %rsi, %rsi
je 0xfe10b
negq %rbp
pushq $0x8
popq %r13
xorl %edi, %edi
cmpq (%rsi), %rdi
jae 0xfe045
movq 0x10(%rsi), %rax
movq -0x8(%rax,%r13), %r14
addq %r14, %r14
movl %ebp, %ecx
shrq %cl, %r14
movq (%rax,%r13), %r12
addq %r12, %r12
shrq %cl, %r12
cmpq %r12, %r14
je 0xfe039
movq (%r15), %rcx
movq 0x80(%r15), %rax
movl (%rcx,%r14,4), %edx
incq %rax
cmpq %rdx, %rax
jb 0xfe039
movl (%rcx,%r12,4), %ecx
cmpq %rcx, %rax
jb 0xfe039
orq $-0x1, 0x8(%rsp)
movq %rdi, 0x28(%rsp)
imulq $0x30, %r14, %rdi
addq 0x10(%rbx), %rdi
xorps %xmm0, %xmm0
movq %r12, %rsi
xorl %edx, %edx
leaq 0x8(%rsp), %rcx
callq 0xfa2fb
imulq $0x30, %r12, %rdi
addq 0x10(%rbx), %rdi
xorps %xmm0, %xmm0
movq %r14, %rsi
xorl %edx, %edx
leaq 0x8(%rsp), %rcx
callq 0xfa2fb
movq 0x28(%rsp), %rdi
movq 0x18(%rsp), %rsi
incq %rdi
addq $0x20, %r13
jmp 0xfdfa8
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rdi
callq 0x8c8a9
movq %rax, %r14
movq %rax, %rdi
movq 0x20(%rsp), %r13
movq %r13, %rsi
callq 0xfbd2b
leaq 0x30(%rsp), %r12
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0xfa940
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0xfb703
movq %r14, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0xfcb50
movq %r14, %rdi
callq 0x68f68
movq %r12, %rdi
callq 0xfbbc2
xorl %eax, %eax
pushq $0x18
popq %rcx
cmpq (%rbx), %rax
jae 0xfe0fc
imulq $0x30, %rax, %rdx
movq %rcx, %rsi
xorl %edi, %edi
movq 0x10(%rbx), %r8
cmpq (%r8,%rdx), %rdi
jae 0xfe0f7
addq %rdx, %r8
movq 0x10(%r8), %r8
andb $-0x80, (%r8,%rsi)
movq 0x10(%rbx), %r8
movq 0x10(%r8,%rdx), %r8
cmpb $0x0, (%r8,%rsi)
js 0xfe0ee
cmpq $-0x1, -0x8(%r8,%rsi)
je 0xfe0ee
movb $0x1, (%r8,%rsi)
incq %rdi
addq $0x28, %rsi
jmp 0xfe0bb
incq %rax
jmp 0xfe0ad
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rdi
xorl %r13d, %r13d
leaq 0x8(%rsp), %rbp
movl 0x14(%rdi), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpq %rax, %r13
jae 0xfe04e
movq (%r15), %rax
movq 0x80(%r15), %rcx
movl (%rax,%r13,4), %eax
incq %rcx
cmpq %rax, %rcx
jae 0xfe148
incq %r13
jmp 0xfe11c
imulq $0x30, %r13, %r12
xorl %r14d, %r14d
movl 0x14(%rdi), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpq %rax, %r14
jae 0xfe143
cmpq %r13, %r14
je 0xfe1b5
movq (%r15), %rax
movq 0x80(%r15), %rcx
movl (%rax,%r14,4), %eax
incq %rcx
cmpq %rax, %rcx
jb 0xfe1b5
orq $-0x1, 0x8(%rsp)
imulq $0x30, %r14, %rdi
addq 0x10(%rbx), %rdi
xorps %xmm0, %xmm0
movq %r13, %rsi
xorl %edx, %edx
movq %rbp, %rcx
callq 0xfa2fb
movq 0x10(%rbx), %rdi
addq %r12, %rdi
xorps %xmm0, %xmm0
movq %r14, %rsi
xorl %edx, %edx
movq %rbp, %rcx
callq 0xfa2fb
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rdi
incq %r14
jmp 0xfe14f