// File: chhylp123[P]hifiasm/horder.cpp
// Function: get_sub_cov(kvec_pe_hit*, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, int)
uint64_t get_sub_cov(kvec_pe_hit *hits, uint64_t sidx, uint64_t eidx, uint64_t ulen, 
uint64_t rs, uint64_t re, uint64_t limit_s, uint64_t limit_e, int unique_only)
{
    uint64_t i, p0s, p0e, p1s, p1e, span_s, span_e, cnt = 0;


    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;
        if(unique_only && hits->a.a[i].id == 0) 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)
        {
            if(span_s >= limit_s && span_e <= limit_e) cnt++;
        } 
    }

    return cnt;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movl 0x20(%rbp), %eax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq $0x0, -0x70(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x23dfeb
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x38(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rax
shlq %rax
movq -0x8(%rbp), %rdx
movl $0x40, %ecx
subq 0x48(%rdx), %rcx
shrq %cl, %rax
movq -0x8(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x38(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rcx
movq 0x8(%rcx), %rdx
shlq %rdx
movq -0x8(%rbp), %rsi
movl $0x40, %ecx
subq 0x48(%rsi), %rcx
shrq %cl, %rdx
movq %rdx, %rcx
cmpq %rcx, %rax
je 0x23dafc
jmp 0x23dfda
cmpl $0x0, 0x20(%rbp)
je 0x23db21
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x38(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
cmpq $0x0, 0x10(%rax)
jne 0x23db21
jmp 0x23dfda
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x38(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
andq 0x50(%rcx), %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x38(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rax
shrq $0x3f, %rax
cmpq $0x0, %rax
je 0x23dc01
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x38(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
andq 0x50(%rcx), %rax
addq $0x1, %rax
movq -0x8(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x38(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rcx
movq 0x18(%rcx), %rcx
shrq $0x20, %rcx
cmpq %rcx, %rax
jb 0x23dbef
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x38(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
andq 0x50(%rcx), %rax
addq $0x1, %rax
movq -0x8(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x38(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rcx
movq 0x18(%rcx), %rcx
shrq $0x20, %rcx
subq %rcx, %rax
movq %rax, -0x78(%rbp)
jmp 0x23dbf7
xorl %eax, %eax
movq %rax, -0x78(%rbp)
jmp 0x23dbf7
movq -0x78(%rbp), %rax
movq %rax, -0x80(%rbp)
jmp 0x23dc45
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x38(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
andq 0x50(%rcx), %rax
movq -0x8(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x38(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rcx
movq 0x18(%rcx), %rcx
shrq $0x20, %rcx
addq %rcx, %rax
subq $0x1, %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x38(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
andq 0x50(%rcx), %rax
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x38(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
shrq $0x3f, %rax
cmpq $0x0, %rax
je 0x23dd39
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x38(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
andq 0x50(%rcx), %rax
addq $0x1, %rax
movq -0x8(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x38(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rcx
movq 0x18(%rcx), %rcx
movl %ecx, %ecx
cmpq %rcx, %rax
jb 0x23dd1e
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x38(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
andq 0x50(%rcx), %rax
addq $0x1, %rax
movq -0x8(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x38(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rcx
movq 0x18(%rcx), %rcx
movl %ecx, %ecx
subq %rcx, %rax
movq %rax, -0x88(%rbp)
jmp 0x23dd29
xorl %eax, %eax
movq %rax, -0x88(%rbp)
jmp 0x23dd29
movq -0x88(%rbp), %rax
movq %rax, -0x90(%rbp)
jmp 0x23dd7f
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x38(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
andq 0x50(%rcx), %rax
movq -0x8(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x38(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rcx
movq 0x18(%rcx), %rcx
movl %ecx, %ecx
addq %rcx, %rax
subq $0x1, %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x48(%rbp), %rax
ja 0x23dda1
movq -0x40(%rbp), %rax
movq %rax, -0x98(%rbp)
jmp 0x23ddac
movq -0x48(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x58(%rbp), %rax
ja 0x23ddd1
movq -0x50(%rbp), %rax
movq %rax, -0xa8(%rbp)
jmp 0x23dddc
movq -0x58(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0xa0(%rbp), %rax
movq -0xa8(%rbp), %rcx
cmpq %rcx, %rax
ja 0x23de21
movq -0x40(%rbp), %rax
cmpq -0x48(%rbp), %rax
ja 0x23de06
movq -0x40(%rbp), %rax
movq %rax, -0xb0(%rbp)
jmp 0x23de11
movq -0x48(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rax
movq %rax, -0xb8(%rbp)
jmp 0x23de51
movq -0x50(%rbp), %rax
cmpq -0x58(%rbp), %rax
ja 0x23de38
movq -0x50(%rbp), %rax
movq %rax, -0xc0(%rbp)
jmp 0x23de43
movq -0x58(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0xc0(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq -0x20(%rbp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
ja 0x23de7a
movq -0x60(%rbp), %rax
movq %rax, -0xc8(%rbp)
jmp 0x23de89
movq -0x20(%rbp), %rax
subq $0x1, %rax
movq %rax, -0xc8(%rbp)
movq -0xc8(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x48(%rbp), %rax
jb 0x23deab
movq -0x40(%rbp), %rax
movq %rax, -0xd0(%rbp)
jmp 0x23deb6
movq -0x48(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x58(%rbp), %rax
jb 0x23dedb
movq -0x50(%rbp), %rax
movq %rax, -0xe0(%rbp)
jmp 0x23dee6
movq -0x58(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq -0xd8(%rbp), %rax
movq -0xe0(%rbp), %rcx
cmpq %rcx, %rax
jb 0x23df2b
movq -0x40(%rbp), %rax
cmpq -0x48(%rbp), %rax
jb 0x23df10
movq -0x40(%rbp), %rax
movq %rax, -0xe8(%rbp)
jmp 0x23df1b
movq -0x48(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0xe8(%rbp), %rax
movq %rax, -0xf0(%rbp)
jmp 0x23df5b
movq -0x50(%rbp), %rax
cmpq -0x58(%rbp), %rax
jb 0x23df42
movq -0x50(%rbp), %rax
movq %rax, -0xf8(%rbp)
jmp 0x23df4d
movq -0x58(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq -0xf8(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq -0xf0(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq -0x20(%rbp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
ja 0x23df84
movq -0x68(%rbp), %rax
movq %rax, -0x100(%rbp)
jmp 0x23df93
movq -0x20(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x100(%rbp)
movq -0x100(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x28(%rbp), %rax
ja 0x23dfd8
movq -0x68(%rbp), %rax
cmpq -0x30(%rbp), %rax
jb 0x23dfd8
movq -0x60(%rbp), %rax
cmpq 0x10(%rbp), %rax
jb 0x23dfd6
movq -0x68(%rbp), %rax
cmpq 0x18(%rbp), %rax
ja 0x23dfd6
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
jmp 0x23dfd8
jmp 0x23dfda
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x23da8e
movq -0x70(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax,%rax)