// File: /workspace/github_cpp_makefile_star2_O3/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
leaq 0xb6f90(%rip), %rax     # 0x296318
imulq $0x58, %rsi, %r14
addq 0x48(%rax), %r14
movq %rdi, %rbx
movq 0x88(%rdi), %rax
movslq %edx, %rbp
imulq $0x68, %rbp, %r13
movq 0x58(%rax,%r13), %rcx
leaq 0x30(%rsp), %r15
movq %rcx, 0x10(%r15)
movups 0x48(%rax,%r13), %xmm0
movaps %xmm0, (%r15)
movq 0x20(%rdi), %rdi
movq 0x28(%rbx), %rax
movq 0x30(%rax), %rdx
movq %r14, %rsi
movq %r15, %rcx
callq 0x1da4a8
movq 0x10(%r15), %rcx
movq 0x88(%rbx), %r12
movq %rcx, 0x58(%r12,%r13)
movdqa (%r15), %xmm0
movdqu %xmm0, 0x48(%r12,%r13)
testl %eax, %eax
je 0x1df5e9
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 0x1df471
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 0x20(%r14), %rax
movq $0x0, 0x20(%r15)
testq %rax, %rax
je 0x1df4ec
xorl %ecx, %ecx
xorl %eax, %eax
movq 0x18(%r15), %rdx
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, (%rdx,%rdi)
movq 0x30(%r14), %rsi
shlq $0x2, %rcx
leaq (%rcx,%rcx,8), %rcx
movdqu (%rsi,%rcx), %xmm0
pshufd $0xc9, %xmm0, %xmm0     # xmm0 = xmm0[1,2,0,3]
movdqu %xmm0, 0x4(%rdx,%rdi)
movl 0x10(%rsi,%rcx), %esi
movl %esi, 0x14(%rdx,%rdi)
orb $0x40, 0x1b(%rdx,%rdi)
movq 0x30(%r14), %rsi
movl 0x20(%rsi,%rcx), %ecx
andl $-0x20, %ecx
shll $0x1a, %ecx
orl $0x40000000, %ecx       # imm = 0x40000000
movl %ecx, 0x18(%rdx,%rdi)
incl %eax
movq %rax, %rcx
cmpq %rax, 0x20(%r14)
ja 0x1df482
leaq (%r12,%r13), %rcx
addq $0x18, %rcx
movq 0x88(%rbx), %rax
cmpq $0x0, 0x48(%rax,%r13)
movq %rbp, 0x28(%rsp)
je 0x1df579
movl $0x1, %ebp
xorl %edi, %edi
movq 0x58(%rax,%r13), %rax
movl (%rax,%rdi,8), %esi
movq 0x28(%rbx), %r8
movq (%rbx), %rax
movq 0x20(%rbx), %r9
movq 0x30(%r8), %rdx
movq 0x68(%rax), %xmm0
movq 0x80(%rbx), %rax
movq 0x28(%rsp), %rdi
movq (%rax,%rdi,8), %rax
addq $0x60, %rax
movq %rax, 0x18(%rsp)
movq %rdx, (%rsp)
movq $0x10, 0x8(%rsp)
movq %r14, %rdi
movq %r15, %rdx
movq %rcx, %r12
callq 0x1dc5f6
movq %r12, %rcx
movl %ebp, %edi
movq 0x88(%rbx), %rax
movq 0x48(%rax,%r13), %rdx
incl %ebp
cmpq %rdi, %rdx
ja 0x1df50f
jmp 0x1df57b
xorl %edx, %edx
movq 0x58(%rax,%r13), %rsi
leaq 0x30(%rsp), %r12
movq %rsi, 0x10(%r12)
movq %rdx, (%r12)
movq 0x50(%rax,%r13), %rax
movq %rax, 0x8(%r12)
movq 0x28(%rbx), %rdi
movq 0x30(%rdi), %rax
movq %rax, (%rsp)
movq %r15, %rdx
movq %r14, %r8
movq %r12, %r9
callq 0x1dc8e3
movq 0x10(%r12), %rcx
movq 0x88(%rbx), %rdx
movq %rcx, 0x58(%rdx,%r13)
movdqa (%r12), %xmm0
movdqu %xmm0, 0x48(%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