// File: /workspace/github_cpp_makefile_star2_O1/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 $0x68, %rsp
movsd %xmm0, 0x10(%rsp)
movq 0x8(%r9), %rax
movq %rax, 0x40(%rsp)
movq $0x0, (%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 0x76f60
movq %r8, %r14
movl %edx, 0x18(%rsp)
movl %ecx, 0x1c(%rsp)
movq 0xb0(%rsp), %r13
cmpq %r13, 0x8(%r8)
jbe 0x76f7f
movq %r9, %rbx
addq %rsi, %r15
addq %rsi, %r12
leaq 0x4c(%rsp), %rbp
movq %rdi, 0x8(%rsp)
movq %r15, %rsi
movq %r12, %rdx
movq %rbp, %rcx
callq 0x74866
movups (%rbp), %xmm0
movaps %xmm0, 0x20(%rsp)
movups 0xc(%rbp), %xmm0
movups %xmm0, 0x2c(%rsp)
movl 0xc(%rbp), %eax
movl %eax, 0x20(%rsp)
movl (%rbp), %eax
movl %eax, 0x2c(%rsp)
movq 0x10(%rbp), %rax
movq %rax, 0x24(%rsp)
movq 0x4(%rbp), %rax
movq %rax, 0x30(%rsp)
movq (%r14), %rax
leaq (,%r13,8), %rcx
addq %r13, %rcx
leaq (%rcx,%rcx,2), %rdx
addq %r13, %rdx
leaq (%rax,%rdx), %rcx
movl (%rax,%rdx), %eax
movl 0x10(%r15), %edx
cmpl %edx, %eax
jne 0x76da1
movl 0xc(%rcx), %esi
cmpl 0x10(%r12), %esi
jne 0x76da1
cmpl $-0x1, %r13d
je 0x76d41
movl 0xc(%r15), %eax
addl 0x20(%r15), %eax
cmpl %r13d, %eax
jbe 0x76d41
movl %r13d, %edx
movl %eax, %ecx
subq $0x8, %rsp
leaq 0x8(%rsp), %rax
leaq 0x54(%rsp), %r8
movq 0x10(%rsp), %rdi
movq %r14, %rsi
movsd 0x18(%rsp), %xmm0
movq 0xa8(%rsp), %r9
pushq %rax
pushq $0x0
pushq %rbx
callq 0x74f0f
addq $0x20, %rsp
cmpq $0x0, (%rsp)
jne 0x76e5b
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 0x76e5b
movl %ecx, %edx
movl %eax, %ecx
subq $0x8, %rsp
leaq 0x8(%rsp), %rax
leaq 0x28(%rsp), %r8
movq 0x10(%rsp), %rdi
movq %r14, %rsi
movsd 0x18(%rsp), %xmm0
movq 0xa8(%rsp), %r9
pushq %rax
pushq $0x1
jmp 0x76e51
cmpl %edx, 0xc(%rcx)
jne 0x76f41
cmpl 0x10(%r12), %eax
jne 0x76f41
cmpl $-0x1, %r13d
je 0x76e00
movl 0xc(%r12), %eax
addl 0x20(%r12), %eax
cmpl %r13d, %eax
jbe 0x76e00
movl %r13d, %edx
movl %eax, %ecx
subq $0x8, %rsp
leaq 0x8(%rsp), %rax
leaq 0x28(%rsp), %r8
movq 0x10(%rsp), %rdi
movq %r14, %rsi
movsd 0x18(%rsp), %xmm0
movq 0xa8(%rsp), %r9
pushq %rax
pushq $0x1
pushq %rbx
callq 0x74f0f
addq $0x20, %rsp
cmpq $0x0, (%rsp)
jne 0x76e5b
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 0x76e5b
movl %ecx, %edx
movl %eax, %ecx
subq $0x8, %rsp
leaq 0x8(%rsp), %rax
leaq 0x54(%rsp), %r8
movq 0x10(%rsp), %rdi
movq %r14, %rsi
movsd 0x18(%rsp), %xmm0
movq 0xa8(%rsp), %r9
pushq %rax
pushq $0x0
pushq %rbx
callq 0x74f0f
addq $0x20, %rsp
movq 0xd0(%rsp), %r14
movl 0x18(%rsp), %eax
movl %eax, (%r14)
movl 0x1c(%rsp), %eax
movl %eax, 0xc(%r14)
orb $0x40, 0x1b(%r14)
xorl %eax, %eax
movl %eax, 0x10(%r14)
movl %eax, 0x4(%r14)
movl $0x1, %ebp
cmpq $0x0, (%rsp)
movq 0x40(%rsp), %r13
je 0x76eaa
movl %r13d, %eax
movq %rax, 0x8(%rbx)
movl %ebp, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rbx), %r8
movl %r13d, %eax
cmpq %rax, %r8
jbe 0x76f9e
movq 0xb8(%rsp), %r9
leaq (%rax,%rax,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rax, %rcx
addq (%rbx), %rcx
subl %r13d, %r8d
subq $0x8, %rsp
movq 0x10(%rsp), %rdi
movq %r15, %rsi
movq %r12, %rdx
pushq 0xd0(%rsp)
pushq 0xb0(%rsp)
pushq 0xd8(%rsp)
callq 0x767c0
addq $0x20, %rsp
testq %rax, %rax
je 0x76e92
andb $-0x41, 0x1b(%r14)
testq %rax, %rax
jle 0x76f20
movl %eax, 0x4(%r14)
movl $0x0, 0x10(%r14)
jmp 0x76e92
movl $0x0, 0x4(%r14)
movl %eax, %ecx
negl %ecx
movl %ecx, 0x10(%r14)
xorl %ebp, %ebp
cmpq $-0x80000000, %rax      # imm = 0x80000000
setne %bpl
jmp 0x76e92
leaq 0x1b17c5(%rip), %rdi    # 0x22870d
leaq 0x1ae6f4(%rip), %rsi    # 0x225643
leaq 0x1b16ea(%rip), %rcx    # 0x228640
movl $0x532c, %edx           # imm = 0x532C
callq 0x2110
leaq 0x1b16c7(%rip), %rdi    # 0x22862e
leaq 0x1ae6d5(%rip), %rsi    # 0x225643
leaq 0x1b16cb(%rip), %rcx    # 0x228640
movl $0x531b, %edx           # imm = 0x531B
callq 0x2110
leaq 0x1b1773(%rip), %rdi    # 0x2286f9
leaq 0x1ae6b6(%rip), %rsi    # 0x225643
leaq 0x1b16ac(%rip), %rcx    # 0x228640
movl $0x531c, %edx           # imm = 0x531C
callq 0x2110
leaq 0x1b17ad(%rip), %rdi    # 0x228752
leaq 0x1ae697(%rip), %rsi    # 0x225643
leaq 0x1b168d(%rip), %rcx    # 0x228640
movl $0x533e, %edx           # imm = 0x533E
callq 0x2110