// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/inter.cpp
// Function: worker_ul_rescall_pipeline(void*, int, void*)
static void *worker_ul_rescall_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;
		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; s->mm = p->mm;
        while ((ret = kseq_read(p->ks)) >= 0) 
        {
			if ((p->ks->seq.l < (uint64_t)p->opt->k) || (p->ks->seq.l < asm_opt.ul_min_base)) 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;
            MALLOC(s->seq[s->n], l);
            s->sum_len += l;
            memcpy(s->seq[s->n], p->ks->seq.s, l);
			// fprintf(stderr, "s->n->%d, l->%lu\n", s->n, l);
			// fprintf(stderr, "+++++rid->%lu, l->%lu, %.*s\n", 
			// 			s->id + s->n, l, (int32_t)p->ks->name.l, p->ks->name.s);
            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->mk, 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_rescall_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]); 
			kv_destroy(s->mk[i].idx); kv_destroy(s->mk[i].srt);
			//free(s->seq[i]);
		}
		free(s->hab); free(s->ll); free(s->mk); ///free(s->len); free(s->seq); 
		free(s->buf); free(s->gdp); free(s->mzs); free(s->sps); ///free(s);
		return s;
    } else if (step == 2) { // step 3: dump
		utepdat_t *s = (utepdat_t*)in; int64_t i, rid;
		// fprintf(stderr, "[M::%s::dump_start] ==> s->id: %lu, s->n:% d\n", __func__, s->id, s->n);
		for (i = 0; i < s->n; ++i) {
			rid = s->id + i;
			if(UL_INF.a[rid].dd == 3 && p->ucr_s && p->ucr_s->flag == 1) {///for the scaffolding
				assert(s->seq[i]);
				// if(s->seq[i] == NULL) fprintf(stderr, "[M::%s::]rid->%ld, len->%lu\n", __func__, rid, s->len[i]);
				///for debug interval
				write_compress_base_disk(p->ucr_s->fp, rid, s->seq[i], s->len[i], &(p->ucr_s->u));
			}
			// if(UL_INF.a[rid].dd) fprintf(stderr, "rid->%ld\n", rid);
			free(s->seq[i]);
		}
		// fprintf(stderr, "[M::%s::dump_done] ==> s->id: %lu, s->n:% d\n", __func__, s->id, s->n);
		free(s->len); free(s->seq); free(s);
	}
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbp
testl %esi, %esi
je 0x1d8275
movq %rdx, %r14
cmpl $0x1, %esi
je 0x1d805d
cmpl $0x2, %esi
jne 0x1d83d1
cmpl $0x0, 0x38(%r14)
jle 0x1d8043
xorl %ebx, %ebx
leaq 0xb3338(%rip), %r15     # 0x28b318
movq 0x50(%r14), %rsi
addq %rbx, %rsi
movq 0x48(%r15), %rax
imulq $0x58, %rsi, %rcx
cmpb $0x3, 0x50(%rax,%rcx)
jne 0x1d802a
movq 0x40(%rbp), %r8
testq %r8, %r8
je 0x1d802a
cmpq $0x1, 0x60(%r8)
jne 0x1d802a
movq 0x58(%r14), %rax
movq (%rax,%rbx,8), %rdx
testq %rdx, %rdx
je 0x1d83e6
movq (%r8), %rdi
movq 0x48(%r14), %rax
movl (%rax,%rbx,8), %ecx
addq $0x8, %r8
callq 0x3851a
movq 0x58(%r14), %rax
movq (%rax,%rbx,8), %rdi
callq 0x2220
incq %rbx
movslq 0x38(%r14), %rax
cmpq %rax, %rbx
jl 0x1d7fe0
movq 0x48(%r14), %rdi
callq 0x2220
movq 0x58(%r14), %rdi
callq 0x2220
movq %r14, %r15
jmp 0x1d83c1
movq 0x58(%rbp), %r15
movq %r15, 0xc0(%r14)
movl $0x8, %esi
movq %r15, %rdi
callq 0x2120
movq %rax, 0x80(%r14)
movl $0x68, %esi
movq %r15, %rdi
callq 0x2120
movq %rax, 0x88(%r14)
movl $0x8, %esi
movq %r15, %rdi
callq 0x2120
movq %rax, 0x78(%r14)
movl $0xc0, %esi
movq %r15, %rdi
callq 0x2120
movq %rax, 0x90(%r14)
movl $0x10, %esi
movq %r15, %rdi
callq 0x2120
movq %rax, 0x60(%r14)
movl $0x18, %esi
movq %r15, %rdi
callq 0x2120
movq %rax, 0x68(%r14)
movl $0x30, %esi
movq %r15, %rdi
callq 0x2120
movq %rax, 0x98(%r14)
movq 0x58(%rbp), %rdi
testq %rdi, %rdi
je 0x1d813d
xorl %ebx, %ebx
xorl %edi, %edi
xorl %esi, %esi
movl $0x1, %edx
callq 0x39240
movq 0x80(%r14), %rcx
movq %rax, (%rcx,%rbx,8)
movl $0x1, %edi
movl $0x10, %esi
callq 0x2120
movq %rax, %r15
callq 0x1e35d3
movq %rax, (%r15)
movq 0x78(%r14), %rax
movq %r15, (%rax,%rbx,8)
incq %rbx
movq 0x58(%rbp), %rdi
cmpq %rdi, %rbx
jb 0x1d80f6
movslq 0x38(%r14), %rcx
leaq 0xa58a(%rip), %rsi      # 0x1e26d2
movq %r14, %rdx
callq 0x1047b4
cmpq $0x0, 0x58(%rbp)
je 0x1d822a
movq %rbp, %rcx
movl $0x8, %r15d
xorl %r12d, %r12d
xorl %r13d, %r13d
xorl %ebp, %ebp
xorl %ebx, %ebx
movq %rcx, (%rsp)
movq 0x80(%r14), %rax
movq (%rax,%rbx,8), %rdi
movq 0xf0(%rdi), %rax
addq %rax, 0xd0(%rcx)
movq 0xf8(%rdi), %rax
addq %rax, 0xd8(%rcx)
callq 0x395cd
movq 0x88(%r14), %rdi
addq %r13, %rdi
callq 0x19912e
movq 0x78(%r14), %rax
movq (%rax,%rbx,8), %rdi
callq 0x196f11
movq 0x90(%r14), %rdi
addq %rbp, %rdi
callq 0x19915c
movq 0x60(%r14), %rax
movq (%rax,%r15), %rdi
callq 0x2220
movq 0x68(%r14), %rax
movq 0x10(%rax,%r12), %rdi
callq 0x2220
movq 0x98(%r14), %rax
movq 0x10(%rax,%r12,2), %rdi
callq 0x2220
movq 0x98(%r14), %rax
movq 0x18(%rax,%r12,2), %rdi
callq 0x2220
movq (%rsp), %rcx
incq %rbx
addq $0xc0, %rbp
addq $0x68, %r13
addq $0x10, %r15
addq $0x18, %r12
cmpq 0x58(%rcx), %rbx
jb 0x1d8172
movq 0x80(%r14), %rdi
callq 0x2220
movq 0x88(%r14), %rdi
callq 0x2220
movq 0x98(%r14), %rdi
callq 0x2220
movq 0x78(%r14), %rdi
callq 0x2220
movq 0x90(%r14), %rdi
callq 0x2220
movq 0x60(%r14), %rdi
callq 0x2220
movq 0x68(%r14), %r15
jmp 0x1d83c4
movl $0x1, %edi
movl $0xd0, %esi
callq 0x2120
movq %rax, %r15
movq (%rbp), %rax
movq %rax, 0x8(%r15)
movq 0x8(%rbp), %rax
movq %rax, 0x10(%r15)
movq 0x68(%rbp), %rax
movq %rax, 0x50(%r15)
movq 0x10(%rbp), %rax
movq %rax, (%r15)
movq 0x30(%rbp), %rax
movq %rax, 0x30(%r15)
movq 0x28(%rbp), %rax
movq %rax, 0x28(%r15)
movq 0x20(%rbp), %rax
movq %rax, 0x20(%r15)
movq 0x38(%rbp), %rax
movq %rax, 0xa0(%r15)
movq 0x48(%rbp), %rdi
callq 0x1c406c
testl %eax, %eax
js 0x1d83b2
leaq 0xb2477(%rip), %r12     # 0x28a758
movq 0x10(%rbp), %rcx
movq 0x48(%rbp), %rax
movq 0x30(%rax), %rax
movslq 0x4(%rcx), %rcx
cmpq %rcx, %rax
jb 0x1d83a1
movl 0x260(%r12), %ecx
cmpq %rcx, %rax
jb 0x1d83a1
movslq 0x38(%r15), %rbx
movl 0x3c(%r15), %eax
cmpl %eax, %ebx
jne 0x1d8353
movl %ebx, %ecx
sarl %ecx
addl %eax, %ecx
cmpl $0x10, %eax
movl $0x10, %eax
cmovll %eax, %ecx
movl %ecx, 0x3c(%r15)
movq 0x48(%r15), %rdi
movslq %ecx, %r14
shlq $0x3, %r14
movq %r14, %rsi
callq 0x2370
movq %rax, 0x48(%r15)
movq 0x58(%r15), %rdi
movq %r14, %rsi
callq 0x2370
movq %rax, 0x58(%r15)
movq 0x48(%rbp), %rax
movq 0x30(%rax), %r14
movq %r14, %rdi
callq 0x2280
movq 0x58(%r15), %rcx
movq %rax, (%rcx,%rbx,8)
movl 0x40(%r15), %r13d
addl %r14d, %r13d
movl %r13d, 0x40(%r15)
movq 0x48(%rbp), %rcx
movq 0x40(%rcx), %rsi
movq %rax, %rdi
movq %r14, %rdx
callq 0x2160
movq 0x48(%r15), %rax
leal 0x1(%rbx), %ecx
movl %ecx, 0x38(%r15)
movq %r14, (%rax,%rbx,8)
movslq %r13d, %rax
cmpq %rax, 0x50(%rbp)
jle 0x1d83b2
movq 0x48(%rbp), %rdi
callq 0x1c406c
testl %eax, %eax
jns 0x1d82e1
movslq 0x38(%r15), %rax
addq %rax, 0x68(%rbp)
cmpl $0x0, 0x40(%r15)
jne 0x1d83d4
xorl %r14d, %r14d
movq %r15, %rdi
callq 0x2220
movq %r14, %r15
jmp 0x1d83d4
xorl %r15d, %r15d
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6096d(%rip), %rdi     # 0x238d5a
leaq 0x5b597(%rip), %rsi     # 0x23398b
leaq 0x60969(%rip), %rcx     # 0x238d64
movl $0x332f, %edx           # imm = 0x332F
callq 0x2110