// File: 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
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x235c66
movq -0x38(%rbp), %rax
movq $0x0, 0x8(%rax)
cmpq $0x0, -0x20(%rbp)
je 0x235c74
cmpq $0x0, -0x18(%rbp)
jne 0x235c81
movq $-0x1, -0x8(%rbp)
jmp 0x235ff6
movq $0x0, -0x48(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
shrq %rax
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
subq $0x1, %rcx
movq (%rax,%rcx,8), %rax
shrq %rax
movq %rax, -0x70(%rbp)
movq $0x0, -0x80(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x235cd0
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x235ce2
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x70(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x235fee
movq -0x50(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rax
movq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rax
andq $0x1, %rax
cmpq $0x0, %rax
je 0x235d34
movq -0x50(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x235d40
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
movq -0x58(%rbp), %rax
cmpq -0x20(%rbp), %rax
jge 0x235d6c
movq -0x50(%rbp), %rax
cmpq -0x20(%rbp), %rax
jl 0x235d6c
movq -0x10(%rbp), %rax
movq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq %rax
movq %rax, -0x60(%rbp)
jmp 0x235fdb
movq -0x58(%rbp), %rax
cmpq -0x20(%rbp), %rax
jl 0x235fd9
movq -0x50(%rbp), %rax
cmpq -0x20(%rbp), %rax
jge 0x235fd9
movq -0x10(%rbp), %rax
movq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq %rax
cmpq -0x70(%rbp), %rax
jg 0x235db5
movq -0x10(%rbp), %rax
movq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq %rax
movq %rax, -0x88(%rbp)
jmp 0x235dc0
movq -0x70(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x68(%rbp), %rax
jl 0x235de5
movq -0x60(%rbp), %rax
movq %rax, -0x98(%rbp)
jmp 0x235df0
movq -0x68(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x90(%rbp), %rax
movq -0x98(%rbp), %rcx
cmpq %rcx, %rax
jle 0x235e89
movq -0x10(%rbp), %rax
movq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq %rax
cmpq -0x70(%rbp), %rax
jg 0x235e34
movq -0x10(%rbp), %rax
movq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq %rax
movq %rax, -0xa0(%rbp)
jmp 0x235e3f
movq -0x70(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x68(%rbp), %rax
jl 0x235e64
movq -0x60(%rbp), %rax
movq %rax, -0xb0(%rbp)
jmp 0x235e6f
movq -0x68(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0xa8(%rbp), %rax
movq -0xb0(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0xb8(%rbp)
jmp 0x235e94
xorl %eax, %eax
movq %rax, -0xb8(%rbp)
jmp 0x235e94
movq -0xb8(%rbp), %rax
movq %rax, -0x78(%rbp)
cmpq $0x0, -0x78(%rbp)
jne 0x235eab
jmp 0x235fdd
cmpq $0x0, -0x38(%rbp)
je 0x235fcd
jmp 0x235eb8
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x38(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jne 0x235f25
movq -0x38(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x235ee9
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
shlq %rax
movq %rax, -0xc0(%rbp)
jmp 0x235ef7
movl $0x2, %eax
movq %rax, -0xc0(%rbp)
jmp 0x235ef7
movq -0xc0(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x38(%rbp), %rax
movq (%rax), %rdi
movq -0x38(%rbp), %rax
imulq $0x18, 0x10(%rax), %rsi
callq 0x2360
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq -0x38(%rbp), %rdx
movq 0x8(%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x8(%rdx)
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x80(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x68(%rbp), %rax
jl 0x235f61
movq -0x60(%rbp), %rax
movq %rax, -0xc8(%rbp)
jmp 0x235f6c
movq -0x68(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0xc8(%rbp), %rcx
movq -0x80(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq %rax
cmpq -0x70(%rbp), %rax
jg 0x235fa7
movq -0x10(%rbp), %rax
movq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq %rax
movq %rax, -0xd0(%rbp)
jmp 0x235fb2
movq -0x70(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rcx
movq -0x80(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x58(%rbp), %rcx
movq -0x80(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x78(%rbp), %rax
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0x235fdb
jmp 0x235fdd
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x235cfa
movq -0x48(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xd0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)