// File: /workspace/github_cpp_makefile_star2_O3/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
movq $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 0x7696d
movl %edx, 0x20(%rsp)
movl %ecx, 0x24(%rsp)
movq %r8, 0x28(%rsp)
movq 0xc0(%rsp), %r13
cmpq %r13, 0x8(%r14)
jbe 0x7698c
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 0x742e4
movaps (%rbp), %xmm0
movaps %xmm0, 0x30(%rsp)
movups 0xc(%rbp), %xmm0
movups %xmm0, 0x3c(%rsp)
movl 0xc(%rbp), %eax
movsd 0x10(%rbp), %xmm0
unpcklpd (%rbp), %xmm0           # xmm0 = xmm0[0],mem[0]
movl %eax, 0x30(%rsp)
movups %xmm0, 0x34(%rsp)
movl 0x8(%rbp), %eax
movl %eax, 0x44(%rsp)
movq (%r14), %rcx
leaq (,%r13,8), %rax
addq %r13, %rax
leaq (%rax,%rax,2), %rdx
addq %r13, %rdx
movl (%rcx,%rdx), %eax
movl 0xc(%rcx,%rdx), %ecx
movl 0x10(%r15), %edx
cmpl %edx, %eax
jne 0x767af
cmpl 0x10(%r12), %ecx
jne 0x767af
cmpl $-0x1, %r13d
movq 0xb0(%rsp), %rbp
je 0x7675f
movl 0xc(%r15), %eax
addl 0x20(%r15), %eax
cmpl %r13d, %eax
jbe 0x7675f
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 0x749a5
addq $0x20, %rsp
cmpq $0x0, (%r13)
jne 0x76867
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 0x76867
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 0x7685d
cmpl %edx, %ecx
jne 0x7694e
cmpl 0x10(%r12), %eax
jne 0x7694e
cmpl $-0x1, %r13d
movq 0xb0(%rsp), %rbp
je 0x76818
movl 0xc(%r12), %eax
addl 0x20(%r12), %eax
cmpl %r13d, %eax
jbe 0x76818
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 0x749a5
addq $0x20, %rsp
cmpq $0x0, (%r13)
jne 0x76867
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 0x76867
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 0x749a5
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)
xorl %eax, %eax
movl %eax, 0x10(%r13)
movl %eax, 0x4(%r13)
cmpq $0x0, 0x10(%rsp)
je 0x768b5
movl 0x28(%rsp), %r14d
movq %r14, 0x8(%rbx)
movl $0x1, %ecx
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), %rdx
movl %edx, %r14d
cmpq %r14, %r8
jbe 0x769ab
movq 0xc8(%rsp), %r9
leaq (%r14,%r14,8), %rax
leaq (%rax,%rax,2), %rcx
addq %r14, %rcx
addq (%rbx), %rcx
subl %edx, %r8d
subq $0x8, %rsp
movq 0x10(%rsp), %rdi
movq %r15, %rsi
movq %r12, %rdx
pushq 0xe0(%rsp)
pushq %rbp
pushq 0xe8(%rsp)
callq 0x761b0
addq $0x20, %rsp
testq %rax, %rax
je 0x7689b
andb $-0x41, 0x1b(%r13)
testq %rax, %rax
jle 0x7692a
movl %eax, 0x4(%r13)
movl $0x0, 0x10(%r13)
jmp 0x7689b
movl $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 0x768a4
leaq 0x1bdec8(%rip), %rdi    # 0x23481d
leaq 0x1badf7(%rip), %rsi    # 0x231753
leaq 0x1bdded(%rip), %rcx    # 0x234750
movl $0x532c, %edx           # imm = 0x532C
callq 0x2110
leaq 0x1bddca(%rip), %rdi    # 0x23473e
leaq 0x1badd8(%rip), %rsi    # 0x231753
leaq 0x1bddce(%rip), %rcx    # 0x234750
movl $0x531b, %edx           # imm = 0x531B
callq 0x2110
leaq 0x1bde76(%rip), %rdi    # 0x234809
leaq 0x1badb9(%rip), %rsi    # 0x231753
leaq 0x1bddaf(%rip), %rcx    # 0x234750
movl $0x531c, %edx           # imm = 0x531C
callq 0x2110
leaq 0x1bdeb0(%rip), %rdi    # 0x234862
leaq 0x1bad9a(%rip), %rsi    # 0x231753
leaq 0x1bdd90(%rip), %rcx    # 0x234750
movl $0x533e, %edx           # imm = 0x533E
callq 0x2110