// File: 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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jae 0x2568c0
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x30(%rbp), %rcx
addq %rcx, %rax
movzbl 0x2c(%rax), %eax
cmpl -0x14(%rbp), %eax
jne 0x2568b0
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x2568b2
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x25687b
movq -0x38(%rbp), %rax
movq -0x8(%rbp), %rcx
movl 0x8(%rcx), %ecx
cmpq %rcx, %rax
jbe 0x2568fe
movq -0x38(%rbp), %rax
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
imulq $0x28, %rax, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0xc(%rax)
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jae 0x256c5f
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x30(%rbp), %rcx
addq %rcx, %rax
movzbl 0x2c(%rax), %eax
cmpl -0x14(%rbp), %eax
jne 0x256c4c
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rbp), %rdx
movl 0xc(%rdx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, 0xc(%rdx)
movl %ecx, %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x30(%rbp), %rcx
addq %rcx, %rax
movl (%rax), %eax
movl %eax, %ecx
movq -0x40(%rbp), %rax
movq %rcx, (%rax)
movq -0x40(%rbp), %rax
movq (%rax), %rcx
shlq $0x20, %rcx
movq -0x40(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x30(%rbp), %rcx
addq %rcx, %rax
movl 0x10(%rax), %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x40(%rbp), %rax
movq (%rax), %rcx
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x30(%rbp), %rdx
addq %rdx, %rax
movl 0x4(%rax), %eax
orq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x30(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %ecx
addl $0x1, %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x30(%rbp), %rcx
addq %rcx, %rax
movl 0x14(%rax), %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x30(%rbp), %rcx
addq %rcx, %rax
movl 0x18(%rax), %ecx
addl $0x1, %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x14(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x30(%rbp), %rcx
addq %rcx, %rax
movl 0x1c(%rax), %ecx
movq -0x40(%rbp), %rax
movl %ecx, %ecx
movl %ecx, %edx
movq 0x18(%rax), %rcx
andq $0x1, %rdx
shlq $0x1f, %rdx
movabsq $-0x80000001, %rsi      # imm = 0xFFFFFFFF7FFFFFFF
andq %rsi, %rcx
orq %rdx, %rcx
movq %rcx, 0x18(%rax)
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
imulq $0xa8, -0x30(%rbp), %rdx
addq %rdx, %rcx
movl 0x10(%rcx), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, %ecx
movq -0x40(%rbp), %rax
movl %ecx, %ecx
movl %ecx, %edx
movq 0x18(%rax), %rcx
andq $0x7fffffff, %rdx       # imm = 0x7FFFFFFF
shlq $0x20, %rdx
movabsq $-0x7fffffff00000001, %rsi # imm = 0x80000000FFFFFFFF
andq %rsi, %rcx
orq %rdx, %rcx
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x30(%rbp), %rcx
addq %rcx, %rax
movsbl 0x2e(%rax), %ecx
movq -0x40(%rbp), %rax
movl %ecx, %ecx
movl %ecx, %edx
movq 0x18(%rax), %rcx
andq $0x1, %rdx
shlq $0x1e, %rdx
andq $-0x40000001, %rcx      # imm = 0xBFFFFFFF
orq %rdx, %rcx
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x30(%rbp), %rcx
addq %rcx, %rax
movb 0x2d(%rax), %cl
movq -0x40(%rbp), %rax
movb %cl, 0x21(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x30(%rbp), %rcx
addq %rcx, %rax
movl 0x24(%rax), %eax
movb %al, %cl
movq -0x40(%rbp), %rax
movb %cl, 0x20(%rax)
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rax
shrq $0x1f, %rax
andq $0x1, %rax
cmpl $0x0, %eax
je 0x256ba5
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rax
shrq $0x20, %rax
andq $0x7fffffff, %rax       # imm = 0x7FFFFFFF
movl %eax, %ecx
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x30(%rbp), %rdx
addq %rdx, %rax
subl 0x18(%rax), %ecx
subl $0x1, %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rax
shrq $0x20, %rax
andq $0x7fffffff, %rax       # imm = 0x7FFFFFFF
movl %eax, %ecx
movq -0x10(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x30(%rbp), %rdx
addq %rdx, %rax
subl 0x14(%rax), %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x14(%rax)
cmpl $0x1, -0x14(%rbp)
jne 0x256c32
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rax
shrq $0x1e, %rax
andq $0x1, %rax
cmpl $0x1, %eax
jne 0x256bd4
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x10(%rax)
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rax
shrq $0x1e, %rax
andq $0x1, %rax
cmpl $0x0, %eax
jne 0x256bf9
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x18(%rax)
movq -0x40(%rbp), %rax
movzbl 0x20(%rax), %eax
cmpl $0x1, %eax
jne 0x256c16
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x20(%rax)
movq -0x40(%rbp), %rax
cmpb $0x0, 0x21(%rax)
je 0x256c30
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x28(%rax)
jmp 0x256c32
movq -0x40(%rbp), %rax
movabsq $0x7fffffffffffffff, %rcx # imm = 0x7FFFFFFFFFFFFFFF
andq 0x18(%rax), %rcx
orq $0x0, %rcx
movq %rcx, 0x18(%rax)
jmp 0x256c4e
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x256911
cmpl $0x1, -0x14(%rbp)
jne 0x256c78
movq -0x8(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, %ecx
movq -0x28(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
cmpl $0x2, -0x14(%rbp)
jne 0x256c93
movq -0x8(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, %ecx
movq -0x28(%rbp), %rax
addq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)