// File: /workspace/github_cpp_makefile_star2_O2/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
movq %xmm0, 0x30(%rsp)
movq %r8, 0x20(%rsp)
movq %rcx, 0x48(%rsp)
movq %rdx, %r15
movq %rsi, %rbx
andq $0x0, (%r9)
movq 0x90(%rsp), %rax
orq $-0x1, (%rax)
movq %rsp, %rcx
movq %rdi, 0x28(%rsp)
callq 0x421df
testq %rax, %rax
je 0x42777
movq %r15, 0x38(%rsp)
movq %r14, 0x40(%rsp)
movl 0xc(%rbx), %ebp
testq %rbp, %rbp
je 0x42576
movl 0x20(%rbx), %ecx
movl 0xc(%rsp), %r13d
movq 0x48(%rsp), %rax
movq (%rax), %rax
movq %rcx, 0x50(%rsp)
imulq $0x1c, %rcx, %rcx
leaq (%rax,%rcx), %r12
addq %rcx, %rax
addq $0xc, %rax
xorl %r14d, %r14d
cmpq %r14, %rbp
je 0x42426
cmpl %r13d, (%rax)
jae 0x42429
incq %r14
addq $0x1c, %rax
jmp 0x42413
movq %rbp, %r14
cmpq %rbp, %r14
jae 0x42576
imulq $0x1c, %r14, %rbx
cmpl %r13d, 0xc(%r12,%rbx)
jne 0x42576
addq %r12, %rbx
movq 0x28(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movl (%rsp), %ecx
movl 0xc(%rsp), %esi
movl (%rax,%rcx,8), %edx
movl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
andq %rdi, %rdx
movl (%rax,%rsi,8), %ecx
andq %rdi, %rcx
movq %rsp, %rdi
movq %rbx, %rsi
movq 0x30(%rsp), %xmm0
callq 0x17eb54
testq %rax, %rax
je 0x42568
leaq 0x1(%r14), %r15
cmpq %rbp, %r15
jae 0x425e6
imulq $0x1c, %r15, %rsi
movl (%r12,%rsi), %ecx
cmpl (%rbx), %ecx
jne 0x425e6
addq %r12, %rsi
movl 0xc(%rsi), %eax
cmpl 0xc(%rbx), %eax
jne 0x425e6
movl 0x18(%rsi), %eax
movl 0x18(%rbx), %edx
movl %edx, %edi
xorl %eax, %edi
js 0x425e6
movl $0x3fffffff, %edi       # imm = 0x3FFFFFFF
andq %rdi, %rax
andq %rdi, %rdx
leal 0x1(%rdx), %edi
cmpl %edi, %eax
jne 0x425e6
movq 0x20(%rsp), %rdi
movq (%rdi), %rdi
imulq $0x18, %rcx, %rcx
movq 0x8(%rdi,%rcx), %r8
cmpq %rdx, %r8
jbe 0x425e6
cmpq %rax, %r8
jbe 0x425e6
addq %rcx, %rdi
movq (%rdi), %rcx
shlq $0x5, %rdx
movb 0x1c(%rcx,%rdx), %dl
testb $0x20, %dl
je 0x425e6
testb $0x1f, %dl
jne 0x425e6
shlq $0x5, %rax
movb 0x1c(%rcx,%rax), %al
andb $0x3f, %al
cmpb $0x21, %al
jne 0x425e6
movq 0x28(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movl (%rsp), %ecx
movl 0xc(%rsp), %edi
movl (%rax,%rcx,8), %edx
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
andq %r8, %rdx
movl (%rax,%rdi,8), %ecx
andq %r8, %rcx
movq %rsp, %rdi
movq 0x30(%rsp), %xmm0
callq 0x17eb54
movq %r15, %r14
testq %rax, %rax
je 0x4256b
jmp 0x425e6
movq %r14, %r15
incq %r15
movq %r15, %r14
jmp 0x42429
movl 0x8(%rsp), %eax
movl 0xc(%rsp), %ecx
movq (%rsp), %xmm0
movl %ecx, (%rsp)
movq 0x10(%rsp), %xmm1
punpcklqdq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0]
movdqu %xmm1, 0x4(%rsp)
movl %eax, 0x14(%rsp)
movq 0x38(%rsp), %rax
movl 0xc(%rax), %r13d
testq %r13, %r13
je 0x42777
movl 0x20(%rax), %edx
movq 0x48(%rsp), %rax
movq (%rax), %rax
imulq $0x1c, %rdx, %rcx
leaq (%rax,%rcx), %rbp
movd %xmm0, %r12d
addq %rcx, %rax
addq $0xc, %rax
xorl %r14d, %r14d
movq %rdx, 0x38(%rsp)
cmpq %r14, %r13
je 0x4263b
cmpl %r12d, (%rax)
jae 0x4263e
incq %r14
addq $0x1c, %rax
jmp 0x425d3
imulq $0x1c, %r14, %rax
movl (%r12,%rax), %edx
movl 0x18(%r12,%rax), %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
movq 0x20(%rsp), %rcx
movq (%rcx), %rcx
imulq $0x18, %rdx, %rdx
cmpq %rax, 0x8(%rcx,%rdx)
jbe 0x42631
addq %rdx, %rcx
movq (%rcx), %rcx
shlq $0x5, %rax
testb $0x20, 0x1c(%rcx,%rax)
jne 0x42631
addq %rax, %rcx
cmpl $-0x1, 0x8(%rcx)
jne 0x42631
movq 0x40(%rsp), %rax
movq $0x1, (%rax)
addq 0x50(%rsp), %r14
jmp 0x427ca
movq %r13, %r14
cmpq %r13, %r14
jae 0x42777
imulq $0x1c, %r14, %rbx
cmpl %r12d, 0xc(%rbp,%rbx)
jne 0x42777
addq %rbp, %rbx
movq 0x28(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movl (%rsp), %ecx
movl 0xc(%rsp), %esi
movl (%rax,%rcx,8), %edx
movl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
andq %rdi, %rdx
movl (%rax,%rsi,8), %ecx
andq %rdi, %rcx
movq %rsp, %rdi
movq %rbx, %rsi
movq 0x30(%rsp), %xmm0
callq 0x17eb54
testq %rax, %rax
je 0x42769
leaq 0x1(%r14), %r15
cmpq %r13, %r15
jae 0x4277b
imulq $0x1c, %r15, %rsi
movl (%rbp,%rsi), %ecx
cmpl (%rbx), %ecx
jne 0x4277b
addq %rbp, %rsi
movl 0xc(%rsi), %eax
cmpl 0xc(%rbx), %eax
jne 0x4277b
movl 0x18(%rsi), %eax
movl 0x18(%rbx), %edx
movl %edx, %edi
xorl %eax, %edi
js 0x4277b
movl $0x3fffffff, %edi       # imm = 0x3FFFFFFF
andq %rdi, %rax
andq %rdi, %rdx
leal 0x1(%rdx), %edi
cmpl %edi, %eax
jne 0x4277b
movq 0x20(%rsp), %rdi
movq (%rdi), %rdi
imulq $0x18, %rcx, %rcx
movq 0x8(%rdi,%rcx), %r8
cmpq %rdx, %r8
jbe 0x4277b
cmpq %rax, %r8
jbe 0x4277b
addq %rcx, %rdi
movq (%rdi), %rcx
shlq $0x5, %rdx
movb 0x1c(%rcx,%rdx), %dl
testb $0x20, %dl
je 0x4277b
testb $0x1f, %dl
jne 0x4277b
shlq $0x5, %rax
movb 0x1c(%rcx,%rax), %al
andb $0x3f, %al
cmpb $0x21, %al
jne 0x4277b
movq 0x28(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movl (%rsp), %ecx
movl 0xc(%rsp), %edi
movl (%rax,%rcx,8), %edx
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
andq %r8, %rdx
movl (%rax,%rdi,8), %ecx
andq %r8, %rcx
movq %rsp, %rdi
movq 0x30(%rsp), %xmm0
callq 0x17eb54
movq %r15, %r14
testq %rax, %rax
je 0x4276c
jmp 0x4277b
movq %r14, %r15
incq %r15
movq %r15, %r14
jmp 0x4263e
xorl %eax, %eax
jmp 0x427d8
imulq $0x1c, %r14, %rax
movl (%rbp,%rax), %edx
movl 0x18(%rbp,%rax), %eax
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
movq 0x20(%rsp), %rcx
movq (%rcx), %rcx
imulq $0x18, %rdx, %rdx
cmpq %rax, 0x8(%rcx,%rdx)
jbe 0x427c5
addq %rdx, %rcx
movq (%rcx), %rcx
shlq $0x5, %rax
testb $0x20, 0x1c(%rcx,%rax)
jne 0x427c5
addq %rax, %rcx
cmpl $-0x1, 0x8(%rcx)
jne 0x427c5
movq 0x40(%rsp), %rax
movq $0x1, (%rax)
addq 0x38(%rsp), %r14
movq 0x90(%rsp), %rax
movq %r14, (%rax)
pushq $0x1
popq %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq