// File: /workspace/github_cpp_makefile_star2_O1/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 0x170375
movq $0x0, 0x8(%r9)
testq %r14, %r14
sete %al
testq %rsi, %rsi
sete %dl
orb %al, %dl
movq $-0x1, %r11
jne 0x1704f1
testq %rcx, %rcx
je 0x17039a
movq (%rcx), %r10
jmp 0x1703a0
movq (%rdi), %r10
shrq %r10
testq %r8, %r8
je 0x1703aa
movq (%r8), %r8
jmp 0x1703b2
movq -0x8(%rdi,%rsi,8), %r8
shrq %r8
testq %rsi, %rsi
je 0x1704ee
xorl %edx, %edx
xorl %ebx, %ebx
xorl %r13d, %r13d
xorl %r11d, %r11d
movq %r9, 0x20(%rsp)
movq %rsi, 0x18(%rsp)
movq %rdi, 0x10(%rsp)
movq %r10, 0x8(%rsp)
movq %r8, (%rsp)
movq %r13, %r15
movq (%rdi,%rbx,8), %rbp
movl %ebp, %r13d
andl $0x1, %r13d
negq %r13
orq $0x1, %r13
addq %r15, %r13
cmpq %r14, %r15
setge %al
cmpq %r14, %r13
setl %cl
orb %al, %cl
je 0x1704da
cmpq %r14, %r13
setl %al
cmpq %r14, %r15
setge %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x1704e0
shrq %rbp
cmpq %r8, %rbp
cmovgeq %r8, %rbp
cmpq %r10, %rdx
movq %r10, %r12
cmovgq %rdx, %r12
cmpq %r12, %rbp
jle 0x1704e0
testq %r9, %r9
je 0x1704d2
movq %rdx, 0x30(%rsp)
movq 0x10(%r9), %rax
cmpq %rax, 0x8(%r9)
jne 0x17049e
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x10(%r9)
movq (%r9), %rdi
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rsi
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 (%r9), %rax
movq 0x8(%r9), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r9)
leaq (%rcx,%rcx,2), %rcx
movq %r12, (%rax,%rcx,8)
movq (%rdi,%rbx,8), %rdx
shrq %rdx
cmpq %r8, %rdx
cmovgeq %r8, %rdx
movq %rdx, 0x8(%rax,%rcx,8)
movq %r15, 0x10(%rax,%rcx,8)
movq 0x30(%rsp), %rdx
subq %r12, %r11
addq %rbp, %r11
jmp 0x1704e0
shrq %rbp
movq %rbp, %rdx
incq %rbx
cmpq %rbx, %rsi
jne 0x1703dd
jmp 0x1704f1
xorl %r11d, %r11d
movq %r11, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq