// File: chhylp123[P]hifiasm/gfa_ut.cpp
// Function: quick_check(uc_block_t*, asg_t*, path_dp_t*, double, double)
uint32_t quick_check(uc_block_t *a, asg_t *g, path_dp_t *b, double diff_rate, double filter_rate)
{
    uint64_t ref_l = 0, pat_l = 0, mm, min, max, l, k, s, e, match_s, match_e, unmatch_s, unmatch_e, match_l, unmatch_l;
    if(b->ref.n == 0 || b->pat.n == 0) return 0;
    assert(b->g_flt.a[(uint32_t)b->pat.a[0]]);
    for (k = 1; k < b->pat.n; k++) {///k = 0, must be matched
        if(b->g_flt.a[(uint32_t)b->pat.a[k]]) break;
    }
    if(k >= b->pat.n) return 0;

    ref_l = (b->ref.a[b->ref.n-1]>>32) + g->seq[((uint32_t)b->ref.a[b->ref.n-1])>>1].len;
    pat_l = (b->pat.a[b->pat.n-1]>>32) + g->seq[((uint32_t)b->pat.a[b->pat.n-1])>>1].len;
    mm = MIN(ref_l, pat_l); min = mm * (1.0 - diff_rate); max = mm * (1.0 + diff_rate);

    match_s = match_e = unmatch_s = unmatch_e = (uint64_t)-1; match_l = unmatch_l = 0;
    for (k = 0; k < b->pat.n; k++) {
        l = (b->pat.a[k]>>32) + g->seq[((uint32_t)b->pat.a[k])>>1].len; 
        s = b->pat_cor.a[k]>>32; e = (uint32_t)b->pat_cor.a[k];
        if(l <= min) {
            if(unmatch_e == (uint64_t)-1 || s >= unmatch_e) {
                if(unmatch_e != (uint64_t)-1) unmatch_l += unmatch_e - unmatch_s;
                unmatch_s = s; unmatch_e = e;
            } else {
                if(e > unmatch_e) unmatch_e = e;
            }
        }

        if(l <= max) {
            if(b->g_flt.a[(uint32_t)b->pat.a[k]]) {
                if(match_e == (uint64_t)-1 || s >= match_e) {
                    if(match_e != (uint64_t)-1) match_l += match_e - match_s;
                    match_s = s; match_e = e;
                } else {
                    if(e > match_e) match_e = e;
                }
            }
        }
        if(l > max) break;
    }
    
    if(unmatch_e != (uint64_t)-1) unmatch_l += unmatch_e - unmatch_s;
    if(match_e != (uint64_t)-1) match_l += match_e - match_s;
    // fprintf(stderr, "[M::%s::] min::%lu, max::%lu, match_l::%lu, unmatch_l::%lu\n", __func__, 
    //         min, max, match_l, unmatch_l);
    if(match_l >= unmatch_l*filter_rate) return 1;
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movsd %xmm0, -0x28(%rbp)
movsd %xmm1, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x20(%rbp), %rax
cmpq $0x0, (%rax)
je 0x324196
movq -0x20(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0x3241a2
movl $0x0, -0x4(%rbp)
jmp 0x324666
movq -0x20(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x28(%rcx), %rcx
movq (%rcx), %rcx
movl %ecx, %ecx
cmpb $0x0, (%rax,%rcx)
je 0x3241bf
jmp 0x3241de
leaq 0x729e6(%rip), %rdi     # 0x396bac
leaq 0x71fec(%rip), %rsi     # 0x3961b9
movl $0xdcf, %edx            # imm = 0xDCF
leaq 0x729f5(%rip), %rcx     # 0x396bce
callq 0x2130
movq $0x1, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq -0x20(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jae 0x324226
movq -0x20(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x28(%rcx), %rcx
movq -0x68(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %ecx
cmpb $0x0, (%rax,%rcx)
je 0x324216
jmp 0x324226
jmp 0x324218
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
jmp 0x3241e6
movq -0x68(%rbp), %rax
movq -0x20(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jb 0x324240
movl $0x0, -0x4(%rbp)
jmp 0x324666
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x20(%rbp), %rcx
movq (%rcx), %rcx
subq $0x1, %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movq -0x18(%rbp), %rcx
movq 0x20(%rcx), %rcx
movq -0x20(%rbp), %rdx
movq 0x10(%rdx), %rdx
movq -0x20(%rbp), %rsi
movq (%rsi), %rsi
subq $0x1, %rsi
movq (%rdx,%rsi,8), %rdx
shrl %edx
movl %edx, %edx
movl (%rcx,%rdx,8), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x18(%rcx), %rcx
subq $0x1, %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movq -0x18(%rbp), %rcx
movq 0x20(%rcx), %rcx
movq -0x20(%rbp), %rdx
movq 0x28(%rdx), %rdx
movq -0x20(%rbp), %rsi
movq 0x18(%rsi), %rsi
subq $0x1, %rsi
movq (%rdx,%rsi,8), %rdx
shrl %edx
movl %edx, %edx
movl (%rcx,%rdx,8), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
ja 0x3242f9
movq -0x38(%rbp), %rax
movq %rax, -0xb0(%rbp)
jmp 0x324304
movq -0x40(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %xmm0
movaps 0x5dcf5(%rip), %xmm4    # 0x382010
punpckldq %xmm4, %xmm0    # xmm0 = xmm0[0],xmm4[0],xmm0[1],xmm4[1]
movapd 0x5dcf9(%rip), %xmm2    # 0x382020
subpd %xmm2, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd -0x28(%rbp), %xmm5
movsd 0x5dcbd(%rip), %xmm3    # 0x382000
movaps %xmm3, %xmm1
subsd %xmm5, %xmm1
mulsd %xmm1, %xmm0
movaps %xmm0, %xmm1
cvttsd2si %xmm1, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
movsd 0x5dc93(%rip), %xmm1    # 0x381ff8
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %xmm0
punpckldq %xmm4, %xmm0    # xmm0 = xmm0[0],xmm4[0],xmm0[1],xmm4[1]
subpd %xmm2, %xmm0
movaps %xmm0, %xmm2
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm2, %xmm0
movsd -0x28(%rbp), %xmm2
addsd %xmm3, %xmm2
mulsd %xmm2, %xmm0
movaps %xmm0, %xmm2
cvttsd2si %xmm2, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0x58(%rbp)
movq $-0x1, -0x98(%rbp)
movq $-0x1, -0x90(%rbp)
movq $-0x1, -0x88(%rbp)
movq $-0x1, -0x80(%rbp)
movq $0x0, -0xa8(%rbp)
movq $0x0, -0xa0(%rbp)
movq $0x0, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq -0x20(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jae 0x3245bd
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x68(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movq -0x18(%rbp), %rcx
movq 0x20(%rcx), %rcx
movq -0x20(%rbp), %rdx
movq 0x28(%rdx), %rdx
movq -0x68(%rbp), %rsi
movq (%rdx,%rsi,8), %rdx
shrl %edx
movl %edx, %edx
movl (%rcx,%rdx,8), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x20(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x68(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movq %rax, -0x70(%rbp)
movq -0x20(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x68(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
movq %rax, -0x78(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x50(%rbp), %rax
ja 0x324503
cmpq $-0x1, -0x98(%rbp)
je 0x3244a9
movq -0x70(%rbp), %rax
cmpq -0x98(%rbp), %rax
jb 0x3244e7
cmpq $-0x1, -0x98(%rbp)
je 0x3244cf
movq -0x98(%rbp), %rax
subq -0x90(%rbp), %rax
addq -0xa8(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x98(%rbp)
jmp 0x324501
movq -0x78(%rbp), %rax
cmpq -0x98(%rbp), %rax
jbe 0x3244ff
movq -0x78(%rbp), %rax
movq %rax, -0x98(%rbp)
jmp 0x324501
jmp 0x324503
movq -0x60(%rbp), %rax
cmpq -0x58(%rbp), %rax
ja 0x32459e
movq -0x20(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x28(%rcx), %rcx
movq -0x68(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %ecx
cmpb $0x0, (%rax,%rcx)
je 0x32459c
cmpq $-0x1, -0x88(%rbp)
je 0x324548
movq -0x70(%rbp), %rax
cmpq -0x88(%rbp), %rax
jb 0x324580
cmpq $-0x1, -0x88(%rbp)
je 0x32456b
movq -0x88(%rbp), %rax
subq -0x80(%rbp), %rax
addq -0xa0(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x88(%rbp)
jmp 0x32459a
movq -0x78(%rbp), %rax
cmpq -0x88(%rbp), %rax
jbe 0x324598
movq -0x78(%rbp), %rax
movq %rax, -0x88(%rbp)
jmp 0x32459a
jmp 0x32459c
jmp 0x32459e
movq -0x60(%rbp), %rax
cmpq -0x58(%rbp), %rax
jbe 0x3245aa
jmp 0x3245bd
jmp 0x3245ac
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
jmp 0x324406
cmpq $-0x1, -0x98(%rbp)
je 0x3245e3
movq -0x98(%rbp), %rax
subq -0x90(%rbp), %rax
addq -0xa8(%rbp), %rax
movq %rax, -0xa8(%rbp)
cmpq $-0x1, -0x88(%rbp)
je 0x324606
movq -0x88(%rbp), %rax
subq -0x80(%rbp), %rax
addq -0xa0(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %xmm0
movaps 0x5d9fb(%rip), %xmm3    # 0x382010
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
movapd 0x5d9ff(%rip), %xmm2    # 0x382020
subpd %xmm2, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movq -0xa8(%rbp), %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
mulsd -0x30(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jb 0x32465f
movl $0x1, -0x4(%rbp)
jmp 0x324666
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xb0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)