// File: 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
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movl 0x14(%rax), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
shll %esi
leaq -0x58(%rbp), %rdi
callq 0x1ce570
movq $0x1, -0x60(%rbp)
movq -0x60(%rbp), %rax
movl %eax, %ecx
movl $0x1, %eax
shll %cl, %eax
cltq
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x1d310f
jmp 0x1d3101
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x1d30e7
movl $0x40, %eax
subq -0x60(%rbp), %rax
movq %rax, -0x78(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x1d325d
movq $0x0, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x1d3258
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x68(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rax
shlq %rax
movq -0x78(%rbp), %rcx
shrq %cl, %rax
movq %rax, -0x80(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x68(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
shlq %rax
movq -0x78(%rbp), %rcx
shrq %cl, %rax
movq %rax, -0x88(%rbp)
movq -0x80(%rbp), %rax
cmpq -0x88(%rbp), %rax
jne 0x1d319e
jmp 0x1d3247
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x80(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x28(%rbp), %rcx
movq 0x80(%rcx), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jbe 0x1d31c5
jmp 0x1d3247
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x88(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x28(%rbp), %rcx
movq 0x80(%rcx), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jbe 0x1d31ec
jmp 0x1d3247
movq $-0x1, -0x90(%rbp)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
imulq $0x30, -0x80(%rbp), %rax
addq %rax, %rdi
movq -0x88(%rbp), %rsi
xorps %xmm0, %xmm0
xorl %edx, %edx
leaq -0x90(%rbp), %rcx
callq 0x1cb380
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
imulq $0x30, -0x88(%rbp), %rax
addq %rax, %rdi
movq -0x80(%rbp), %rsi
xorps %xmm0, %xmm0
xorl %edx, %edx
leaq -0x90(%rbp), %rcx
callq 0x1cb380
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
jmp 0x1d312f
jmp 0x1d337d
movq $0x0, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rcx
movl 0x14(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl %ecx, %ecx
cmpq %rcx, %rax
jae 0x1d337b
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x68(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x28(%rbp), %rcx
movq 0x80(%rcx), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jbe 0x1d32ac
jmp 0x1d336a
movq $0x0, -0x70(%rbp)
movq -0x70(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rcx
movl 0x14(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl %ecx, %ecx
cmpq %rcx, %rax
jae 0x1d3368
movq -0x70(%rbp), %rax
cmpq -0x68(%rbp), %rax
je 0x1d3300
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x70(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x28(%rbp), %rcx
movq 0x80(%rcx), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jbe 0x1d3302
jmp 0x1d3357
movq $-0x1, -0x90(%rbp)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
imulq $0x30, -0x70(%rbp), %rax
addq %rax, %rdi
movq -0x68(%rbp), %rsi
xorps %xmm0, %xmm0
xorl %edx, %edx
leaq -0x90(%rbp), %rcx
callq 0x1cb380
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
imulq $0x30, -0x68(%rbp), %rax
addq %rax, %rdi
movq -0x70(%rbp), %rsi
xorps %xmm0, %xmm0
xorl %edx, %edx
leaq -0x90(%rbp), %rcx
callq 0x1cb380
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
jmp 0x1d32b4
jmp 0x1d336a
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
jmp 0x1d3265
jmp 0x1d337d
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x10b830
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x1ceb40
movq -0x98(%rbp), %rdi
movq -0x20(%rbp), %rsi
leaq -0x58(%rbp), %rdx
callq 0x1cc270
movq -0x98(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rcx
leaq -0x58(%rbp), %rdx
callq 0x1cdcc0
movq -0x98(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x1d0b60
movq -0x98(%rbp), %rdi
callq 0xcd170
leaq -0x58(%rbp), %rdi
callq 0x1ce6b0
movq $0x0, -0x70(%rbp)
movq -0x70(%rbp), %rax
movq -0x20(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x1d34f5
movq $0x0, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq -0x20(%rbp), %rcx
movq 0x10(%rcx), %rcx
imulq $0x30, -0x70(%rbp), %rdx
addq %rdx, %rcx
cmpq (%rcx), %rax
jae 0x1d34e2
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x70(%rbp), %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
imulq $0x28, -0x68(%rbp), %rcx
addq %rcx, %rax
movb 0x18(%rax), %cl
andb $-0x80, %cl
orb $0x0, %cl
movb %cl, 0x18(%rax)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x70(%rbp), %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
imulq $0x28, -0x68(%rbp), %rcx
addq %rcx, %rax
movb 0x18(%rax), %al
shrb $0x7, %al
cmpb $0x0, %al
je 0x1d3484
jmp 0x1d34d1
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x70(%rbp), %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
imulq $0x28, -0x68(%rbp), %rcx
addq %rcx, %rax
cmpq $-0x1, 0x10(%rax)
jne 0x1d34a9
jmp 0x1d34d1
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x70(%rbp), %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
imulq $0x28, -0x68(%rbp), %rcx
addq %rcx, %rax
movb 0x18(%rax), %cl
andb $-0x80, %cl
orb $0x1, %cl
movb %cl, 0x18(%rax)
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
jmp 0x1d3417
jmp 0x1d34e4
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
jmp 0x1d33fe
addq $0xa0, %rsp
popq %rbp
retq
nop