// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %r8, 0x38(%rsp)
movq %rcx, 0x30(%rsp)
movq %rdx, 0x28(%rsp)
movq %rdi, 0x20(%rsp)
movl 0xa0(%rsp), %eax
testl %eax, %eax
je 0x1583e9
movq %rsi, %r13
movq 0xb0(%rsp), %r11
movl 0xa8(%rsp), %r12d
movl %r12d, %r15d
movl %eax, %r14d
xorl %ebp, %ebp
xorpd %xmm0, %xmm0
movq %r9, 0x8(%rsp)
movq %r14, 0x18(%rsp)
movq (%r13), %rdx
movq 0x80(%r13), %rcx
movl (%rdx,%r15,4), %eax
incq %rcx
cmpq %rax, %rcx
jb 0x1583ad
leaq (,%rbp,2), %rbx
addq %rbp, %rbx
shlq $0x4, %rbx
movl 0x14(%r9,%rbx), %eax
movl (%rdx,%rax,4), %edx
cmpq %rdx, %rcx
jb 0x1583ad
cmpl %r12d, %eax
je 0x1581a1
movq 0x28(%r11), %rcx
movq (%rcx,%r15,8), %rsi
movq (%rcx,%rax,8), %rdi
cmpl %esi, %edi
movl %esi, %edx
cmovbl %edi, %edx
movl %eax, %ecx
cmovbl %r12d, %ecx
cmovbq %rdi, %rsi
testl %edx, %edx
je 0x1583ad
movq 0x10(%r11), %rdi
shrq $0x20, %rsi
leaq (%rsi,%rsi,2), %rsi
shlq $0x4, %rsi
leaq (%rdi,%rsi), %r8
cmpl %ecx, 0x14(%r8)
jne 0x1583bb
movsd %xmm0, 0x10(%rsp)
addq %r9, %rbx
movq 0x28(%rsp), %r9
movq 0x28(%r9), %rcx
movq 0x40(%r9), %rdx
movsd (%rdx,%r15,8), %xmm0
movsd 0xcd07b(%rip), %xmm1    # 0x225240
unpcklps %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0xcd080(%rip), %xmm2    # 0x225250
subpd %xmm2, %xmm0
movapd %xmm0, %xmm3
unpckhpd %xmm0, %xmm3            # xmm3 = xmm3[1],xmm0[1]
addsd %xmm0, %xmm3
movapd %xmm3, 0x50(%rsp)
movsd (%rdx,%rax,8), %xmm0
unpcklps %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
subpd %xmm2, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
movl 0xc(%rbx), %r10d
movl 0x10(%rbx), %r11d
movl %r11d, %edx
subl %r10d, %edx
xorps %xmm2, %xmm2
cvtsi2sd %rdx, %xmm2
addsd %xmm0, %xmm1
movq 0x20(%rsp), %rdi
movq (%rdi), %rdx
movq 0x18(%rdx), %rdx
movq 0x20(%rdx), %rdx
movl (%rdx,%rax,8), %esi
movl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
andl %r14d, %esi
xorps %xmm0, %xmm0
cvtsi2sd %esi, %xmm0
divsd %xmm0, %xmm2
mulsd %xmm1, %xmm2
movsd 0xcd029(%rip), %xmm0    # 0x225270
maxsd %xmm2, %xmm0
movapd %xmm0, 0x40(%rsp)
movq (%rcx,%r15,8), %r8
movq %r8, %rcx
shrq $0x1b, %rcx
andq $-0x20, %rcx
addq 0x10(%r9), %rcx
movq %r12, %r9
movl (%rdx,%r15,8), %r12d
andl %r14d, %r12d
subq $0x8, %rsp
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rdx
movq %r9, %r14
pushq %r11
pushq %r10
pushq %rax
pushq %r12
pushq $0x0
callq 0x1579b8
addq $0x30, %rsp
ucomisd 0xcd27f(%rip), %xmm0    # 0x225518
jne 0x15829d
jnp 0x1582c6
movapd 0x50(%rsp), %xmm3
movapd %xmm3, %xmm1
movapd 0x40(%rsp), %xmm4
cmplesd %xmm4, %xmm1
movapd %xmm1, %xmm2
andpd %xmm3, %xmm2
andnpd %xmm4, %xmm1
orpd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd 0x10(%rsp), %xmm1
addsd %xmm0, %xmm1
movapd %xmm1, %xmm0
movl 0x14(%rbx), %r9d
movq %r14, %r12
cmpl %r12d, %r9d
jne 0x1582f7
movq 0x8(%rsp), %r9
movq 0xb0(%rsp), %r11
movq 0x18(%rsp), %r14
jmp 0x1583ad
movsd %xmm0, 0x10(%rsp)
movq 0x28(%rsp), %rdx
movq 0x28(%rdx), %rax
movq (%rax,%r9,8), %r8
movq %r8, %rcx
shrq $0x1b, %rcx
andq $-0x20, %rcx
addq 0x10(%rdx), %rcx
movl 0xc(%rbx), %eax
movl 0x10(%rbx), %r10d
movq 0x20(%rsp), %rdi
movq (%rdi), %rdx
movq 0x18(%rdx), %rdx
movq 0x20(%rdx), %rdx
movl (%rdx,%r15,8), %r11d
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl %edx, %r11d
subq $0x8, %rsp
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rdx
pushq %r11
pushq $0x0
pushq %r12
pushq %r10
pushq %rax
callq 0x1579b8
addq $0x30, %rsp
ucomisd 0xcd1b4(%rip), %xmm0    # 0x225518
movq 0x18(%rsp), %r14
jne 0x15836d
jnp 0x158392
movapd 0x50(%rsp), %xmm2
movapd %xmm2, %xmm1
movapd 0x40(%rsp), %xmm3
cmplesd %xmm3, %xmm1
andpd %xmm1, %xmm2
andnpd %xmm3, %xmm1
orpd %xmm2, %xmm1
divsd %xmm1, %xmm0
movq 0x8(%rsp), %r9
movq 0xb0(%rsp), %r11
movsd 0x10(%rsp), %xmm1
addsd %xmm0, %xmm1
movapd %xmm1, %xmm0
incq %rbp
cmpq %r14, %rbp
jne 0x15811e
jmp 0x1583ed
movl %edx, %edx
addq %rsi, %rdi
addq $0x44, %rdi
leaq -0x1(%rdx), %rsi
xorl %r8d, %r8d
cmpq %r8, %rsi
je 0x1583ad
leaq 0x30(%rdi), %r10
incq %r8
cmpl %ecx, (%rdi)
movq %r10, %rdi
jne 0x1583cb
cmpq %rdx, %r8
jb 0x1581a1
jmp 0x1583ad
xorpd %xmm0, %xmm0
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq