// File: /workspace/github_cpp_makefile_star2_O3/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 0x1fcbb8
movq 0x18(%rdx), %rcx
testq %rcx, %rcx
je 0x1fcbb8
movq 0x28(%rdx), %rdi
movq 0x58(%rdx), %r8
movl (%rdi), %r10d
cmpb $0x0, (%r8,%r10)
je 0x1fcbc7
cmpq $0x1, %rcx
je 0x1fcbb8
movl $0x1, %r10d
movl (%rdi,%r10,8), %r11d
cmpb $0x0, (%r8,%r11)
jne 0x1fc980
incq %r10
cmpq %r10, %rcx
jne 0x1fc968
jmp 0x1fcbb8
movq 0x10(%rdx), %r10
movq 0x40(%rdx), %rax
movq %rax, 0x20(%rsp)
movq -0x8(%r10,%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
movq %rax, 0x18(%rsp)
movl (%rax,%r10,8), %r10d
andq %r9, %r10
addq %r11, %r10
cmpq %r10, %rsi
cmovbq %rsi, %r10
cvtsi2sd %r10, %xmm2
movsd 0x3492e(%rip), %xmm3    # 0x231310
movapd %xmm3, %xmm4
subsd %xmm0, %xmm4
mulsd %xmm2, %xmm4
cvttsd2si %xmm4, %rsi
movq %rsi, %r10
sarq $0x3f, %r10
movsd 0x34906(%rip), %xmm5    # 0x231308
subsd %xmm5, %xmm4
cvttsd2si %xmm4, %r9
andq %r10, %r9
orq %rsi, %r9
addsd %xmm3, %xmm0
mulsd %xmm2, %xmm0
cvttsd2si %xmm0, %rsi
movq %rsi, %r10
sarq $0x3f, %r10
subsd %xmm5, %xmm0
cvttsd2si %xmm0, %rbx
andq %r10, %rbx
orq %rsi, %rbx
movq $-0x1, %r11
movq $0x0, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
movq $-0x1, (%rsp)
movq $-0x1, %rbp
movq $-0x1, %r10
xorl %r15d, %r15d
movq (%rdi,%r15,8), %r14
movq %r14, %r12
shrq $0x20, %r12
movl %r14d, %esi
shrl %esi
movq 0x18(%rsp), %rax
movl (%rax,%rsi,8), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
addq %r12, %rsi
movq 0x20(%rsp), %rax
movq (%rax,%r15,8), %r13
movl %r13d, %r12d
shrq $0x20, %r13
cmpq %r9, %rsi
ja 0x1fcad6
cmpq $-0x1, %r11
setne %al
cmpq %r11, %r13
setb %dl
testb %dl, %al
je 0x1fcab6
cmpq %r11, %r12
cmovaq %r12, %r11
jmp 0x1fcad6
movq %r11, %rax
subq (%rsp), %rax
cmpq $-0x1, %r11
movl $0x0, %edx
cmovneq %rax, %rdx
addq %rdx, 0x8(%rsp)
movq %r13, (%rsp)
movq %r12, %r11
cmpq %rbx, %rsi
ja 0x1fcb36
movl %r14d, %eax
cmpb $0x0, (%r8,%rax)
je 0x1fcb02
cmpq $-0x1, %rbp
setne %al
cmpq %rbp, %r13
setb %dl
testb %dl, %al
je 0x1fcb0a
cmpq %rbp, %r12
cmovbeq %rbp, %r12
movq %r10, %r13
jmp 0x1fcb22
movq %r10, %r13
movq %rbp, %r12
jmp 0x1fcb22
movq %rbp, %rax
subq %r10, %rax
cmpq $-0x1, %rbp
movl $0x0, %edx
cmovneq %rax, %rdx
addq %rdx, 0x10(%rsp)
incq %r15
movq %r12, %rbp
movq %r13, %r10
cmpq %r15, %rcx
jne 0x1fca66
jmp 0x1fcb3c
movq %r10, %r13
movq %rbp, %r12
movq %r11, %rax
subq (%rsp), %rax
xorl %ecx, %ecx
cmpq $-0x1, %r11
cmoveq %rcx, %rax
addq 0x8(%rsp), %rax
movq %r12, %rdx
subq %r13, %rdx
cmpq $-0x1, %r12
cmoveq %rcx, %rdx
addq 0x10(%rsp), %rdx
movq %rdx, %xmm0
movq 0x3470e(%rip), %xmm2    # 0x231280
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
movapd 0x34712(%rip), %xmm3    # 0x231290
subpd %xmm3, %xmm0
movapd %xmm0, %xmm4
unpckhpd %xmm0, %xmm4            # xmm4 = xmm4[1],xmm0[1]
addsd %xmm0, %xmm4
movq %rax, %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 0x1fcbb8
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4942e(%rip), %rdi     # 0x245ffc
leaq 0x48a34(%rip), %rsi     # 0x245609
leaq 0x49442(%rip), %rcx     # 0x24601e
movl $0xdcf, %edx            # imm = 0xDCF
callq 0x2110