// File: /workspace/github_cpp_makefile_star2_O3/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 0xa0c42
movq 0x10(%r14), %rcx
testq %rcx, %rcx
jle 0x3852b
movl $0x2e, %ebp
xorl %r13d, %r13d
xorl %r12d, %r12d
movq (%r14), %rax
movzbl -0x2(%rax,%rbp), %edx
cmpl %ebx, %edx
jne 0x38516
movl -0x2e(%rax,%rbp), %ecx
movl -0x2a(%rax,%rbp), %edx
shlq $0x20, %rcx
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 0x38497
movl -0x1a(%rax,%rbp), %esi
movl %esi, 0x10(%rsp)
movl -0x16(%rax,%rbp), %esi
movq 0x25ddb7(%rip), %rdi    # 0x296248
movq (%rdi,%rdx,8), %rdx
jmp 0x384b6
movq 0x25ddaa(%rip), %rsi    # 0x296248
movq (%rsi,%rdx,8), %rdx
movl -0x16(%rax,%rbp), %esi
notl %esi
addl %edx, %esi
movl %esi, 0x10(%rsp)
movl -0x1a(%rax,%rbp), %esi
notl %esi
addl %edx, %esi
incq %r12
incl %esi
movl %esi, 0x14(%rsp)
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 0xa058c
movq 0x10(%r14), %rcx
incq %r13
addq $0xa8, %rbp
cmpq %rcx, %r13
jl 0x38420
jmp 0x3852e
xorl %r12d, %r12d
movq %r12, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq