// File: /workspace/github_cpp_makefile_star2_O1/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, %r14
movsd %xmm0, 0x30(%rsp)
movq %r8, 0x20(%rsp)
movq %rcx, %r13
movq %rdx, %r15
movq %rsi, %rbx
movq 0x90(%rsp), %rax
movq $0x0, (%r9)
movq $-0x1, (%rax)
leaq 0x4(%rsp), %rcx
movq %rdi, 0x28(%rsp)
callq 0x74866
testq %rax, %rax
je 0x74e37
movq %r15, 0x38(%rsp)
movq %r14, 0x40(%rsp)
movl 0xc(%rbx), %r12d
testq %r12, %r12
je 0x74c45
movl 0x20(%rbx), %edx
movl 0x10(%rsp), %r15d
movq (%r13), %rax
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rcx
movq %rdx, 0x48(%rsp)
addq %rdx, %rcx
leaq (%rax,%rcx), %rbp
addq %rcx, %rax
addq $0xc, %rax
xorl %r14d, %r14d
cmpl %r15d, (%rax)
jae 0x74aba
incq %r14
addq $0x1c, %rax
cmpq %r14, %r12
jne 0x74aa6
movq %r12, %r14
cmpq %r12, %r14
jae 0x74c45
movq %r13, 0x50(%rsp)
leaq (%r14,%r14,8), %rax
leaq (%rax,%rax,2), %rbx
addq %r14, %rbx
cmpl %r15d, 0xc(%rbp,%rbx)
jne 0x74c45
addq %rbp, %rbx
movq 0x28(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movl 0x4(%rsp), %ecx
movl 0x10(%rsp), %esi
movl (%rax,%rcx,8), %edx
movl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
andq %rdi, %rdx
movl (%rax,%rsi,8), %ecx
andq %rdi, %rcx
leaq 0x4(%rsp), %rdi
movq %rbx, %rsi
movsd 0x30(%rsp), %xmm0
callq 0x1c09f8
testq %rax, %rax
je 0x74c2e
leaq 0x1(%r14), %r13
cmpq %r12, %r13
jae 0x74e3e
leaq (,%r13,8), %rax
addq %r13, %rax
leaq (%rax,%rax,2), %rsi
addq %r13, %rsi
movl (%rbp,%rsi), %ecx
movl (%rbx), %edx
cmpl %edx, %ecx
jne 0x74e3e
addq %rbp, %rsi
movl 0xc(%rsi), %eax
cmpl 0xc(%rbx), %eax
jne 0x74e3e
movl 0x18(%rsi), %eax
movl 0x18(%rbx), %edi
movl %edi, %r8d
xorl %eax, %r8d
js 0x74e3e
movl $0x3fffffff, %r8d       # imm = 0x3FFFFFFF
andq %r8, %rax
andq %r8, %rdi
leal 0x1(%rdi), %r8d
cmpl %r8d, %eax
jne 0x74e3e
movq 0x20(%rsp), %r8
movq (%r8), %r8
leaq (%rdx,%rdx,2), %rdx
cmpq %rdi, 0x8(%r8,%rdx,8)
jbe 0x74e3e
leaq (%rcx,%rcx,2), %rcx
cmpq %rax, 0x8(%r8,%rcx,8)
jbe 0x74e3e
leaq (%r8,%rdx,8), %rdx
movq (%rdx), %rdx
shlq $0x5, %rdi
movb 0x1c(%rdx,%rdi), %dl
testb $0x20, %dl
je 0x74e3e
testb $0x1f, %dl
jne 0x74e3e
leaq (%r8,%rcx,8), %rcx
movq (%rcx), %rcx
shlq $0x5, %rax
movb 0x1c(%rcx,%rax), %al
andb $0x3f, %al
cmpb $0x21, %al
jne 0x74e3e
movq 0x28(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movl 0x4(%rsp), %ecx
movl 0x10(%rsp), %edi
movl (%rax,%rcx,8), %edx
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
andq %r8, %rdx
movl (%rax,%rdi,8), %ecx
andq %r8, %rcx
leaq 0x4(%rsp), %rdi
movsd 0x30(%rsp), %xmm0
callq 0x1c09f8
movq %r13, %r14
testq %rax, %rax
je 0x74c31
jmp 0x74e3e
movq %r14, %r13
incq %r13
movq %r13, %r14
cmpq %r12, %r13
movq 0x50(%rsp), %r13
jb 0x74ac8
movl 0x4(%rsp), %ebp
movl 0x10(%rsp), %eax
movl %eax, 0x4(%rsp)
movl %ebp, 0x10(%rsp)
movq 0x8(%rsp), %rax
movq 0x14(%rsp), %rcx
movq %rcx, 0x8(%rsp)
movq %rax, 0x14(%rsp)
movq 0x38(%rsp), %rax
movl 0xc(%rax), %r15d
testq %r15, %r15
je 0x74e37
movl 0x20(%rax), %edx
movq (%r13), %rax
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rdx, %rcx
leaq (%rax,%rcx), %r13
addq %rcx, %rax
addq $0xc, %rax
xorl %r14d, %r14d
cmpl %ebp, (%rax)
jae 0x74cae
incq %r14
addq $0x1c, %rax
cmpq %r14, %r15
jne 0x74c9b
movq %r15, %r14
cmpq %r15, %r14
jae 0x74e37
movq %rdx, 0x38(%rsp)
xorl %eax, %eax
leaq (%r14,%r14,8), %rcx
leaq (%rcx,%rcx,2), %rbx
addq %r14, %rbx
cmpl %ebp, 0xc(%r13,%rbx)
jne 0x74f00
addq %r13, %rbx
movq 0x28(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movl 0x4(%rsp), %ecx
movl 0x10(%rsp), %esi
movl (%rax,%rcx,8), %edx
movl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
andq %rdi, %rdx
movl (%rax,%rsi,8), %ecx
andq %rdi, %rcx
leaq 0x4(%rsp), %rdi
movq %rbx, %rsi
movsd 0x30(%rsp), %xmm0
callq 0x1c09f8
testq %rax, %rax
je 0x74e1b
leaq 0x1(%r14), %r12
cmpq %r15, %r12
jae 0x74e97
leaq (%r12,%r12,8), %rax
leaq (%rax,%rax,2), %rsi
addq %r12, %rsi
movl (%r13,%rsi), %ecx
movl (%rbx), %edx
cmpl %edx, %ecx
jne 0x74e97
addq %r13, %rsi
movl 0xc(%rsi), %eax
cmpl 0xc(%rbx), %eax
jne 0x74e97
movl 0x18(%rsi), %eax
movl 0x18(%rbx), %edi
movl %edi, %r8d
xorl %eax, %r8d
js 0x74e97
movl $0x3fffffff, %r8d       # imm = 0x3FFFFFFF
andq %r8, %rax
andq %r8, %rdi
leal 0x1(%rdi), %r8d
cmpl %r8d, %eax
jne 0x74e97
movq 0x20(%rsp), %r8
movq (%r8), %r8
leaq (%rdx,%rdx,2), %rdx
cmpq %rdi, 0x8(%r8,%rdx,8)
jbe 0x74e97
leaq (%rcx,%rcx,2), %rcx
cmpq %rax, 0x8(%r8,%rcx,8)
jbe 0x74e97
leaq (%r8,%rdx,8), %rdx
movq (%rdx), %rdx
shlq $0x5, %rdi
movb 0x1c(%rdx,%rdi), %dl
testb $0x20, %dl
je 0x74e97
testb $0x1f, %dl
jne 0x74e97
leaq (%r8,%rcx,8), %rcx
movq (%rcx), %rcx
shlq $0x5, %rax
movb 0x1c(%rcx,%rax), %al
andb $0x3f, %al
cmpb $0x21, %al
jne 0x74e97
movq 0x28(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movl 0x4(%rsp), %ecx
movl 0x10(%rsp), %edi
movl (%rax,%rcx,8), %edx
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
andq %r8, %rdx
movl (%rax,%rdi,8), %ecx
andq %r8, %rcx
leaq 0x4(%rsp), %rdi
movsd 0x30(%rsp), %xmm0
callq 0x1c09f8
movq %r12, %r14
testq %rax, %rax
je 0x74e1e
jmp 0x74e97
movq %r14, %r12
incq %r12
movq %r12, %r14
cmpq %r15, %r12
movl $0x0, %eax
jb 0x74cbe
jmp 0x74f00
xorl %eax, %eax
jmp 0x74f00
leaq (%r14,%r14,8), %rax
leaq (%rax,%rax,2), %rax
addq %r14, %rax
movl (%rbp,%rax), %edx
movl 0x18(%rbp,%rax), %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
movq 0x20(%rsp), %rcx
movq (%rcx), %rcx
leaq (%rdx,%rdx,2), %rdx
cmpq %rax, 0x8(%rcx,%rdx,8)
jbe 0x74e90
leaq (%rcx,%rdx,8), %rcx
movq (%rcx), %rcx
shlq $0x5, %rax
testb $0x20, 0x1c(%rcx,%rax)
jne 0x74e90
addq %rax, %rcx
cmpl $-0x1, 0x8(%rcx)
jne 0x74e90
movq 0x40(%rsp), %rax
movq $0x1, (%rax)
addq 0x48(%rsp), %r14
jmp 0x74ef0
leaq (%r14,%r14,8), %rax
leaq (%rax,%rax,2), %rax
addq %r14, %rax
movl (%r13,%rax), %edx
movl 0x18(%r13,%rax), %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
movq 0x20(%rsp), %rcx
movq (%rcx), %rcx
leaq (%rdx,%rdx,2), %rdx
cmpq %rax, 0x8(%rcx,%rdx,8)
jbe 0x74eeb
leaq (%rcx,%rdx,8), %rcx
movq (%rcx), %rcx
shlq $0x5, %rax
testb $0x20, 0x1c(%rcx,%rax)
jne 0x74eeb
addq %rax, %rcx
cmpl $-0x1, 0x8(%rcx)
jne 0x74eeb
movq 0x40(%rsp), %rax
movq $0x1, (%rax)
addq 0x38(%rsp), %r14
movq 0x90(%rsp), %rax
movq %r14, (%rax)
movl $0x1, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq