// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/inter.cpp
// Function: worker_ul_recorrect_pipeline(void*, int, void*)
static void *worker_ul_recorrect_pipeline(void *data, int step, void *in) // callback for kt_pipeline()
{
    uldat_t *p = (uldat_t*)data;
    ///uint64_t total_base = 0, total_pair = 0;
    if (step == 0) { // step 1: read a block of sequences
        int ret;
        uint64_t l, rid;
		utepdat_t *s;
		CALLOC(s, 1);
        s->ha_flt_tab = p->ha_flt_tab; s->ha_idx = p->ha_idx; s->id = p->total_pair; 
		s->opt = p->opt; s->uu = p->uu; s->uopt = p->uopt; s->rg = p->rg;
        while ((ret = kseq_read(p->ks)) >= 0) 
        {
            if (p->ks->seq.l < (uint64_t)p->opt->k) continue;
            if (s->n == s->m) {
                s->m = s->m < 16? 16 : s->m + (s->n>>1);
                REALLOC(s->len, s->m);
                REALLOC(s->seq, s->m);
            }
			// append_ul_t(&UL_INF, NULL, p->ks->name.s, p->ks->name.l, NULL, 0, NULL, 0, P_CHAIN_COV, s->uopt);		
            l = p->ks->seq.l; s->seq[s->n] = NULL; rid = s->id + s->n;
			if(UL_INF.a[rid].rlen & ((uint32_t)(0x80000000))) {
				MALLOC(s->seq[s->n], l); memcpy(s->seq[s->n], p->ks->seq.s, l);
			}
            s->sum_len += l;
            s->len[s->n++] = l;
            if (s->sum_len >= p->chunk_size) break;            
        }
        p->total_pair += s->n;
        if (s->sum_len == 0) free(s);
		else return s;
    }
    else if (step == 1) { // step 2: alignment
        utepdat_t *s = (utepdat_t*)in;

		uint64_t i; s->n_thread = p->n_thread;
		CALLOC(s->hab, p->n_thread); CALLOC(s->ll, p->n_thread); CALLOC(s->buf, p->n_thread); 
		CALLOC(s->gdp, p->n_thread); CALLOC(s->mzs, p->n_thread); CALLOC(s->sps, p->n_thread); 

		// CALLOC(s->buf, p->n_thread);
		for (i = 0; i < p->n_thread; ++i) {
			s->hab[i] = ha_ovec_init(0, 0, 1); s->buf[i] = mg_tbuf_init();
		}
		fprintf(stderr, "[M::%s::Start] ==> s->id: %lu, s->n:% d\n", __func__, s->id, s->n);
		kt_for(p->n_thread, worker_for_ul_recorrect_alignment, s, s->n);
		fprintf(stderr, "[M::%s::Done] ==> s->id: %lu, s->n:% d\n", __func__, s->id, s->n);
		get_utepdat_t_mem(s, 1);

		for (i = 0; i < p->n_thread; ++i) {
			p->num_bases += s->hab[i]->num_read_base;
			p->num_corrected_bases += s->hab[i]->num_correct_base;

			// s->num_recorrected_bases += s->hab[i]->num_recorrect_base;
			ha_ovec_destroy(s->hab[i]); hc_glchain_destroy(&(s->ll[i]));
			mg_tbuf_destroy(s->buf[i]); hc_gdpchain_destroy(&(s->gdp[i])); 
			kv_destroy(s->mzs[i]); kv_destroy(s->sps[i]); free(s->seq[i]);
		}
		free(s->hab); free(s->ll); free(s->len); free(s->seq); 
		free(s->buf); free(s->gdp); free(s->mzs); free(s->sps); free(s);
    } 
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %r14
testl %esi, %esi
je 0x1e2580
cmpl $0x1, %esi
jne 0x1e2704
movq %rdx, %r15
movq %r14, %rdi
movq %rdx, %rsi
callq 0x29b78
jmp 0x1e26fc
movl $0x1, %edi
movl $0xd0, %esi
callq 0x2120
movq %rax, %r15
movups (%r14), %xmm0
movups %xmm0, 0x8(%rax)
movq 0x68(%r14), %rbx
movq %rbx, 0x50(%rax)
movq 0x10(%r14), %rax
movq %rax, (%r15)
movq 0x30(%r14), %rax
movq %rax, 0x30(%r15)
movups 0x20(%r14), %xmm0
movups %xmm0, 0x20(%r15)
movq 0x48(%r14), %rdi
callq 0x1ce059
testl %eax, %eax
js 0x1e26fc
movq %r15, 0x10(%rsp)
xorl %r15d, %r15d
imulq $0x58, %rbx, %rax
movq %rax, 0x20(%rsp)
movq $0x0, 0x18(%rsp)
xorl %r12d, %r12d
movl $0x0, 0xc(%rsp)
xorl %ebp, %ebp
movq 0x10(%r14), %rax
movq 0x48(%r14), %rdi
movq 0x30(%rdi), %r13
movslq 0x4(%rax), %rax
cmpq %rax, %r13
jb 0x1e26de
movl 0xc(%rsp), %eax
cmpl %eax, %ebp
jne 0x1e2665
movl %eax, %ebx
sarl %ebx
addl %eax, %ebx
cmpl $0x10, %eax
movl $0x10, %eax
cmovll %eax, %ebx
movq 0x10(%rsp), %r13
movl %ebx, 0x3c(%r13)
movslq %ebx, %r15
shlq $0x3, %r15
movq %r12, %rdi
movq %r15, %rsi
callq 0x2370
movq %rax, 0x48(%r13)
movq 0x58(%r13), %rdi
movq %r15, %rsi
callq 0x2370
movq %rax, %r15
movq %rax, 0x58(%r13)
movq 0x48(%r14), %rax
movq 0x30(%rax), %r13
movl %ebx, 0xc(%rsp)
jmp 0x1e266a
movq 0x18(%rsp), %r15
movslq %ebp, %rbx
movq $0x0, (%r15,%rbx,8)
leaq 0xb3c9c(%rip), %rax     # 0x296318
movq 0x48(%rax), %rax
addq 0x20(%rsp), %rax
imulq $0x58, %rbx, %rcx
cmpl $0x0, 0x18(%rcx,%rax)
jns 0x1e26af
movq %r13, %rdi
callq 0x2280
movq %rax, (%r15,%rbx,8)
movq 0x48(%r14), %rcx
movq 0x40(%rcx), %rsi
movq %rax, %rdi
movq %r13, %rdx
callq 0x2160
movq %r15, 0x18(%rsp)
movq 0x10(%rsp), %rax
movl 0x40(%rax), %r15d
addl %r13d, %r15d
movl %r15d, 0x40(%rax)
movq 0x48(%rax), %r12
incl %ebp
movl %ebp, 0x38(%rax)
movq %r13, (%r12,%rbx,8)
movslq %r15d, %rax
cmpq %rax, 0x50(%r14)
jle 0x1e26eb
movq 0x48(%r14), %rdi
callq 0x1ce059
testl %eax, %eax
jns 0x1e25f3
movslq %ebp, %rax
addq %rax, 0x68(%r14)
testl %r15d, %r15d
movq 0x10(%rsp), %r15
jne 0x1e2707
movq %r15, %rdi
callq 0x2220
xorl %r15d, %r15d
movq %r15, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq