// File: 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
movq %rsp, %rbp
pushq %rbx
subq $0x88, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
leaq 0xd778a(%rip), %rax     # 0x3c53b8
movq 0x48(%rax), %rax
imulq $0x58, -0x18(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq 0x88(%rax), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x68, %rcx, %rcx
addq %rcx, %rax
movq 0x58(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x48(%rbp), %rax
movq 0x88(%rax), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x68, %rcx, %rcx
addq %rcx, %rax
movq 0x48(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x48(%rbp), %rax
movq 0x88(%rax), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x68, %rcx, %rcx
addq %rcx, %rax
movq 0x50(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x48(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x28(%rbp), %rsi
movq -0x48(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x30(%rax), %rdx
movq -0x18(%rbp), %r8
leaq -0x40(%rbp), %rcx
callq 0x2e4ab0
movl %eax, -0x4c(%rbp)
movq -0x30(%rbp), %rcx
movq -0x48(%rbp), %rax
movq 0x88(%rax), %rax
movslq -0x1c(%rbp), %rdx
imulq $0x68, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x58(%rax)
movq -0x40(%rbp), %rcx
movq -0x48(%rbp), %rax
movq 0x88(%rax), %rax
movslq -0x1c(%rbp), %rdx
imulq $0x68, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x48(%rax)
movq -0x38(%rbp), %rcx
movq -0x48(%rbp), %rax
movq 0x88(%rax), %rax
movslq -0x1c(%rbp), %rdx
imulq $0x68, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x50(%rax)
cmpl $0x0, -0x4c(%rbp)
jne 0x2edd2d
jmp 0x2ee18d
movq -0x48(%rbp), %rax
movq 0x88(%rax), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x68, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x48(%rbp), %rax
movq 0x88(%rax), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x68, %rcx, %rcx
addq %rcx, %rax
addq $0x18, %rax
movq %rax, -0x60(%rbp)
movq -0x48(%rbp), %rax
movq 0x80(%rax), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0xf0(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0xf0(%rax)
movq -0x60(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x28(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jae 0x2ede66
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rcx
movq -0x60(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x60(%rbp), %rax
movq 0x10(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0x10(%rax)
movq -0x60(%rbp), %rax
movq 0x10(%rax), %rcx
shrq %rcx
movq -0x60(%rbp), %rax
orq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
movq -0x60(%rbp), %rax
movq 0x10(%rax), %rcx
shrq $0x2, %rcx
movq -0x60(%rbp), %rax
orq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
movq -0x60(%rbp), %rax
movq 0x10(%rax), %rcx
shrq $0x4, %rcx
movq -0x60(%rbp), %rax
orq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
movq -0x60(%rbp), %rax
movq 0x10(%rax), %rcx
shrq $0x8, %rcx
movq -0x60(%rbp), %rax
orq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
movq -0x60(%rbp), %rax
movq 0x10(%rax), %rcx
shrq $0x10, %rcx
movq -0x60(%rbp), %rax
orq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
movq -0x60(%rbp), %rax
movq 0x10(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x10(%rax)
movq -0x60(%rbp), %rax
movq (%rax), %rdi
movq -0x60(%rbp), %rax
imulq $0x1c, 0x10(%rax), %rsi
callq 0x2360
movq %rax, %rcx
movq -0x60(%rbp), %rax
movq %rcx, (%rax)
jmp 0x2ede68
movq -0x60(%rbp), %rax
movq $0x0, 0x8(%rax)
movl $0x0, -0x50(%rbp)
movl -0x50(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jae 0x2edfb1
movq -0x60(%rbp), %rax
movq (%rax), %rax
movq -0x60(%rbp), %rdx
movq 0x8(%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x8(%rdx)
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movl -0x50(%rbp), %ecx
movq -0x68(%rbp), %rax
movl %ecx, (%rax)
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x50(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %ecx
movq -0x68(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x50(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %ecx
movq -0x68(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x50(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %ecx
movq -0x68(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x50(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %ecx
movq -0x68(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x50(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %ecx
movq -0x68(%rbp), %rax
movl %ecx, 0x14(%rax)
movq -0x68(%rbp), %rax
movl 0x18(%rax), %ecx
andl $0xbfffffff, %ecx       # imm = 0xBFFFFFFF
orl $0x40000000, %ecx       # imm = 0x40000000
movl %ecx, 0x18(%rax)
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x50(%rbp), %ecx
imulq $0x24, %rcx, %rcx
addq %rcx, %rax
movb 0x20(%rax), %al
shrb $0x5, %al
andb $0x1, %al
movzbl %al, %edx
movq -0x68(%rbp), %rax
movl 0x18(%rax), %ecx
andl $0x1, %edx
shll $0x1f, %edx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl %edx, %ecx
movl %ecx, 0x18(%rax)
movq -0x68(%rbp), %rax
movl 0x18(%rax), %ecx
andl $0xc0000000, %ecx       # imm = 0xC0000000
orl $0x0, %ecx
movl %ecx, 0x18(%rax)
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x2ede7b
movl $0x0, -0x50(%rbp)
movl -0x50(%rbp), %eax
movq -0x48(%rbp), %rcx
movq 0x88(%rcx), %rcx
movslq -0x1c(%rbp), %rdx
imulq $0x68, %rdx, %rdx
addq %rdx, %rcx
cmpq 0x48(%rcx), %rax
jae 0x2ee07b
movq -0x28(%rbp), %rdi
movq -0x48(%rbp), %rax
movq 0x88(%rax), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x68, %rcx, %rcx
addq %rcx, %rax
movq 0x58(%rax), %rax
movl -0x50(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, %esi
movq -0x58(%rbp), %rdx
movq -0x60(%rbp), %rcx
movq -0x48(%rbp), %rax
movq 0x28(%rax), %r8
movq -0x48(%rbp), %rax
movq 0x20(%rax), %r9
movq -0x48(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x30(%rax), %r11
movq -0x48(%rbp), %rax
movq (%rax), %rax
movsd 0x68(%rax), %xmm0
movq -0x18(%rbp), %r10
movq -0x48(%rbp), %rax
movq 0x80(%rax), %rax
movslq -0x1c(%rbp), %rbx
movq (%rax,%rbx,8), %rax
addq $0x48, %rax
addq $0x18, %rax
movq %r11, (%rsp)
movq $0x10, 0x8(%rsp)
movq %r10, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x2e7ce0
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x2edfb8
movq -0x48(%rbp), %rax
movq 0x88(%rax), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x68, %rcx, %rcx
addq %rcx, %rax
movq 0x58(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x48(%rbp), %rax
movq 0x88(%rax), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x68, %rcx, %rcx
addq %rcx, %rax
movq 0x48(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x48(%rbp), %rax
movq 0x88(%rax), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x68, %rcx, %rcx
addq %rcx, %rax
movq 0x50(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x48(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x48(%rbp), %rax
movq 0x20(%rax), %rsi
movq -0x58(%rbp), %rdx
movq -0x60(%rbp), %rcx
movq -0x28(%rbp), %r8
movq -0x48(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x30(%rax), %rax
leaq -0x40(%rbp), %r9
movq %rax, (%rsp)
callq 0x2e8190
movl %eax, -0x4c(%rbp)
movq -0x30(%rbp), %rcx
movq -0x48(%rbp), %rax
movq 0x88(%rax), %rax
movslq -0x1c(%rbp), %rdx
imulq $0x68, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x58(%rax)
movq -0x40(%rbp), %rcx
movq -0x48(%rbp), %rax
movq 0x88(%rax), %rax
movslq -0x1c(%rbp), %rdx
imulq $0x68, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x48(%rax)
movq -0x38(%rbp), %rcx
movq -0x48(%rbp), %rax
movq 0x88(%rax), %rax
movslq -0x1c(%rbp), %rdx
imulq $0x68, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x50(%rax)
movl -0x4c(%rbp), %eax
movl %eax, %ecx
movq -0x48(%rbp), %rax
movq 0x80(%rax), %rax
movslq -0x1c(%rbp), %rdx
movq (%rax,%rdx,8), %rax
addq 0xf8(%rax), %rcx
movq %rcx, 0xf8(%rax)
addq $0x88, %rsp
popq %rbx
popq %rbp
retq
nopw (%rax,%rax)