// File: /workspace/github_cpp_makefile_star2_O1/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, 0x10(%rsp)
movq %rsi, 0x50(%rsp)
movq %rdi, %r13
movl 0x110(%rsp), %edi
testl %r8d, %r8d
je 0x157a3a
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 0x157a42
jb 0x157a2e
leaq -0x1(%r12), %rax
jmp 0x157a33
leaq 0x1(%r12), %rdx
cmpq %rax, %rdx
jle 0x1579f9
jmp 0x157a42
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %r12d, %r12d
xorpd %xmm0, %xmm0
cmpl %edi, %esi
jne 0x1580b2
cmpl %r8d, %r12d
jae 0x157d96
movl %r12d, %r15d
movl %r8d, %eax
movq %rax, 0x20(%rsp)
xorl %ebp, %ebp
flds 0xd75ba(%rip)           # 0x22f024
fstpt 0x44(%rsp)
fld1
fchs
fstpt 0x38(%rsp)
fldl 0xd757c(%rip)           # 0x22eff8
fstpt 0x2c(%rsp)
fldl 0xd757a(%rip)           # 0x22f000
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 0x157d88
cmpl 0x100(%rsp), %ecx
jb 0x157d88
incl %r8d
cmpl 0x108(%rsp), %r8d
ja 0x157d88
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 0x157d96
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 0x157d88
incl %ecx
cmpl 0x120(%rsp), %ecx
ja 0x157d88
movsd %xmm0, 0x18(%rsp)
movq 0x50(%rsp), %rsi
movq %r13, %rdx
xorl %ecx, %ecx
callq 0x143e3e
cmpq $-0x1, %rax
je 0x157c08
movsd 0xcd6d2(%rip), %xmm0    # 0x225270
cmpq $0x0, 0x10(%rsp)
je 0x157d7a
movq 0x10(%rsp), %rcx
cmpq %rax, 0x18(%rcx)
jbe 0x157c13
movq 0x8(%rcx), %rdx
testq %rdx, %rdx
je 0x157cb9
movq 0x10(%rsp), %rcx
movq (%rcx), %rcx
movq %rdx, %rsi
negq %rsi
addq $0x20, %rcx
movb $0x1, %r8b
movl $0x1, %edi
cmpq %rax, -0x18(%rcx)
jbe 0x157be8
cmpq %rax, -0x20(%rcx)
jbe 0x157c64
cmpq %rdx, %rdi
setb %r8b
leaq (%rsi,%rdi), %r9
incq %r9
incq %rdi
addq $0x28, %rcx
cmpq $0x1, %r9
jne 0x157bdc
jmp 0x157cb9
movsd 0x18(%rsp), %xmm0
jmp 0x157d88
fldt 0x80(%r13)
movq %rax, 0xb0(%rsp)
xorl %ecx, %ecx
testq %rax, %rax
sets %cl
fildll 0xb0(%rsp)
leaq 0xd73b0(%rip), %rax     # 0x22efe8
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
jmp 0x157d05
testb $0x1, %r8b
je 0x157cb9
movq (%rcx), %rax
movq %rax, %xmm1
movq 0xcd5c6(%rip), %xmm2    # 0x225240
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0xcd5ca(%rip), %xmm3    # 0x225250
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 0x157d05
fldt 0x80(%r13)
movq %rax, 0xa0(%rsp)
xorl %ecx, %ecx
testq %rax, %rax
sets %cl
fildll 0xa0(%rsp)
leaq 0xd730a(%rip), %rax     # 0x22efe8
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
movsd %xmm0, 0x90(%rsp)
fldl 0x90(%rsp)
fldz
fucomi %st(1), %st
fxch %st(1)
fcmovnbe %st(1), %st
fstp %st(1)
faddl 0xd728b(%rip)           # 0x22efb0
fldt 0x44(%rsp)
fxch %st(1)
fucomi %st(1), %st
fcmovnbe %st(1), %st
fstp %st(1)
faddl 0xd72b9(%rip)           # 0x22eff0
fld1
fdivp %st, %st(1)
fldt 0x38(%rsp)
faddp %st, %st(1)
fstpt (%rsp)
callq 0x20b0
fmuls 0xd72d9(%rip)           # 0x22f028
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 0x18(%rsp), %xmm1
addsd %xmm0, %xmm1
movapd %xmm1, %xmm0
incq %r15
cmpq 0x20(%rsp), %r15
jne 0x157a8d
testq %r12, %r12
jle 0x1580b2
xorl %r15d, %r15d
flds 0xd727c(%rip)           # 0x22f024
fstpt 0x20(%rsp)
fld1
fchs
fstpt 0x44(%rsp)
fldl 0xd723e(%rip)           # 0x22eff8
fstpt 0x38(%rsp)
fldl 0xd723c(%rip)           # 0x22f000
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 0x1580a8
cmpl 0x100(%rsp), %ecx
jb 0x1580a8
incl %r8d
cmpl 0x108(%rsp), %r8d
ja 0x1580a8
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 0x1580b2
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 0x1580a8
incl %ecx
cmpl 0x120(%rsp), %ecx
ja 0x1580a8
movsd %xmm0, 0x18(%rsp)
movq 0x50(%rsp), %rsi
movq %r13, %rdx
xorl %ecx, %ecx
callq 0x143e3e
cmpq $-0x1, %rax
je 0x157f49
movsd 0xcd391(%rip), %xmm0    # 0x225270
cmpq $0x0, 0x10(%rsp)
je 0x15809a
movq 0x10(%rsp), %rcx
cmpq %rax, 0x18(%rcx)
jbe 0x157f54
movq 0x8(%rcx), %rdx
testq %rdx, %rdx
je 0x157ff4
movq 0x10(%rsp), %rcx
movq (%rcx), %rcx
movq %rdx, %rsi
negq %rsi
addq $0x20, %rcx
movb $0x1, %r8b
movl $0x1, %edi
cmpq %rax, -0x18(%rcx)
jbe 0x157f29
cmpq %rax, -0x20(%rcx)
jbe 0x157f9f
cmpq %rdx, %rdi
setb %r8b
leaq (%rsi,%rdi), %r9
incq %r9
incq %rdi
addq $0x28, %rcx
cmpq $0x1, %r9
jne 0x157f1d
jmp 0x157ff4
movsd 0x18(%rsp), %xmm0
jmp 0x1580a8
fldt 0x80(%r13)
movq %rax, 0x80(%rsp)
xorl %ecx, %ecx
testq %rax, %rax
sets %cl
fildll 0x80(%rsp)
leaq 0xd706f(%rip), %rax     # 0x22efe8
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
jmp 0x158034
testb $0x1, %r8b
je 0x157ff4
movq (%rcx), %rax
movq %rax, %xmm1
movq 0xcd28b(%rip), %xmm2    # 0x225240
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0xcd28f(%rip), %xmm3    # 0x225250
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 0x158034
fldt 0x80(%r13)
movq %rax, 0x70(%rsp)
xorl %ecx, %ecx
testq %rax, %rax
sets %cl
fildll 0x70(%rsp)
leaq 0xd6fd5(%rip), %rax     # 0x22efe8
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
movsd %xmm0, 0x60(%rsp)
fldl 0x60(%rsp)
fldz
fucomi %st(1), %st
fxch %st(1)
fcmovnbe %st(1), %st
fstp %st(1)
faddl 0xd6f62(%rip)           # 0x22efb0
fldt 0x20(%rsp)
fxch %st(1)
fucomi %st(1), %st
fcmovnbe %st(1), %st
fstp %st(1)
faddl 0xd6f90(%rip)           # 0x22eff0
fld1
fdivp %st, %st(1)
fldt 0x44(%rsp)
faddp %st, %st(1)
fstpt (%rsp)
callq 0x20b0
fmuls 0xd6fb0(%rip)           # 0x22f028
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 0x18(%rsp), %xmm1
addsd %xmm0, %xmm1
movapd %xmm1, %xmm0
cmpq $0x1, %rbp
jg 0x157dc8
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq