// File: chhylp123[P]hifiasm/Correct.cpp
// Function: push_info(haplotype_evdience_alloc*, haplotype_evdience*, unsigned long, haplotype_evdience*, overlap_region*, asg8_v*, unsigned long)
int push_info(haplotype_evdience_alloc* h, haplotype_evdience* a, uint64_t a_n, haplotype_evdience* u_a, overlap_region *oa, asg8_v *v8, uint64_t scw)
{
    uint64_t i, k, m, occ_0, occ_1[6], occ_2, diff, rev_n; uint8_t ihpc = 0;
    occ_0 = occ_2 = diff = rev_n = 0; memset(occ_1, 0, sizeof(uint64_t)*6);

    radix_sort_haplotype_evdience_id_srt(a, a + a_n);
    for (k = 1, m = i = 0; k <= a_n; k++) {
        if((k == a_n) || (a[k].overlapID != a[m].overlapID)) {
            a[i] = a[m];
            if(hh_tp(a[i]) == 0){
                occ_0 += a[i].cov;
                if((oa) && (oa[a[i].overlapID].y_pos_strand == 0)) {
                    rev_n += a[i].cov;
                }
                if((!ihpc) && (hh_hp(a[i]))) ihpc = 1;
            }else if(hh_tp(a[i]) == 1){
                occ_1[seq_nt6_table[(uint8_t)(a[i].misBase)]] += a[i].cov;
                diff += a[i].cov;
            }
            occ_2 += a[i].cov;

            i++; m = k;
        }
    }
    a_n = i;
    
    // for (i = 0; i < a_n; i++) {
    //     if(hh_tp(a[i]) == 0){
    //         occ_0 += a[i].cov;
    //         if((oa) && (oa[a[i].overlapID].y_pos_strand == 0)) {
    //             rev_n += a[i].cov;
    //         }
    //         if((!ihpc) && (hh_hp(a[i]))) ihpc = 1;
    //     }else if(hh_tp(a[i]) == 1){
    //         occ_1[seq_nt6_table[(uint8_t)(a[i].misBase)]] += a[i].cov;
    //         diff += a[i].cov;
    //     }
    //     occ_2 += a[i].cov;
    // }


    /**
     1. if occ_0 = 0, that means all overlaps are different with this read at this site
     2. it is not possible that occ_1 = 0,
     3. if occ_1 = 1, there are only one difference. It must be a sequencing error.
        (for repeat, it maybe a snp at repeat. but ...)
    **/
    SnpStats *p = NULL; 
    if(occ_0 == 0 || diff <= 1) return 0;
    if((oa) && (rev_n == occ_0)) return 0;
    if(!oa) {
        rev_n = occ_2;
    } else {
        rev_n++;
    }

    for (i = m = 0; i < 4; i++) {
        if(occ_1[i] >= 2){
            kv_pushp(SnpStats, h->snp_stat, &p);
            p->id = h->snp_stat.n-1;
            p->occ_0 = 1 + occ_0;
            p->occ_1 = occ_1[i];
            p->occ_2 = occ_2 - p->occ_0 - p->occ_1;
            p->site = a[0].site;
            p->score = -1;
            p->overlap_num = rev_n;
            p->is_homopolymer = ihpc;
            occ_1[i] = p->id;
            m++;
            // fprintf(stderr, "[M::%s]\tsite::%u\tn0::%u\tn1::%u\n", __func__, p->site, p->occ_0, p->occ_1);
        } else {
            occ_1[i] = (uint64_t)-1;
        }
    }
    occ_1[4] = occ_1[5] = (uint64_t)-1;
    if(m == 0) return 0;
    
    if(!v8) {
        for (i = m = 0; i < a_n; i++) {
            // fprintf(stderr, "[M::%s] a[%lu].misBase->%c\n", __func__, i, a[i].misBase);
            if(hh_tp(a[i]) == 0) {
                a[i].overlapSite = h->snp_stat.n-1;
            } else if(occ_1[seq_nt6_table[(uint8_t)(a[i].misBase)]]!=(uint64_t)-1){
                a[i].cov = a[i].overlapSite;///note: only renew cov here!!!
                a[i].overlapSite = occ_1[seq_nt6_table[(uint8_t)(a[i].misBase)]];
            } else {
                continue;
            }
            u_a[m++] = a[i];
        }
    } else {
        uint64_t tpos, tqual, wqual;
        for (i = m = 0; i < a_n; i++) {
            tpos = a[i].overlapSite;
            if(hh_tp(a[i]) == 0) {
                a[i].overlapSite = h->snp_stat.n-1;
            } else if(occ_1[seq_nt6_table[(uint8_t)(a[i].misBase)]]!=(uint64_t)-1){
                a[i].cov = a[i].overlapSite;///note: only renew cov here!!!
                a[i].overlapSite = occ_1[seq_nt6_table[(uint8_t)(a[i].misBase)]];
            } else {
                continue;
            }
            get_wqual(oa[a[i].overlapID].y_id, tpos, oa[a[i].overlapID].y_pos_strand, v8, NULL, scw, &tqual, &wqual);
            a[i].type |= (tqual<<2); a[i].type |= (wqual<<(sc_bn+2));
            // assert(hh_bq(a[i]) == tqual); assert(hh_wq(a[i]) == wqual); 
            // fprintf(stderr, "[M::%s] site::%u, type::%u, occ0::%lu, occ2::%lu, tqual::%lu, wqual::%lu\n", __func__, a[i].site, hh_tp(a[i]), occ_0, occ_2, tqual, wqual);
            u_a[m++] = a[i];
        }
    }
    

    return m;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movb $0x0, -0xa9(%rbp)
movq $0x0, -0xa8(%rbp)
movq $0x0, -0xa0(%rbp)
movq $0x0, -0x98(%rbp)
movq $0x0, -0x58(%rbp)
leaq -0x90(%rbp), %rdi
xorl %esi, %esi
movl $0x30, %edx
callq 0x2100
movq -0x18(%rbp), %rdi
movq -0x18(%rbp), %rsi
imulq $0x18, -0x20(%rbp), %rax
addq %rax, %rsi
callq 0x2e440
movq $0x1, -0x48(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x20(%rbp), %rax
ja 0x4abc0
movq -0x48(%rbp), %rax
cmpq -0x20(%rbp), %rax
je 0x4aa33
movq -0x18(%rbp), %rax
imulq $0x18, -0x48(%rbp), %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movq -0x18(%rbp), %rcx
imulq $0x18, -0x50(%rbp), %rdx
addq %rdx, %rcx
cmpl 0x4(%rcx), %eax
je 0x4abad
movq -0x18(%rbp), %rcx
imulq $0x18, -0x50(%rbp), %rax
addq %rax, %rcx
movq -0x18(%rbp), %rax
imulq $0x18, -0x40(%rbp), %rdx
addq %rdx, %rax
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movq 0x10(%rcx), %rcx
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rax
imulq $0x18, -0x40(%rbp), %rcx
addq %rcx, %rax
movzbl 0xc(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x4ab07
movq -0x18(%rbp), %rax
imulq $0x18, -0x40(%rbp), %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
addq -0x58(%rbp), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x4aadb
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
imulq $0x18, -0x40(%rbp), %rdx
addq %rdx, %rcx
movl 0x4(%rcx), %ecx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0x1c(%rax)
jne 0x4aadb
movq -0x18(%rbp), %rax
imulq $0x18, -0x40(%rbp), %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
addq -0xa8(%rbp), %rax
movq %rax, -0xa8(%rbp)
cmpb $0x0, -0xa9(%rbp)
jne 0x4ab05
movq -0x18(%rbp), %rax
imulq $0x18, -0x40(%rbp), %rcx
addq %rcx, %rax
movzbl 0xc(%rax), %eax
sarl %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x4ab05
movb $0x1, -0xa9(%rbp)
jmp 0x4ab7c
movq -0x18(%rbp), %rax
imulq $0x18, -0x40(%rbp), %rcx
addq %rcx, %rax
movzbl 0xc(%rax), %eax
andl $0x1, %eax
cmpl $0x1, %eax
jne 0x4ab7a
movq -0x18(%rbp), %rax
imulq $0x18, -0x40(%rbp), %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
movl %eax, %ecx
movq -0x18(%rbp), %rax
imulq $0x18, -0x40(%rbp), %rdx
addq %rdx, %rax
movzbl 0x14(%rax), %eax
movl %eax, %edx
leaq 0x379b07(%rip), %rax    # 0x3c4650
movzbl (%rax,%rdx), %eax
addq -0x90(%rbp,%rax,8), %rcx
movq %rcx, -0x90(%rbp,%rax,8)
movq -0x18(%rbp), %rax
imulq $0x18, -0x40(%rbp), %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
addq -0xa0(%rbp), %rax
movq %rax, -0xa0(%rbp)
jmp 0x4ab7c
movq -0x18(%rbp), %rax
imulq $0x18, -0x40(%rbp), %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
addq -0x98(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x50(%rbp)
jmp 0x4abaf
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x4a9f7
movq -0x40(%rbp), %rax
movq %rax, -0x20(%rbp)
movq $0x0, -0xb8(%rbp)
cmpq $0x0, -0x58(%rbp)
je 0x4abe4
cmpq $0x1, -0xa0(%rbp)
ja 0x4abf0
movl $0x0, -0x4(%rbp)
jmp 0x4b17d
cmpq $0x0, -0x30(%rbp)
je 0x4ac10
movq -0xa8(%rbp), %rax
cmpq -0x58(%rbp), %rax
jne 0x4ac10
movl $0x0, -0x4(%rbp)
jmp 0x4b17d
cmpq $0x0, -0x30(%rbp)
jne 0x4ac27
movq -0x98(%rbp), %rax
movq %rax, -0xa8(%rbp)
jmp 0x4ac39
movq -0xa8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xa8(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x40(%rbp)
cmpq $0x4, -0x40(%rbp)
jae 0x4ae1e
movq -0x40(%rbp), %rax
cmpq $0x2, -0x90(%rbp,%rax,8)
jb 0x4adfb
jmp 0x4ac69
movq -0x10(%rbp), %rax
movq 0x220(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x228(%rcx), %rax
jne 0x4acf0
movq -0x10(%rbp), %rax
cmpq $0x0, 0x228(%rax)
je 0x4aca6
movq -0x10(%rbp), %rax
movq 0x228(%rax), %rax
shlq %rax
movq %rax, -0xd8(%rbp)
jmp 0x4acb4
movl $0x2, %eax
movq %rax, -0xd8(%rbp)
jmp 0x4acb4
movq -0xd8(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x228(%rax)
movq -0x10(%rbp), %rax
movq 0x218(%rax), %rdi
movq -0x10(%rbp), %rax
imulq $0x28, 0x228(%rax), %rsi
callq 0x2360
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x218(%rax)
movq -0x10(%rbp), %rax
movq 0x218(%rax), %rax
movq -0x10(%rbp), %rdx
movq 0x220(%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x220(%rdx)
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0xb8(%rbp)
movq -0x10(%rbp), %rax
movq 0x220(%rax), %rax
subq $0x1, %rax
movl %eax, %ecx
movq -0xb8(%rbp), %rax
movl %ecx, (%rax)
movq -0x58(%rbp), %rax
addq $0x1, %rax
movl %eax, %ecx
movq -0xb8(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x40(%rbp), %rax
movq -0x90(%rbp,%rax,8), %rax
movl %eax, %ecx
movq -0xb8(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x98(%rbp), %rax
movq -0xb8(%rbp), %rcx
movl 0x8(%rcx), %ecx
subq %rcx, %rax
movq -0xb8(%rbp), %rcx
movl 0xc(%rcx), %ecx
subq %rcx, %rax
movl %eax, %ecx
movq -0xb8(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x18(%rbp), %rax
movl (%rax), %ecx
movq -0xb8(%rbp), %rax
movl %ecx, 0x20(%rax)
movq -0xb8(%rbp), %rax
movl $0xffffffff, 0x1c(%rax) # imm = 0xFFFFFFFF
movq -0xa8(%rbp), %rax
movl %eax, %ecx
movq -0xb8(%rbp), %rax
movl %ecx, 0x4(%rax)
movb -0xa9(%rbp), %cl
movq -0xb8(%rbp), %rax
movb %cl, 0x24(%rax)
movq -0xb8(%rbp), %rax
movl (%rax), %eax
movl %eax, %ecx
movq -0x40(%rbp), %rax
movq %rcx, -0x90(%rbp,%rax,8)
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x4ae0b
movq -0x40(%rbp), %rax
movq $-0x1, -0x90(%rbp,%rax,8)
jmp 0x4ae0d
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x4ac49
movq $-0x1, -0x68(%rbp)
movq $-0x1, -0x70(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x4ae41
movl $0x0, -0x4(%rbp)
jmp 0x4b17d
cmpq $0x0, -0x38(%rbp)
jne 0x4af7b
movq $0x0, -0x50(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x20(%rbp), %rax
jae 0x4af76
movq -0x18(%rbp), %rax
imulq $0x18, -0x40(%rbp), %rcx
addq %rcx, %rax
movzbl 0xc(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x4aea7
movq -0x10(%rbp), %rax
movq 0x220(%rax), %rax
subq $0x1, %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
imulq $0x18, -0x40(%rbp), %rdx
addq %rdx, %rax
movl %ecx, 0x8(%rax)
jmp 0x4af29
movq -0x18(%rbp), %rax
imulq $0x18, -0x40(%rbp), %rcx
addq %rcx, %rax
movzbl 0x14(%rax), %eax
movl %eax, %ecx
leaq 0x379790(%rip), %rax    # 0x3c4650
movzbl (%rax,%rcx), %eax
cmpq $-0x1, -0x90(%rbp,%rax,8)
je 0x4af25
movq -0x18(%rbp), %rax
imulq $0x18, -0x40(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %ecx
movq -0x18(%rbp), %rax
imulq $0x18, -0x40(%rbp), %rdx
addq %rdx, %rax
movl %ecx, 0x10(%rax)
movq -0x18(%rbp), %rax
imulq $0x18, -0x40(%rbp), %rcx
addq %rcx, %rax
movzbl 0x14(%rax), %eax
movl %eax, %ecx
leaq 0x37974a(%rip), %rax    # 0x3c4650
movzbl (%rax,%rcx), %eax
movq -0x90(%rbp,%rax,8), %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
imulq $0x18, -0x40(%rbp), %rdx
addq %rdx, %rax
movl %ecx, 0x8(%rax)
jmp 0x4af27
jmp 0x4af65
jmp 0x4af29
movq -0x18(%rbp), %rcx
imulq $0x18, -0x40(%rbp), %rax
addq %rax, %rcx
movq -0x28(%rbp), %rax
movq -0x50(%rbp), %rdx
movq %rdx, %rsi
addq $0x1, %rsi
movq %rsi, -0x50(%rbp)
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movq 0x10(%rcx), %rcx
movq %rcx, 0x10(%rax)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x4ae5c
jmp 0x4b176
movq $0x0, -0x50(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x20(%rbp), %rax
jae 0x4b174
movq -0x18(%rbp), %rax
imulq $0x18, -0x40(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movq %rax, -0xc0(%rbp)
movq -0x18(%rbp), %rax
imulq $0x18, -0x40(%rbp), %rcx
addq %rcx, %rax
movzbl 0xc(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x4afec
movq -0x10(%rbp), %rax
movq 0x220(%rax), %rax
subq $0x1, %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
imulq $0x18, -0x40(%rbp), %rdx
addq %rdx, %rax
movl %ecx, 0x8(%rax)
jmp 0x4b071
movq -0x18(%rbp), %rax
imulq $0x18, -0x40(%rbp), %rcx
addq %rcx, %rax
movzbl 0x14(%rax), %eax
movl %eax, %ecx
leaq 0x37964b(%rip), %rax    # 0x3c4650
movzbl (%rax,%rcx), %eax
cmpq $-0x1, -0x90(%rbp,%rax,8)
je 0x4b06a
movq -0x18(%rbp), %rax
imulq $0x18, -0x40(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %ecx
movq -0x18(%rbp), %rax
imulq $0x18, -0x40(%rbp), %rdx
addq %rdx, %rax
movl %ecx, 0x10(%rax)
movq -0x18(%rbp), %rax
imulq $0x18, -0x40(%rbp), %rcx
addq %rcx, %rax
movzbl 0x14(%rax), %eax
movl %eax, %ecx
leaq 0x379605(%rip), %rax    # 0x3c4650
movzbl (%rax,%rcx), %eax
movq -0x90(%rbp,%rax,8), %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
imulq $0x18, -0x40(%rbp), %rdx
addq %rdx, %rax
movl %ecx, 0x8(%rax)
jmp 0x4b06f
jmp 0x4b163
jmp 0x4b071
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
imulq $0x18, -0x40(%rbp), %rdx
addq %rdx, %rcx
movl 0x4(%rcx), %ecx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
movl %eax, %edi
movq -0xc0(%rbp), %rsi
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
imulq $0x18, -0x40(%rbp), %rdx
addq %rdx, %rcx
movl 0x4(%rcx), %ecx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movl 0x1c(%rax), %eax
movl %eax, %edx
movq -0x38(%rbp), %rcx
movq 0x10(%rbp), %r9
xorl %eax, %eax
movl %eax, %r8d
leaq -0xc8(%rbp), %r10
leaq -0xd0(%rbp), %rax
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x45d00
movq -0xc8(%rbp), %rdx
shlq $0x2, %rdx
movq -0x18(%rbp), %rax
imulq $0x18, -0x40(%rbp), %rcx
addq %rcx, %rax
movzbl 0xc(%rax), %ecx
orq %rdx, %rcx
movb %cl, 0xc(%rax)
movq -0xd0(%rbp), %rdx
shlq $0x4, %rdx
movq -0x18(%rbp), %rax
imulq $0x18, -0x40(%rbp), %rcx
addq %rcx, %rax
movzbl 0xc(%rax), %ecx
orq %rdx, %rcx
movb %cl, 0xc(%rax)
movq -0x18(%rbp), %rcx
imulq $0x18, -0x40(%rbp), %rax
addq %rax, %rcx
movq -0x28(%rbp), %rax
movq -0x50(%rbp), %rdx
movq %rdx, %rsi
addq $0x1, %rsi
movq %rsi, -0x50(%rbp)
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movq 0x10(%rcx), %rcx
movq %rcx, 0x10(%rax)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x4af8b
jmp 0x4b176
movq -0x50(%rbp), %rax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xf0, %rsp
popq %rbp
retq
nopl (%rax)