// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/horder.cpp
// Function: debug_sub_cov(kvec_pe_hit*, unsigned long, unsigned long, unsigned long, ma_utg_t*, asg_t*, unsigned long, unsigned long)
void debug_sub_cov(kvec_pe_hit *hits, uint64_t sidx, uint64_t eidx, uint64_t ulen, ma_utg_t *u, asg_t* r_g,
uint64_t rid, uint64_t i_cnt)
{
    uint64_t i, offset, beg, end, rs, re;
    uint64_t p0s, p0e, p1s, p1e, span_s, span_e, cnt = 0;
    rs = re = (uint64_t)-1;
    for (i = offset = 0; i < u->n; i++)
    {
        end = offset + ((u->a[i] != (uint64_t)-1?r_g->seq[u->a[i]>>33].len:GAP_LEN));
        offset += (u->a[i] != (uint64_t)-1? (uint32_t)u->a[i]:GAP_LEN);
        beg = offset;

        if(u->a[i] == (uint64_t)-1) beg -= GAP_LEN;
        if(end <= beg && i + 1 < u->n && u->a[i+1] == (uint64_t)-1)
        {
            end = beg + GAP_LEN;
        }
        if(rid == i)
        {
            rs = beg;
            re = end;
        }
    }

    for (i = sidx; i < eidx; i++)///keep all hic hits that contain interval we want
    {
        if(get_hit_suid(*hits, i) != get_hit_euid(*hits, i)) continue;
        p0s = get_hit_spos(*hits, i);
        p0e = get_hit_spos_e(*hits, i);
        p1s = get_hit_epos(*hits, i);
        p1e = get_hit_epos_e(*hits, i);

        span_s = MIN(MIN(p0s, p0e), MIN(p1s, p1e));
        span_s = MIN(span_s, ulen-1);
        span_e = MAX(MAX(p0s, p0e), MAX(p1s, p1e));
        span_e = MIN(span_e, ulen-1) + 1;

        //if(span_e - span_s <= ulen*BREAK_CUTOFF)//need it or not?
        {
            if(span_s <= rs && span_e >= re) cnt++;
        }
    }

    // if(cnt != i_cnt) fprintf(stderr, "cnt-%lu, i_cnt-%lu\n", cnt, i_cnt);
    fprintf(stderr, "******cnt-%lu, i_cnt-%lu\n", cnt, i_cnt);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rcx, -0x10(%rsp)
movq %rsi, -0x8(%rsp)
movq %rdi, -0x18(%rsp)
movl 0x10(%r8), %edi
testq %rdi, %rdi
jne 0x20603
movabsq $-0x1, %r11
movq %r11, %r10
jmp 0x206b2
movq 0x38(%rsp), %rbx
movq 0x18(%r8), %r8
movq %rdi, %r14
negq %r14
negq %rbx
movabsq $-0x1, %r10
movabsq $0x1, %r15
xorl %eax, %eax
movabsq $0x64, %r12
movq %r10, %r11
movq %rax, %r13
movq -0x8(%r8,%r15,8), %rcx
movq %r12, %rbp
cmpq $-0x1, %rcx
je 0x2065d
movq 0x20(%r9), %rax
movq %rcx, %rbp
shrq $0x21, %rbp
movl (%rax,%rbp,8), %ebp
andl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
cmpq $-0x1, %rcx
movl %ecx, %esi
cmoveq %r12, %rsi
leaq (%rsi,%r13), %rax
cmpq $-0x1, %rcx
leaq -0x64(%rsi,%r13), %rcx
cmovneq %rax, %rcx
addq %r13, %rbp
cmpq %rcx, %rbp
ja 0x20692
cmpq %rdi, %r15
jae 0x20692
leaq 0x64(%rcx), %rsi
cmpq $-0x1, (%r8,%r15,8)
cmoveq %rsi, %rbp
leaq (%rbx,%r15), %rsi
cmpq $0x1, %rsi
cmoveq %rcx, %r11
cmoveq %rbp, %r10
leaq (%r14,%r15), %rcx
incq %rcx
incq %r15
cmpq $0x1, %rcx
jne 0x20638
movq 0x40(%rsp), %r8
movq -0x8(%rsp), %rsi
subq %rsi, %rdx
jbe 0x207c4
movq -0x18(%rsp), %rbp
movq 0x10(%rbp), %rax
movabsq $0x40, %rcx
subq 0x48(%rbp), %rcx
movq -0x10(%rsp), %r13
decq %r13
shlq $0x5, %rsi
addq %rax, %rsi
addq $0x18, %rsi
xorl %r9d, %r9d
movq -0x18(%rsi), %rax
leaq (%rax,%rax), %rdi
shrq %cl, %rdi
movq -0x10(%rsi), %r12
leaq (%r12,%r12), %rbx
shrq %cl, %rbx
cmpq %rbx, %rdi
jne 0x207b5
movq 0x50(%rbp), %r14
movq %r14, %rbx
andq %rax, %rbx
testq %rax, %rax
js 0x2072c
movl 0x4(%rsi), %eax
leaq (%rbx,%rax), %r15
decq %r15
jmp 0x20740
leaq 0x1(%rbx), %rax
movl 0x4(%rsi), %edi
subq %rdi, %rax
movl $0x0, %r15d
cmovaeq %rax, %r15
andq %r12, %r14
testq %r12, %r12
js 0x20753
movl (%rsi), %eax
leaq (%r14,%rax), %r12
decq %r12
jmp 0x20766
leaq 0x1(%r14), %rax
movl (%rsi), %edi
subq %rdi, %rax
movl $0x0, %r12d
cmovaeq %rax, %r12
cmpq %r15, %rbx
movq %r15, %rdi
cmovbq %rbx, %rdi
cmpq %r12, %r14
movq %r12, %rax
cmovbq %r14, %rax
cmpq %rax, %rdi
cmovbq %rdi, %rax
cmpq %r13, %rax
jb 0x20789
movq %r13, %rax
cmpq %r11, %rax
ja 0x207b5
cmpq %r12, %r14
cmovaq %r14, %r12
cmpq %r15, %rbx
cmovaq %rbx, %r15
cmpq %r12, %r15
cmovbeq %r12, %r15
cmpq %r13, %r15
jb 0x207ab
movq %r13, %r15
incq %r15
cmpq %r10, %r15
sbbq $-0x1, %r9
addq $0x20, %rsi
decq %rdx
jne 0x206f2
jmp 0x207c7
xorl %r9d, %r9d
movq 0x269812(%rip), %rax    # 0x289fe0
movq (%rax), %rdi
leaq 0x210ed1(%rip), %rsi    # 0x2316a9
movq %r9, %rdx
movq %r8, %rcx
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x22b0