// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/hic.cpp
// Function: get_interval_weight(ha_ug_index*, hc_links*, trans_idx*, pe_hit*, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int)
double get_interval_weight(ha_ug_index* idx, hc_links* link, trans_idx* dis, 
pe_hit *hits, uint32_t occ, uint32_t qid, uint32_t qs, uint32_t qe, uint32_t tid, uint32_t ts, uint32_t te)
{
    int64_t s_idx = 0, e_idx = (int64_t)occ - 1, m_idx = 0;
    uint32_t m_uid = (uint32_t)-1;
    while (s_idx <= e_idx)
    {
        m_idx = s_idx + (e_idx - s_idx)/2;
        m_uid = ((hits[m_idx].e<<1)>>(64 - idx->uID_bits)); 
        if (m_uid == tid)
            break;
        if (m_uid < tid)
            s_idx = m_idx + 1;
        else
            e_idx = m_idx - 1;
    }
    if(m_uid != tid) return 0;
    

    uint32_t k, s_uid, s_beg, s_end, e_uid, e_beg, e_end;
    uint64_t t_d;
    double w, weight;
    w = 0;
    for (k = m_idx; k < occ; k++)///all hits of qid
    {   
        interpr_hit(idx, hits[k].s, hits[k].len>>32, &s_uid, &s_beg, &s_end);
        if(s_uid != qid) continue;
        if(!(qs <= s_beg && qe >= s_end)) continue;

        interpr_hit(idx, hits[k].e, (uint32_t)hits[k].len, &e_uid, &e_beg, &e_end);
        if(e_uid != tid) break;
        if(!(ts <= e_beg && te >= e_end)) continue;

        t_d = get_hic_distance(&hits[k], link, idx, NULL);
        if(t_d == (uint64_t)-1) continue;

        weight = 1;
        if(dis) weight = get_trans_weight_advance(idx, t_d, dis);

        w += weight;
    }

    for (m_idx -= 1; m_idx >= 0; m_idx--)
    {
        k = m_idx;
        interpr_hit(idx, hits[k].s, hits[k].len>>32, &s_uid, &s_beg, &s_end);
        if(s_uid != qid) continue;
        if(!(qs <= s_beg && qe >= s_end)) continue;

        interpr_hit(idx, hits[k].e, (uint32_t)hits[k].len, &e_uid, &e_beg, &e_end);
        if(e_uid != tid) break;
        if(!(ts <= e_beg && te >= e_end)) continue;

        t_d = get_hic_distance(&hits[k], link, idx, NULL);
        if(t_d == (uint64_t)-1) continue;

        weight = 1;
        if(dis) weight = get_trans_weight_advance(idx, t_d, dis);

        w += weight;
    }
    return w;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movl %r9d, %ebx
movq %rcx, %r14
movq %rdx, 0x18(%rsp)
movq %rsi, 0x50(%rsp)
movq %rdi, %r13
movl 0x110(%rsp), %edi
testl %r8d, %r8d
je 0x15e3ac
movl %r8d, %eax
decq %rax
movl $0x40, %ecx
subq 0x18(%r13), %rcx
xorl %edx, %edx
movq %rax, %rsi
subq %rdx, %rsi
movq %rsi, %r12
shrq $0x3f, %r12
addq %rsi, %r12
sarq %r12
addq %rdx, %r12
movq %r12, %rsi
shlq $0x5, %rsi
movq 0x8(%r14,%rsi), %rsi
addq %rsi, %rsi
shrq %cl, %rsi
cmpl %edi, %esi
je 0x15e3c6
jb 0x15e3a0
leaq -0x1(%r12), %rax
jmp 0x15e3a5
leaq 0x1(%r12), %rdx
cmpq %rax, %rdx
jle 0x15e36b
jmp 0x15e3b4
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %r12d, %r12d
xorpd %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
cmpl %edi, %esi
jne 0x15e9c8
xorpd %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
cmpl %r8d, %r12d
jae 0x15e6e5
movl %r12d, %r15d
movl %r8d, %eax
movq %rax, 0x20(%rsp)
movsd %xmm0, 0x10(%rsp)
xorl %ebp, %ebp
flds 0xdce82(%rip)           # 0x23b274
fstpt 0x44(%rsp)
fld1
fchs
fstpt 0x38(%rsp)
fldl 0xdce44(%rip)           # 0x23b248
fstpt 0x2c(%rsp)
fldl 0xdce42(%rip)           # 0x23b250
fstpt 0xbc(%rsp)
movq %r15, %rdi
shlq $0x5, %rdi
movq (%r14,%rdi), %r10
movq 0x18(%r14,%rdi), %rdx
movq %rdx, %r8
shrq $0x20, %r8
leaq (%r10,%r10), %r9
movq 0x18(%r13), %rsi
movq %rsi, %rcx
negq %rcx
shrq %cl, %r9
movq 0x30(%r13), %rax
movq %rax, %r11
andq %r10, %r11
movq %r11, %rcx
subq %r8, %rcx
decq %r8
incq %rcx
testq %r10, %r10
cmovsq %rbp, %r8
cmovnsq %r11, %rcx
addq %r11, %r8
testq %r8, %r8
cmovleq %rbp, %r8
testq %rcx, %rcx
cmovleq %rbp, %rcx
cmpl %ebx, %r9d
jne 0x15e683
cmpl 0x100(%rsp), %ecx
jb 0x15e683
incl %r8d
cmpl 0x108(%rsp), %r8d
ja 0x15e683
addq %r14, %rdi
movl $0x40, %ecx
subq %rsi, %rcx
movq 0x8(%rdi), %rsi
leaq (%rsi,%rsi), %r8
shrq %cl, %r8
cmpl 0x110(%rsp), %r8d
jne 0x15e6e5
andq %rsi, %rax
movl %edx, %ecx
movq %rax, %rdx
subq %rcx, %rdx
decq %rcx
incq %rdx
testq %rsi, %rsi
cmovsq %rbp, %rcx
cmovnsq %rax, %rdx
addq %rax, %rcx
testq %rcx, %rcx
cmovleq %rbp, %rcx
testq %rdx, %rdx
cmovleq %rbp, %rdx
cmpl 0x118(%rsp), %edx
jb 0x15e683
incl %ecx
cmpl 0x120(%rsp), %ecx
ja 0x15e683
movq 0x50(%rsp), %rsi
movq %r13, %rdx
xorl %ecx, %ecx
callq 0x14a518
cmpq $-0x1, %rax
je 0x15e683
movsd 0xd2dec(%rip), %xmm0    # 0x231310
cmpq $0x0, 0x18(%rsp)
je 0x15e673
movq 0x18(%rsp), %rcx
cmpq %rax, 0x18(%rcx)
jbe 0x15e5b2
movq 0x8(%rcx), %rdx
testq %rdx, %rdx
je 0x15e564
movq (%rcx), %rcx
addq $0x20, %rcx
cmpq %rax, -0x18(%rcx)
jbe 0x15e55b
cmpq %rax, -0x20(%rcx)
jbe 0x15e693
addq $0x28, %rcx
decq %rdx
jne 0x15e54b
fldt 0x80(%r13)
movq %rax, 0xa0(%rsp)
xorl %ecx, %ecx
testq %rax, %rax
sets %cl
fildll 0xa0(%rsp)
leaq 0xdccaf(%rip), %rax     # 0x23b238
fadds (%rax,%rcx,4)
fldt 0xa0(%r13)
fdivrp %st, %st(1)
fmulp %st, %st(1)
fldt 0x90(%r13)
faddp %st, %st(1)
fstpl 0x98(%rsp)
movsd 0x98(%rsp), %xmm0
jmp 0x15e5fe
fldt 0x80(%r13)
movq %rax, 0xb0(%rsp)
xorl %ecx, %ecx
testq %rax, %rax
sets %cl
fildll 0xb0(%rsp)
leaq 0xdcc61(%rip), %rax     # 0x23b238
fadds (%rax,%rcx,4)
fldt 0xa0(%r13)
fdivrp %st, %st(1)
fmulp %st, %st(1)
fldt 0x90(%r13)
faddp %st, %st(1)
fstpl 0xa8(%rsp)
movsd 0xa8(%rsp), %xmm0
movsd %xmm0, 0x90(%rsp)
fldl 0x90(%rsp)
fldz
fucomi %st(1), %st
fxch %st(1)
fcmovnbe %st(1), %st
fstp %st(1)
faddl 0xdcba2(%rip)           # 0x23b1c0
fldt 0x44(%rsp)
fxch %st(1)
fucomi %st(1), %st
fcmovnbe %st(1), %st
fstp %st(1)
faddl 0xdcc10(%rip)           # 0x23b240
fld1
fdivp %st, %st(1)
fldt 0x38(%rsp)
faddp %st, %st(1)
fstpt (%rsp)
callq 0x20b0
fmuls 0xdcc30(%rip)           # 0x23b278
fldt 0x2c(%rsp)
fucomi %st(1), %st
fxch %st(1)
fcmovnbe %st(1), %st
fstp %st(1)
fldt 0xbc(%rsp)
fxch %st(1)
fucomi %st(1), %st
fcmovnbe %st(1), %st
fstp %st(1)
fstpl 0x88(%rsp)
movsd 0x88(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
incq %r15
cmpq 0x20(%rsp), %r15
jne 0x15e415
jmp 0x15e6e5
movq (%rcx), %rax
movq %rax, %xmm1
movq 0xd2bdd(%rip), %xmm2    # 0x231280
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0xd2be1(%rip), %xmm3    # 0x231290
subpd %xmm3, %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addq -0x8(%rcx), %rax
addsd %xmm1, %xmm0
movq %rax, %xmm1
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
subpd %xmm3, %xmm1
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
divsd %xmm2, %xmm0
jmp 0x15e5fe
testq %r12, %r12
jle 0x15e9c8
xorl %r15d, %r15d
flds 0xdcb7d(%rip)           # 0x23b274
fstpt 0x20(%rsp)
fld1
fchs
fstpt 0x44(%rsp)
fldl 0xdcb3f(%rip)           # 0x23b248
fstpt 0x38(%rsp)
fldl 0xdcb3d(%rip)           # 0x23b250
fstpt 0x2c(%rsp)
movq %r12, %rbp
decq %r12
movl %r12d, %edi
shlq $0x5, %rdi
movq (%r14,%rdi), %r10
movq 0x18(%r14,%rdi), %rdx
movq %rdx, %r8
shrq $0x20, %r8
leaq (%r10,%r10), %r9
movq 0x18(%r13), %rsi
movq %rsi, %rcx
negq %rcx
shrq %cl, %r9
movq 0x30(%r13), %rax
movq %rax, %r11
andq %r10, %r11
movq %r11, %rcx
subq %r8, %rcx
decq %r8
incq %rcx
testq %r10, %r10
cmovsq %r15, %r8
cmovnsq %r11, %rcx
addq %r11, %r8
testq %r8, %r8
cmovleq %r15, %r8
testq %rcx, %rcx
cmovleq %r15, %rcx
cmpl %ebx, %r9d
jne 0x15e96a
cmpl 0x100(%rsp), %ecx
jb 0x15e96a
incl %r8d
cmpl 0x108(%rsp), %r8d
ja 0x15e96a
addq %r14, %rdi
movl $0x40, %ecx
subq %rsi, %rcx
movq 0x8(%rdi), %rsi
leaq (%rsi,%rsi), %r8
shrq %cl, %r8
cmpl 0x110(%rsp), %r8d
jne 0x15e9c8
andq %rsi, %rax
movl %edx, %ecx
movq %rax, %rdx
subq %rcx, %rdx
decq %rcx
incq %rdx
testq %rsi, %rsi
cmovsq %r15, %rcx
cmovnsq %rax, %rdx
addq %rax, %rcx
testq %rcx, %rcx
cmovleq %r15, %rcx
testq %rdx, %rdx
cmovleq %r15, %rdx
cmpl 0x118(%rsp), %edx
jb 0x15e96a
incl %ecx
cmpl 0x120(%rsp), %ecx
ja 0x15e96a
movq 0x50(%rsp), %rsi
movq %r13, %rdx
xorl %ecx, %ecx
callq 0x14a518
cmpq $-0x1, %rax
je 0x15e96a
movsd 0xd2ae4(%rip), %xmm0    # 0x231310
cmpq $0x0, 0x18(%rsp)
je 0x15e95a
movq 0x18(%rsp), %rcx
cmpq %rax, 0x18(%rcx)
jbe 0x15e8ae
movq 0x8(%rcx), %rdx
testq %rdx, %rdx
je 0x15e86c
movq (%rcx), %rcx
addq $0x20, %rcx
cmpq %rax, -0x18(%rcx)
jbe 0x15e863
cmpq %rax, -0x20(%rcx)
jbe 0x15e976
addq $0x28, %rcx
decq %rdx
jne 0x15e853
fldt 0x80(%r13)
movq %rax, 0x70(%rsp)
xorl %ecx, %ecx
testq %rax, %rax
sets %cl
fildll 0x70(%rsp)
leaq 0xdc9ad(%rip), %rax     # 0x23b238
fadds (%rax,%rcx,4)
fldt 0xa0(%r13)
fdivrp %st, %st(1)
fmulp %st, %st(1)
fldt 0x90(%r13)
faddp %st, %st(1)
fstpl 0x68(%rsp)
movsd 0x68(%rsp), %xmm0
jmp 0x15e8f4
fldt 0x80(%r13)
movq %rax, 0x80(%rsp)
xorl %ecx, %ecx
testq %rax, %rax
sets %cl
fildll 0x80(%rsp)
leaq 0xdc965(%rip), %rax     # 0x23b238
fadds (%rax,%rcx,4)
fldt 0xa0(%r13)
fdivrp %st, %st(1)
fmulp %st, %st(1)
fldt 0x90(%r13)
faddp %st, %st(1)
fstpl 0x78(%rsp)
movsd 0x78(%rsp), %xmm0
movsd %xmm0, 0x60(%rsp)
fldl 0x60(%rsp)
fldz
fucomi %st(1), %st
fxch %st(1)
fcmovnbe %st(1), %st
fstp %st(1)
faddl 0xdc8b2(%rip)           # 0x23b1c0
fldt 0x20(%rsp)
fxch %st(1)
fucomi %st(1), %st
fcmovnbe %st(1), %st
fstp %st(1)
faddl 0xdc920(%rip)           # 0x23b240
fld1
fdivp %st, %st(1)
fldt 0x44(%rsp)
faddp %st, %st(1)
fstpt (%rsp)
callq 0x20b0
fmuls 0xdc940(%rip)           # 0x23b278
fldt 0x38(%rsp)
fucomi %st(1), %st
fxch %st(1)
fcmovnbe %st(1), %st
fstp %st(1)
fldt 0x2c(%rsp)
fxch %st(1)
fucomi %st(1), %st
fcmovnbe %st(1), %st
fstp %st(1)
fstpl 0x58(%rsp)
movsd 0x58(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
cmpq $0x1, %rbp
jg 0x15e717
jmp 0x15e9c8
movq (%rcx), %rax
movq %rax, %xmm1
movq 0xd28fa(%rip), %xmm2    # 0x231280
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0xd28fe(%rip), %xmm3    # 0x231290
subpd %xmm3, %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addq -0x8(%rcx), %rax
addsd %xmm1, %xmm0
movq %rax, %xmm1
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
subpd %xmm3, %xmm1
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
divsd %xmm2, %xmm0
jmp 0x15e8f4
movsd 0x10(%rsp), %xmm0
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq