// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Correct.cpp
// Function: gen_mask_ovlp0(ma_ug_t*, overlap_region*, unsigned int, unsigned int, kv_ul_ov_t*, kv_ul_ov_t*, idx_emask_t*, double, long, unsigned long, asg64_v*, asg64_v*, long, ul_ov_t*)
uint32_t gen_mask_ovlp0(ma_ug_t *ug, overlap_region *a, uint32_t qi, uint32_t ti, kv_ul_ov_t *ov_db, kv_ul_ov_t *buf, idx_emask_t *mm, double len_diff, int64_t rlen, uint64_t ovdb_idx, asg64_v *coor_srt, 
asg64_v* buf1, int64_t bd, ul_ov_t *res)
{
    ul_ov_t *ref, r0, r1; uint32_t bn = buf->n, s, e; uint64_t is_exact = 0; 
    overlap_region *q = &(a[qi]), *t = &(a[ti]); int64_t dd = 0;
    assert(q->y_id < t->y_id); 
    assert(ovdb_idx < ov_db->n);///quickly jump to the related qn-tn pair ov_db[]
    cal_x_ul_ovlp(ug, q, t, &r0); 
    r1 = r0; 
    r1.qn = r0.tn; r1.tn = r0.qn;
    r1.qs = r0.ts; r1.qe = r0.te;
    r1.ts = r0.qs; r1.te = r0.qe;

    if((ov_db->a[ovdb_idx].qn==q->y_id) && (ov_db->a[ovdb_idx].tn==t->y_id)) {
        ref = &(r0); s = ovdb_idx; e = q->overlapLen+q->x_pos_strand;
        if((s!=((uint32_t)-1))&&(e > s)) push_consist_ul_ovlps(ug, ov_db, s, e, len_diff, ref, mm, buf, 0, &is_exact);

        if(!is_exact) {
            ref = &(r1); s = t->overlapLen; e = t->overlapLen+t->x_pos_strand;
            if((s!=((uint32_t)-1))&&(e > s)) push_consist_ul_ovlps(ug, ov_db, s, e, len_diff, ref, mm, buf, 1, &is_exact);
        }
    } else {
        assert((ov_db->a[ovdb_idx].tn==q->y_id) && (ov_db->a[ovdb_idx].qn==t->y_id));
        ref = &(r1); s = ovdb_idx; e = t->overlapLen+t->x_pos_strand;
        if((s!=((uint32_t)-1))&&(e > s)) push_consist_ul_ovlps(ug, ov_db, s, e, len_diff, ref, mm, buf, 1, &is_exact);

        if(!is_exact) {
            ref = &(r0); s = q->overlapLen; e = q->overlapLen+q->x_pos_strand;
            if((s!=((uint32_t)-1))&&(e > s)) push_consist_ul_ovlps(ug, ov_db, s, e, len_diff, ref, mm, buf, 0, &is_exact);
        }
    }
    // prt_masks(ug, buf->a + bn, buf->n - bn);
    ///p->qn/p->tn:: id within the ol->list
    ///p->el:: if equally best
    ///p->qs:: err(query)-err(target)
    ///p->ts:: err(target)-err(query)
    ref = &(r0); 
    res->qn = qi; res->tn = ti;
    res->el = 1; res->qs = res->ts = 0;
    if(!is_exact) {
        assert(buf->n > bn);
        dd = cal_paired_distance(ug, q, t, buf->a + bn, buf->n - bn, coor_srt, buf1, mm, bd);
        if(dd != 0) {
            res->el = 0;
            if(dd > 0) {///q has more error than t
                res->qs = dd; res->ts = 0;
            } else {
                res->qs = 0; res->ts = -dd;
            }
        }
    }
    buf->n = bn;
    if(dd!=INT32_MIN) return 1;
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movsd %xmm0, 0x18(%rsp)
movq %r8, %r14
movq 0x8(%r9), %r8
andq $0x0, 0x10(%rsp)
movl %edx, %eax
imulq $0xa8, %rax, %r15
movl %ecx, %eax
imulq $0xa8, %rax, %r12
movl 0x10(%rsi,%r15), %eax
cmpl 0x10(%rsi,%r12), %eax
jae 0x44770
movl %edx, 0x20(%rsp)
movl %ecx, 0x24(%rsp)
movq %r8, 0x28(%rsp)
movq 0xc0(%rsp), %r13
cmpq %r13, 0x8(%r14)
jbe 0x4478f
movq %r9, %rbx
addq %rsi, %r15
addq %rsi, %r12
leaq 0x50(%rsp), %rbp
movq %rdi, 0x8(%rsp)
movq %r15, %rsi
movq %r12, %rdx
movq %rbp, %rcx
callq 0x421df
movaps (%rbp), %xmm0
movaps %xmm0, 0x30(%rsp)
movups 0xc(%rbp), %xmm0
movups %xmm0, 0x3c(%rsp)
movl 0xc(%rbp), %eax
movl %eax, 0x30(%rsp)
movsd 0x10(%rbp), %xmm0
unpcklpd (%rbp), %xmm0           # xmm0 = xmm0[0],mem[0]
movups %xmm0, 0x34(%rsp)
movl 0x8(%rbp), %eax
movl %eax, 0x44(%rsp)
movq (%r14), %rcx
imulq $0x1c, %r13, %rdx
movl (%rcx,%rdx), %eax
movl 0xc(%rcx,%rdx), %ecx
movl 0x10(%r15), %edx
cmpl %edx, %eax
jne 0x445c4
cmpl 0x10(%r12), %ecx
jne 0x445c4
cmpl $-0x1, %r13d
movq 0xb0(%rsp), %rbp
je 0x44574
movl 0xc(%r15), %eax
addl 0x20(%r15), %eax
cmpl %r13d, %eax
jbe 0x44574
movl %r13d, %edx
movl %eax, %ecx
subq $0x8, %rsp
leaq 0x18(%rsp), %r13
leaq 0x58(%rsp), %r8
movq 0x10(%rsp), %rdi
movq %r14, %rsi
movsd 0x20(%rsp), %xmm0
movq %rbp, %r9
pushq %r13
pushq $0x0
pushq %rbx
callq 0x427e7
addq $0x20, %rsp
cmpq $0x0, (%r13)
jne 0x4467c
movl 0x20(%r12), %ecx
movl 0xc(%r12), %eax
addl %ecx, %eax
cmpl $-0x1, %ecx
setne %dl
cmpl %ecx, %eax
seta %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0x4467c
movl %ecx, %edx
movl %eax, %ecx
subq $0x8, %rsp
leaq 0x18(%rsp), %rax
leaq 0x38(%rsp), %r8
movq 0x10(%rsp), %rdi
movq %r14, %rsi
movsd 0x20(%rsp), %xmm0
movq %rbp, %r9
pushq %rax
pushq $0x1
jmp 0x44672
cmpl %edx, %ecx
jne 0x44751
cmpl 0x10(%r12), %eax
jne 0x44751
cmpl $-0x1, %r13d
movq 0xb0(%rsp), %rbp
je 0x4462d
movl 0xc(%r12), %eax
addl 0x20(%r12), %eax
cmpl %r13d, %eax
jbe 0x4462d
movl %r13d, %edx
movl %eax, %ecx
subq $0x8, %rsp
leaq 0x18(%rsp), %r13
leaq 0x38(%rsp), %r8
movq 0x10(%rsp), %rdi
movq %r14, %rsi
movsd 0x20(%rsp), %xmm0
movq %rbp, %r9
pushq %r13
pushq $0x1
pushq %rbx
callq 0x427e7
addq $0x20, %rsp
cmpq $0x0, (%r13)
jne 0x4467c
movl 0x20(%r15), %ecx
movl 0xc(%r15), %eax
addl %ecx, %eax
cmpl $-0x1, %ecx
setne %dl
cmpl %ecx, %eax
seta %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0x4467c
movl %ecx, %edx
movl %eax, %ecx
subq $0x8, %rsp
leaq 0x18(%rsp), %rax
leaq 0x58(%rsp), %r8
movq 0x10(%rsp), %rdi
movq %r14, %rsi
movsd 0x20(%rsp), %xmm0
movq %rbp, %r9
pushq %rax
pushq $0x0
pushq %rbx
callq 0x427e7
addq $0x20, %rsp
movq 0xe0(%rsp), %r13
movl 0x20(%rsp), %eax
movl %eax, (%r13)
movl 0x24(%rsp), %eax
movl %eax, 0xc(%r13)
orb $0x40, 0x1b(%r13)
andl $0x0, 0x10(%r13)
andl $0x0, 0x4(%r13)
cmpq $0x0, 0x10(%rsp)
je 0x446c8
movl 0x28(%rsp), %r14d
movq %r14, 0x8(%rbx)
pushq $0x1
popq %rcx
movl %ecx, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rbx), %r8
movq 0x28(%rsp), %rax
movl %eax, %r14d
cmpq %r14, %r8
jbe 0x447ae
movq 0xc8(%rsp), %r9
imulq $0x1c, %r14, %rcx
addq (%rbx), %rcx
subl %eax, %r8d
subq $0x8, %rsp
movq 0x10(%rsp), %rdi
movq %r15, %rsi
movq %r12, %rdx
pushq 0xe0(%rsp)
pushq %rbp
pushq 0xe8(%rsp)
callq 0x43f47
addq $0x20, %rsp
testq %rax, %rax
je 0x446b0
andb $-0x41, 0x1b(%r13)
testq %rax, %rax
jle 0x44730
movl %eax, 0x4(%r13)
andl $0x0, 0x10(%r13)
jmp 0x446b0
andl $0x0, 0x4(%r13)
movl %eax, %ecx
negl %ecx
movl %ecx, 0x10(%r13)
xorl %ecx, %ecx
cmpq $-0x80000000, %rax      # imm = 0x80000000
setne %cl
movq %r14, 0x8(%rbx)
jmp 0x446b7
leaq 0x1a2015(%rip), %rdi    # 0x1e676d
leaq 0x19ef44(%rip), %rsi    # 0x1e36a3
leaq 0x1a1f3a(%rip), %rcx    # 0x1e66a0
movl $0x532c, %edx           # imm = 0x532C
callq 0x2110
leaq 0x1a1f17(%rip), %rdi    # 0x1e668e
leaq 0x19ef25(%rip), %rsi    # 0x1e36a3
leaq 0x1a1f1b(%rip), %rcx    # 0x1e66a0
movl $0x531b, %edx           # imm = 0x531B
callq 0x2110
leaq 0x1a1fc3(%rip), %rdi    # 0x1e6759
leaq 0x19ef06(%rip), %rsi    # 0x1e36a3
leaq 0x1a1efc(%rip), %rcx    # 0x1e66a0
movl $0x531c, %edx           # imm = 0x531C
callq 0x2110
leaq 0x1a1ffd(%rip), %rdi    # 0x1e67b2
leaq 0x19eee7(%rip), %rsi    # 0x1e36a3
leaq 0x1a1edd(%rip), %rcx    # 0x1e66a0
movl $0x533e, %edx           # imm = 0x533E
callq 0x2110