// File: 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
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
callq 0x2510
movsd %xmm0, -0x28(%rbp)
movl $0x0, -0x4c(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x10(%rbp), %rax
jge 0xce80a
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x8(%rbp), %rcx
imulq $0x18, -0x30(%rbp), %rdx
addq %rdx, %rcx
movl 0xc(%rcx), %ecx
cmpq %rcx, %rax
jge 0xce7f7
movq -0x8(%rbp), %rax
imulq $0x18, -0x30(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
imulq $0x28, -0x38(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
shrq $0x20, %rax
movl %eax, -0x44(%rbp)
movq -0x8(%rbp), %rax
imulq $0x18, -0x30(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
imulq $0x28, -0x38(%rbp), %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
movl %eax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movl -0x48(%rbp), %eax
imulq $0x18, %rax, %rax
addq %rax, %rdi
movl -0x48(%rbp), %esi
movl -0x44(%rbp), %edx
callq 0xce1b0
movq %rax, -0x40(%rbp)
cmpq $-0x1, -0x40(%rbp)
je 0xce6c9
movl $0x0, -0x4c(%rbp)
movq -0x8(%rbp), %rax
imulq $0x18, -0x30(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
imulq $0x28, -0x38(%rbp), %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
shrq $0x3f, %rax
cmpl $0x0, %eax
jne 0xce4ac
movq -0x8(%rbp), %rax
movl -0x48(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
imulq $0x28, -0x40(%rbp), %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
shrq $0x3f, %rax
cmpl $0x0, %eax
je 0xce4b3
movl $0x1, -0x4c(%rbp)
movq -0x8(%rbp), %rax
imulq $0x18, -0x30(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
imulq $0x28, -0x38(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movq -0x8(%rbp), %rcx
imulq $0x18, -0x30(%rbp), %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
imulq $0x28, -0x38(%rbp), %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
subl %ecx, %eax
movl %eax, %eax
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rax
movl -0x48(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
imulq $0x28, -0x40(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movq -0x8(%rbp), %rcx
movl -0x48(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
imulq $0x28, -0x40(%rbp), %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
subl %ecx, %eax
movl %eax, %eax
movq %rax, -0x60(%rbp)
movq -0x58(%rbp), %rax
cmpq -0x60(%rbp), %rax
jne 0xce578
movl -0x44(%rbp), %eax
cmpl -0x48(%rbp), %eax
jae 0xce576
movq -0x8(%rbp), %rax
movl -0x48(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rdi
imulq $0x28, -0x40(%rbp), %rax
addq %rax, %rdi
movq -0x8(%rbp), %rax
imulq $0x18, -0x30(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rsi
imulq $0x28, -0x38(%rbp), %rax
addq %rax, %rsi
callq 0xce230
jmp 0xce5b9
movq -0x58(%rbp), %rax
cmpq -0x60(%rbp), %rax
jle 0xce5b7
movq -0x8(%rbp), %rax
movl -0x48(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rdi
imulq $0x28, -0x40(%rbp), %rax
addq %rax, %rdi
movq -0x8(%rbp), %rax
imulq $0x18, -0x30(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rsi
imulq $0x28, -0x38(%rbp), %rax
addq %rax, %rsi
callq 0xce230
jmp 0xce5b9
cmpl $0x0, -0x14(%rbp)
je 0xce602
movq -0x8(%rbp), %rax
imulq $0x18, -0x30(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
imulq $0x28, -0x38(%rbp), %rcx
addq %rcx, %rax
cmpb $0x0, 0x20(%rax)
je 0xce602
movq -0x8(%rbp), %rax
movl -0x48(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
imulq $0x28, -0x40(%rbp), %rcx
addq %rcx, %rax
cmpb $0x0, 0x20(%rax)
je 0xce602
movl $0x0, -0x4c(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0xce646
movq -0x20(%rbp), %rax
movl -0x44(%rbp), %ecx
movzbl (%rax,%rcx), %eax
leaq 0x2f61dd(%rip), %rcx    # 0x3c47f8
cmpq 0x2b8(%rcx), %rax
jbe 0xce63f
movq -0x20(%rbp), %rax
movl -0x48(%rbp), %ecx
movzbl (%rax,%rcx), %eax
leaq 0x2f61c2(%rip), %rcx    # 0x3c47f8
cmpq 0x2b8(%rcx), %rax
ja 0xce646
movl $0x1, -0x4c(%rbp)
movl -0x4c(%rbp), %ecx
movq -0x8(%rbp), %rax
imulq $0x18, -0x30(%rbp), %rdx
addq %rdx, %rax
movq (%rax), %rax
imulq $0x28, -0x38(%rbp), %rdx
addq %rdx, %rax
movl %ecx, %ecx
movl %ecx, %edx
movq 0x18(%rax), %rcx
andq $0x1, %rdx
shlq $0x3f, %rdx
movabsq $0x7fffffffffffffff, %rsi # imm = 0x7FFFFFFFFFFFFFFF
andq %rsi, %rcx
orq %rdx, %rcx
movq %rcx, 0x18(%rax)
movl -0x4c(%rbp), %ecx
movq -0x8(%rbp), %rax
movl -0x48(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq (%rax), %rax
imulq $0x28, -0x40(%rbp), %rdx
addq %rdx, %rax
movl %ecx, %ecx
movl %ecx, %edx
movq 0x18(%rax), %rcx
andq $0x1, %rdx
shlq $0x3f, %rdx
movabsq $0x7fffffffffffffff, %rsi # imm = 0x7FFFFFFFFFFFFFFF
andq %rsi, %rcx
orq %rdx, %rcx
movq %rcx, 0x18(%rax)
jmp 0xce7e4
movl $0x1, -0x4c(%rbp)
movq -0x8(%rbp), %rax
imulq $0x18, -0x30(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rsi
imulq $0x28, -0x38(%rbp), %rax
addq %rax, %rsi
leaq -0x88(%rbp), %rdi
callq 0xce230
cmpl $0x0, -0x14(%rbp)
je 0xce723
movq -0x8(%rbp), %rax
imulq $0x18, -0x30(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
imulq $0x28, -0x38(%rbp), %rcx
addq %rcx, %rax
cmpb $0x0, 0x20(%rax)
je 0xce723
cmpb $0x0, -0x68(%rbp)
je 0xce723
movl $0x0, -0x4c(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0xce767
movq -0x20(%rbp), %rax
movl -0x44(%rbp), %ecx
movzbl (%rax,%rcx), %eax
leaq 0x2f60bc(%rip), %rcx    # 0x3c47f8
cmpq 0x2b8(%rcx), %rax
jbe 0xce760
movq -0x20(%rbp), %rax
movl -0x48(%rbp), %ecx
movzbl (%rax,%rcx), %eax
leaq 0x2f60a1(%rip), %rcx    # 0x3c47f8
cmpq 0x2b8(%rcx), %rax
ja 0xce767
movl $0x1, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movq -0x70(%rbp), %rcx
andq $0x1, %rax
movq %rax, %rdx
shlq $0x3f, %rdx
movabsq $0x7fffffffffffffff, %rsi # imm = 0x7FFFFFFFFFFFFFFF
andq %rsi, %rcx
orq %rdx, %rcx
movq %rcx, -0x70(%rbp)
movl %eax, %ecx
movq -0x8(%rbp), %rax
imulq $0x18, -0x30(%rbp), %rdx
addq %rdx, %rax
movq (%rax), %rax
imulq $0x28, -0x38(%rbp), %rdx
addq %rdx, %rax
movl %ecx, %ecx
movl %ecx, %edx
movq 0x18(%rax), %rcx
andq $0x1, %rdx
shlq $0x3f, %rdx
movabsq $0x7fffffffffffffff, %rsi # imm = 0x7FFFFFFFFFFFFFFF
andq %rsi, %rcx
orq %rdx, %rcx
movq %rcx, 0x18(%rax)
movq -0x8(%rbp), %rdi
movl -0x48(%rbp), %eax
imulq $0x18, %rax, %rax
addq %rax, %rdi
leaq -0x88(%rbp), %rsi
callq 0xcd340
jmp 0xce7e6
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0xce3d9
jmp 0xce7f9
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0xce3c3
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)