// File: chhylp123[P]hifiasm/gfa_ut.cpp
// Function: idx_check_rate(unsigned long*, unsigned long, unsigned long, unsigned long, float)
uint32_t idx_check_rate(uint64_t *a, uint64_t a_n, uint64_t tot, uint64_t winlen, float match_rate)
{
    if(a_n == 0) return 0;
    if(tot < winlen) winlen = tot;
    uint64_t k, mm = a[0]>>32, ks, s, e; int64_t p;
    s = 0; e = winlen;
    for (k = ks = 0; k < a_n; k++) {
        assert(a[k] != (uint64_t)-1);
        // if(mm != (a[k]>>32)) {
        //     fprintf(stderr, "***[M::%s::] mm::%lu, (a[%lu]>>32)::%lu\n", 
        //     __func__, mm, k, (a[k]>>32));
        // }
        assert(mm == (a[k]>>32));
        if(((uint32_t)a[k]) >= s && ((uint32_t)a[k]) < e) continue;
        break;
    }
    p = k;
    if(p > 0 && p >= (int64_t)(winlen*match_rate)) return 1;

    for (; k < a_n; k++) {
        assert(a[k] != (uint64_t)-1);
        assert(mm == (a[k]>>32));
        e = ((uint32_t)a[k]) + 1; p++;
        for (; ks < k; ks++) {
            if(e - ((uint32_t)a[ks]) <= winlen) break;
            p--;
        }
        assert(p >= 0);
        if(p > 0 && p >= (int64_t)(winlen*match_rate)) return 1;
    }
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movss %xmm0, -0x2c(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x34b753
movl $0x0, -0x4(%rbp)
jmp 0x34ba44
movq -0x20(%rbp), %rax
cmpq -0x28(%rbp), %rax
jae 0x34b765
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
shrq $0x20, %rax
movq %rax, -0x40(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x58(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x34b849
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
cmpq $-0x1, (%rax,%rcx,8)
je 0x34b7b3
jmp 0x34b7d2
leaq 0x4d8eb(%rip), %rdi     # 0x3990a5
leaq 0x4a9f8(%rip), %rsi     # 0x3961b9
movl $0x27ed, %edx           # imm = 0x27ED
leaq 0x4d8ed(%rip), %rcx     # 0x3990ba
callq 0x2130
movq -0x40(%rbp), %rax
movq -0x10(%rbp), %rcx
movq -0x38(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
cmpq %rcx, %rax
jne 0x34b7ed
jmp 0x34b80c
leaq 0x4d90f(%rip), %rdi     # 0x399103
leaq 0x4a9be(%rip), %rsi     # 0x3961b9
movl $0x27f2, %edx           # imm = 0x27F2
leaq 0x4d8b3(%rip), %rcx     # 0x3990ba
callq 0x2130
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
cmpq -0x50(%rbp), %rax
jb 0x34b836
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
cmpq -0x58(%rbp), %rax
jae 0x34b836
jmp 0x34b838
jmp 0x34b849
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x34b794
movq -0x38(%rbp), %rax
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
jle 0x34b8bd
movq -0x60(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x28(%rbp), %rax
movq %rax, %rdx
shrq %rdx
movl %eax, %ecx
andl $0x1, %ecx
orq %rdx, %rcx
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
cvtsi2ss %rax, %xmm1
movss %xmm1, -0x68(%rbp)
testq %rax, %rax
movss %xmm0, -0x64(%rbp)
js 0x34b899
movss -0x68(%rbp), %xmm0
movss %xmm0, -0x64(%rbp)
movq -0x70(%rbp), %rax
movss -0x64(%rbp), %xmm0
mulss -0x2c(%rbp), %xmm0
cvttss2si %xmm0, %rcx
cmpq %rcx, %rax
jl 0x34b8bd
movl $0x1, -0x4(%rbp)
jmp 0x34ba44
jmp 0x34b8bf
movq -0x38(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x34ba3d
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
cmpq $-0x1, (%rax,%rcx,8)
je 0x34b8de
jmp 0x34b8fd
leaq 0x4d7c0(%rip), %rdi     # 0x3990a5
leaq 0x4a8cd(%rip), %rsi     # 0x3961b9
movl $0x27fa, %edx           # imm = 0x27FA
leaq 0x4d7c2(%rip), %rcx     # 0x3990ba
callq 0x2130
movq -0x40(%rbp), %rax
movq -0x10(%rbp), %rcx
movq -0x38(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
cmpq %rcx, %rax
jne 0x34b918
jmp 0x34b937
leaq 0x4d7e4(%rip), %rdi     # 0x399103
leaq 0x4a893(%rip), %rsi     # 0x3961b9
movl $0x27fb, %edx           # imm = 0x27FB
leaq 0x4d788(%rip), %rcx     # 0x3990ba
callq 0x2130
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
addl $0x1, %eax
movl %eax, %eax
movq %rax, -0x58(%rbp)
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x38(%rbp), %rax
jae 0x34b999
movq -0x58(%rbp), %rax
movq -0x10(%rbp), %rcx
movq -0x48(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %ecx
subq %rcx, %rax
cmpq -0x28(%rbp), %rax
ja 0x34b97f
jmp 0x34b999
movq -0x60(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x60(%rbp)
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x34b958
cmpq $0x0, -0x60(%rbp)
jl 0x34b9a2
jmp 0x34b9c1
leaq 0x4d76b(%rip), %rdi     # 0x399114
leaq 0x4a809(%rip), %rsi     # 0x3961b9
movl $0x2801, %edx           # imm = 0x2801
leaq 0x4d6fe(%rip), %rcx     # 0x3990ba
callq 0x2130
cmpq $0x0, -0x60(%rbp)
jle 0x34ba2a
movq -0x60(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x28(%rbp), %rax
movq %rax, %rdx
shrq %rdx
movl %eax, %ecx
andl $0x1, %ecx
orq %rdx, %rcx
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
cvtsi2ss %rax, %xmm1
movss %xmm1, -0x78(%rbp)
testq %rax, %rax
movss %xmm0, -0x74(%rbp)
js 0x34ba09
movss -0x78(%rbp), %xmm0
movss %xmm0, -0x74(%rbp)
movq -0x80(%rbp), %rax
movss -0x74(%rbp), %xmm0
mulss -0x2c(%rbp), %xmm0
cvttss2si %xmm0, %rcx
cmpq %rcx, %rax
jl 0x34ba2a
movl $0x1, -0x4(%rbp)
jmp 0x34ba44
jmp 0x34ba2c
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x34b8bf
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq