// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Overlaps.cpp
// Function: normalize_ma_hit_t_single_side_advance(ma_hit_t_alloc*, long long, unsigned int, unsigned char*)
void normalize_ma_hit_t_single_side_advance(ma_hit_t_alloc* sources, long long num_sources, uint32_t recuse_el, uint8_t *cmk)
{
    double startTime = Get_T();

    long long i, j, index;
    uint32_t qn, tn, is_del = 0;
    long long qLen_0, qLen_1;
    ma_hit_t ele;
    for (i = 0; i < num_sources; i++)
    {

        for (j = 0; j < sources[i].length; j++)
        {
            qn = Get_qn(sources[i].buffer[j]);
            tn = Get_tn(sources[i].buffer[j]);

            // sources[i].buffer[j].bl = Get_qe(sources[i].buffer[j]) - Get_qs(sources[i].buffer[j]);

            ///if(sources[i].buffer[j].del) continue;

            index = get_specific_overlap(&(sources[tn]), tn, qn);


            ///if(index != -1 && sources[tn].buffer[index].del == 0)
            if(index != -1) {
                is_del = 0;
                if(sources[i].buffer[j].del || sources[tn].buffer[index].del) is_del = 1;

                qLen_0 = Get_qe(sources[i].buffer[j]) - Get_qs(sources[i].buffer[j]);
                qLen_1 = Get_qe(sources[tn].buffer[index]) - Get_qs(sources[tn].buffer[index]);

                if(qLen_0 == qLen_1) {
                    ///qn must be not equal to tn
                    ///make sources[qn] = sources[tn] if qn > tn
                    if(qn < tn) {
                        set_reverse_overlap(&(sources[tn].buffer[index]), &(sources[i].buffer[j]));
                    }
                } else if(qLen_0 > qLen_1) {
                    set_reverse_overlap(&(sources[tn].buffer[index]), &(sources[i].buffer[j]));
                }

                if(recuse_el && sources[i].buffer[j].el && sources[tn].buffer[index].el) is_del = 0;
                if(cmk && (cmk[qn] <= asm_opt.chemical_cov/**FORCE_CUT**/ || cmk[tn] <= asm_opt.chemical_cov/**FORCE_CUT**/)) is_del = 1;
                
                sources[i].buffer[j].del = is_del;
                sources[tn].buffer[index].del = is_del;
            } else {///means this edge just occurs in one direction
                is_del = 1; 
                set_reverse_overlap(&ele, &(sources[i].buffer[j]));
                if(recuse_el && sources[i].buffer[j].el && ele.el) is_del = 0;
                if(cmk && (cmk[qn] <= asm_opt.chemical_cov/**FORCE_CUT**/ || cmk[tn] <= asm_opt.chemical_cov/**FORCE_CUT**/)) is_del = 1;
                sources[i].buffer[j].del = ele.del = is_del;
                add_ma_hit_t_alloc(&(sources[tn]), &ele);
            }
        }
    }

    if(VERBOSE >= 1)
    {
        fprintf(stderr, "[M::%s] takes %0.2fs\n\n", __func__, Get_T()-startTime);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rcx, %rbx
movl %edx, 0xc(%rsp)
movq %rsi, %r14
movq %rdi, %r15
callq 0x2f3fc
movq %r14, 0x38(%rsp)
testq %r14, %r14
jle 0xa1037
movq %r15, %r11
movq %rbx, %r10
movabsq $0x7fffffffffffffff, %rax # imm = 0x7FFFFFFFFFFFFFFF
leaq -0x3fffffff(%rax), %rcx
movq %rcx, 0x58(%rsp)
incq %rax
movq %rax, 0x50(%rsp)
xorl %eax, %eax
movq %rbx, 0x28(%rsp)
movq %r15, 0x20(%rsp)
movq %rax, 0x40(%rsp)
leaq (%rax,%rax,2), %rax
cmpl $0x0, 0xc(%r11,%rax,8)
je 0xa1024
leaq (%r11,%rax,8), %rsi
movq %rbp, 0x30(%rsp)
xorl %r14d, %r14d
movq %rsi, 0x18(%rsp)
movq (%rsi), %rax
leaq (%r14,%r14,4), %rcx
movq %rcx, 0x10(%rsp)
leaq (%rax,%rcx,8), %rsi
movq (%rsi), %rcx
movq %rcx, %r15
shrq $0x20, %r15
movl 0xc(%rsi), %r12d
leaq (%r12,%r12,2), %rdx
leaq (%r11,%rdx,8), %r13
movl 0xc(%r13), %edx
testq %rdx, %rdx
je 0xa0e3d
movq (%r13), %rdi
shlq $0x3, %rdx
leaq (%rdx,%rdx,4), %r8
xorl %ebx, %ebx
cmpl %r15d, 0xc(%rdi,%rbx)
jne 0xa0e34
movq (%rdi,%rbx), %rdx
movq %rdx, %r9
shrq $0x20, %r9
cmpl %r9d, %r12d
je 0xa0f30
addq $0x28, %rbx
cmpq %rbx, %r8
jne 0xa0e19
cmpl $0x0, 0xc(%rsp)
sete %dil
movq %r12, %rdx
shlq $0x20, %rdx
movl 0x10(%rsi), %r8d
orq %rdx, %r8
movq %r8, 0x60(%rsp)
movl 0x14(%rsi), %edx
movl %edx, 0x68(%rsp)
movl %r15d, 0x6c(%rsp)
movl %ecx, 0x70(%rsp)
movl 0x8(%rsi), %ecx
movl %ecx, 0x74(%rsp)
movq 0x18(%rsi), %rcx
movb 0x20(%rsi), %r8b
testb %r8b, %r8b
sete %dl
orb %dil, %dl
movb %r8b, 0x80(%rsp)
movb 0x21(%rsi), %sil
movb %sil, 0x81(%rsp)
testq %r10, %r10
je 0xa0ec5
movzbl (%r10,%r15), %edi
leaq 0x1f48b2(%rip), %rsi    # 0x295758
movq 0x2b8(%rsi), %rsi
cmpq %rdi, %rsi
movq 0x10(%rsp), %r8
jae 0xa0ec1
movzbl (%r10,%r12), %edi
cmpq %rdi, %rsi
jb 0xa0eca
movb $0x1, %dl
jmp 0xa0eca
movq 0x10(%rsp), %r8
movq 0x30(%rsp), %rsi
andl $0x3fffffff, %esi       # imm = 0x3FFFFFFF
movq %rcx, %rbp
andq 0x58(%rsp), %rbp
orq %rsi, %rbp
testb %dl, %dl
movl $0x0, %edx
cmovneq 0x50(%rsp), %rdx
orq %rdx, %rbp
movq %rbp, 0x78(%rsp)
movabsq $0x7fffffffffffffff, %rsi # imm = 0x7FFFFFFFFFFFFFFF
andq %rsi, %rcx
orq %rdx, %rcx
movq %rcx, 0x18(%rax,%r8,8)
movq %r13, %rdi
leaq 0x60(%rsp), %rsi
callq 0xa058c
movq 0x28(%rsp), %r10
movq %rbp, 0x30(%rsp)
movq 0x20(%rsp), %r11
movq 0x18(%rsp), %rsi
jmp 0xa1015
movq 0x10(%rsp), %r8
cmpq $0x0, 0x18(%rax,%r8,8)
js 0xa0f48
xorl %r9d, %r9d
cmpq $0x0, 0x18(%rdi,%rbx)
jns 0xa0f4e
movl $0x1, %r9d
movl 0x8(%rsi), %eax
subl %ecx, %eax
movl 0x8(%rdi,%rbx), %ecx
subl %edx, %ecx
cmpl %ecx, %eax
jne 0xa0f60
cmpl %r15d, %r12d
jbe 0xa0f83
addq %rbx, %rdi
movq %r9, 0x48(%rsp)
callq 0xa0cca
movq 0x48(%rsp), %r9
movq 0x10(%rsp), %r8
movq 0x20(%rsp), %r11
movq 0x28(%rsp), %r10
cmpl $0x0, 0xc(%rsp)
je 0xa0fae
movq 0x18(%rsp), %rsi
movq (%rsi), %rax
cmpb $0x0, 0x20(%rax,%r8,8)
je 0xa0fb3
movq (%r13), %rax
cmpb $0x0, 0x20(%rax,%rbx)
movl $0x0, %eax
cmovnel %eax, %r9d
jmp 0xa0fb3
movq 0x18(%rsp), %rsi
testq %r10, %r10
je 0xa0fe0
movzbl (%r10,%r15), %ecx
leaq 0x1f4794(%rip), %rax    # 0x295758
movq 0x2b8(%rax), %rax
cmpq %rcx, %rax
jae 0xa0fda
movzbl (%r10,%r12), %ecx
cmpq %rcx, %rax
jb 0xa0fe0
movl $0x1, %r9d
movq (%rsi), %rax
shlq $0x3f, %r9
movq 0x18(%rax,%r8,8), %rcx
movabsq $0x7fffffffffffffff, %rdx # imm = 0x7FFFFFFFFFFFFFFF
andq %rdx, %rcx
orq %r9, %rcx
movq %rcx, 0x18(%rax,%r8,8)
movq (%r13), %rax
movq 0x18(%rax,%rbx), %rcx
andq %rdx, %rcx
orq %r9, %rcx
movq %rcx, 0x18(%rax,%rbx)
incq %r14
movl 0xc(%rsi), %eax
cmpq %rax, %r14
jb 0xa0ddc
movq 0x40(%rsp), %rax
incq %rax
cmpq 0x38(%rsp), %rax
jne 0xa0db6
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq