// File: chhylp123[P]hifiasm/ecovlp.cpp
// Function: check_well_cal(asg16_v*, asg64_v*, unsigned char*, unsigned char*, long, long, ma_hit_t_alloc*)
void check_well_cal(asg16_v *sc, asg64_v *idx, uint8_t *f_ec, uint8_t *abnormal, int64_t len, int64_t min_dp, ma_hit_t_alloc *in)
{
    uint64_t k, s, e; int64_t dp, old_dp, st = 0, ed; ma_hit_t *z; 

    (*f_ec) = 1; (*abnormal) = 0; idx->n = 0;
    for (k = 0; k < in->length; k++) {
        z = &(in->buffer[k]);
        s = ((uint32_t)(z->qns)); e = z->qe;
        kv_push(uint64_t, (*idx), (s<<1));
        kv_push(uint64_t, (*idx), (e<<1)|1);
    }

    radix_sort_ec64(idx->a, idx->a + idx->n);
    for (k = 0, dp = 0, st = ed = 0; k < idx->n; ++k) {
        old_dp = dp;
        ///if a[j] is qe
        if (idx->a[k]&1) --dp;
        else ++dp;

        ed = idx->a[k]>>1;
        if(ed > st) {
            if(old_dp < min_dp) (*f_ec) = 0;
            if(old_dp == 0) {
                if(st > 0 && ed < len) {
                    (*abnormal) = 1;
                }else if((*abnormal)==0){
                    (*abnormal) = 2;
                }
            }
        }

        st = ed;
    }


    ed = len; old_dp = dp;
    if(ed > st) {
        if(old_dp < min_dp) (*f_ec) = 0;
        if(old_dp == 0) {
            if(st > 0 && ed < len) {
                (*abnormal) = 1;
            }else if((*abnormal) == 0){
                (*abnormal) = 2;
            }
        }
    }

    if((*f_ec)) {
        for (k = 0; (k < sc->n) && ((sc->a[k]>>14) == 0); k++);
        if(k < sc->n) (*f_ec) = 0;
    }    
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
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, -0x60(%rbp)
movq -0x18(%rbp), %rax
movb $0x1, (%rax)
movq -0x20(%rbp), %rax
movb $0x0, (%rax)
movq -0x10(%rbp), %rax
movq $0x0, (%rax)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq 0x10(%rbp), %rcx
movl 0xc(%rcx), %ecx
cmpq %rcx, %rax
jae 0x257180
movq 0x10(%rbp), %rax
movq (%rax), %rax
imulq $0x28, -0x38(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movq (%rax), %rax
movl %eax, %eax
movq %rax, -0x40(%rbp)
movq -0x70(%rbp), %rax
movl 0x8(%rax), %eax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x2570b7
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x25707c
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x78(%rbp)
jmp 0x257087
movl $0x2, %eax
movq %rax, -0x78(%rbp)
jmp 0x257087
movq -0x78(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x40(%rbp), %rdx
shlq %rdx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movq %rdx, (%rax,%rcx,8)
jmp 0x2570dd
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x257145
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x25710a
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x80(%rbp)
jmp 0x257115
movl $0x2, %eax
movq %rax, -0x80(%rbp)
jmp 0x257115
movq -0x80(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x48(%rbp), %rdx
shlq %rdx
orq $0x1, %rdx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movq %rdx, (%rax,%rcx,8)
jmp 0x25716f
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x257010
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x10(%rbp), %rax
movq (%rax), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x24aba0
movq $0x0, -0x38(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x68(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x257295
movq -0x50(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
andq $0x1, %rax
cmpq $0x0, %rax
je 0x257204
movq -0x50(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x257210
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
cmpq -0x60(%rbp), %rax
jle 0x25727c
movq -0x58(%rbp), %rax
cmpq -0x30(%rbp), %rax
jge 0x257242
movq -0x18(%rbp), %rax
movb $0x0, (%rax)
cmpq $0x0, -0x58(%rbp)
jne 0x25727a
cmpq $0x0, -0x60(%rbp)
jle 0x257263
movq -0x68(%rbp), %rax
cmpq -0x28(%rbp), %rax
jge 0x257263
movq -0x20(%rbp), %rax
movb $0x1, (%rax)
jmp 0x257278
movq -0x20(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x0, %eax
jne 0x257276
movq -0x20(%rbp), %rax
movb $0x2, (%rax)
jmp 0x257278
jmp 0x25727a
jmp 0x25727c
movq -0x68(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x2571c3
movq -0x28(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x68(%rbp), %rax
cmpq -0x60(%rbp), %rax
jle 0x2572fa
movq -0x58(%rbp), %rax
cmpq -0x30(%rbp), %rax
jge 0x2572c0
movq -0x18(%rbp), %rax
movb $0x0, (%rax)
cmpq $0x0, -0x58(%rbp)
jne 0x2572f8
cmpq $0x0, -0x60(%rbp)
jle 0x2572e1
movq -0x68(%rbp), %rax
cmpq -0x28(%rbp), %rax
jge 0x2572e1
movq -0x20(%rbp), %rax
movb $0x1, (%rax)
jmp 0x2572f6
movq -0x20(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x0, %eax
jne 0x2572f4
movq -0x20(%rbp), %rax
movb $0x2, (%rax)
jmp 0x2572f6
jmp 0x2572f8
jmp 0x2572fa
movq -0x18(%rbp), %rax
cmpb $0x0, (%rax)
je 0x257371
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rcx
movq -0x8(%rbp), %rdx
xorl %eax, %eax
cmpq (%rdx), %rcx
movb %al, -0x81(%rbp)
jae 0x25733f
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x38(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
sarl $0xe, %eax
cmpl $0x0, %eax
sete %al
movb %al, -0x81(%rbp)
movb -0x81(%rbp), %al
testb $0x1, %al
jne 0x25734b
jmp 0x25735b
jmp 0x25734d
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x25730b
movq -0x38(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x25736f
movq -0x18(%rbp), %rax
movb $0x0, (%rax)
jmp 0x257371
addq $0x90, %rsp
popq %rbp
retq
nopw (%rax,%rax)