// File: /workspace/github_cpp_makefile_star2_O3/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
movl %edx, %ebp
movq %rdi, %r14
movq 0x10(%rsi), %r8
testq %r8, %r8
je 0x187b27
movq %rcx, %r15
movq %rsi, %r12
movq (%rsi), %rcx
addq $0x2c, %rcx
xorl %eax, %eax
movq %r8, %rdx
movzbl (%rcx), %esi
xorl %edi, %edi
cmpl %ebp, %esi
sete %dil
addq %rdi, %rax
addq $0xa8, %rcx
decq %rdx
jne 0x187ad0
movl 0x8(%r14), %ecx
cmpq %rcx, %rax
jbe 0x187b3b
movl %eax, 0x8(%r14)
movq (%r14), %rdi
movl %eax, %eax
shlq $0x3, %rax
leaq (%rax,%rax,4), %rsi
callq 0x2370
movq %rax, (%r14)
movq 0x10(%r12), %r8
leaq 0xc(%r14), %rax
movl $0x0, 0xc(%r14)
testq %r8, %r8
jne 0x187b47
jmp 0x187c9d
movl $0x0, 0xc(%r14)
addq $0xc, %r14
movq %r14, %rax
jmp 0x187c9d
leaq 0xc(%r14), %rax
movl $0x0, 0xc(%r14)
movq %rax, (%rsp)
xorl %ecx, %ecx
xorl %edi, %edi
movq (%r12), %rax
movzbl 0x2c(%rax,%rcx), %edx
cmpl %ebp, %edx
jne 0x187c86
movq (%r14), %rdx
movl 0xc(%r14), %esi
leal 0x1(%rsi), %r8d
movl %r8d, 0xc(%r14)
leaq (%rsi,%rsi,4), %rsi
leaq (%rdx,%rsi,8), %r8
movl (%rax,%rcx), %edx
movl 0x4(%rax,%rcx), %esi
shlq $0x20, %rdx
orq %rdx, %rsi
movq %rsi, (%r8)
movl 0x8(%rax,%rcx), %edx
incl %edx
movl %edx, 0x8(%r8)
movq 0x10(%rax,%rcx), %rdx
movq %rdx, 0xc(%r8)
movl 0x18(%rax,%rcx), %edx
incl %edx
movl %edx, 0x14(%r8)
movl 0x1c(%rax,%rcx), %r13d
shll $0x1f, %r13d
movq 0x18(%r8), %r9
movabsq $-0x80000001, %rax      # imm = 0xFFFFFFFF7FFFFFFF
andq %rax, %r9
orq %r13, %r9
movq %r9, 0x18(%r8)
movq 0x18(%r15), %rax
movq (%r12), %rdx
movl 0x10(%rdx,%rcx), %edx
movq (%rax,%rdx,8), %r11
movl %r11d, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
shlq $0x20, %rax
movabsq $-0x7fffffff00000001, %rdx # imm = 0x80000000FFFFFFFF
andq %rdx, %r9
orq %rax, %r9
movq %r9, 0x18(%r8)
movq (%r12), %rax
movzbl 0x2e(%rax,%rcx), %eax
andl $0x1, %eax
movl %eax, %edx
shll $0x1e, %edx
andq $-0x40000001, %r9       # imm = 0xBFFFFFFF
orq %rdx, %r9
movq %r9, 0x18(%r8)
movq (%r12), %rsi
movb 0x2d(%rsi,%rcx), %r10b
movb %r10b, 0x21(%r8)
movb 0x24(%rsi,%rcx), %dl
movb %dl, 0x20(%r8)
testl %r13d, %r13d
je 0x187c4e
andl $0x7fffffff, %r11d      # imm = 0x7FFFFFFF
movl 0x18(%rsi,%rcx), %r13d
notl %r13d
addl %r11d, %r13d
movl %r13d, 0x10(%r8)
subl 0x14(%rsi,%rcx), %r11d
movl %r11d, 0x14(%r8)
cmpl $0x1, %ebp
jne 0x187c7c
testb %al, %al
je 0x187c5f
incq 0x10(%rbx)
movq 0x18(%r8), %r9
btl $0x1e, %r9d
jb 0x187c6a
incq 0x18(%rbx)
cmpb $0x1, %dl
jne 0x187c73
incq 0x20(%rbx)
testb %r10b, %r10b
je 0x187c7c
incq 0x28(%rbx)
andb $0x7f, 0x1f(%r8)
movq 0x10(%r12), %r8
incq %rdi
addq $0xa8, %rcx
cmpq %r8, %rdi
jb 0x187b4f
movq (%rsp), %rax
cmpl $0x1, %ebp
je 0x187cab
cmpl $0x2, %ebp
jne 0x187cb0
addq $0x8, %rbx
movl (%rax), %eax
addq %rax, (%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq