// File: /workspace/github_cpp_makefile_star2_O3/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 $0x38, %rsp
movq %rcx, 0x30(%rsp)
movq %rdi, %r13
movq 0x10(%rsi), %rcx
testq %rcx, %rcx
je 0x18790c
movl %edx, %ebp
movq %rsi, %r12
movq (%rsi), %rdx
addq $0x2c, %rdx
xorl %eax, %eax
movzbl (%rdx), %esi
xorl %edi, %edi
cmpl %ebp, %esi
sete %dil
addq %rdi, %rax
addq $0xa8, %rdx
decq %rcx
jne 0x1878b3
movl 0x8(%r13), %ecx
cmpq %rcx, %rax
jbe 0x187919
movl %eax, 0x8(%r13)
movq (%r13), %rdi
movl %eax, %eax
shlq $0x3, %rax
leaq (%rax,%rax,4), %rsi
movq %r8, %rbx
callq 0x2370
movq %rbx, %r8
movq %rax, (%r13)
cmpq $0x0, 0x10(%r12)
movl $0x0, 0xc(%r13)
jne 0x187921
jmp 0x187a93
movl $0x0, 0xc(%r13)
jmp 0x187a93
movl $0x0, 0xc(%r13)
movq (%r12), %r15
xorl %r14d, %r14d
xorl %ebx, %ebx
movq %r8, 0x28(%rsp)
movl %ebp, 0xc(%rsp)
movq %r13, 0x20(%rsp)
movzbl 0x2c(%r15,%r14), %eax
cmpl %ebp, %eax
jne 0x187a7e
movq (%r13), %rax
movl 0xc(%r13), %ecx
leal 0x1(%rcx), %edx
movl %edx, 0xc(%r13)
leaq (%rcx,%rcx,4), %rcx
movl (%r15,%r14), %edx
movl 0x4(%r15,%r14), %esi
shlq $0x20, %rdx
orq %rdx, %rsi
movq %rsi, (%rax,%rcx,8)
movl 0x8(%r15,%r14), %edx
incl %edx
movl %edx, 0x8(%rax,%rcx,8)
movq 0x10(%r15,%r14), %rdx
movq %rdx, 0xc(%rax,%rcx,8)
movl 0x18(%r15,%r14), %edx
incl %edx
movl %edx, 0x14(%rax,%rcx,8)
movl 0x1c(%r15,%r14), %esi
shll $0x1f, %esi
movq 0x18(%rax,%rcx,8), %rdx
movabsq $-0x80000001, %rdi      # imm = 0xFFFFFFFF7FFFFFFF
andq %rdi, %rdx
orq %rsi, %rdx
movq %rdx, 0x18(%rax,%rcx,8)
movq 0x30(%rsp), %rsi
movq 0x18(%rsi), %rsi
movq (%r12), %rdi
movl 0x10(%rdi,%r14), %edi
movq (%rsi,%rdi,8), %rsi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
shlq $0x20, %rsi
movabsq $-0x7fffffff00000001, %rdi # imm = 0x80000000FFFFFFFF
andq %rdi, %rdx
orq %rsi, %rdx
movq %rdx, 0x18(%rax,%rcx,8)
movq (%r12), %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 (%r12), %r15
movb 0x2d(%r15,%r14), %dl
movb %dl, 0x21(%rax,%rcx,8)
testq %r8, %r8
je 0x187a7e
leaq (%rax,%rcx,8), %rbp
leaq (%r15,%r14), %r13
movq %r13, %rdi
movq %r8, %rsi
leaq 0x1c(%rsp), %rdx
leaq 0x18(%rsp), %rcx
leaq 0x14(%rsp), %r8
leaq 0x10(%rsp), %r9
callq 0x1875df
movb $0x0, 0x20(%rbp)
movl 0x18(%rsp), %eax
movl 0x1c(%rsp), %ecx
cmpl %ecx, %eax
jbe 0x187a70
movl (%r13), %edx
shlq $0x20, %rdx
orq %rcx, %rdx
movq %rdx, (%rbp)
movl %eax, 0x8(%rbp)
movl 0x14(%rsp), %eax
movl %eax, 0x10(%rbp)
movl 0x10(%rsp), %eax
movl %eax, 0x14(%rbp)
movb $0x1, 0x20(%rbp)
movq 0x28(%rsp), %r8
movl 0xc(%rsp), %ebp
movq 0x20(%rsp), %r13
incq %rbx
addq $0xa8, %r14
cmpq 0x10(%r12), %rbx
jb 0x187938
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq