// File: /workspace/github_cpp_makefile_star2_O2/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 0xc21ca(%rip), %rax     # 0x254318
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 0x18d2bc
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 0x192368
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 0x192227
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
incq %rcx
movq %rcx, 0x28(%r15)
movq 0x18(%r15), %rdi
imulq $0x1c, %rcx, %rsi
callq 0x2370
movq %rax, 0x18(%r15)
leaq (%r12,%r13), %rax
addq $0x18, %rax
movq %rax, 0x28(%rsp)
andq $0x0, 0x20(%r15)
xorl %eax, %eax
movl %eax, %ecx
cmpq %rcx, 0x20(%r14)
jbe 0x19229b
movq 0x18(%r15), %rdx
movq 0x20(%r15), %rsi
leaq 0x1(%rsi), %rdi
movq %rdi, 0x20(%r15)
imulq $0x1c, %rsi, %rsi
movl %eax, (%rdx,%rsi)
movq 0x30(%r14), %rdi
imulq $0x24, %rcx, %rcx
movdqu (%rdi,%rcx), %xmm0
pshufd $0xc9, %xmm0, %xmm0     # xmm0 = xmm0[1,2,0,3]
movdqu %xmm0, 0x4(%rdx,%rsi)
movl 0x10(%rdi,%rcx), %edi
movl %edi, 0x14(%rdx,%rsi)
orb $0x40, 0x1b(%rdx,%rsi)
movq 0x30(%r14), %rdi
movl 0x20(%rdi,%rcx), %ecx
andl $-0x20, %ecx
shll $0x1a, %ecx
orl $0x40000000, %ecx       # imm = 0x40000000
movl %ecx, 0x18(%rdx,%rsi)
incl %eax
jmp 0x19223b
movq %rbp, %r12
xorl %eax, %eax
movl %eax, %ebp
movq 0x88(%rbx), %rax
movq 0x48(%rax,%r13), %rdx
movq 0x58(%rax,%r13), %rcx
cmpq %rbp, %rdx
jbe 0x192305
movl (%rcx,%rbp,8), %esi
movq 0x28(%rbx), %r8
movq (%rbx), %rax
movq 0x20(%rbx), %r9
movq 0x30(%r8), %rcx
movq 0x68(%rax), %xmm0
movq 0x80(%rbx), %rax
movq (%rax,%r12,8), %rax
addq $0x60, %rax
movq %rax, 0x18(%rsp)
movq %rcx, (%rsp)
movq $0x10, 0x8(%rsp)
movq %r14, %rdi
movq %r15, %rdx
movq 0x28(%rsp), %rcx
callq 0x18ecca
leal 0x1(%rbp), %eax
jmp 0x1922a0
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 0x28(%rsp), %rcx
movq %r14, %r8
movq %rbp, %r9
callq 0x18ef85
movq 0x10(%rbp), %rcx
movq 0x88(%rbx), %rdx
movq %rcx, 0x58(%rdx,%r13)
movaps (%rbp), %xmm0
movups %xmm0, 0x48(%rdx,%r13)
movl %eax, %eax
movq 0x80(%rbx), %rcx
movq (%rcx,%r12,8), %rcx
addq %rax, 0xf8(%rcx)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq