// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/ecovlp.cpp
// Function: push_ff_ovlp(ma_hit_t_alloc*, overlap_region_alloc*, unsigned int, All_reads*, unsigned long*)
void push_ff_ovlp(ma_hit_t_alloc* paf, overlap_region_alloc* ov, uint32_t flag, All_reads* R_INF, uint64_t *cnt)
{
    // if(qu && tu) {
    //     debug_extract_max_exact_sub(qid, qu, tu);
    // }
    uint64_t k, n; ma_hit_t *z; 
    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) {
            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;
            z->el = ov->list[k].shared_seed;

            if(z->rev) {
                z->ts = z->bl - ov->list[k].y_pos_e - 1;
                z->te = z->bl - ov->list[k].y_pos_s;
            }

            if(flag == 1) {
                if(z->ml == 1) cnt[2]++;
                if(z->ml == 0) cnt[3]++;
                if(z->el == 1) cnt[4]++;
                if(z->no_l_indel) cnt[5]++;
            }
            z->del = 0;
        }
    }

    if(flag == 1) cnt[0] += paf->length;
    if(flag == 2) cnt[1] += paf->length;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r8, 0x8(%rsp)
movq %rcx, 0x10(%rsp)
movl %edx, %ebp
movq %rsi, %r12
movq %rdi, %r14
movq 0x10(%rsi), %rcx
pushq $0x2c
popq %rdx
xorl %eax, %eax
subq $0x1, %rcx
jb 0x14346a
movq (%r12), %rsi
movzbl (%rsi,%rdx), %esi
xorl %edi, %edi
cmpl %ebp, %esi
sete %dil
addq %rdi, %rax
addq $0xa8, %rdx
jmp 0x143448
movl 0x8(%r14), %ecx
cmpq %rcx, %rax
jbe 0x143488
movl %eax, 0x8(%r14)
movq (%r14), %rdi
movl %eax, %eax
imulq $0x28, %rax, %rsi
callq 0x2370
movq %rax, (%r14)
andl $0x0, 0xc(%r14)
xorl %eax, %eax
xorl %esi, %esi
cmpq 0x10(%r12), %rsi
jae 0x1435f4
movq (%r12), %rcx
movzbl 0x2c(%rcx,%rax), %edx
cmpl %ebp, %edx
jne 0x1435e6
movq (%r14), %r8
movl 0xc(%r14), %edx
leal 0x1(%rdx), %edi
movl %edi, 0xc(%r14)
imulq $0x28, %rdx, %r10
leaq (%r8,%r10), %rdi
movl (%rcx,%rax), %edx
movl 0x4(%rcx,%rax), %r9d
shlq $0x20, %rdx
orq %rdx, %r9
movq %r9, (%r8,%r10)
movl 0x8(%rcx,%rax), %edx
incl %edx
movl %edx, 0x8(%r8,%r10)
movq 0x10(%rcx,%rax), %rdx
movq %rdx, 0xc(%r8,%r10)
movl 0x18(%rcx,%rax), %edx
incl %edx
movl %edx, 0x14(%r8,%r10)
movl 0x1c(%rcx,%rax), %ecx
shll $0x1f, %ecx
movq 0x18(%r8,%r10), %r9
movabsq $-0x80000001, %rdx      # imm = 0xFFFFFFFF7FFFFFFF
andq %rdx, %r9
orq %rcx, %r9
movq %r9, 0x18(%r8,%r10)
movq 0x10(%rsp), %rdx
movq 0x18(%rdx), %rdx
movq (%r12), %r11
movl 0x10(%r11,%rax), %r11d
movq (%rdx,%r11,8), %r13
movl %r13d, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
shlq $0x20, %rdx
movabsq $-0x7fffffff00000001, %r11 # imm = 0x80000000FFFFFFFF
andq %r11, %r9
orq %rdx, %r9
movq %r9, 0x18(%r8,%r10)
movq (%r12), %rdx
movzbl 0x2e(%rdx,%rax), %edx
andl $0x1, %edx
movl %edx, %r11d
shll $0x1e, %r11d
andq $-0x40000001, %r9       # imm = 0xBFFFFFFF
orq %r11, %r9
movq %r9, 0x18(%r8,%r10)
movq (%r12), %rbx
movb 0x2d(%rbx,%rax), %r11b
movb %r11b, 0x21(%r8,%r10)
movb 0x24(%rbx,%rax), %r15b
movb %r15b, 0x20(%r8,%r10)
testl %ecx, %ecx
je 0x1435a9
andl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
movl 0x18(%rbx,%rax), %ecx
notl %ecx
addl %r13d, %ecx
movl %ecx, 0x10(%rdi)
subl 0x14(%rbx,%rax), %r13d
movl %r13d, 0x14(%rdi)
cmpl $0x1, %ebp
jne 0x1435e2
testb %dl, %dl
movq 0x8(%rsp), %rcx
je 0x1435bf
incq 0x10(%rcx)
movq 0x18(%rdi), %r9
btl $0x1e, %r9d
jb 0x1435ca
incq 0x18(%rcx)
cmpb $0x1, %r15b
jne 0x1435d4
incq 0x20(%rcx)
testb %r11b, %r11b
je 0x1435e2
movq 0x8(%rsp), %rcx
incq 0x28(%rcx)
andb $0x7f, 0x1f(%rdi)
incq %rsi
addq $0xa8, %rax
jmp 0x143491
cmpl $0x1, %ebp
movq 0x8(%rsp), %rcx
je 0x143607
cmpl $0x2, %ebp
jne 0x14360e
addq $0x8, %rcx
movl 0xc(%r14), %eax
addq %rax, (%rcx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq