// File: /workspace/github_cpp_makefile_star2_O2/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 $0x48, %rsp
movl %r9d, 0x24(%rsp)
movq %rcx, 0x30(%rsp)
movq %rdx, %r9
movq %rsi, 0x40(%rsp)
movq %rdi, %r13
movl 0x90(%rsp), %r10d
movl %r8d, %eax
movq %rax, %r14
leaq -0x1(%rax), %rsi
pushq $-0x1
popq %rdx
xorl %edi, %edi
pushq $0x2
popq %r8
xorl %ebp, %ebp
movq %rsi, %rax
subq %rdi, %rax
jl 0x117cc3
cqto
idivq %r8
movq %rax, %rbp
addq %rdi, %rbp
movq %rbp, %rax
shlq $0x5, %rax
movq 0x30(%rsp), %rcx
movq 0x8(%rcx,%rax), %rdx
addq %rdx, %rdx
movb 0x18(%r13), %al
xorl %ecx, %ecx
subb %al, %cl
shrq %cl, %rdx
cmpl %r10d, %edx
je 0x117cd0
leaq 0x1(%rbp), %rax
leaq -0x1(%rbp), %rcx
cmpl %r10d, %edx
cmovbq %rax, %rdi
cmovaeq %rcx, %rsi
jmp 0x117c77
xorpd %xmm0, %xmm0
cmpl %r10d, %edx
jne 0x117efa
movq %r9, 0x38(%rsp)
movl %ebp, %ebx
movq %rbx, %r15
shlq $0x5, %r15
addq 0x30(%rsp), %r15
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
cmpq %r14, %rbx
jae 0x117ded
movq (%r15), %rsi
movq 0x18(%r15), %r12
movq %r12, %rdx
shrq $0x20, %rdx
movq %r13, %rdi
leaq 0x2c(%rsp), %rcx
leaq 0x20(%rsp), %r8
leaq 0x1c(%rsp), %r9
callq 0x117804
movl 0x24(%rsp), %eax
cmpl %eax, 0x2c(%rsp)
jne 0x117ddb
movl 0x80(%rsp), %eax
cmpl %eax, 0x20(%rsp)
movsd 0x8(%rsp), %xmm0
jb 0x117de1
movl 0x88(%rsp), %eax
cmpl %eax, 0x1c(%rsp)
ja 0x117de1
movq 0x8(%r15), %rsi
movq %r13, %rdi
movl %r12d, %edx
leaq 0x28(%rsp), %rcx
leaq 0x18(%rsp), %r8
leaq 0x14(%rsp), %r9
callq 0x117804
movl 0x90(%rsp), %eax
cmpl %eax, 0x28(%rsp)
jne 0x117ded
movl 0x98(%rsp), %eax
cmpl %eax, 0x18(%rsp)
jb 0x117ddb
movl 0xa0(%rsp), %eax
cmpl %eax, 0x14(%rsp)
ja 0x117ddb
movq %r15, %rdi
movq 0x40(%rsp), %rsi
movq %r13, %rdx
xorl %ecx, %ecx
callq 0x102875
cmpq $-0x1, %rax
je 0x117ddb
movsd 0xcb4ea(%rip), %xmm0    # 0x1e32a0
movq 0x38(%rsp), %rdx
testq %rdx, %rdx
je 0x117dcb
movq %r13, %rdi
movq %rax, %rsi
callq 0x1216b6
movsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
movapd %xmm1, %xmm0
jmp 0x117de1
movsd 0x8(%rsp), %xmm0
incq %rbx
addq $0x20, %r15
jmp 0x117ce7
movq %rbp, %r14
testq %r14, %r14
jle 0x117ef4
leaq -0x1(%r14), %rbp
movl %ebp, %r15d
shlq $0x5, %r15
movq 0x30(%rsp), %rax
movq (%rax,%r15), %rsi
movq 0x18(%rax,%r15), %r12
movq %r12, %rdx
shrq $0x20, %rdx
leaq 0x2c(%rsp), %rbx
leaq 0x20(%rsp), %r8
leaq 0x1c(%rsp), %r9
movq %r13, %rdi
movq %rbx, %rcx
callq 0x117804
movl 0x24(%rsp), %eax
cmpl %eax, (%rbx)
jne 0x117eb8
movl 0x80(%rsp), %eax
cmpl %eax, 0x20(%rsp)
jb 0x117eb8
movl 0x88(%rsp), %eax
cmpl %eax, 0x1c(%rsp)
ja 0x117eb8
addq 0x30(%rsp), %r15
movq 0x8(%r15), %rsi
leaq 0x28(%rsp), %rbx
leaq 0x18(%rsp), %r8
leaq 0x14(%rsp), %r9
movq %r13, %rdi
movl %r12d, %edx
movq %rbx, %rcx
callq 0x117804
movl 0x90(%rsp), %eax
cmpl %eax, (%rbx)
jne 0x117ef4
movl 0x98(%rsp), %eax
cmpl %eax, 0x18(%rsp)
jb 0x117eb8
movl 0xa0(%rsp), %eax
cmpl %eax, 0x14(%rsp)
ja 0x117eb8
movq %r15, %rdi
movq 0x40(%rsp), %rsi
movq %r13, %rdx
xorl %ecx, %ecx
callq 0x102875
cmpq $-0x1, %rax
jne 0x117ec0
decq %r14
jmp 0x117df0
movq 0x38(%rsp), %rdx
testq %rdx, %rdx
je 0x117ed7
movq %r13, %rdi
movq %rax, %rsi
callq 0x1216b6
jmp 0x117edf
movsd 0xcb3c1(%rip), %xmm0    # 0x1e32a0
movsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
jmp 0x117ded
movsd 0x8(%rsp), %xmm0
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq