// File: chhylp123[P]hifiasm/Correct.cpp
// Function: push_idel_info(haplotype_evdience_alloc*, unsigned long, unsigned long, unsigned long, ul_ov_t*, unsigned long, ul_ov_t*, unsigned long, overlap_region*, unsigned long*, unsigned long, unsigned long, long, long, long, double, long)
void push_idel_info(haplotype_evdience_alloc *h, uint64_t s, uint64_t e, uint64_t err, ul_ov_t *a, uint64_t an, ul_ov_t *a1, uint64_t an1, overlap_region *oa, uint64_t *idx, uint64_t idx_n, uint64_t rid, int64_t het_cov, int64_t hom_cov, int64_t n_hap, double cut_rate, int64_t cut_bd)
{
    // fprintf(stderr, "\n");
    uint64_t k, q[2], os, oe, /**hn = h->length,**/ bl0 = h->length; int64_t cc, occ0, occ1, occ2; ul_ov_t *p; overlap_region *z; haplotype_evdience ev; int64_t ec; SnpStats *ps = NULL;
    for (k = occ0 = occ1 = occ2 = 0; k < idx_n; k++) {
        p = &(a[idx[k]]); z = &(oa[ovlp_id(*p)]); 
        if(z->is_match != 1) continue;

        q[0] = z->w_list.a[ovlp_cur_wid(*p)].x_start+ovlp_bd(*p);
        q[1] = z->w_list.a[ovlp_cur_wid(*p)].x_end+1-ovlp_bd(*p);
        os = MAX(q[0], s); oe = MIN(q[1], e);
        if((oe > os) && ((oe - os) >= ((e - s) - (oe - os)))) {
            // fprintf(stderr, "[M::%s]\ts::%lu\n", __func__, s);
            ec = extract_sub_err(z, s, e, os, oe, err, 0.2, p);
            if(ec >= 0) {
                occ0++;
                ev.misBase = 0;
                ev.overlapID = ovlp_id(*p);
                ev.site = s;
                ev.overlapSite = h->snp_stat.n;
                ev.type = 0;
                ev.cov = ec;///error
                // fprintf(stderr, "+0+[M::%s]\th->length::%u\tsite::%u\toverlapSite::%u\n", __func__, h->length, ev.site, ev.overlapSite);
                addHaplotypeEvdience(h, &ev, NULL);
            } else {
                occ2++;
            }
        }
    }

    ///add sv
    for (k = 0, occ1 = an1; k < an1; k++) {
        ev.misBase = 0;
        ev.overlapID = a1[k].tn;
        ev.site = s;
        ev.overlapSite = h->snp_stat.n;
        ev.type = 1;
        ev.cov = a1[k].qn;///error
        // fprintf(stderr, "+1+[M::%s]\th->length::%u\tsite::%u\toverlapSite::%u\n", __func__, h->length, ev.site, ev.overlapSite);
        addHaplotypeEvdience(h, &ev, NULL);
    }
    
    // for (k = hn; k < h->length; k++) {
    //     z = &(oa[h->list[k].overlapID]); 
        // fprintf(stderr, "[M::%s]\t%.*s\tq::[%u, %u)\terr::%u\ttype::%u\n", __func__, (int)Get_NAME_LENGTH(R_INF, z->y_id), Get_NAME(R_INF, z->y_id), h->list[k].site, h->list[k].overlapSite, h->list[k].cov, h->list[k].type);
    // }
    
    ///for debug indel
    // if(occ0 < 2 || occ1 < 2) {
    //     h->length = bl0;
    //     return;
    // }
    occ0++;
    cc = ((het_cov > 0)?(het_cov):(hom_cov/n_hap)); cc *= cut_rate; if(cc < cut_bd) cc = cut_bd;
    if(occ0 < cc || occ1 < cc) {
        h->length = bl0;
        return;
    }

    kv_pushp(SnpStats, h->snp_stat, &ps);
    ps->id = h->snp_stat.n-1;
    ps->occ_0 = occ0;
    ps->occ_1 = occ1;
    ps->occ_2 = occ2;
    ps->site = s;
    ps->score = -1;
    ps->overlap_num = 0;
    ps->is_homopolymer = 0;
    // fprintf(stderr, "-[M::%s]\trid::%lu\t%.*s\tq::[%lu,%lu)\terr::%lu\tocc0::%lu\tocc1::%lu\tocc2::%lu\n", __func__, rid, (int)Get_NAME_LENGTH(R_INF, rid), Get_NAME(R_INF, rid), s, e, err, 1 + occ0, occ1, occ2);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq 0x58(%rbp), %rax
movq 0x50(%rbp), %rax
movq 0x48(%rbp), %rax
movq 0x40(%rbp), %rax
movq 0x38(%rbp), %rax
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movsd %xmm0, -0x38(%rbp)
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
movq %rax, -0x68(%rbp)
movq $0x0, -0xc0(%rbp)
movq $0x0, -0x88(%rbp)
movq $0x0, -0x80(%rbp)
movq $0x0, -0x78(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq 0x30(%rbp), %rax
jae 0x77b73
movq -0x28(%rbp), %rax
movq 0x28(%rbp), %rcx
movq -0x40(%rbp), %rdx
imulq $0x1c, (%rcx,%rdx,8), %rcx
addq %rcx, %rax
movq %rax, -0x90(%rbp)
movq 0x20(%rbp), %rax
movq -0x90(%rbp), %rcx
movl 0xc(%rcx), %ecx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
movzbl 0x2c(%rax), %eax
cmpl $0x1, %eax
je 0x779a6
jmp 0x77b62
movq -0x98(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x90(%rbp), %rcx
movl (%rcx), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movl (%rax), %eax
movq -0x90(%rbp), %rcx
movl 0x18(%rcx), %ecx
andl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
addl %ecx, %eax
cltq
movq %rax, -0x50(%rbp)
movq -0x98(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x90(%rbp), %rcx
movl (%rcx), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
addl $0x1, %eax
movq -0x90(%rbp), %rcx
movl 0x18(%rcx), %ecx
andl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
subl %ecx, %eax
cltq
movq %rax, -0x48(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x10(%rbp), %rax
jb 0x77a2b
movq -0x50(%rbp), %rax
movq %rax, -0xc8(%rbp)
jmp 0x77a36
movq -0x10(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0xc8(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x18(%rbp), %rax
ja 0x77a58
movq -0x48(%rbp), %rax
movq %rax, -0xd0(%rbp)
jmp 0x77a63
movq -0x18(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x58(%rbp), %rax
jbe 0x77b60
movq -0x60(%rbp), %rax
subq -0x58(%rbp), %rax
movq -0x18(%rbp), %rcx
subq -0x10(%rbp), %rcx
movq -0x60(%rbp), %rdx
subq -0x58(%rbp), %rdx
subq %rdx, %rcx
cmpq %rcx, %rax
jb 0x77b60
movq -0x98(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x58(%rbp), %rcx
movq -0x60(%rbp), %r8
movq -0x20(%rbp), %r9
movq -0x90(%rbp), %rax
movsd 0x307546(%rip), %xmm0   # 0x37f010
movq %rax, (%rsp)
callq 0x6eb30
movq %rax, -0xb8(%rbp)
cmpq $0x0, -0xb8(%rbp)
jl 0x77b4c
movq -0x78(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x78(%rbp)
movb $0x0, -0x9c(%rbp)
movq -0x90(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0xac(%rbp)
movq -0x10(%rbp), %rax
movl %eax, -0xb0(%rbp)
movq -0x8(%rbp), %rax
movq 0x220(%rax), %rax
movl %eax, -0xa8(%rbp)
movb $0x0, -0xa4(%rbp)
movq -0xb8(%rbp), %rax
movl %eax, -0xa0(%rbp)
movq -0x8(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0xa0e90
jmp 0x77b5e
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
jmp 0x77b60
jmp 0x77b62
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x77949
movq $0x0, -0x40(%rbp)
movq 0x18(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x40(%rbp), %rax
cmpq 0x18(%rbp), %rax
jae 0x77c01
movb $0x0, -0x9c(%rbp)
movq 0x10(%rbp), %rax
imulq $0x1c, -0x40(%rbp), %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
movl %eax, -0xac(%rbp)
movq -0x10(%rbp), %rax
movl %eax, -0xb0(%rbp)
movq -0x8(%rbp), %rax
movq 0x220(%rax), %rax
movl %eax, -0xa8(%rbp)
movb $0x1, -0xa4(%rbp)
movq 0x10(%rbp), %rax
imulq $0x1c, -0x40(%rbp), %rcx
addq %rcx, %rax
movl (%rax), %eax
movl %eax, -0xa0(%rbp)
movq -0x8(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0xa0e90
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x77b83
movq -0x78(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x78(%rbp)
cmpq $0x0, 0x40(%rbp)
jle 0x77c21
movq 0x40(%rbp), %rax
movq %rax, -0xd8(%rbp)
jmp 0x77c32
movq 0x48(%rbp), %rax
cqto
idivq 0x50(%rbp)
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rax
movq %rax, -0x70(%rbp)
movsd -0x38(%rbp), %xmm1
cvtsi2sdq -0x70(%rbp), %xmm0
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
cmpq 0x58(%rbp), %rax
jge 0x77c67
movq 0x58(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x78(%rbp), %rax
cmpq -0x70(%rbp), %rax
jl 0x77c7b
movq -0x80(%rbp), %rax
cmpq -0x70(%rbp), %rax
jge 0x77c8d
movq -0x68(%rbp), %rax
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x10(%rax)
jmp 0x77dcc
jmp 0x77c8f
movq -0x8(%rbp), %rax
movq 0x220(%rax), %rax
movq -0x8(%rbp), %rcx
cmpq 0x228(%rcx), %rax
jne 0x77d16
movq -0x8(%rbp), %rax
cmpq $0x0, 0x228(%rax)
je 0x77ccc
movq -0x8(%rbp), %rax
movq 0x228(%rax), %rax
shlq %rax
movq %rax, -0xe0(%rbp)
jmp 0x77cda
movl $0x2, %eax
movq %rax, -0xe0(%rbp)
jmp 0x77cda
movq -0xe0(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x228(%rax)
movq -0x8(%rbp), %rax
movq 0x218(%rax), %rdi
movq -0x8(%rbp), %rax
imulq $0x28, 0x228(%rax), %rsi
callq 0x2360
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x218(%rax)
movq -0x8(%rbp), %rax
movq 0x218(%rax), %rax
movq -0x8(%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, -0xc0(%rbp)
movq -0x8(%rbp), %rax
movq 0x220(%rax), %rax
subq $0x1, %rax
movl %eax, %ecx
movq -0xc0(%rbp), %rax
movl %ecx, (%rax)
movq -0x78(%rbp), %rax
movl %eax, %ecx
movq -0xc0(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x80(%rbp), %rax
movl %eax, %ecx
movq -0xc0(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x88(%rbp), %rax
movl %eax, %ecx
movq -0xc0(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x10(%rbp), %rax
movl %eax, %ecx
movq -0xc0(%rbp), %rax
movl %ecx, 0x20(%rax)
movq -0xc0(%rbp), %rax
movl $0xffffffff, 0x1c(%rax) # imm = 0xFFFFFFFF
movq -0xc0(%rbp), %rax
movl $0x0, 0x4(%rax)
movq -0xc0(%rbp), %rax
movb $0x0, 0x24(%rax)
addq $0xf0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)