// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movsd %xmm0, 0x38(%rsp)
movq %rcx, 0x40(%rsp)
movq %rdi, %r14
movq 0xa0(%rsp), %r10
movl 0x10(%rdi), %eax
movl %eax, 0x2c(%rsp)
testq %r10, %r10
movq %rsi, 0x18(%rsp)
je 0x72022
movq %r8, %r15
movq %rdx, %r13
movq 0x98(%rsp), %r11
movq 0x90(%rsp), %rbx
xorl %r12d, %r12d
movq $0x0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movq (%r11,%r12,8), %rax
leaq (%rax,%rax,8), %rcx
leaq (%rcx,%rcx,2), %rbp
addq %rax, %rbp
movl 0xc(%r15,%rbp), %eax
imulq $0xa8, %rax, %rdi
cmpb $0x1, 0x2c(%rbx,%rdi)
jne 0x7200f
addq %r15, %rbp
addq %rbx, %rdi
movq 0x58(%rdi), %rax
movl (%rbp), %r8d
movl 0x18(%rbp), %edx
shlq $0x5, %r8
movslq (%rax,%r8), %rcx
andl $0x3fffffff, %edx       # imm = 0x3FFFFFFF
addq %rdx, %rcx
cmpq %rsi, %rcx
ja 0x71f06
movq %rsi, %rcx
movl 0x4(%rax,%r8), %eax
subl %edx, %eax
incl %eax
movslq %eax, %r8
cmpq %r13, %r8
jb 0x71f1a
movq %r13, %r8
movq %r8, %rax
subq %rcx, %rax
jbe 0x7200f
movq %r13, %r9
subq %rax, %r9
subq %rsi, %r9
cmpq %r9, %rax
jb 0x7200f
movq %rbp, (%rsp)
movq %r13, %rdx
movq 0x40(%rsp), %r9
movsd 0x1b3534(%rip), %xmm0   # 0x225480
callq 0x6d7e9
testq %rax, %rax
js 0x71fed
movq %rax, %rdi
movl 0xc(%rbp), %ebx
movl 0x220(%r14), %ebp
movl 0x10(%r14), %eax
leal 0x1(%rax), %ecx
cmpl 0x14(%r14), %ecx
jbe 0x71fb9
movl %eax, %ecx
shrl %ecx
orl %eax, %ecx
movl %ecx, %eax
shrl $0x2, %eax
orl %ecx, %eax
movl %eax, %ecx
shrl $0x4, %ecx
orl %eax, %ecx
movl %ecx, %eax
shrl $0x8, %eax
orl %ecx, %eax
movl %eax, %ecx
shrl $0x10, %ecx
orl %eax, %ecx
incl %ecx
movl %ecx, 0x14(%r14)
movq %rdi, 0x30(%rsp)
movq (%r14), %rdi
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rsi
callq 0x2370
movq 0x30(%rsp), %rdi
movq %rax, (%r14)
incq 0x10(%rsp)
movq (%r14), %rax
movl 0x10(%r14), %ecx
leaq (%rcx,%rcx,2), %rcx
movq 0x18(%rsp), %rsi
movl %esi, (%rax,%rcx,8)
movl %ebx, 0x4(%rax,%rcx,8)
movl %ebp, 0x8(%rax,%rcx,8)
xorl %edx, %edx
movb %dl, 0xc(%rax,%rcx,8)
movl %edi, 0x10(%rax,%rcx,8)
movb %dl, 0x14(%rax,%rcx,8)
incl 0x10(%r14)
jmp 0x71ff7
incq 0x20(%rsp)
movq 0x18(%rsp), %rsi
movq 0xa0(%rsp), %r10
movq 0x98(%rsp), %r11
movq 0x90(%rsp), %rbx
incq %r12
cmpq %r12, %r10
jne 0x71eb6
incq 0x10(%rsp)
jmp 0x72035
movl $0x1, %eax
movq %rax, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
cmpq $0x0, 0x88(%rsp)
je 0x720e7
movq 0x80(%rsp), %r12
movq 0x88(%rsp), %r13
movl (%r12), %ebp
movl 0xc(%r12), %r15d
movl 0x220(%r14), %ebx
movl 0x10(%r14), %eax
leal 0x1(%rax), %ecx
cmpl 0x14(%r14), %ecx
jbe 0x720b1
movl %eax, %ecx
shrl %ecx
orl %eax, %ecx
movl %ecx, %eax
shrl $0x2, %eax
orl %ecx, %eax
movl %eax, %ecx
shrl $0x4, %ecx
orl %eax, %ecx
movl %ecx, %eax
shrl $0x8, %eax
orl %ecx, %eax
movl %eax, %ecx
shrl $0x10, %ecx
orl %eax, %ecx
incl %ecx
movl %ecx, 0x14(%r14)
movq (%r14), %rdi
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rsi
callq 0x2370
movq 0x18(%rsp), %rsi
movq %rax, (%r14)
movq (%r14), %rax
movl 0x10(%r14), %ecx
leaq (%rcx,%rcx,2), %rcx
movl %esi, (%rax,%rcx,8)
movl %r15d, 0x4(%rax,%rcx,8)
movl %ebx, 0x8(%rax,%rcx,8)
movb $0x1, 0xc(%rax,%rcx,8)
movl %ebp, 0x10(%rax,%rcx,8)
movb $0x0, 0x14(%rax,%rcx,8)
incl 0x10(%r14)
addq $0x1c, %r12
decq %r13
jne 0x72054
movq 0xc8(%rsp), %rcx
movq 0xb0(%rsp), %rax
testq %rax, %rax
jg 0x7210e
movq 0xb8(%rsp), %rax
cqto
idivq 0xc0(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
mulsd 0x38(%rsp), %xmm0
cvttsd2si %xmm0, %rax
cmpq %rcx, %rax
cmovgq %rax, %rcx
movq 0x10(%rsp), %r15
cmpq %rcx, %r15
setge %al
movq 0x88(%rsp), %rbx
cmpq %rbx, %rcx
setle %cl
testb %cl, %al
jne 0x72152
movl 0x2c(%rsp), %eax
movl %eax, 0x10(%r14)
jmp 0x721e4
movq 0x228(%r14), %rax
cmpq %rax, 0x220(%r14)
jne 0x72199
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmovneq %rcx, %rax
movq %rax, 0x228(%r14)
movq 0x218(%r14), %rdi
shlq $0x3, %rax
leaq (%rax,%rax,4), %rsi
callq 0x2370
movq 0x18(%rsp), %rsi
movq %rax, 0x218(%r14)
movq 0x218(%r14), %rax
movq 0x220(%r14), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x220(%r14)
leaq (%rcx,%rcx,4), %rdx
movl %ecx, (%rax,%rdx,8)
movl %r15d, 0x8(%rax,%rdx,8)
movl %ebx, 0xc(%rax,%rdx,8)
movq 0x20(%rsp), %rcx
movl %ecx, 0x10(%rax,%rdx,8)
movl %esi, 0x20(%rax,%rdx,8)
movl $0xffffffff, 0x1c(%rax,%rdx,8) # imm = 0xFFFFFFFF
movl $0x0, 0x4(%rax,%rdx,8)
movb $0x0, 0x24(%rax,%rdx,8)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq