// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/inter.cpp
// Function: worker_for_contain_consensus(void*, long, int)
static void worker_for_contain_consensus(void *data, long i, int tid)
{
    ul_vec_t *p = &(UL_INF.a[i]); asg64_v b0; 
    utepdat_t *s = (utepdat_t*)data; uint32_t ff, k; 

	// if(i != 304) return;
    copy_asg_arr(b0, s->ll[tid].srt.a); 
    ff = refine_contain_consensus_chain(s->rg, p, s->uopt->ruIndex, &b0, i);
    copy_asg_arr(s->ll[tid].srt.a, b0);
    // fprintf(stderr, "[M::%s::%.*s(id:%ld), len:%u] ff:%u\n", __func__, 
    // UL_INF.nid.a[i].n, UL_INF.nid.a[i].a, i, p->rlen, ff);
	// if(debug_out) {
	// 	for (k = 0; k < p->bb.n; k++) {
	// 		fprintf(stderr, "[M::%.*s] q::[%u, %u), t::[%u, %u), is_cr::%u, pidx::%u, aidx::%u\n", 
	// 		(int)Get_NAME_LENGTH(R_INF, p->bb.a[k].hid), Get_NAME(R_INF, p->bb.a[k].hid), 
	// 		p->bb.a[k].qs, p->bb.a[k].qe, p->bb.a[k].ts, p->bb.a[k].te, 
	// 		!!(is_contain_r((*(s->uopt->ruIndex)), p->bb.a[k].hid)), p->bb.a[k].pidx, p->bb.a[k].aidx);
    // 	}
	// 	fprintf(stderr, "***[M::%s::%.*s(id:%ld), len:%u] ff:%u, sp_chn::%u, p->bb.n::%u\n\n", __func__, 
    // 	UL_INF.nid.a[i].n, UL_INF.nid.a[i].a, i, p->rlen, ff, (uint32_t)s->ll[tid].srt.a.n, (uint32_t)p->bb.n);
	// }
    if(!ff) return;
	
	// char *as = NULL; 
	// asprintf(&as, "\n[M::%s]\trid::%ld\tlen::%lu\tname::%.*s\tb0.n::%u\n", 
	// __func__, s->id+i, s->len[i], (int32_t)UL_INF.nid.a[s->id+i].n, UL_INF.nid.a[s->id+i].a, (uint32_t)b0.n);
    // push_vlog(&(overall_zdbg->a[s->id+i]), as); free(as); as = NULL;



    kv_ul_ov_t *idx = &(s->ll[tid].lo), *dump = &(s->ll[tid].tk); ul_ov_t *z;
    // if(p->dd == 1) return; //fully aligned
    // if(p->bb.n == 1 && p->bb.a[0].base) return;///no alignment
    // if(p->bb.n == 0) return;///no alignment
    s->hab[tid]->num_read_base++; 

	// if(i == 442462) {
	// 	fprintf(stderr, "\n[M::%s::%.*s(id:%ld), len:%u] ff:%u, sp_chn::%u, p->bb.n::%u\n", __func__, 
    // 	UL_INF.nid.a[i].n, UL_INF.nid.a[i].a, i, p->rlen, ff, (uint32_t)s->ll[tid].srt.a.n, (uint32_t)p->bb.n);
	// }

	// fprintf(stderr, "[M::%s]\tp->bb.n::%u\n", __func__, (uint32_t)p->bb.n);
    kv_resize(ul_ov_t, *dump, p->bb.n);
    for (k = dump->n = 0; k < p->bb.n; k++) {
        z = &(dump->a[dump->n++]); ///memset(z, 0, sizeof((*z)));
        z->qn = k; z->qs = p->bb.a[k].qs; z->qe = p->bb.a[k].qe; 
        z->tn = p->bb.a[k].hid; z->ts = p->bb.a[k].ts; z->te = p->bb.a[k].te; 
        z->el = 1; z->rev = p->bb.a[k].rev; z->sec = 0;
		// if(i == 442462) {
		// 	fprintf(stderr, "[M::%s::id->%u::%.*s] q::[%u, %u), t::[%u, %u), is_rev::%u, is_cr::%u\n", 
		// 	__func__, z->tn, (int)Get_NAME_LENGTH(R_INF, z->tn), Get_NAME(R_INF, z->tn), 
		// 	z->qs, z->qe, z->ts, z->te, z->rev, !!(is_contain_r((*(s->uopt->ruIndex)), z->tn)));
		// }
    }
    
    for (k = 0; k < s->ll[tid].srt.a.n; k++) {
        gen_contain_consensus_chain(p, s->ll[tid].srt.a.a[k], idx, dump, s->uopt, s->rg, s->uopt->ruIndex, G_CHAIN_BW, s->opt->diff_ec_ul, i, &(s->hab[tid]->clist.chainDP));
    }
	
    copy_asg_arr(b0, s->ll[tid].srt.a);
	ff = update_consensus_chain(s->uopt, s->rg, idx, dump, p, &b0, s->uopt->ruIndex);
    copy_asg_arr(s->ll[tid].srt.a, b0);
	s->hab[tid]->num_correct_base += ff;
	// fprintf(stderr, "[M::%s::%.*s(id:%ld), len:%u] ffa->%u, sp_chn::%u\n", __func__, 
    // UL_INF.nid.a[i].n, UL_INF.nid.a[i].a, i, p->rlen, ff, (uint32_t)s->ll[tid].srt.a.n);

    // s->hab[tid]->num_correct_base += direct_gchain(s->buf[tid], p, &(s->ll[tid]), &(s->gdp[tid]), &(s->sps[tid]), &(s->hab[tid]->hap), s->uu, s->uopt, G_CHAIN_BW, s->opt->diff_ec_ul, UG_SKIP, i, &(s->hab[tid]->clist.chainDP), s->rg, ((ff==2)?1:0));
    // gl_chain_refine_advance(&b->olist, &b->correct, &b->hap, bl, s->uu, s->opt->diff_ec_ul, winLen, s->len[i], s->uopt, s->id+i, km);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %rbx
leaq 0xb5f34(%rip), %rax     # 0x28b318
imulq $0x58, %rsi, %r14
addq 0x48(%rax), %r14
movq 0x88(%rdi), %rax
movslq %edx, %rbp
imulq $0x68, %rbp, %r13
movq 0x58(%rax,%r13), %rcx
leaq 0x30(%rsp), %r15
movq %rcx, 0x10(%r15)
movq 0x48(%rax,%r13), %rcx
movq %rcx, (%r15)
movq 0x50(%rax,%r13), %rax
movq %rax, 0x8(%r15)
movq 0x20(%rdi), %rdi
movq 0x28(%rbx), %rax
movq 0x30(%rax), %rdx
movq %r14, %rsi
movq %r15, %rcx
callq 0x1d04b1
movq 0x10(%r15), %rcx
movq 0x88(%rbx), %r12
movq %rcx, 0x58(%r12,%r13)
movq (%r15), %rcx
movq %rcx, 0x48(%r12,%r13)
movq 0x8(%r15), %rcx
movq %rcx, 0x50(%r12,%r13)
testl %eax, %eax
je 0x1d566a
movq 0x80(%rbx), %rax
movq (%rax,%rbp,8), %rax
incq 0xf0(%rax)
leaq (%r12,%r13), %r15
movq 0x20(%r14), %rax
cmpq %rax, 0x28(%r12,%r13)
jae 0x1d54d2
decq %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
leaq 0x1(%rcx), %rax
movq %rax, 0x28(%r15)
movq 0x18(%r15), %rdi
leaq (%rax,%rax,8), %rax
leaq (%rax,%rax,2), %rax
leaq (%rcx,%rax), %rsi
incq %rsi
callq 0x2370
movq %rax, 0x18(%r15)
movq $0x0, 0x20(%r15)
cmpq $0x0, 0x20(%r14)
je 0x1d556e
xorl %edx, %edx
xorl %eax, %eax
movq 0x18(%r15), %rcx
movq 0x20(%r15), %rsi
leaq 0x1(%rsi), %rdi
movq %rdi, 0x20(%r15)
leaq (%rsi,%rsi,8), %rdi
leaq (%rdi,%rdi,2), %rdi
addq %rsi, %rdi
movl %eax, (%rcx,%rdi)
movq 0x30(%r14), %rsi
shlq $0x2, %rdx
leaq (%rdx,%rdx,8), %rdx
movl 0x4(%rsi,%rdx), %r8d
movl %r8d, 0x4(%rcx,%rdi)
movl 0x8(%rsi,%rdx), %r8d
movl %r8d, 0x8(%rcx,%rdi)
movl (%rsi,%rdx), %r8d
movl %r8d, 0xc(%rcx,%rdi)
movl 0xc(%rsi,%rdx), %r8d
movl %r8d, 0x10(%rcx,%rdi)
movl 0x10(%rsi,%rdx), %esi
movl %esi, 0x14(%rcx,%rdi)
orb $0x40, 0x1b(%rcx,%rdi)
movq 0x30(%r14), %rsi
movl 0x20(%rsi,%rdx), %edx
andl $-0x20, %edx
shll $0x1a, %edx
orl $0x40000000, %edx       # imm = 0x40000000
movl %edx, 0x18(%rcx,%rdi)
incl %eax
movq %rax, %rdx
cmpq %rax, 0x20(%r14)
ja 0x1d54e9
addq %r13, %r12
addq $0x18, %r12
movq 0x88(%rbx), %rax
movq 0x48(%rax,%r13), %rdx
testq %rdx, %rdx
movq %rbp, 0x28(%rsp)
je 0x1d55f7
movl $0x1, %ebp
xorl %ecx, %ecx
movq 0x58(%rax,%r13), %rax
movl (%rax,%rcx,8), %esi
movq 0x28(%rbx), %r8
movq (%rbx), %rax
movq 0x20(%rbx), %r9
movq 0x30(%r8), %rcx
movsd 0x68(%rax), %xmm0
movq 0x80(%rbx), %rax
movq 0x28(%rsp), %rdx
movq (%rax,%rdx,8), %rax
addq $0x60, %rax
movq %rax, 0x18(%rsp)
movq %rcx, (%rsp)
movq $0x10, 0x8(%rsp)
movq %r14, %rdi
movq %r15, %rdx
movq %r12, %rcx
callq 0x1d2562
movl %ebp, %ecx
movq 0x88(%rbx), %rax
movq 0x48(%rax,%r13), %rdx
incl %ebp
cmpq %rcx, %rdx
ja 0x1d5592
movq 0x58(%rax,%r13), %rcx
leaq 0x30(%rsp), %rbp
movq %rcx, 0x10(%rbp)
movq %rdx, (%rbp)
movq 0x50(%rax,%r13), %rax
movq %rax, 0x8(%rbp)
movq 0x28(%rbx), %rdi
movq 0x30(%rdi), %rax
movq %rax, (%rsp)
movq %r15, %rdx
movq %r12, %rcx
movq %r14, %r8
movq %rbp, %r9
callq 0x1d2856
movq 0x10(%rbp), %rcx
movq 0x88(%rbx), %rdx
movq %rcx, 0x58(%rdx,%r13)
movq (%rbp), %rcx
movq %rcx, 0x48(%rdx,%r13)
movq 0x8(%rbp), %rcx
movq %rcx, 0x50(%rdx,%r13)
movl %eax, %eax
movq 0x80(%rbx), %rcx
movq 0x28(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
addq %rax, 0xf8(%rcx)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq