// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq (%rdx), %r9
xorl %eax, %eax
testq %r9, %r9
je 0x1f161b
movq 0x18(%rdx), %rcx
testq %rcx, %rcx
je 0x1f161b
movq 0x28(%rdx), %rdi
movq 0x58(%rdx), %r8
movl (%rdi), %r10d
cmpb $0x0, (%r8,%r10)
je 0x1f162a
cmpq $0x1, %rcx
setne %r10b
je 0x1f161b
movl 0x8(%rdi), %r11d
cmpb $0x0, (%r8,%r11)
jne 0x1f13d4
movl $0x2, %r10d
subq %rcx, %r10
movl $0x1, %r11d
leaq (%r10,%r11), %rbx
cmpq $0x1, %rbx
je 0x1f161b
movl 0x8(%rdi,%r11,8), %ebx
incq %r11
cmpb $0x0, (%r8,%rbx)
je 0x1f13b0
cmpq %rcx, %r11
setb %r10b
testb %r10b, %r10b
je 0x1f161b
movq %r8, 0x20(%rsp)
movq 0x10(%rdx), %rax
movq -0x8(%rax,%r9,8), %r9
movq %r9, %r10
shrq $0x20, %r10
movq 0x20(%rsi), %rax
shrl %r9d
movl (%rax,%r9,8), %esi
movl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
andq %r9, %rsi
addq %r10, %rsi
movq -0x8(%rdi,%rcx,8), %r10
movq %r10, %r11
shrq $0x20, %r11
shrl %r10d
movl (%rax,%r10,8), %r10d
andq %r9, %r10
addq %r11, %r10
cmpq %r10, %rsi
cmovbq %rsi, %r10
cvtsi2sd %r10, %xmm2
movsd 0x33e3a(%rip), %xmm3    # 0x225270
movapd %xmm3, %xmm4
subsd %xmm0, %xmm4
mulsd %xmm2, %xmm4
cvttsd2si %xmm4, %rsi
movq 0x40(%rdx), %rdx
movq %rsi, %r10
sarq $0x3f, %r10
movsd 0x33e0e(%rip), %xmm5    # 0x225268
subsd %xmm5, %xmm4
cvttsd2si %xmm4, %r9
andq %r10, %r9
addsd %xmm3, %xmm0
mulsd %xmm2, %xmm0
cvttsd2si %xmm0, %r10
orq %rsi, %r9
movq %r10, %rsi
sarq $0x3f, %rsi
subsd %xmm5, %xmm0
cvttsd2si %xmm0, %r11
andq %rsi, %r11
orq %r10, %r11
decq %rcx
movq $-0x1, %r15
movq $0x0, 0x18(%rsp)
movq $0x0, 0x10(%rsp)
movq $-0x1, 0x8(%rsp)
movq $-0x1, %rbx
movq $-0x1, (%rsp)
xorl %r13d, %r13d
movq (%rdi,%r13,8), %rsi
movq %rsi, %r14
shrq $0x20, %r14
movl %esi, %r12d
shrl %r12d
movl (%rax,%r12,8), %ebp
andl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
addq %r14, %rbp
movq (%rdx,%r13,8), %r12
movl %r12d, %r14d
shrq $0x20, %r12
cmpq %r9, %rbp
ja 0x1f1531
cmpq $-0x1, %r15
setne %r10b
cmpq %r15, %r12
setb %r8b
testb %r8b, %r10b
je 0x1f150e
cmpq %r15, %r14
cmovaq %r14, %r15
jmp 0x1f1531
movq %r15, %r8
subq 0x8(%rsp), %r8
cmpq $-0x1, %r15
movl $0x0, %r10d
cmovneq %r8, %r10
addq %r10, 0x18(%rsp)
movq %r12, 0x8(%rsp)
movq %r14, %r15
cmpq %r11, %rbp
ja 0x1f1582
movl %esi, %esi
movq 0x20(%rsp), %r8
cmpb $0x0, (%r8,%rsi)
je 0x1f1582
cmpq $-0x1, %rbx
setne %sil
cmpq %rbx, %r12
setb %r8b
testb %r8b, %sil
je 0x1f1561
cmpq %rbx, %r14
cmovaq %r14, %rbx
jmp 0x1f1582
movq %rbx, %rsi
subq (%rsp), %rsi
cmpq $-0x1, %rbx
movl $0x0, %r8d
cmovneq %rsi, %r8
addq %r8, 0x10(%rsp)
movq %r12, (%rsp)
movq %r14, %rbx
cmpq %r11, %rbp
ja 0x1f1597
leaq 0x1(%r13), %rsi
cmpq %r13, %rcx
movq %rsi, %r13
jne 0x1f14c3
movq %r15, %rax
subq 0x8(%rsp), %rax
xorl %ecx, %ecx
cmpq $-0x1, %r15
cmoveq %rcx, %rax
movq 0x18(%rsp), %rdx
addq %rax, %rdx
movq %rbx, %rax
subq (%rsp), %rax
cmpq $-0x1, %rbx
cmoveq %rcx, %rax
movq 0x10(%rsp), %rcx
addq %rax, %rcx
movq %rcx, %xmm0
movq 0x33c6b(%rip), %xmm2    # 0x225240
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
movapd 0x33c6f(%rip), %xmm3    # 0x225250
subpd %xmm3, %xmm0
movapd %xmm0, %xmm4
unpckhpd %xmm0, %xmm4            # xmm4 = xmm4[1],xmm0[1]
addsd %xmm0, %xmm4
movq %rdx, %xmm0
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
subpd %xmm3, %xmm0
movapd %xmm0, %xmm2
unpckhpd %xmm0, %xmm2            # xmm2 = xmm2[1],xmm0[1]
addsd %xmm0, %xmm2
mulsd %xmm1, %xmm2
movl $0x1, %eax
ucomisd %xmm2, %xmm4
jae 0x1f161b
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x486e7(%rip), %rdi     # 0x239d18
leaq 0x47ced(%rip), %rsi     # 0x239325
leaq 0x486fb(%rip), %rcx     # 0x239d3a
movl $0xdcf, %edx            # imm = 0xDCF
callq 0x2110