// File: /workspace/github_cpp_makefile_star2_O2/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 0x1b0e88
movq 0x18(%rdx), %rbx
testq %rbx, %rbx
je 0x1b0e88
movq 0x28(%rdx), %rdi
movq 0x58(%rdx), %r8
movl (%rdi), %r10d
cmpb $0x0, (%r8,%r10)
je 0x1b0e97
pushq $0x1
popq %r10
cmpq %r10, %rbx
je 0x1b0e88
movl (%rdi,%r10,8), %r11d
incq %r10
cmpb $0x0, (%r8,%r11)
je 0x1b0c32
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,%rbx,8), %r10
movq %r10, %r11
shrq $0x20, %r11
shrl %r10d
movq %rax, 0x20(%rsp)
movl (%rax,%r10,8), %r10d
andq %r9, %r10
addq %r11, %r10
cmpq %r10, %rsi
cmovbq %rsi, %r10
cvtsi2sd %r10, %xmm2
movsd 0x325fe(%rip), %xmm3    # 0x1e32a0
movapd %xmm3, %xmm4
subsd %xmm0, %xmm4
mulsd %xmm2, %xmm4
cvttsd2si %xmm4, %rsi
movq %rsi, %r10
sarq $0x3f, %r10
movsd 0x325d6(%rip), %xmm5    # 0x1e3298
subsd %xmm5, %xmm4
cvttsd2si %xmm4, %rax
andq %r10, %rax
orq %rsi, %rax
movq %rax, 0x18(%rsp)
addsd %xmm3, %xmm0
mulsd %xmm2, %xmm0
cvttsd2si %xmm0, %rsi
movq %rsi, %r10
sarq $0x3f, %r10
subsd %xmm5, %xmm0
cvttsd2si %xmm0, %r11
andq %r10, %r11
orq %rsi, %r11
pushq $-0x1
popq %r14
xorl %r12d, %r12d
movq %r14, %r13
movq %r14, (%rsp)
movq %r14, %r9
movq $0x0, 0x10(%rsp)
movq $0x0, 0x8(%rsp)
cmpq %r12, %rbx
je 0x1b0e0d
movq (%rdi,%r12,8), %r10
movq %r10, %r15
shrq $0x20, %r15
movl %r10d, %esi
shrl %esi
movq 0x20(%rsp), %rax
movl (%rax,%rsi,8), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
addq %r15, %rsi
movq 0x40(%rdx), %r15
movq (%r15,%r12,8), %r15
movl %r15d, %ebp
shrq $0x20, %r15
cmpq 0x18(%rsp), %rsi
ja 0x1b0db1
movq %r14, %rcx
movq %r8, %r14
movq %r11, %r8
movq %r9, %r11
cmpq $-0x1, %r9
setne %al
cmpq %r9, %r15
setb %r9b
testb %r9b, %al
je 0x1b0d87
cmpq %r11, %rbp
cmovaq %rbp, %r11
movq %r11, %r9
jmp 0x1b0da8
movq %r11, %rax
subq (%rsp), %rax
cmpq $-0x1, %r11
movl $0x0, %r9d
cmovneq %rax, %r9
addq %r9, 0x8(%rsp)
movq %r15, (%rsp)
movq %rbp, %r9
movq %r8, %r11
movq %r14, %r8
movq %rcx, %r14
cmpq %r11, %rsi
ja 0x1b0e0d
movl %r10d, %eax
cmpb $0x0, (%r8,%rax)
je 0x1b0ddf
cmpq $-0x1, %r13
setne %al
cmpq %r13, %r15
setb %sil
testb %sil, %al
je 0x1b0de7
cmpq %r13, %rbp
cmovbeq %r13, %rbp
movq %r14, %r15
jmp 0x1b0dff
movq %r14, %r15
movq %r13, %rbp
jmp 0x1b0dff
movq %r13, %rax
subq %r14, %rax
cmpq $-0x1, %r13
movl $0x0, %esi
cmovneq %rax, %rsi
addq %rsi, 0x10(%rsp)
incq %r12
movq %r15, %r14
movq %rbp, %r13
jmp 0x1b0d1c
movq %r9, %rcx
subq (%rsp), %rcx
xorl %eax, %eax
cmpq $-0x1, %r9
cmoveq %rax, %rcx
addq 0x8(%rsp), %rcx
movq %r13, %rdx
subq %r14, %rdx
cmpq $-0x1, %r13
cmoveq %rax, %rdx
movq 0x10(%rsp), %rsi
addq %rdx, %rsi
movq %rsi, %xmm0
movq 0x3242a(%rip), %xmm2    # 0x1e3270
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
movapd 0x3242e(%rip), %xmm3    # 0x1e3280
subpd %xmm3, %xmm0
movapd %xmm0, %xmm4
unpckhpd %xmm0, %xmm4            # xmm4 = xmm4[1],xmm0[1]
addsd %xmm0, %xmm4
movq %rcx, %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
ucomisd %xmm2, %xmm4
jb 0x1b0e88
pushq $0x1
popq %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4702e(%rip), %rdi     # 0x1f7ecc
leaq 0x46634(%rip), %rsi     # 0x1f74d9
leaq 0x47042(%rip), %rcx     # 0x1f7eee
movl $0xdcf, %edx            # imm = 0xDCF
callq 0x2110