// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Correct.cpp
// Function: generate_haplotypes_naive(haplotype_evdience_alloc*, overlap_region_alloc*, All_reads*, long long, int)
int generate_haplotypes_naive(haplotype_evdience_alloc* hap, overlap_region_alloc* overlap_list, All_reads* R_INF, long long rLen, 
int force_repeat)
{
    int j, i;

    
    if(hap->snp_stat.n == 0)
    {
        return 0;
    }

    ///if hap->available_snp == 1, the following codes would have bugs
    ///filter snps that are highly likly false 
    if(hap->snp_stat.n > 1)
    {
        i = 0;
        ///if a snp is very close to others, it should not be a real snp
        for (j = 0; j < (int)hap->snp_stat.n; j++)
        {
            
            if(j > 0 && j + 1 < (int)hap->snp_stat.n)
            {
                if(hap->snp_stat.a[j].site != hap->snp_stat.a[j - 1].site + 1
                    &&
                hap->snp_stat.a[j].site + 1 != hap->snp_stat.a[j + 1].site)
                {
                    hap->snp_stat.a[i] = hap->snp_stat.a[j];
                    i++;
                }

            }
            else if(j == 0)
            {
                if(hap->snp_stat.a[j].site + 1 != hap->snp_stat.a[j + 1].site)
                {
                    hap->snp_stat.a[i] = hap->snp_stat.a[j];
                    i++;
                }
            }
            else
            {
                if(hap->snp_stat.a[j].site != hap->snp_stat.a[j - 1].site + 1)
                {
                    hap->snp_stat.a[i] = hap->snp_stat.a[j];
                    i++;
                }
            }
        }
        hap->snp_stat.n = i;
    }


    long long m;
    if(hap->snp_stat.n > 0)
    {
        ///************************debug**************************///
        m = 0;
        for (i = 0; i < (int)hap->snp_stat.n; i++)
        {
            if(check_informative_site(hap, &(hap->snp_stat.a[i])))
            {
                hap->snp_stat.a[m] = hap->snp_stat.a[i];
                m++;
            }
        }
        hap->snp_stat.n = m;
        ///************************debug**************************///



        init_DP_matrix(&(hap->dp), hap->snp_stat.n);

        for (i = 0; i < (int)hap->snp_stat.n; i++)
        {
            hap->dp.max_buffer[i] = i;
        }
        hap->dp.max_snp_num = hap->snp_stat.n;
        remove_reads(hap, hap->dp.max_buffer, hap->dp.max_snp_num, overlap_list);

        return 1;

    }
    else
    {
        return 0;
    }

}

// Assembly:
movq 0x220(%rdi), %rcx
xorl %eax, %eax
testq %rcx, %rcx
je 0x52352
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rsi, %rbx
movq %rdi, %r14
cmpq $0x1, %rcx
je 0x5220f
movq 0x220(%r14), %rdi
xorl %ecx, %ecx
testl %edi, %edi
jle 0x52208
movl $0x1, %edx
xorl %esi, %esi
testq %rsi, %rsi
je 0x521a1
movslq %edi, %r11
movq 0x218(%r14), %rdi
leaq (%rdi,%rsi), %r8
movl -0x8(%rdi,%rsi), %r10d
movl 0x20(%rdi,%rsi), %r9d
incl %r10d
cmpq %r11, %rdx
jge 0x521fe
cmpl %r10d, %r9d
je 0x521de
incl %r9d
cmpl 0x48(%rdi,%rsi), %r9d
jne 0x521b8
jmp 0x521de
movq 0x218(%r14), %rdi
movl 0x20(%rdi), %r9d
incl %r9d
movq %rdi, %r8
cmpl 0x48(%rdi), %r9d
je 0x521de
movslq %ecx, %rcx
leaq (%rcx,%rcx,4), %r9
movq 0x20(%r8), %r10
movq %r10, 0x20(%rdi,%r9,8)
movups (%r8), %xmm0
movups 0x10(%r8), %xmm1
movups %xmm1, 0x10(%rdi,%r9,8)
movups %xmm0, (%rdi,%r9,8)
incl %ecx
movq 0x220(%r14), %rdi
movslq %edi, %r8
addq $0x28, %rsi
leaq 0x1(%rdx), %r9
cmpq %r8, %rdx
movq %r9, %rdx
jl 0x5216b
jmp 0x52205
cmpl %r10d, %r9d
jne 0x521b8
jmp 0x521de
movslq %ecx, %rcx
movq %rcx, 0x220(%r14)
cmpq $0x0, 0x220(%r14)
je 0x5234a
cmpl $0x0, 0x220(%r14)
jle 0x522ed
xorl %eax, %eax
xorl %esi, %esi
movq 0x218(%r14), %rcx
leaq (%rax,%rax,4), %rdx
leaq (%rcx,%rdx,8), %rdi
addq $0x8, %rdi
movl -0x8(%rdi), %r8d
movl 0x1c8(%r14), %r9d
imulq %r9, %r8
addq 0x1d0(%r14), %r8
movq $0x0, (%rdi)
leaq (%rcx,%rdx,8), %r10
addq $0xc, %r10
movl $0x0, 0x4(%r10)
testq %r9, %r9
je 0x522a9
leaq (%rcx,%rdx,8), %r11
addq $0x10, %r11
xorl %r15d, %r15d
movzbl (%r8,%r15), %ebp
movq %rdi, %r12
testl %ebp, %ebp
je 0x5229d
cmpl $0x2, %ebp
je 0x5229a
movq %r10, %r12
cmpl $0x1, %ebp
je 0x5229d
jmp 0x522a1
movq %r11, %r12
incl (%r12)
incq %r15
cmpq %r15, %r9
jne 0x5227f
cmpl $0x1, (%rdi)
ja 0x522b4
cmpl $0x2, (%r10)
jb 0x522d8
leaq (%rcx,%rdx,8), %rdx
leaq (%rsi,%rsi,4), %rdi
movq 0x20(%rdx), %r8
movq %r8, 0x20(%rcx,%rdi,8)
movups (%rdx), %xmm0
movups 0x10(%rdx), %xmm1
movups %xmm1, 0x10(%rcx,%rdi,8)
movups %xmm0, (%rcx,%rdi,8)
incq %rsi
incq %rax
movslq 0x220(%r14), %rcx
cmpq %rcx, %rax
jl 0x5222f
jmp 0x522ef
xorl %esi, %esi
movq %rsi, 0x220(%r14)
leaq 0x250(%r14), %rdi
callq 0x8786d
movq 0x220(%r14), %rax
testl %eax, %eax
jle 0x52329
movq 0x298(%r14), %rcx
movl %eax, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
xorl %esi, %esi
movl %esi, (%rcx,%rsi,4)
incq %rsi
cmpq %rsi, %rdx
jne 0x5231e
movl %eax, 0x2a0(%r14)
movq 0x298(%r14), %rsi
movslq %eax, %rdx
movq %r14, %rdi
movq %rbx, %rcx
callq 0x51776
movl $0x1, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq