// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/ecovlp.cpp
// Function: push_ne_ovlp(ma_hit_t_alloc*, overlap_region_alloc*, unsigned int, All_reads*, asg16_v*)
void push_ne_ovlp(ma_hit_t_alloc* paf, overlap_region_alloc* ov, uint32_t flag, All_reads* R_INF, asg16_v *ec/**, uint64_t qid, UC_Read *qu, UC_Read *tu**/)
{
    // if(qu && tu) {
    //     debug_extract_max_exact_sub(qid, qu, tu);
    // }
    uint64_t k, n; ma_hit_t *z; uint32_t rxs, rxe, rys, rye;
    for (k = n = 0; k < ov->length; k++) {
        if(ov->list[k].is_match == flag) n++;
    }

    if(n > paf->size) {
        paf->size = n;
        REALLOC(paf->buffer, paf->size);
    }

    for (k = paf->length = 0; k < ov->length; k++) {
        if(ov->list[k].is_match == flag) {
            // fprintf(stderr, "@%s\tSN:%.*s(id::%u)\terr::%u\n", flag==1?"SQ":"RQ", (int32_t)Get_NAME_LENGTH((*R_INF), ov->list[k].y_id), Get_NAME((*R_INF), ov->list[k].y_id), ov->list[k].y_id, ov->list[k].non_homopolymer_errors);

            z = &(paf->buffer[paf->length++]);

            z->qns = ov->list[k].x_id;
            z->qns = z->qns << 32;
            z->tn = ov->list[k].y_id;

            z->qns = z->qns | (uint64_t)(ov->list[k].x_pos_s);
            z->qe = ov->list[k].x_pos_e + 1;
            z->ts = ov->list[k].y_pos_s;
            z->te = ov->list[k].y_pos_e + 1;

            ///for overlap_list, the x_strand of all overlaps are 0, so the tmp.rev is the same as the y_strand
            z->rev = ov->list[k].y_pos_strand;

            z->bl = Get_READ_LENGTH((*R_INF), ov->list[k].y_id);
            z->ml = ov->list[k].strong;
            z->no_l_indel = ov->list[k].without_large_indel;

            if(ec) {
                extract_max_exact(&ov->list[k], ec, /**qu, tu,**/ &rxs, &rxe, &rys, &rye);
                z->el = 0;
                // fprintf(stderr, "[M::%s]\tq::[%u,\t%u)\tt::[%u,\t%u)\teq::[%u,\t%u)\tet::[%u,\t%u)\n", __func__, ov->list[k].x_pos_s, ov->list[k].x_pos_e + 1, ov->list[k].y_pos_s, ov->list[k].y_pos_e + 1, rxs, rxe, rys, rye);
                if(rxe > rxs) {
                    z->qns = ov->list[k].x_id;
                    z->qns = z->qns << 32;
                    z->qns = z->qns | (uint64_t)(rxs);
                    z->qe = rxe;
                    z->ts = rys;
                    z->te = rye;

                    z->el = 1;
                }
            }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, 0x20(%rsp)
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %r12
movq 0x10(%rsi), %rcx
pushq $0x2c
popq %rdx
xorl %eax, %eax
subq $0x1, %rcx
jb 0x143270
movq (%r14), %rsi
movzbl (%rsi,%rdx), %esi
xorl %edi, %edi
cmpl %ebp, %esi
sete %dil
addq %rdi, %rax
addq $0xa8, %rdx
jmp 0x14324f
movl 0x8(%r12), %ecx
cmpq %rcx, %rax
jbe 0x143298
movl %eax, 0x8(%r12)
movq (%r12), %rdi
movl %eax, %eax
imulq $0x28, %rax, %rsi
movq %r8, %rbx
callq 0x2370
movq %rbx, %r8
movq %rax, (%r12)
andl $0x0, 0xc(%r12)
xorl %r13d, %r13d
xorl %r15d, %r15d
movq %r14, 0x18(%rsp)
cmpq 0x10(%r14), %r15
jae 0x143410
movq (%r14), %rcx
movzbl 0x2c(%rcx,%r13), %eax
cmpl %ebp, %eax
jne 0x143401
movq (%r12), %rbx
movl 0xc(%r12), %eax
leal 0x1(%rax), %edx
movl %edx, 0xc(%r12)
imulq $0x28, %rax, %rax
movl (%rcx,%r13), %edx
movl 0x4(%rcx,%r13), %esi
shlq $0x20, %rdx
orq %rdx, %rsi
movq %rsi, (%rbx,%rax)
movl 0x8(%rcx,%r13), %edx
incl %edx
movl %edx, 0x8(%rbx,%rax)
movq 0x10(%rcx,%r13), %rdx
movq %rdx, 0xc(%rbx,%rax)
movl 0x18(%rcx,%r13), %edx
incl %edx
movl %edx, 0x14(%rbx,%rax)
movl 0x1c(%rcx,%r13), %edx
shll $0x1f, %edx
movq 0x18(%rbx,%rax), %rcx
movabsq $-0x80000001, %rsi      # imm = 0xFFFFFFFF7FFFFFFF
andq %rsi, %rcx
orq %rdx, %rcx
movq %rcx, 0x18(%rbx,%rax)
movq 0x20(%rsp), %rdx
movq 0x18(%rdx), %rdx
movq (%r14), %rsi
movl 0x10(%rsi,%r13), %esi
movq (%rdx,%rsi,8), %rdx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
shlq $0x20, %rdx
movabsq $-0x7fffffff00000001, %rsi # imm = 0x80000000FFFFFFFF
andq %rsi, %rcx
orq %rdx, %rcx
movq %rcx, 0x18(%rbx,%rax)
movq (%r14), %rdx
movzbl 0x2e(%rdx,%r13), %edx
andl $0x1, %edx
shll $0x1e, %edx
andq $-0x40000001, %rcx      # imm = 0xBFFFFFFF
orq %rdx, %rcx
movq %rcx, 0x18(%rbx,%rax)
movq (%r14), %rdi
movb 0x2d(%rdi,%r13), %cl
movb %cl, 0x21(%rbx,%rax)
testq %r8, %r8
je 0x143401
addq %rax, %rbx
addq %r13, %rdi
movq %r8, %rsi
leaq 0x14(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movl %ebp, %r14d
movq %r12, %rbp
movq %r8, %r12
leaq 0xc(%rsp), %r8
leaq 0x8(%rsp), %r9
callq 0x143002
movq %r12, %r8
movq %rbp, %r12
movl %r14d, %ebp
movq 0x18(%rsp), %r14
movb $0x0, 0x20(%rbx)
movl 0x10(%rsp), %eax
movl 0x14(%rsp), %ecx
cmpl %ecx, %eax
jbe 0x143401
movq (%r14), %rdx
movl (%rdx,%r13), %edx
shlq $0x20, %rdx
orq %rcx, %rdx
movq %rdx, (%rbx)
movl %eax, 0x8(%rbx)
movl 0xc(%rsp), %eax
movl %eax, 0x10(%rbx)
movl 0x8(%rsp), %eax
movl %eax, 0x14(%rbx)
movb $0x1, 0x20(%rbx)
incq %r15
addq $0xa8, %r13
jmp 0x1432a9
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq