// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %ecx, %ebx
movq %rdx, %r14
movq %rdi, %r15
callq 0xa04a2
cmpq $0x0, 0x10(%r14)
jle 0x38f80
movl $0x2e, %ebp
xorl %r13d, %r13d
xorl %r12d, %r12d
movq (%r14), %rax
movzbl -0x2(%rax,%rbp), %ecx
cmpl %ebx, %ecx
jne 0x38f6a
movl -0x2e(%rax,%rbp), %ecx
shlq $0x20, %rcx
movq %rcx, (%rsp)
movl -0x2a(%rax,%rbp), %edx
orq %rcx, %rdx
movq %rdx, (%rsp)
movl -0x26(%rax,%rbp), %ecx
incl %ecx
movl %ecx, 0x8(%rsp)
movl -0x12(%rax,%rbp), %esi
movl %esi, %edx
shll $0x1f, %edx
movq 0x18(%rsp), %rcx
movabsq $-0x80000001, %rdi      # imm = 0xFFFFFFFF7FFFFFFF
andq %rdi, %rcx
orq %rdx, %rcx
movq %rcx, 0x18(%rsp)
movl -0x1e(%rax,%rbp), %edx
movl %edx, 0xc(%rsp)
testb $0x1, %sil
jne 0x38edb
movl -0x1a(%rax,%rbp), %esi
movl %esi, 0x10(%rsp)
movl -0x16(%rax,%rbp), %esi
movl %esi, 0x14(%rsp)
jmp 0x38f05
movq 0x252366(%rip), %rsi    # 0x28b248
movl -0x1e(%rax,%rbp), %edi
movl -0x16(%rax,%rbp), %r8d
movl (%rsi,%rdi,8), %esi
notl %r8d
addl %esi, %r8d
movl %r8d, 0x10(%rsp)
movl -0x1a(%rax,%rbp), %edi
notl %edi
addl %esi, %edi
movl %edi, 0x14(%rsp)
incq %r12
incl 0x14(%rsp)
movq 0x252335(%rip), %rsi    # 0x28b248
movq (%rsi,%rdx,8), %rdx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
shlq $0x20, %rdx
movabsq $-0x7fffffff00000001, %rsi # imm = 0x80000000FFFFFFFF
andq %rsi, %rcx
orq %rdx, %rcx
movq %rcx, 0x18(%rsp)
movzbl (%rax,%rbp), %edx
andl $0x1, %edx
shll $0x1e, %edx
andq $-0x40000001, %rcx      # imm = 0xBFFFFFFF
orq %rdx, %rcx
movq %rcx, 0x18(%rsp)
movb -0x1(%rax,%rbp), %cl
movb %cl, 0x21(%rsp)
movb -0xa(%rax,%rbp), %al
movb %al, 0x20(%rsp)
movq %r15, %rdi
movq %rsp, %rsi
callq 0x9fdd9
incq %r13
addq $0xa8, %rbp
cmpq 0x10(%r14), %r13
jl 0x38e67
jmp 0x38f83
xorl %r12d, %r12d
movq %r12, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq