// File: /workspace/github_cpp_makefile_star2_O2/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 0x13314c
andq $0x0, 0x8(%r9)
testq %r14, %r14
sete %al
testq %rsi, %rsi
sete %dl
orb %al, %dl
je 0x133172
pushq $-0x1
popq %r11
movq %r11, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %rcx, %rcx
je 0x13317c
movq (%rcx), %r10
jmp 0x133182
movq (%rdi), %r10
shrq %r10
testq %r8, %r8
je 0x13318c
movq (%r8), %r8
jmp 0x133194
movq -0x8(%rdi,%rsi,8), %r8
shrq %r8
xorl %r11d, %r11d
xorl %ebp, %ebp
xorl %ebx, %ebx
xorl %edx, %edx
movq %r9, 0x20(%rsp)
movq %rsi, 0x18(%rsp)
movq %rdi, 0x10(%rsp)
movq %r10, 0x8(%rsp)
movq %r8, (%rsp)
cmpq %rbx, %rsi
je 0x133160
movq %rbp, %r15
movq (%rdi,%rbx,8), %r13
movl %r13d, %ebp
andl $0x1, %ebp
negq %rbp
orq $0x1, %rbp
addq %r15, %rbp
cmpq %r14, %r15
setge %al
cmpq %r14, %rbp
setl %cl
orb %al, %cl
je 0x1332b0
cmpq %r14, %rbp
setl %al
cmpq %r14, %r15
setge %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x1332b6
shrq %r13
cmpq %r8, %r13
cmovgeq %r8, %r13
cmpq %r10, %rdx
movq %r10, %r12
cmovgq %rdx, %r12
cmpq %r12, %r13
jle 0x1332b6
testq %r9, %r9
je 0x1332a8
movq %rdx, 0x30(%rsp)
movq (%r9), %rax
movq 0x8(%r9), %rcx
cmpq 0x10(%r9), %rcx
jne 0x13327b
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rdx
movq %rdx, 0x10(%r9)
imulq $0x18, %rdx, %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)
imulq $0x18, %rcx, %rcx
movq %r12, (%rax,%rcx)
movq (%rdi,%rbx,8), %rdx
shrq %rdx
cmpq %r8, %rdx
cmovgeq %r8, %rdx
movq %rdx, 0x8(%rax,%rcx)
movq %r15, 0x10(%rax,%rcx)
movq 0x30(%rsp), %rdx
subq %r12, %r11
addq %r13, %r11
jmp 0x1332b6
shrq %r13
movq %r13, %rdx
incq %rbx
jmp 0x1331b5