// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Correct.cpp
// Function: check_mask_exist(ma_ug_t*, overlap_region*, overlap_region*, kv_ul_ov_t*, idx_emask_t*, double, unsigned long*, unsigned long*)
uint64_t check_mask_exist(ma_ug_t *ug, overlap_region *q, overlap_region *t, kv_ul_ov_t *ov_db, idx_emask_t *mm, double len_diff, uint64_t *is_exact, uint64_t *ovdb_idx)
{
    ul_ov_t rr, *a; uint64_t k, eid, an, ss; (*is_exact) = 0; (*ovdb_idx) = (uint64_t)-1;
    if(!cal_x_ul_ovlp(ug, q, t, &rr)) return 0;
    ss = q->overlapLen;
    if(q->x_pos_strand) {///if q does not have mask
        eid = rr.tn; a = ov_db->a + ss; an = q->x_pos_strand;
        for (k = 0; k < an && a[k].tn < eid; k++);
        for (; k < an && a[k].tn == eid; k++) {
            if((!check_ul_ov_t_consist(&rr, &(a[k]), ug->g->seq[rr.qn].len, ug->g->seq[rr.tn].len, len_diff))) continue;
            if(is_ul_ov_pe(a, an, k, (*mm))) {
                k++; if((!check_ul_ov_t_consist(&rr, &(a[k]), ug->g->seq[rr.qn].len, ug->g->seq[rr.tn].len, len_diff))) continue;
            }
            if(is_exact_ov(a[k],(*mm))) (*is_exact) = 1;
            (*ovdb_idx) = ss + k;
            return 1;
        }
    }

    k = rr.qn; rr.qn = rr.tn; rr.tn = k;
    k = rr.qs; rr.qs = rr.ts; rr.ts = k;
    k = rr.qe; rr.qe = rr.te; rr.te = k;
    ss = t->overlapLen;
    if(t->x_pos_strand) {///if t does not have mask
        eid = rr.tn; a = ov_db->a + ss; an = t->x_pos_strand;
        for (k = 0; k < an && a[k].tn < eid; k++);
        for (; k < an && a[k].tn == eid; k++) {
            if((!check_ul_ov_t_consist(&rr, &(a[k]), ug->g->seq[rr.qn].len, ug->g->seq[rr.tn].len, len_diff))) continue;
            if(is_ul_ov_pe(a, an, k, (*mm))) {
                k++; if((!check_ul_ov_t_consist(&rr, &(a[k]), ug->g->seq[rr.qn].len, ug->g->seq[rr.tn].len, len_diff))) continue;
            }
            if(is_exact_ov(a[k],(*mm))) (*is_exact) = 1;
            (*ovdb_idx) = ss + k;
            return 1;
        }
    }
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r9, %rbx
movq %xmm0, 0x40(%rsp)
movq %r8, 0x30(%rsp)
movq %rcx, (%rsp)
movq %rdx, %r13
movq %rsi, %rbp
movq 0x90(%rsp), %rax
movq $0x0, (%r9)
movq $-0x1, (%rax)
leaq 0x10(%rsp), %rcx
movq %rdi, 0x38(%rsp)
callq 0x742e4
testq %rax, %rax
je 0x748b7
movq %rbx, 0x48(%rsp)
movl 0xc(%rbp), %r12d
testq %r12, %r12
je 0x746b7
movl 0x20(%rbp), %edx
movl 0x1c(%rsp), %r15d
movq (%rsp), %rax
movq (%rax), %rax
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rcx
movq %rdx, 0x50(%rsp)
addq %rdx, %rcx
leaq (%rax,%rcx), %r9
addq %rcx, %rax
addq $0xc, %rax
xorl %r14d, %r14d
cmpl %r15d, (%rax)
jae 0x74539
incq %r14
addq $0x1c, %rax
cmpq %r14, %r12
jne 0x74523
jmp 0x746b7
cmpq %r12, %r14
jae 0x746b7
movq %r9, 0x8(%rsp)
leaq (%r14,%r14,8), %rax
leaq (%rax,%rax,2), %rbp
addq %r14, %rbp
cmpl %r15d, 0xc(%r9,%rbp)
jne 0x746b7
addq %r9, %rbp
movq 0x38(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movl 0x10(%rsp), %ecx
movl 0x1c(%rsp), %esi
movl (%rax,%rcx,8), %edx
movl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
andq %rdi, %rdx
movl (%rax,%rsi,8), %ecx
andq %rdi, %rcx
leaq 0x10(%rsp), %rdi
movq %rbp, %rsi
movq 0x40(%rsp), %xmm0
callq 0x1ca9e4
testq %rax, %rax
je 0x746a0
leaq 0x1(%r14), %rbx
cmpq %r12, %rbx
jae 0x748cc
leaq (%rbx,%rbx,8), %rax
leaq (%rax,%rax,2), %rsi
addq %rbx, %rsi
movq 0x8(%rsp), %r9
movl (%r9,%rsi), %ecx
cmpl (%rbp), %ecx
jne 0x748d1
addq %r9, %rsi
movl 0xc(%rsi), %eax
cmpl 0xc(%rbp), %eax
jne 0x748d1
movl 0x18(%rsi), %eax
movl 0x18(%rbp), %edx
movl %edx, %edi
xorl %eax, %edi
js 0x748d1
movl $0x3fffffff, %edi       # imm = 0x3FFFFFFF
andq %rdi, %rax
andq %rdi, %rdx
leal 0x1(%rdx), %edi
cmpl %edi, %eax
jne 0x748d1
movq 0x30(%rsp), %rdi
movq (%rdi), %rdi
leaq (%rcx,%rcx,2), %rcx
movq 0x8(%rdi,%rcx,8), %r8
cmpq %rdx, %r8
jbe 0x748d1
cmpq %rax, %r8
jbe 0x748d1
leaq (%rdi,%rcx,8), %rcx
movq (%rcx), %rcx
shlq $0x5, %rdx
movb 0x1c(%rcx,%rdx), %dl
testb $0x20, %dl
je 0x748d1
testb $0x1f, %dl
jne 0x748d1
shlq $0x5, %rax
movb 0x1c(%rcx,%rax), %al
andb $0x3f, %al
cmpb $0x21, %al
jne 0x748d1
movq 0x38(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movl 0x10(%rsp), %ecx
movl 0x1c(%rsp), %edi
movl (%rax,%rcx,8), %edx
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
andq %r8, %rdx
movl (%rax,%rdi,8), %ecx
andq %r8, %rcx
leaq 0x10(%rsp), %rdi
movq 0x40(%rsp), %xmm0
callq 0x1ca9e4
movq 0x8(%rsp), %r9
movq %rbx, %r14
testq %rax, %rax
je 0x746a8
jmp 0x748d1
movq %r14, %rbx
movq 0x8(%rsp), %r9
incq %rbx
movq %rbx, %r14
cmpq %r12, %rbx
jb 0x74547
movl 0x18(%rsp), %eax
movl 0x1c(%rsp), %ecx
movq 0x10(%rsp), %xmm0
movl %ecx, 0x10(%rsp)
movq 0x20(%rsp), %xmm1
punpcklqdq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0]
movdqu %xmm1, 0x14(%rsp)
movl %eax, 0x24(%rsp)
movl 0xc(%r13), %ebx
testq %rbx, %rbx
je 0x748b7
movl 0x20(%r13), %edx
movq (%rsp), %rax
movq (%rax), %rax
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rdx, %rcx
leaq (%rax,%rcx), %r9
movd %xmm0, %r15d
addq %rcx, %rax
addq $0xc, %rax
xorl %r12d, %r12d
xorl %r14d, %r14d
cmpl %r15d, (%rax)
jae 0x7472c
incq %r14
addq $0x1c, %rax
cmpq %r14, %rbx
jne 0x74716
jmp 0x748ba
cmpq %rbx, %r14
jae 0x748b7
movq %rdx, 0x8(%rsp)
xorl %r12d, %r12d
movq %r9, (%rsp)
leaq (%r14,%r14,8), %rax
leaq (%rax,%rax,2), %rbp
addq %r14, %rbp
cmpl %r15d, 0xc(%r9,%rbp)
jne 0x748ba
addq %r9, %rbp
movq 0x38(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movl 0x10(%rsp), %ecx
movl 0x1c(%rsp), %esi
movl (%rax,%rcx,8), %edx
movl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
andq %rdi, %rdx
movl (%rax,%rsi,8), %ecx
andq %rdi, %rcx
leaq 0x10(%rsp), %rdi
movq %rbp, %rsi
movq 0x40(%rsp), %xmm0
callq 0x1ca9e4
testq %rax, %rax
je 0x7489f
leaq 0x1(%r14), %r13
cmpq %rbx, %r13
jae 0x74933
leaq (,%r13,8), %rax
addq %r13, %rax
leaq (%rax,%rax,2), %rsi
addq %r13, %rsi
movq (%rsp), %r9
movl (%r9,%rsi), %ecx
cmpl (%rbp), %ecx
jne 0x74937
addq %r9, %rsi
movl 0xc(%rsi), %eax
cmpl 0xc(%rbp), %eax
jne 0x74937
movl 0x18(%rsi), %eax
movl 0x18(%rbp), %edx
movl %edx, %edi
xorl %eax, %edi
js 0x74937
movl $0x3fffffff, %edi       # imm = 0x3FFFFFFF
andq %rdi, %rax
andq %rdi, %rdx
leal 0x1(%rdx), %edi
cmpl %edi, %eax
jne 0x74937
movq 0x30(%rsp), %rdi
movq (%rdi), %rdi
leaq (%rcx,%rcx,2), %rcx
movq 0x8(%rdi,%rcx,8), %r8
cmpq %rdx, %r8
jbe 0x74937
cmpq %rax, %r8
jbe 0x74937
leaq (%rdi,%rcx,8), %rcx
movq (%rcx), %rcx
shlq $0x5, %rdx
movb 0x1c(%rcx,%rdx), %dl
testb $0x20, %dl
je 0x74937
testb $0x1f, %dl
jne 0x74937
shlq $0x5, %rax
movb 0x1c(%rcx,%rax), %al
andb $0x3f, %al
cmpb $0x21, %al
jne 0x74937
movq 0x38(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movl 0x10(%rsp), %ecx
movl 0x1c(%rsp), %edi
movl (%rax,%rcx,8), %edx
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
andq %r8, %rdx
movl (%rax,%rdi,8), %ecx
andq %r8, %rcx
leaq 0x10(%rsp), %rdi
movq 0x40(%rsp), %xmm0
callq 0x1ca9e4
movq (%rsp), %r9
movq %r13, %r14
testq %rax, %rax
je 0x748a6
jmp 0x74937
movq %r14, %r13
movq (%rsp), %r9
incq %r13
movq %r13, %r14
cmpq %rbx, %r13
jb 0x74741
jmp 0x748ba
xorl %r12d, %r12d
movq %r12, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rsp), %r9
leaq (%r14,%r14,8), %rax
leaq (%rax,%rax,2), %rax
addq %r14, %rax
movl (%r9,%rax), %edx
movl 0x18(%r9,%rax), %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
movq 0x30(%rsp), %rcx
movq (%rcx), %rcx
leaq (%rdx,%rdx,2), %rdx
cmpq %rax, 0x8(%rcx,%rdx,8)
movq 0x90(%rsp), %rsi
jbe 0x7492c
leaq (%rcx,%rdx,8), %rcx
movq (%rcx), %rcx
shlq $0x5, %rax
testb $0x20, 0x1c(%rcx,%rax)
jne 0x7492c
addq %rax, %rcx
cmpl $-0x1, 0x8(%rcx)
jne 0x7492c
movq 0x48(%rsp), %rax
movq $0x1, (%rax)
addq 0x50(%rsp), %r14
jmp 0x74997
movq (%rsp), %r9
leaq (%r14,%r14,8), %rax
leaq (%rax,%rax,2), %rax
addq %r14, %rax
movl (%r9,%rax), %edx
movl 0x18(%r9,%rax), %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
movq 0x30(%rsp), %rcx
movq (%rcx), %rcx
leaq (%rdx,%rdx,2), %rdx
cmpq %rax, 0x8(%rcx,%rdx,8)
jbe 0x7498a
leaq (%rcx,%rdx,8), %rcx
movq (%rcx), %rcx
shlq $0x5, %rax
testb $0x20, 0x1c(%rcx,%rax)
jne 0x7498a
addq %rax, %rcx
cmpl $-0x1, 0x8(%rcx)
jne 0x7498a
movq 0x48(%rsp), %rax
movq $0x1, (%rax)
addq 0x8(%rsp), %r14
movq 0x90(%rsp), %rsi
movq %r14, (%rsi)
movl $0x1, %r12d
jmp 0x748ba