// File: /workspace/github_cpp_makefile_star2_O1/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, %r15
movq 0x10(%rsi), %rcx
testq %rcx, %rcx
je 0x1803b1
movq (%r15), %rdx
addq $0x2c, %rdx
xorl %eax, %eax
movzbl (%rdx), %esi
xorl %r9d, %r9d
cmpl %ebp, %esi
sete %r9b
addq %r9, %rax
addq $0xa8, %rdx
decq %rcx
jne 0x180394
jmp 0x1803b3
xorl %eax, %eax
movl 0x8(%rdi), %ecx
cmpq %rcx, %rax
movq %rdi, 0x10(%rsp)
jbe 0x1803e3
movl %eax, 0x8(%rdi)
movq (%rdi), %rdi
movl %eax, %eax
shlq $0x3, %rax
leaq (%rax,%rax,4), %rsi
movq %r8, %rbx
callq 0x2370
movq 0x10(%rsp), %rdi
movq %rbx, %r8
movq %rax, (%rdi)
movl $0x0, 0xc(%rdi)
cmpq $0x0, 0x10(%r15)
je 0x180571
xorl %r14d, %r14d
xorl %ebx, %ebx
movq %r15, 0x18(%rsp)
movq (%r15), %rdx
movzbl 0x2c(%rdx,%r14), %eax
cmpl %ebp, %eax
jne 0x18055d
movq (%rdi), %rax
movl 0xc(%rdi), %ecx
leal 0x1(%rcx), %esi
movl %esi, 0xc(%rdi)
leaq (%rcx,%rcx,4), %rcx
movl (%rdx,%r14), %esi
shlq $0x20, %rsi
movq %rsi, (%rax,%rcx,8)
movl 0x10(%rdx,%r14), %r9d
movl %r9d, 0xc(%rax,%rcx,8)
movl 0x4(%rdx,%r14), %r9d
orq %rsi, %r9
movq %r9, (%rax,%rcx,8)
movl 0x8(%rdx,%r14), %esi
incl %esi
movl %esi, 0x8(%rax,%rcx,8)
movl 0x14(%rdx,%r14), %esi
movl %esi, 0x10(%rax,%rcx,8)
movl 0x18(%rdx,%r14), %esi
incl %esi
movl %esi, 0x14(%rax,%rcx,8)
movl 0x1c(%rdx,%r14), %esi
shll $0x1f, %esi
movq 0x18(%rax,%rcx,8), %rdx
movabsq $-0x80000001, %r9       # imm = 0xFFFFFFFF7FFFFFFF
andq %r9, %rdx
orq %rsi, %rdx
movq %rdx, 0x18(%rax,%rcx,8)
movq 0x20(%rsp), %rsi
movq 0x18(%rsi), %rsi
movq (%r15), %r9
movl 0x10(%r9,%r14), %r9d
movq (%rsi,%r9,8), %rsi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
shlq $0x20, %rsi
movabsq $-0x7fffffff00000001, %r9 # imm = 0x80000000FFFFFFFF
andq %r9, %rdx
orq %rsi, %rdx
movq %rdx, 0x18(%rax,%rcx,8)
movq (%r15), %rsi
movzbl 0x2e(%rsi,%r14), %esi
andl $0x1, %esi
shll $0x1e, %esi
andq $-0x40000001, %rdx      # imm = 0xBFFFFFFF
orq %rsi, %rdx
movq %rdx, 0x18(%rax,%rcx,8)
movq (%r15), %r13
movb 0x2d(%r13,%r14), %dl
movb %dl, 0x21(%rax,%rcx,8)
testq %r8, %r8
je 0x18055d
leaq (%rax,%rcx,8), %r12
addq %r14, %r13
movq %r13, %rdi
movq %r8, %rsi
leaq 0xc(%rsp), %rdx
leaq 0x8(%rsp), %rcx
movl %ebp, %r15d
movq %r8, %rbp
leaq 0x4(%rsp), %r8
movq %rsp, %r9
callq 0x1800e0
movq 0x10(%rsp), %rdi
movq %rbp, %r8
movl %r15d, %ebp
movq 0x18(%rsp), %r15
movb $0x0, 0x20(%r12)
movl 0x8(%rsp), %eax
movl 0xc(%rsp), %ecx
cmpl %ecx, %eax
jbe 0x18055d
movl (%r13), %edx
shlq $0x20, %rdx
orq %rcx, %rdx
movq %rdx, (%r12)
movl %eax, 0x8(%r12)
movl 0x4(%rsp), %eax
movl %eax, 0x10(%r12)
movl (%rsp), %eax
movl %eax, 0x14(%r12)
movb $0x1, 0x20(%r12)
incq %rbx
addq $0xa8, %r14
cmpq 0x10(%r15), %rbx
jb 0x1803ff
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq