// File: 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
movq %rsp, %rbp
subq $0xd0, %rsp
movq 0x40(%rbp), %rax
movq 0x38(%rbp), %rax
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movsd %xmm0, -0x38(%rbp)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movl %eax, -0x7c(%rbp)
movq $0x0, -0x90(%rbp)
movq -0x18(%rbp), %rax
movl -0x1c(%rbp), %ecx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x98(%rbp)
movq -0x18(%rbp), %rax
movl -0x20(%rbp), %ecx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0xa0(%rbp)
movq $0x0, -0xa8(%rbp)
movq -0x98(%rbp), %rax
movl 0x10(%rax), %eax
movq -0xa0(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jae 0x81cab
jmp 0x81cca
leaq 0x303654(%rip), %rdi    # 0x385306
leaq 0x300662(%rip), %rsi    # 0x38231b
movl $0x531b, %edx           # imm = 0x531B
leaq 0x303653(%rip), %rcx    # 0x385318
callq 0x2130
movq 0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x81cda
jmp 0x81cf9
leaq 0x3036f0(%rip), %rdi    # 0x3853d1
leaq 0x300633(%rip), %rsi    # 0x38231b
movl $0x531c, %edx           # imm = 0x531C
leaq 0x303624(%rip), %rcx    # 0x385318
callq 0x2130
movq -0x10(%rbp), %rdi
movq -0x98(%rbp), %rsi
movq -0xa0(%rbp), %rdx
leaq -0x5c(%rbp), %rcx
callq 0x7c4c0
movq -0x5c(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x54(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x4c(%rbp), %rax
movq %rax, -0x68(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0x60(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0x78(%rbp)
movl -0x5c(%rbp), %eax
movl %eax, -0x6c(%rbp)
movl -0x4c(%rbp), %eax
movl %eax, -0x74(%rbp)
movl -0x48(%rbp), %eax
movl %eax, -0x70(%rbp)
movl -0x58(%rbp), %eax
movl %eax, -0x68(%rbp)
movl -0x54(%rbp), %eax
movl %eax, -0x64(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, 0x20(%rbp), %rcx
addq %rcx, %rax
movl (%rax), %eax
movq -0x98(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jne 0x81eb2
movq -0x28(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, 0x20(%rbp), %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
movq -0xa0(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jne 0x81eb2
leaq -0x5c(%rbp), %rax
movq %rax, -0x40(%rbp)
movq 0x20(%rbp), %rax
movl %eax, -0x80(%rbp)
movq -0x98(%rbp), %rax
movl 0x20(%rax), %eax
movq -0x98(%rbp), %rcx
addl 0xc(%rcx), %eax
movl %eax, -0x84(%rbp)
cmpl $-0x1, -0x80(%rbp)
je 0x81e19
movl -0x84(%rbp), %eax
cmpl -0x80(%rbp), %eax
jbe 0x81e19
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
movl -0x80(%rbp), %eax
movl %eax, %edx
movl -0x84(%rbp), %eax
movl %eax, %ecx
movsd -0x38(%rbp), %xmm0
movq -0x40(%rbp), %r8
movq 0x10(%rbp), %r9
movq -0x30(%rbp), %r10
xorl %eax, %eax
leaq -0x90(%rbp), %rax
movq %r10, (%rsp)
movq $0x0, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x7d300
cmpq $0x0, -0x90(%rbp)
jne 0x81ead
leaq -0x78(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0xa0(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0x80(%rbp)
movq -0xa0(%rbp), %rax
movl 0x20(%rax), %eax
movq -0xa0(%rbp), %rcx
addl 0xc(%rcx), %eax
movl %eax, -0x84(%rbp)
cmpl $-0x1, -0x80(%rbp)
je 0x81eab
movl -0x84(%rbp), %eax
cmpl -0x80(%rbp), %eax
jbe 0x81eab
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
movl -0x80(%rbp), %eax
movl %eax, %edx
movl -0x84(%rbp), %eax
movl %eax, %ecx
movsd -0x38(%rbp), %xmm0
movq -0x40(%rbp), %r8
movq 0x10(%rbp), %r9
movq -0x30(%rbp), %r10
leaq -0x90(%rbp), %rax
movq %r10, (%rsp)
movq $0x1, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x7d300
jmp 0x81ead
jmp 0x8203f
movq -0x28(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, 0x20(%rbp), %rcx
addq %rcx, %rax
movl 0xc(%rax), %ecx
movq -0x98(%rbp), %rdx
xorl %eax, %eax
cmpl 0x10(%rdx), %ecx
movb %al, -0xa9(%rbp)
jne 0x81efc
movq -0x28(%rbp), %rax
movq (%rax), %rax
imulq $0x1c, 0x20(%rbp), %rcx
addq %rcx, %rax
movl (%rax), %eax
movq -0xa0(%rbp), %rcx
cmpl 0x10(%rcx), %eax
sete %al
movb %al, -0xa9(%rbp)
movb -0xa9(%rbp), %al
testb $0x1, %al
jne 0x81f08
jmp 0x81f0a
jmp 0x81f29
leaq 0x3034d4(%rip), %rdi    # 0x3853e5
leaq 0x300403(%rip), %rsi    # 0x38231b
movl $0x532c, %edx           # imm = 0x532C
leaq 0x3033f4(%rip), %rcx    # 0x385318
callq 0x2130
leaq -0x78(%rbp), %rax
movq %rax, -0x40(%rbp)
movq 0x20(%rbp), %rax
movl %eax, -0x80(%rbp)
movq -0xa0(%rbp), %rax
movl 0x20(%rax), %eax
movq -0xa0(%rbp), %rcx
addl 0xc(%rcx), %eax
movl %eax, -0x84(%rbp)
cmpl $-0x1, -0x80(%rbp)
je 0x81fa7
movl -0x84(%rbp), %eax
cmpl -0x80(%rbp), %eax
jbe 0x81fa7
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
movl -0x80(%rbp), %eax
movl %eax, %edx
movl -0x84(%rbp), %eax
movl %eax, %ecx
movsd -0x38(%rbp), %xmm0
movq -0x40(%rbp), %r8
movq 0x10(%rbp), %r9
movq -0x30(%rbp), %r10
leaq -0x90(%rbp), %rax
movq %r10, (%rsp)
movq $0x1, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x7d300
cmpq $0x0, -0x90(%rbp)
jne 0x8203d
leaq -0x5c(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x98(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0x80(%rbp)
movq -0x98(%rbp), %rax
movl 0x20(%rax), %eax
movq -0x98(%rbp), %rcx
addl 0xc(%rcx), %eax
movl %eax, -0x84(%rbp)
cmpl $-0x1, -0x80(%rbp)
je 0x8203b
movl -0x84(%rbp), %eax
cmpl -0x80(%rbp), %eax
jbe 0x8203b
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
movl -0x80(%rbp), %eax
movl %eax, %edx
movl -0x84(%rbp), %eax
movl %eax, %ecx
movsd -0x38(%rbp), %xmm0
movq -0x40(%rbp), %r8
movq 0x10(%rbp), %r9
movq -0x30(%rbp), %r10
xorl %eax, %eax
leaq -0x90(%rbp), %rax
movq %r10, (%rsp)
movq $0x0, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x7d300
jmp 0x8203d
jmp 0x8203f
leaq -0x5c(%rbp), %rax
movq %rax, -0x40(%rbp)
movl -0x1c(%rbp), %ecx
movq 0x40(%rbp), %rax
movl %ecx, (%rax)
movl -0x20(%rbp), %ecx
movq 0x40(%rbp), %rax
movl %ecx, 0xc(%rax)
movq 0x40(%rbp), %rax
movl 0x18(%rax), %ecx
andl $0xbfffffff, %ecx       # imm = 0xBFFFFFFF
orl $0x40000000, %ecx       # imm = 0x40000000
movl %ecx, 0x18(%rax)
movq 0x40(%rbp), %rax
movl $0x0, 0x10(%rax)
movq 0x40(%rbp), %rax
movl $0x0, 0x4(%rax)
cmpq $0x0, -0x90(%rbp)
jne 0x82189
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x7c(%rbp), %ecx
cmpq %rcx, %rax
jbe 0x820a6
jmp 0x820c5
leaq 0x30337d(%rip), %rdi    # 0x38542a
leaq 0x300267(%rip), %rsi    # 0x38231b
movl $0x533e, %edx           # imm = 0x533E
leaq 0x303258(%rip), %rcx    # 0x385318
callq 0x2130
movq -0x10(%rbp), %rdi
movq -0x98(%rbp), %rsi
movq -0xa0(%rbp), %rdx
movq -0x30(%rbp), %rax
movq (%rax), %rcx
movl -0x7c(%rbp), %eax
imulq $0x1c, %rax, %rax
addq %rax, %rcx
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x7c(%rbp), %r8d
subq %r8, %rax
movl %eax, %r8d
movq 0x28(%rbp), %r9
movq 0x30(%rbp), %r11
movq 0x10(%rbp), %r10
movq 0x38(%rbp), %rax
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x81070
movq %rax, -0xa8(%rbp)
cmpq $0x0, -0xa8(%rbp)
je 0x82187
movq 0x40(%rbp), %rax
movl 0x18(%rax), %ecx
andl $0xbfffffff, %ecx       # imm = 0xBFFFFFFF
orl $0x0, %ecx
movl %ecx, 0x18(%rax)
cmpq $0x0, -0xa8(%rbp)
jle 0x82168
movq -0xa8(%rbp), %rax
movl %eax, %ecx
movq 0x40(%rbp), %rax
movl %ecx, 0x4(%rax)
movq 0x40(%rbp), %rax
movl $0x0, 0x10(%rax)
jmp 0x82185
movq 0x40(%rbp), %rax
movl $0x0, 0x4(%rax)
xorl %eax, %eax
subq -0xa8(%rbp), %rax
movl %eax, %ecx
movq 0x40(%rbp), %rax
movl %ecx, 0x10(%rax)
jmp 0x82187
jmp 0x82189
movl -0x7c(%rbp), %eax
movl %eax, %ecx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
cmpq $-0x80000000, -0xa8(%rbp) # imm = 0x80000000
je 0x821ac
movl $0x1, -0x4(%rbp)
jmp 0x821b3
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xd0, %rsp
popq %rbp
retq
nop