// File: chhylp123[P]hifiasm/Assembly.cpp
// Function: push_final_overlaps(ma_hit_t_alloc*, ma_hit_t_alloc*, overlap_region_alloc*, int)
long long push_final_overlaps(ma_hit_t_alloc* paf, ma_hit_t_alloc* reverse_paf_list, overlap_region_alloc* overlap_list, int flag)
{
    long long i = 0;
    long long available_overlaps = 0;
    ma_hit_t tmp;
    clear_ma_hit_t_alloc(paf); // paf has been preallocated, so we don't need preallocation
    for (i = 0; i < (long long)overlap_list->length; i++)
    {
        if (overlap_list->list[i].is_match == flag)
        {
            available_overlaps++;
            /**********************query***************************/
            //the interval of overlap is half-open [start, end) 
            tmp.qns = overlap_list->list[i].x_id;
            tmp.qns = tmp.qns << 32;
            tmp.qns = tmp.qns | (uint64_t)(overlap_list->list[i].x_pos_s);
            ///the end pos is open
            tmp.qe = overlap_list->list[i].x_pos_e + 1;
            /**********************query***************************/



            ///for overlap_list, the x_strand of all overlaps are 0, so the tmp.rev is the same as the y_strand
            tmp.rev = overlap_list->list[i].y_pos_strand;


            /**********************target***************************/
            tmp.tn = overlap_list->list[i].y_id;
            if(tmp.rev == 1)
            {
                long long y_readLen = R_INF.read_length[overlap_list->list[i].y_id];
                tmp.ts = y_readLen - overlap_list->list[i].y_pos_e - 1;
                tmp.te = y_readLen - overlap_list->list[i].y_pos_s - 1;
            }
            else
            {
                tmp.ts = overlap_list->list[i].y_pos_s;
                tmp.te = overlap_list->list[i].y_pos_e;
            }
            ///the end pos is open
            tmp.te++;
            /**********************target***************************/

            tmp.bl = R_INF.read_length[overlap_list->list[i].y_id];
            tmp.ml = overlap_list->list[i].strong;
            tmp.no_l_indel = overlap_list->list[i].without_large_indel;

            tmp.el = overlap_list->list[i].shared_seed;

            add_ma_hit_t_alloc(paf, &tmp);
        }
    }

    return available_overlaps;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x8(%rbp), %rdi
callq 0xce0a0
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jge 0x147c3
movq -0x18(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x28(%rbp), %rcx
addq %rcx, %rax
movzbl 0x2c(%rax), %eax
cmpl -0x1c(%rbp), %eax
jne 0x147b0
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x28(%rbp), %rcx
addq %rcx, %rax
movl (%rax), %eax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
shlq $0x20, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq -0x18(%rbp), %rcx
movq (%rcx), %rcx
imulq $0xa8, -0x28(%rbp), %rdx
addq %rdx, %rcx
movl 0x4(%rcx), %ecx
orq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x28(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x28(%rbp), %rcx
addq %rcx, %rax
movl 0x1c(%rax), %eax
movl %eax, %ecx
movq -0x40(%rbp), %rax
andq $0x1, %rcx
shlq $0x1f, %rcx
movabsq $-0x80000001, %rdx      # imm = 0xFFFFFFFF7FFFFFFF
andq %rdx, %rax
orq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x28(%rbp), %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
movl %eax, -0x4c(%rbp)
movq -0x40(%rbp), %rax
shrq $0x1f, %rax
andq $0x1, %rax
cmpl $0x1, %eax
jne 0x146c0
movq 0x3b0c8d(%rip), %rax    # 0x3c52e8
movq -0x18(%rbp), %rcx
movq (%rcx), %rcx
imulq $0xa8, -0x28(%rbp), %rdx
addq %rdx, %rcx
movl 0x10(%rcx), %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq -0x18(%rbp), %rcx
movq (%rcx), %rcx
imulq $0xa8, -0x28(%rbp), %rdx
addq %rdx, %rcx
movl 0x18(%rcx), %ecx
subq %rcx, %rax
subq $0x1, %rax
movl %eax, -0x48(%rbp)
movq -0x60(%rbp), %rax
movq -0x18(%rbp), %rcx
movq (%rcx), %rcx
imulq $0xa8, -0x28(%rbp), %rdx
addq %rdx, %rcx
movl 0x14(%rcx), %ecx
subq %rcx, %rax
subq $0x1, %rax
movl %eax, -0x44(%rbp)
jmp 0x146f0
movq -0x18(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x28(%rbp), %rcx
addq %rcx, %rax
movl 0x14(%rax), %eax
movl %eax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x28(%rbp), %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
movq 0x3b0be8(%rip), %rax    # 0x3c52e8
movq -0x18(%rbp), %rcx
movq (%rcx), %rcx
imulq $0xa8, -0x28(%rbp), %rdx
addq %rdx, %rcx
movl 0x10(%rcx), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
movl %eax, %ecx
movq -0x40(%rbp), %rax
andq $0x7fffffff, %rcx       # imm = 0x7FFFFFFF
shlq $0x20, %rcx
movabsq $-0x7fffffff00000001, %rdx # imm = 0x80000000FFFFFFFF
andq %rdx, %rax
orq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x28(%rbp), %rcx
addq %rcx, %rax
movsbl 0x2e(%rax), %eax
movl %eax, %eax
movl %eax, %ecx
movq -0x40(%rbp), %rax
andq $0x1, %rcx
shlq $0x1e, %rcx
andq $-0x40000001, %rax      # imm = 0xBFFFFFFF
orq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x28(%rbp), %rcx
addq %rcx, %rax
movb 0x2d(%rax), %al
movb %al, -0x37(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
imulq $0xa8, -0x28(%rbp), %rcx
addq %rcx, %rax
movl 0x24(%rax), %eax
movb %al, -0x38(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0xcd340
jmp 0x147b2
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x14558
movq -0x30(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)