// File: chhylp123[P]hifiasm/Correct.cpp
// Function: Preorder_Merge(unsigned int, haplotype_evdience_alloc*, int)
void Preorder_Merge(uint32_t snpID, haplotype_evdience_alloc* hap, int is_merge) 
{ 
    int vectorID = hap->snp_stat.a[snpID].id;
    int8_t* vector = Get_SNP_Vector((*hap), vectorID);
    hap->dp.visit[snpID] = 1;
    

    if(is_merge)
    {
        if(hap->snp_stat.a[snpID].is_homopolymer)
        {
            hap->result_stat.homopolymer_num++;
        }
        else
        {
            hap->result_stat.non_homopolymer_num++;
        }
        
        hap->result_stat.score++;
        int flag;
        if((flag = debug_add_to_result_snp_vector(hap, vector, Get_SNP_Vector_Length((*hap))))!= -1)
        {
            fprintf(stderr, "incompatible snp vector....\n");
            exit(0);
        }
    }

    uint32_t* column;
    int j;

    if(hap->dp.backtrack_length[snpID] != 0)
    {
        column = Get_DP_Backtrack_Column(hap->dp, snpID);
        
        if(is_merge)
        {
            int add_ID = 0;
            for (j = 0; j < (int)hap->dp.backtrack_length[snpID]; j++)
            {
                if(hap->snp_stat.a[column[j]].is_homopolymer == 0)
                {
                    add_ID = j;
                }
            }

            for (j = 0; j < (int)hap->dp.backtrack_length[snpID]; j++)
            {
                if(j == add_ID)
                {
                    Preorder_Merge(column[j], hap, 1); 
                }
                else
                {
                    Preorder_Merge(column[j], hap, 0); 
                }
            }
        }
        else
        {
            for (j = 0; j < (int)hap->dp.backtrack_length[snpID]; j++)
            {
                Preorder_Merge(column[j], hap, 0); 
            }
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq 0x218(%rax), %rax
movl -0x4(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x1d0(%rax), %rax
movq -0x10(%rbp), %rcx
movl 0x1c8(%rcx), %ecx
imull -0x18(%rbp), %ecx
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x258(%rax), %rax
movl -0x4(%rbp), %ecx
movb $0x1, (%rax,%rcx)
cmpl $0x0, -0x14(%rbp)
je 0x3e880
movq -0x10(%rbp), %rax
movq 0x218(%rax), %rax
movl -0x4(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
cmpb $0x0, 0x24(%rax)
je 0x3e81a
movq -0x10(%rbp), %rax
movl 0x200(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x200(%rax)
jmp 0x3e82d
movq -0x10(%rbp), %rax
movl 0x204(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x204(%rax)
movq -0x10(%rbp), %rax
movl 0x208(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x208(%rax)
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x10(%rbp), %rax
movl 0x1c8(%rax), %edx
callq 0x3e280
movl %eax, -0x24(%rbp)
cmpl $-0x1, %eax
je 0x3e87e
movq 0x38577a(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x343f42(%rip), %rsi    # 0x3827b2
movb $0x0, %al
callq 0x22a0
xorl %edi, %edi
callq 0x2240
jmp 0x3e880
movq -0x10(%rbp), %rax
movq 0x278(%rax), %rax
movl -0x4(%rbp), %ecx
cmpl $0x0, (%rax,%rcx,4)
je 0x3e9cc
movq -0x10(%rbp), %rax
movq 0x280(%rax), %rax
movq -0x10(%rbp), %rcx
movl 0x250(%rcx), %ecx
imull -0x4(%rbp), %ecx
movl %ecx, %ecx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0x3e98a
movl $0x0, -0x38(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x278(%rcx), %rcx
movl -0x4(%rbp), %edx
cmpl (%rcx,%rdx,4), %eax
jge 0x3e925
movq -0x10(%rbp), %rax
movq 0x218(%rax), %rax
movq -0x30(%rbp), %rcx
movslq -0x34(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movzbl 0x24(%rax), %eax
cmpl $0x0, %eax
jne 0x3e918
movl -0x34(%rbp), %eax
movl %eax, -0x38(%rbp)
jmp 0x3e91a
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x3e8d6
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x278(%rcx), %rcx
movl -0x4(%rbp), %edx
cmpl (%rcx,%rdx,4), %eax
jge 0x3e988
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
jne 0x3e965
movq -0x30(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl (%rax,%rcx,4), %edi
movq -0x10(%rbp), %rsi
movl $0x1, %edx
callq 0x3e780
jmp 0x3e97b
movq -0x30(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl (%rax,%rcx,4), %edi
movq -0x10(%rbp), %rsi
xorl %edx, %edx
callq 0x3e780
jmp 0x3e97d
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x3e92c
jmp 0x3e9ca
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x278(%rcx), %rcx
movl -0x4(%rbp), %edx
cmpl (%rcx,%rdx,4), %eax
jge 0x3e9c8
movq -0x30(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl (%rax,%rcx,4), %edi
movq -0x10(%rbp), %rsi
xorl %edx, %edx
callq 0x3e780
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x3e991
jmp 0x3e9ca
jmp 0x3e9cc
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)