// File: chhylp123[P]hifiasm/hic.cpp
// Function: get_hits_weight(ha_ug_index*, bubble_type*, kvec_pe_hit*, hc_links*, trans_idx*, u_trans_t*, unsigned int, unsigned int, kv_u_trans_t*)
double get_hits_weight(ha_ug_index* idx, bubble_type* bub, kvec_pe_hit* hits, hc_links* link, trans_idx* dis, 
u_trans_t *t_a, uint32_t t_n, uint32_t qid, kv_u_trans_t *ta_idx)
{
    /****************************may have bugs********************************/
    ///need to record self hits
    ///if(u_trans_n(*ta_idx, qid) == 0) return 0;///no hit bridging qid
    /****************************may have bugs********************************/
    uint32_t k, i, x_n, y;
    u_trans_t *x_a = NULL;
    double occ_q, occ_t;
    double w, i_w;
    for (k = 0, w = 0; k < t_n; k++)
    {
        if(IF_HOM(qid, *bub)) continue;
        if(IF_HOM(t_a[k].tn, *bub)) continue;
        /****************************may have bugs********************************/
        if(qid != t_a[k].tn)
        {
            x_n = u_trans_n(*ta_idx, qid); x_a = u_trans_a(*ta_idx, qid); y = t_a[k].tn;
            if(u_trans_n(*ta_idx, t_a[k].tn) < x_n)
            {
                x_n = u_trans_n(*ta_idx, t_a[k].tn); x_a = u_trans_a(*ta_idx, t_a[k].tn); y = qid;
            }
            if(x_n == 0) continue; 

            for (i = 0; i < x_n; i++)
            {
                if(x_a[i].tn == y) break;
            }
            if(i >= x_n) continue; ///no hit bridging tn and qid
        }
        /****************************may have bugs********************************/
        occ_q = hits->occ.a[qid];
        occ_t = hits->occ.a[t_a[k].tn] * ((double)(t_a[k].te - t_a[k].ts) / (double)(idx->ug->g->seq[t_a[k].tn].len));
        if(occ_t < 1) occ_t = 1;

        ///q--->t hits
        i_w = get_interval_weight(idx, link, dis, hits->a.a + (hits->idx.a[qid]>>32),
        (uint32_t)(hits->idx.a[qid]), qid, 0, idx->ug->g->seq[qid].len, t_a[k].tn, 
        t_a[k].ts, t_a[k].te);
        if(i_w != 0) i_w /= (MIN(occ_q, occ_t));
        w += i_w;
        if(t_a[k].tn == qid) continue;

        ///t--->q hits
        i_w = get_interval_weight(idx, link, dis, hits->a.a + (hits->idx.a[t_a[k].tn]>>32),
        (uint32_t)(hits->idx.a[t_a[k].tn]), t_a[k].tn, t_a[k].ts, t_a[k].te, 
        qid, 0, idx->ug->g->seq[qid].len);    
        if(i_w != 0) i_w /= (MIN(occ_q, occ_t));
        w += i_w;
    }
    return w;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0xa0, %rsp
movq 0x20(%rbp), %rax
movl 0x18(%rbp), %eax
movl 0x10(%rbp), %eax
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq %rdx, -0x28(%rbp)
movq %rcx, -0x30(%rbp)
movq %r8, -0x38(%rbp)
movq %r9, -0x40(%rbp)
movq $0x0, -0x58(%rbp)
movl $0x0, -0x44(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x70(%rbp)
movl -0x44(%rbp), %eax
cmpl 0x10(%rbp), %eax
jae 0x20295f
movq -0x20(%rbp), %rax
movq (%rax), %rax
movl 0x18(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movq -0x20(%rbp), %rcx
movq 0x80(%rcx), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jbe 0x2024b9
jmp 0x202951
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0x40(%rbp), %rcx
movl -0x44(%rbp), %edx
imulq $0x30, %rdx, %rdx
addq %rdx, %rcx
movl 0x14(%rcx), %ecx
movl (%rax,%rcx,4), %eax
movq -0x20(%rbp), %rcx
movq 0x80(%rcx), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jbe 0x2024ed
jmp 0x202951
movl 0x18(%rbp), %eax
movq -0x40(%rbp), %rcx
movl -0x44(%rbp), %edx
imulq $0x30, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x14(%rcx), %eax
je 0x20261d
movq 0x20(%rbp), %rax
movq 0x28(%rax), %rax
movl 0x18(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x4c(%rbp)
movq 0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x20(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl 0x18(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x40(%rbp), %rax
movl -0x44(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movl 0x14(%rax), %eax
movl %eax, -0x50(%rbp)
movq 0x20(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x40(%rbp), %rcx
movl -0x44(%rbp), %edx
imulq $0x30, %rdx, %rdx
addq %rdx, %rcx
movl 0x14(%rcx), %ecx
movq (%rax,%rcx,8), %rax
cmpl -0x4c(%rbp), %eax
jae 0x2025cf
movq 0x20(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x40(%rbp), %rcx
movl -0x44(%rbp), %edx
imulq $0x30, %rdx, %rdx
addq %rdx, %rcx
movl 0x14(%rcx), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x4c(%rbp)
movq 0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x20(%rbp), %rcx
movq 0x28(%rcx), %rcx
movq -0x40(%rbp), %rdx
movl -0x44(%rbp), %esi
imulq $0x30, %rsi, %rsi
addq %rsi, %rdx
movl 0x14(%rdx), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movl 0x18(%rbp), %eax
movl %eax, -0x50(%rbp)
cmpl $0x0, -0x4c(%rbp)
jne 0x2025da
jmp 0x202951
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jae 0x20260e
movq -0x58(%rbp), %rax
movl -0x48(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movl 0x14(%rax), %eax
cmpl -0x50(%rbp), %eax
jne 0x202601
jmp 0x20260e
jmp 0x202603
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x2025e1
movl -0x48(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jb 0x20261b
jmp 0x202951
jmp 0x20261d
movq -0x28(%rbp), %rax
movq 0x40(%rax), %rax
movl 0x18(%rbp), %ecx
movq (%rax,%rcx,8), %xmm0
movaps 0x17f9dc(%rip), %xmm2   # 0x382010
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
movapd 0x17f9e0(%rip), %xmm1   # 0x382020
subpd %xmm1, %xmm0
movaps %xmm0, %xmm3
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm3, %xmm0
movsd %xmm0, -0x60(%rbp)
movq -0x28(%rbp), %rax
movq 0x40(%rax), %rdx
movq -0x40(%rbp), %rax
movl -0x44(%rbp), %ecx
leaq (%rcx,%rcx,2), %rsi
shlq $0x4, %rsi
movl 0x14(%rax,%rsi), %ecx
movq (%rdx,%rcx,8), %xmm0
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movl 0xc(%rax,%rsi), %edx
movl 0x10(%rax,%rsi), %eax
subl %edx, %eax
cvtsi2sd %rax, %xmm1
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cvtsi2sd %eax, %xmm2
divsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0x68(%rbp)
movsd 0x17f93a(%rip), %xmm0   # 0x382000
ucomisd -0x68(%rbp), %xmm0
jbe 0x2026da
movsd 0x17f92b(%rip), %xmm0   # 0x382000
movsd %xmm0, -0x68(%rbp)
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rax
movl 0x18(%rbp), %r8d
movq (%rax,%r8,8), %rax
shrq $0x20, %rax
shlq $0x5, %rax
addq %rax, %rcx
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rax
movl 0x18(%rbp), %r8d
movq (%rax,%r8,8), %rax
movl %eax, %r8d
movl 0x18(%rbp), %r9d
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movl 0x18(%rbp), %r10d
movl (%rax,%r10,8), %ebx
andl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
movq -0x40(%rbp), %rax
movl -0x44(%rbp), %r10d
imulq $0x30, %r10, %r10
addq %r10, %rax
movl 0x14(%rax), %r11d
movq -0x40(%rbp), %rax
movl -0x44(%rbp), %r10d
imulq $0x30, %r10, %r10
addq %r10, %rax
movl 0xc(%rax), %r10d
movq -0x40(%rbp), %rax
movl -0x44(%rbp), %r14d
imulq $0x30, %r14, %r14
addq %r14, %rax
movl 0x10(%rax), %eax
xorl %r14d, %r14d
movl $0x0, (%rsp)
movl %ebx, 0x8(%rsp)
movl %r11d, 0x10(%rsp)
movl %r10d, 0x18(%rsp)
movl %eax, 0x20(%rsp)
callq 0x202090
movsd %xmm0, -0x78(%rbp)
movsd -0x78(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x2027ad
jp 0x2027ad
jmp 0x2027e6
movsd -0x60(%rbp), %xmm1
movsd -0x68(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jb 0x2027c9
movsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x80(%rbp)
jmp 0x2027d3
movsd -0x68(%rbp), %xmm0
movsd %xmm0, -0x80(%rbp)
movsd -0x80(%rbp), %xmm1
movsd -0x78(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0x78(%rbp)
movsd -0x78(%rbp), %xmm0
addsd -0x70(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
movq -0x40(%rbp), %rax
movl -0x44(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movl 0x14(%rax), %eax
cmpl 0x18(%rbp), %eax
jne 0x202810
jmp 0x202951
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x40(%rbp), %r8
movl -0x44(%rbp), %r9d
imulq $0x30, %r9, %r9
addq %r9, %r8
movl 0x14(%r8), %r8d
movq (%rax,%r8,8), %rax
shrq $0x20, %rax
shlq $0x5, %rax
addq %rax, %rcx
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x40(%rbp), %r8
movl -0x44(%rbp), %r9d
imulq $0x30, %r9, %r9
addq %r9, %r8
movl 0x14(%r8), %r8d
movq (%rax,%r8,8), %rax
movl %eax, %r8d
movq -0x40(%rbp), %rax
movl -0x44(%rbp), %r9d
imulq $0x30, %r9, %r9
addq %r9, %rax
movl 0x14(%rax), %r9d
movq -0x40(%rbp), %rax
movl -0x44(%rbp), %r10d
imulq $0x30, %r10, %r10
addq %r10, %rax
movl 0xc(%rax), %ebx
movq -0x40(%rbp), %rax
movl -0x44(%rbp), %r10d
imulq $0x30, %r10, %r10
addq %r10, %rax
movl 0x10(%rax), %r11d
movl 0x18(%rbp), %r10d
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movl 0x18(%rbp), %r14d
movl (%rax,%r14,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
xorl %r14d, %r14d
movl %ebx, (%rsp)
movl %r11d, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movl $0x0, 0x18(%rsp)
movl %eax, 0x20(%rsp)
callq 0x202090
movsd %xmm0, -0x78(%rbp)
movsd -0x78(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x202900
jp 0x202900
jmp 0x202942
movsd -0x60(%rbp), %xmm1
movsd -0x68(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jb 0x20291f
movsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x88(%rbp)
jmp 0x20292c
movsd -0x68(%rbp), %xmm0
movsd %xmm0, -0x88(%rbp)
movsd -0x88(%rbp), %xmm1
movsd -0x78(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0x78(%rbp)
movsd -0x78(%rbp), %xmm0
addsd -0x70(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x202487
movsd -0x70(%rbp), %xmm0
addq $0xa0, %rsp
popq %rbx
popq %r14
popq %rbp
retq