// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/inter.cpp
// Function: worker_for_ul_recorrect_alignment(void*, long, int)
static void worker_for_ul_recorrect_alignment(void *data, long i, int tid) // callback for kt_for()
{
    utepdat_t *s = (utepdat_t*)data;
    ha_ovec_buf_t *b = s->hab[tid];
    glchain_t *bl = &(s->ll[tid]);
    int64_t /**rid = s->id+i,**/ winLen = MIN((((double)THRESHOLD_MAX_SIZE)/s->opt->diff_ec_ul), WINDOW), is_correct;
    // uint64_t align = 0;
    int fully_cov, abnormal;
	// if(UL_INF.a[s->id+i].rlen != s->len[i]) {
	// 	fprintf(stderr, "[M::%s] rid:%ld, s->len:%lu, UL_INF->rlen:%u\n", __func__, s->id+i, s->len[i], UL_INF.a[s->id+i].rlen);
	// }
	is_correct = ck_ul_alignment(&(UL_INF.a[s->id+i]));
	if(is_correct) {
		assert((UL_INF.a[s->id+i].rlen == s->len[i]) && (!s->seq[i]));
		return;
	}
	assert(UL_INF.a[s->id+i].rlen&((uint32_t)(0x80000000)));
	UL_INF.a[s->id+i].rlen<<=1; UL_INF.a[s->id+i].rlen>>=1;
	assert((UL_INF.a[s->id+i].rlen == s->len[i]));
	
    // void *km = s->buf?(s->buf[tid]?s->buf[tid]->km:NULL):NULL;
    // if(s->id+i!=41927 && s->id+i!=47072 && s->id+i!=67641 && s->id+i!=90305 && s->id+i!=698342 && s->id+i!=329421) {
	// 	return;
	// }
	// if(s->id+i!=41927) return;

    // fprintf(stderr, "\n[M::%s] rid:%ld, len:%lu\n", __func__, s->id+i, s->len[i]);
    // if (memcmp(UL_INF.nid.a[s->id+i].a, "d0aab024-b3a7-40fb-83cc-22c3d6d951f8", UL_INF.nid.a[s->id+i].n-1)) return;
    // fprintf(stderr, "[M::%s::] ==> len: %lu\n", __func__, s->len[i]);
    ha_get_ul_candidates_interface(b->abl, i, s->seq[i], s->len[i], s->opt->w, s->opt->k, s->uu, &b->olist, &b->olist_hp, &b->clist, s->opt->bw_thres, 
        s->opt->max_n_chain, 1, NULL/**&(b->k_flag)**/, &b->r_buf, &(b->tmp_region), NULL, &(b->sp), 1, NULL);
    
    clear_Cigar_record(&b->cigar1);
    clear_Round2_alignment(&b->round2);
    // return;
    // b->num_correct_base += overlap_statistics(&b->olist, NULL, 0);   

    b->self_read.seq = s->seq[i]; b->self_read.length = s->len[i]; b->self_read.size = 0;
    correct_ul_overlap(&b->olist, s->uu, &b->self_read, &b->correct, &b->ovlp_read, &b->POA_Graph, &b->DAGCon,
            &b->cigar1, &b->hap, &b->round2, &b->r_buf, &(b->tmp_region.w_list), 0, 1, &fully_cov, &abnormal, s->opt->diff_ec_ul, winLen, NULL);

    // uint64_t k;
    // for (k = 0; k < b->olist.length; k++) {
    //  if(b->olist.list[k].is_match == 1) b->num_correct_base += b->olist.list[k].x_pos_e+1-b->olist.list[k].x_pos_s;
    //  if(b->olist.list[k].is_match == 2) b->num_recorrect_base += b->olist.list[k].x_pos_e+1-b->olist.list[k].x_pos_s;
    // }


    // gl_chain_refine(&b->olist, &b->correct, &b->hap, bl, s->uu, s->opt->diff_ec_ul, winLen, s->len[i], km);
    gl_chain_refine_advance_combine(s->buf[tid], &(UL_INF.a[s->id+i]), &b->olist, &b->correct, &b->hap, &(s->sps[tid]), bl, &(s->gdp[tid]), s->uu, s->opt->diff_ec_ul, winLen, s->len[i], s->uopt, s->id+i, tid, NULL);
    // return;
    // b->num_read_base += b->self_read.length;
    // b->num_correct_base += b->correct.corrected_base;
    // b->num_recorrect_base += b->round2.dumy.corrected_base;
    memset(&b->self_read, 0, sizeof(b->self_read));



	is_correct = ck_ul_alignment(&(UL_INF.a[s->id+i]));
	if(is_correct) b->num_correct_base++;
    s->hab[tid]->num_read_base++;

	// fprintf(stderr, "[M::%s] rid:%ld, dd:%u\n", __func__, s->id+i, UL_INF.a[s->id+i].dd);
    // int64_t mem[6], mem_hab[6];
    // if(get_utepdat_t_mem_tid(s, tid, mem, mem_hab)>((int64_t)5*(int64_t)1073741824)) {
    //     fprintf(stderr, "[M::%s::tid->%d::rid->%ld] buffer[0]: %.3fGB(%.3fGB::%.3fGB::%.3fGB::%.3fGB::%.3fGB), buffer[1]: %.3fGB, buffer[2]: %.3fGB, buffer[3]: %.3fGB, buffer[4]: %.3fGB, buffer[5]: %.3fGB\n", 
    //             __func__, tid, i, mem[0]/1073741824.0, 
	// 			mem_hab[0]/1073741824.0, mem_hab[1]/1073741824.0, mem_hab[2]/1073741824.0, 
	// 			mem_hab[3]/1073741824.0, mem_hab[4]/1073741824.0,
	// 			mem[1]/1073741824.0, mem[2]/1073741824.0,
    //             mem[3]/1073741824.0, mem[4]/1073741824.0, mem[5]/1073741824.0);
    // }

    // align = kv_ul_ov_t_statistics(&(bl->tk), i, &(b->num_recorrect_base));
    // if(align == s->len[i]) {
    //  free(s->seq[i]); s->seq[i] = NULL;
    // }
    // b->num_correct_base += align;

    // uint64_t k;
    // b->num_read_base += overlap_statistics(&b->olist, NULL, NULL, 1);
    // for (k = 0; k < bl->tk.n; k++) {
    //  if(bl->tk.a[k].sec == 0) b->num_correct_base += bl->tk.a[k].qe - bl->tk.a[k].qs;
    //  if(bl->tk.a[k].sec > 0) b->num_recorrect_base += bl->tk.a[k].qe - bl->tk.a[k].qs;
    // }
    // for (k = 0; k < bl->lo.n; k++) {
    //  b->num_read_base += bl->lo.a[k].qe - bl->lo.a[k].qs;
    // }

    // uint32_t l1 = overlap_statistics(&b->olist, s->uu->ug, 1), l2 = overlap_statistics(&b->olist, s->uu->ug, 2);
    // 
    // if(l1 == 0 && l2 > 0) fprintf(stderr, "[M::%s::%lu::no_match]\n", UL_INF.nid.a[s->id+i].a, s->len[i]);
    // fprintf(stderr, "[M::%s::%lu::] l1->%u; l2->%u\n", UL_INF.nid.a[s->id+i].a, s->len[i], l1, l2);
    // fprintf(stderr, "[M::%s::rid->%ld] done\n", __func__, s->id+i);
	// exit(1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movq (%rdi), %rcx
movslq %edx, %rbp
imulq $0x68, %rbp, %r15
addq 0x88(%rdi), %r15
movq 0x80(%rdi), %rax
movsd 0x425ec(%rip), %xmm0    # 0x225520
movq %rcx, 0x20(%rsp)
divsd 0x68(%rcx), %xmm0
movsd %xmm0, 0x8(%rsp)
movq (%rax,%rbp,8), %rax
movq %rax, 0x48(%rsp)
leaq 0xa83c4(%rip), %rax     # 0x28b318
imulq $0x58, 0x50(%rdi), %r12
addq 0x48(%rax), %r12
imulq $0x58, %rsi, %r13
leaq (%r12,%r13), %rdi
callq 0x1b9a5a
movl 0x18(%r13,%r12), %edx
testl %eax, %eax
je 0x1e2fab
movq 0x48(%rbx), %rax
cmpq %rdx, (%rax,%r14,8)
jne 0x1e2f8c
movq 0x58(%rbx), %rax
cmpq $0x0, (%rax,%r14,8)
je 0x1e3239
leaq 0x55e75(%rip), %rdi     # 0x238e08
leaq 0x509f1(%rip), %rsi     # 0x23398b
leaq 0x55e9d(%rip), %rcx     # 0x238e3e
movl $0x315d, %edx           # imm = 0x315D
callq 0x2110
movsd 0x8(%rsp), %xmm0
movq 0x20(%rsp), %r10
movq %r15, 0x38(%rsp)
movq 0x48(%rsp), %rsi
movq %rbp, 0x40(%rsp)
testl %edx, %edx
jns 0x1e3248
leaq (%r12,%r13), %rax
addq $0x18, %rax
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movl %edx, (%rax)
movq 0x48(%rbx), %rax
movq %r13, 0x30(%rsp)
movq (%rax,%r14,8), %rcx
cmpq %rdx, %rcx
jne 0x1e3267
movq %r14, %rbp
minsd 0x4252a(%rip), %xmm0    # 0x225528
cvttsd2si %xmm0, %rax
movq %rax, 0x28(%rsp)
movq %rsi, %r14
movq 0xe8(%rsi), %rdi
movq 0x58(%rbx), %rax
movq (%rax,%rbp,8), %rdx
movslq (%r10), %r8
movslq 0x4(%r10), %r9
leaq 0xa0(%rsi), %rax
movq %rax, 0x8(%rsp)
leaq 0xc0(%rsi), %rax
movq %rax, 0x18(%rsp)
leaq 0x48(%rsi), %rax
movq %rax, 0x10(%rsp)
movsd 0x60(%r10), %xmm0
movl 0x80(%r10), %r11d
leaq 0x12160(%rsi), %r13
movq %r13, 0x20(%rsp)
leaq 0x121a0(%rsi), %r15
leaq 0x12250(%rsi), %r12
subq $0x8, %rsp
xorl %eax, %eax
movq %rbp, %rsi
pushq %rax
movl $0x1, %r10d
pushq %r10
pushq %r12
pushq %rax
pushq %r15
pushq %r13
pushq %rax
pushq %r10
pushq %r11
pushq 0x60(%rsp)
pushq 0x70(%rsp)
movq 0x68(%rsp), %r13
pushq %r13
pushq 0x30(%rbx)
callq 0x124a43
addq $0x70, %rsp
leaq 0x108(%r14), %rdi
movq %rdi, 0x10(%rsp)
callq 0x48007
leaq 0x9330(%r14), %r15
movq %r15, %rdi
callq 0x47f99
movq 0x58(%rbx), %rax
movq (%rax,%rbp,8), %rax
leaq 0x8(%r14), %rdx
movq %rax, 0x8(%r14)
movq 0x48(%rbx), %rax
movq (%rax,%rbp,8), %rax
movq %rax, 0x10(%r14)
xorl %r12d, %r12d
movq %r12, 0x18(%r14)
movq (%rbx), %rdi
movq 0x30(%rbx), %rsi
leaq 0x2c0(%r14), %rcx
movq %rcx, 0x18(%rsp)
leaq 0x28(%r14), %r8
leaq 0x148(%r14), %r9
leaq 0x200(%r14), %rax
leaq 0x9040(%r14), %r11
leaq 0x121e8(%r14), %r10
movsd 0x68(%rdi), %xmm0
movq %r13, %rdi
pushq %r12
pushq 0x30(%rsp)
leaq 0x60(%rsp), %r12
pushq %r12
leaq 0x6c(%rsp), %r12
pushq %r12
movl $0x1, %r12d
pushq %r12
pushq $0x0
pushq %r10
pushq 0x58(%rsp)
pushq %r15
pushq %r11
movq %r11, %r13
pushq 0x60(%rsp)
pushq %rax
callq 0x591e6
addq $0x60, %rsp
movq 0x78(%rbx), %rax
movq 0x40(%rsp), %r15
movq (%rax,%r15,8), %rdi
movq 0x50(%rbx), %rax
addq %rbp, %rax
imulq $0x58, %rax, %rsi
leaq 0xa81a0(%rip), %r12     # 0x28b318
addq 0x48(%r12), %rsi
leaq (%r15,%r15,2), %rcx
leaq (,%rcx,8), %r9
addq 0x68(%rbx), %r9
shlq $0x6, %rcx
addq 0x90(%rbx), %rcx
movq 0x30(%rbx), %rdx
movq (%rbx), %r8
movq 0x28(%rbx), %r10
movsd 0x68(%r8), %xmm0
movq 0x48(%rbx), %r8
movq (%r8,%rbp,8), %r8
subq $0x50, %rsp
xorl %r11d, %r11d
movq %r11, 0x40(%rsp)
movq %rax, 0x30(%rsp)
movq %r10, 0x28(%rsp)
movq %r8, 0x20(%rsp)
movq %rdx, 0x10(%rsp)
movq %rcx, 0x8(%rsp)
movq 0x88(%rsp), %rax
movq %rax, (%rsp)
movq 0x58(%rsp), %rdx
movq 0x68(%rsp), %rcx
movq %r13, %r8
callq 0x1aab98
addq $0x50, %rsp
xorpd %xmm0, %xmm0
movupd %xmm0, 0x8(%r14)
movupd %xmm0, 0x18(%r14)
imulq $0x58, 0x50(%rbx), %rdi
addq 0x48(%r12), %rdi
addq 0x30(%rsp), %rdi
callq 0x1b9a5a
testl %eax, %eax
je 0x1e3227
incq 0xf8(%r14)
movq 0x80(%rbx), %rax
movq (%rax,%r15,8), %rax
incq 0xf0(%rax)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x55c29(%rip), %rdi     # 0x238e78
leaq 0x50735(%rip), %rsi     # 0x23398b
leaq 0x55be1(%rip), %rcx     # 0x238e3e
movl $0x3160, %edx           # imm = 0x3160
callq 0x2110
leaq 0x55c3a(%rip), %rdi     # 0x238ea8
leaq 0x50716(%rip), %rsi     # 0x23398b
leaq 0x55bc2(%rip), %rcx     # 0x238e3e
movl $0x3162, %edx           # imm = 0x3162
callq 0x2110