// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/horder.cpp
// Function: get_hic_cov_interval(unsigned long*, unsigned long, long, long*, long*, h_covs*)
uint64_t get_hic_cov_interval(uint64_t *b, uint64_t b_n, int64_t min_dp, int64_t *boundS, int64_t *boundE,
h_covs *res)
{
    if(res) res->n = 0;
    if(min_dp == 0 || b_n == 0) return (uint64_t)-1;
    uint64_t i, len = 0;
    int64_t dp, old_dp, start = 0, bs = b[0]>>1, be = b[b_n-1]>>1, olen;
    h_cov_t *p = NULL;
    if(boundS) bs = (*boundS);
    if(boundE) be = (*boundE);
    for (i = 0, dp = 0, start = 0; i < b_n; ++i) 
    {
        old_dp = dp;
        ///if a[j] is qe
        if (b[i]&1) --dp;
        else ++dp;

        if (old_dp < min_dp && dp >= min_dp) ///old_dp < dp, b.a[j] is qs
        { 
            ///case 2, a[j] is qs
            start = b[i]>>1;
        } 
        else if (old_dp >= min_dp && dp < min_dp) ///old_dp > min_dp, b.a[j] is qe
        {
            olen = OVL(start, (int64_t)(b[i]>>1), bs, be);
            if(olen == 0) continue;
            if(res)
            {
                kv_pushp(h_cov_t, *res, &p);
                p->s = MAX(start, bs); 
                p->e = MIN((int64_t)(b[i]>>1), be);
                p->dp = old_dp;
            }
            len += olen;
        }
    }
    return len;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdx, %r14
testq %r9, %r9
je 0x176f4b
movq $0x0, 0x8(%r9)
testq %r14, %r14
sete %al
testq %rsi, %rsi
sete %dl
orb %al, %dl
movq $-0x1, %r11
jne 0x1770b7
testq %rcx, %rcx
je 0x176f70
movq (%rcx), %r10
jmp 0x176f76
movq (%rdi), %r10
shrq %r10
testq %r8, %r8
je 0x176f80
movq (%r8), %r8
jmp 0x176f88
movq -0x8(%rdi,%rsi,8), %r8
shrq %r8
xorl %edx, %edx
xorl %ebx, %ebx
xorl %ebp, %ebp
xorl %r11d, %r11d
movq %r9, 0x20(%rsp)
movq %rsi, 0x18(%rsp)
movq %rdi, 0x10(%rsp)
movq %r10, 0x8(%rsp)
movq %r8, (%rsp)
movq %rbp, %r12
movq (%rdi,%rbx,8), %r13
movl %r13d, %ebp
andl $0x1, %ebp
negq %rbp
orq $0x1, %rbp
addq %r12, %rbp
cmpq %r14, %r12
setge %al
cmpq %r14, %rbp
setl %cl
orb %al, %cl
je 0x1770a5
cmpq %r14, %rbp
setl %al
cmpq %r14, %r12
setge %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x1770ab
shrq %r13
cmpq %r8, %r13
cmovgeq %r8, %r13
cmpq %r10, %rdx
movq %r10, %r15
cmovgq %rdx, %r15
cmpq %r15, %r13
jle 0x1770ab
testq %r9, %r9
je 0x17709d
movq %rdx, 0x30(%rsp)
movq (%r9), %rax
movq 0x8(%r9), %rcx
cmpq 0x10(%r9), %rcx
jne 0x177070
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rdx
movq %rdx, 0x10(%r9)
shlq $0x3, %rdx
leaq (%rdx,%rdx,2), %rsi
movq %rax, %rdi
movq %r11, 0x28(%rsp)
callq 0x2370
movq 0x28(%rsp), %r11
movq (%rsp), %r8
movq 0x8(%rsp), %r10
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %r9
movq %rax, (%r9)
movq 0x8(%r9), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r9)
leaq (%rcx,%rcx,2), %rcx
movq %r15, (%rax,%rcx,8)
movq (%rdi,%rbx,8), %rdx
shrq %rdx
cmpq %r8, %rdx
cmovgeq %r8, %rdx
movq %rdx, 0x8(%rax,%rcx,8)
movq %r12, 0x10(%rax,%rcx,8)
movq 0x30(%rsp), %rdx
subq %r15, %r11
addq %r13, %r11
jmp 0x1770ab
shrq %r13
movq %r13, %rdx
incq %rbx
cmpq %rbx, %rsi
jne 0x176fa9
movq %r11, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq