// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %rax
movq %r8, %rbx
movq %rcx, %r15
movl %edx, %ebp
movq %rsi, %r12
movq %rdi, %r14
movq 0x10(%rsi), %rcx
testq %rcx, %rcx
je 0x1805c8
movq (%r12), %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 0x1805ac
jmp 0x1805ca
xorl %eax, %eax
movl 0x8(%r14), %ecx
cmpq %rcx, %rax
jbe 0x1805ec
movl %eax, 0x8(%r14)
movq (%r14), %rdi
movl %eax, %eax
shlq $0x3, %rax
leaq (%rax,%rax,4), %rsi
callq 0x2370
movq %rax, (%r14)
movl $0x0, 0xc(%r14)
cmpq $0x0, 0x10(%r12)
je 0x18075f
xorl %eax, %eax
movabsq $-0x80000001, %rcx      # imm = 0xFFFFFFFF7FFFFFFF
movabsq $-0x7fffffff00000001, %rdx # imm = 0x80000000FFFFFFFF
xorl %esi, %esi
movq (%r12), %r8
movzbl 0x2c(%r8,%rax), %edi
cmpl %ebp, %edi
jne 0x18074b
movq (%r14), %rdi
movl 0xc(%r14), %r9d
leal 0x1(%r9), %r10d
movl %r10d, 0xc(%r14)
leaq (%r9,%r9,4), %r9
leaq (%rdi,%r9,8), %rdi
movl (%r8,%rax), %r9d
shlq $0x20, %r9
movq %r9, (%rdi)
movl 0x10(%r8,%rax), %r10d
movl %r10d, 0xc(%rdi)
movl 0x4(%r8,%rax), %r10d
orq %r9, %r10
movq %r10, (%rdi)
movl 0x8(%r8,%rax), %r9d
incl %r9d
movl %r9d, 0x8(%rdi)
movl 0x14(%r8,%rax), %r9d
movl %r9d, 0x10(%rdi)
movl 0x18(%r8,%rax), %r9d
incl %r9d
movl %r9d, 0x14(%rdi)
movl 0x1c(%r8,%rax), %r10d
shll $0x1f, %r10d
movq 0x18(%rdi), %r9
andq %rcx, %r9
orq %r10, %r9
movq %r9, 0x18(%rdi)
movq 0x18(%r15), %r8
movq (%r12), %r11
movl 0x10(%r11,%rax), %r11d
movq (%r8,%r11,8), %r8
movl %r8d, %r11d
andl $0x7fffffff, %r11d      # imm = 0x7FFFFFFF
shlq $0x20, %r11
andq %rdx, %r9
orq %r11, %r9
movq %r9, 0x18(%rdi)
movq (%r12), %r11
movzbl 0x2e(%r11,%rax), %r11d
andl $0x1, %r11d
shll $0x1e, %r11d
andq $-0x40000001, %r9       # imm = 0xBFFFFFFF
orq %r11, %r9
movq %r9, 0x18(%rdi)
movq (%r12), %r13
movb 0x2d(%r13,%rax), %r9b
movb %r9b, 0x21(%rdi)
movb 0x24(%r13,%rax), %r11b
movb %r11b, 0x20(%rdi)
testl %r10d, %r10d
je 0x18071b
andl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
movl 0x18(%r13,%rax), %r10d
notl %r10d
addl %r8d, %r10d
movl %r10d, 0x10(%rdi)
subl 0x14(%r13,%rax), %r8d
movl %r8d, 0x14(%rdi)
cmpl $0x1, %ebp
jne 0x180747
testb $0x40, 0x1b(%rdi)
je 0x18072a
incq 0x10(%rbx)
testb $0x40, 0x1b(%rdi)
jne 0x180734
incq 0x18(%rbx)
cmpb $0x1, %r11b
jne 0x18073e
incq 0x20(%rbx)
testb %r9b, %r9b
je 0x180747
incq 0x28(%rbx)
andb $0x7f, 0x1f(%rdi)
incq %rsi
addq $0xa8, %rax
cmpq 0x10(%r12), %rsi
jb 0x180618
cmpl $0x1, %ebp
je 0x18076d
cmpl $0x2, %ebp
jne 0x180774
addq $0x8, %rbx
movl 0xc(%r14), %eax
addq %rax, (%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq