// File: 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 %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x220(%rax)
jne 0x405e6
movl $0x0, -0x4(%rbp)
jmp 0x40975
movq -0x10(%rbp), %rax
cmpq $0x1, 0x220(%rax)
jbe 0x40820
movl $0x0, -0x34(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x220(%rcx), %rcx
cmpl %ecx, %eax
jge 0x40811
cmpl $0x0, -0x30(%rbp)
jle 0x406fd
movl -0x30(%rbp), %eax
addl $0x1, %eax
movq -0x10(%rbp), %rcx
movq 0x220(%rcx), %rcx
cmpl %ecx, %eax
jge 0x406fd
movq -0x10(%rbp), %rax
movq 0x218(%rax), %rax
movslq -0x30(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x20(%rax), %eax
movq -0x10(%rbp), %rcx
movq 0x218(%rcx), %rcx
movl -0x30(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
movl 0x20(%rcx), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
je 0x406f8
movq -0x10(%rbp), %rax
movq 0x218(%rax), %rax
movslq -0x30(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x20(%rax), %eax
addl $0x1, %eax
movq -0x10(%rbp), %rcx
movq 0x218(%rcx), %rcx
movl -0x30(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x20(%rcx), %eax
je 0x406f8
movq -0x10(%rbp), %rax
movq 0x218(%rax), %rsi
movslq -0x30(%rbp), %rax
imulq $0x28, %rax, %rax
addq %rax, %rsi
movq -0x10(%rbp), %rax
movq 0x218(%rax), %rdi
movslq -0x34(%rbp), %rax
imulq $0x28, %rax, %rax
addq %rax, %rdi
movl $0x28, %edx
callq 0x2180
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x40801
cmpl $0x0, -0x30(%rbp)
jne 0x40780
movq -0x10(%rbp), %rax
movq 0x218(%rax), %rax
movslq -0x30(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x20(%rax), %eax
addl $0x1, %eax
movq -0x10(%rbp), %rcx
movq 0x218(%rcx), %rcx
movl -0x30(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x20(%rcx), %eax
je 0x4077e
movq -0x10(%rbp), %rax
movq 0x218(%rax), %rsi
movslq -0x30(%rbp), %rax
imulq $0x28, %rax, %rax
addq %rax, %rsi
movq -0x10(%rbp), %rax
movq 0x218(%rax), %rdi
movslq -0x34(%rbp), %rax
imulq $0x28, %rax, %rax
addq %rax, %rdi
movl $0x28, %edx
callq 0x2180
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x407ff
movq -0x10(%rbp), %rax
movq 0x218(%rax), %rax
movslq -0x30(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x20(%rax), %eax
movq -0x10(%rbp), %rcx
movq 0x218(%rcx), %rcx
movl -0x30(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
movl 0x20(%rcx), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
je 0x407fd
movq -0x10(%rbp), %rax
movq 0x218(%rax), %rsi
movslq -0x30(%rbp), %rax
imulq $0x28, %rax, %rax
addq %rax, %rsi
movq -0x10(%rbp), %rax
movq 0x218(%rax), %rdi
movslq -0x34(%rbp), %rax
imulq $0x28, %rax, %rax
addq %rax, %rdi
movl $0x28, %edx
callq 0x2180
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x407ff
jmp 0x40801
jmp 0x40803
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x40606
movslq -0x34(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x220(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x220(%rax)
jbe 0x4096e
movq $0x0, -0x40(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x220(%rcx), %rcx
cmpl %ecx, %eax
jge 0x408c6
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x218(%rax), %rsi
movslq -0x34(%rbp), %rax
imulq $0x28, %rax, %rax
addq %rax, %rsi
callq 0xa1dc0
cmpl $0x0, %eax
je 0x408b6
movq -0x10(%rbp), %rax
movq 0x218(%rax), %rsi
movslq -0x34(%rbp), %rax
imulq $0x28, %rax, %rax
addq %rax, %rsi
movq -0x10(%rbp), %rax
movq 0x218(%rax), %rdi
imulq $0x28, -0x40(%rbp), %rax
addq %rax, %rdi
movl $0x28, %edx
callq 0x2180
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x408b8
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x40841
movq -0x40(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x220(%rax)
movq -0x10(%rbp), %rdi
addq $0x250, %rdi            # imm = 0x250
movq -0x10(%rbp), %rax
movq 0x220(%rax), %rax
movl %eax, %esi
callq 0xa1c60
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x220(%rcx), %rcx
cmpl %ecx, %eax
jge 0x4092b
movl -0x34(%rbp), %edx
movq -0x10(%rbp), %rax
movq 0x298(%rax), %rax
movslq -0x34(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x408f9
movq -0x10(%rbp), %rax
movq 0x220(%rax), %rax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x2a0(%rax)
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x298(%rax), %rsi
movq -0x10(%rbp), %rax
movslq 0x2a0(%rax), %rdx
movq -0x18(%rbp), %rcx
callq 0x3f170
movl $0x1, -0x4(%rbp)
jmp 0x40975
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nop