// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rsi, %rbx
movq 0x220(%rdi), %rsi
testq %rsi, %rsi
je 0x2333a
movq %rdi, %r14
cmpq $0x1, %rsi
je 0x23279
xorl %eax, %eax
xorl %edx, %edx
xorl %ecx, %ecx
movslq %esi, %rdi
cmpq %rdi, %rdx
jge 0x23267
testq %rax, %rax
je 0x23215
leal 0x1(%rdx), %r11d
movq 0x218(%r14), %rdi
leaq (%rdi,%rax), %r8
movl -0x8(%rdi,%rax), %r10d
movl 0x20(%rdi,%rax), %r9d
incl %r10d
cmpl %esi, %r11d
jge 0x23260
cmpl %r10d, %r9d
je 0x2324d
incl %r9d
cmpl 0x48(%rdi,%rax), %r9d
jne 0x23229
jmp 0x2324d
movq 0x218(%r14), %rdi
movl 0x20(%rdi), %esi
incl %esi
movq %rdi, %r8
cmpl 0x48(%rdi), %esi
je 0x2324d
movslq %ecx, %rsi
imulq $0x28, %rsi, %rsi
movq 0x20(%r8), %r9
movq %r9, 0x20(%rdi,%rsi)
movups (%r8), %xmm0
movups 0x10(%r8), %xmm1
movups %xmm1, 0x10(%rdi,%rsi)
movups %xmm0, (%rdi,%rsi)
incl %ecx
incq %rdx
movq 0x220(%r14), %rsi
addq $0x28, %rax
jmp 0x231d2
cmpl %r10d, %r9d
jne 0x23229
jmp 0x2324d
movslq %ecx, %rsi
movq %rsi, 0x220(%r14)
testl %esi, %esi
je 0x2333a
xorl %r12d, %r12d
xorl %r13d, %r13d
xorl %r15d, %r15d
movslq %esi, %rax
cmpq %rax, %r13
jge 0x232dc
movq 0x218(%r14), %rsi
addq %r12, %rsi
movq %r14, %rdi
callq 0x53a0f
testl %eax, %eax
je 0x232cc
movq 0x218(%r14), %rax
imulq $0x28, %r15, %rcx
movq 0x20(%rax,%r12), %rdx
movq %rdx, 0x20(%rax,%rcx)
movups (%rax,%r12), %xmm0
movups 0x10(%rax,%r12), %xmm1
movups %xmm1, 0x10(%rax,%rcx)
movups %xmm0, (%rax,%rcx)
incq %r15
incq %r13
movq 0x220(%r14), %rsi
addq $0x28, %r12
jmp 0x23282
movq %r15, 0x220(%r14)
leaq 0x250(%r14), %rdi
movl %r15d, %esi
callq 0x53954
movq 0x220(%r14), %rax
xorl %ecx, %ecx
testl %eax, %eax
movl $0x0, %edx
cmovgl %eax, %edx
cmpq %rcx, %rdx
je 0x23319
movq 0x298(%r14), %rsi
movl %ecx, (%rsi,%rcx,4)
incq %rcx
jmp 0x23305
movl %eax, 0x2a0(%r14)
movq 0x298(%r14), %rsi
movslq %eax, %rdx
movq %r14, %rdi
movq %rbx, %rcx
callq 0x228b3
pushq $0x1
popq %rax
jmp 0x2333c
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq