// File: /workspace/github_cpp_makefile_star2_O2/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
subq $0x18, %rsp
movq %rdi, %r14
testl %esi, %esi
je 0x1951ea
movq %rdx, %rbx
cmpl $0x1, %esi
je 0x194fe7
cmpl $0x2, %esi
jne 0x19533d
xorl %r15d, %r15d
leaq 0xbf39c(%rip), %r12     # 0x254318
movslq 0x38(%rbx), %rax
cmpq %rax, %r15
jge 0x19530f
movq 0x50(%rbx), %rsi
addq %r15, %rsi
movq 0x48(%r12), %rax
imulq $0x58, %rsi, %rcx
cmpb $0x3, 0x50(%rax,%rcx)
jne 0x194fd5
movq 0x40(%r14), %r8
testq %r8, %r8
je 0x194fd5
cmpq $0x1, 0x60(%r8)
jne 0x194fd5
movq 0x58(%rbx), %rax
movq (%rax,%r15,8), %rdx
testq %rdx, %rdx
je 0x195351
movq (%r8), %rdi
movq 0x48(%rbx), %rax
movl (%rax,%r15,8), %ecx
addq $0x8, %r8
callq 0xb7c0
movq 0x58(%rbx), %rax
movq (%rax,%r15,8), %rdi
callq 0x2220
incq %r15
jmp 0x194f7c
movq 0x58(%r14), %r12
movq %r12, 0xc0(%rbx)
pushq $0x8
popq %r15
movq %r12, %rdi
movq %r15, %rsi
callq 0x2120
movq %rax, 0x80(%rbx)
pushq $0x68
popq %rsi
movq %r12, %rdi
callq 0x2120
movq %rax, 0x88(%rbx)
movq %r12, %rdi
movq %r15, 0x8(%rsp)
movq %r15, %rsi
callq 0x2120
movq %rax, 0x78(%rbx)
movl $0xc0, %esi
movq %r12, %rdi
callq 0x2120
movq %rax, 0x90(%rbx)
pushq $0x10
popq %rsi
movq %r12, %rdi
callq 0x2120
movq %rax, 0x60(%rbx)
pushq $0x18
popq %rsi
movq %r12, %rdi
callq 0x2120
movq %rax, 0x68(%rbx)
pushq $0x30
popq %rsi
movq %r12, %rdi
callq 0x2120
movq %rax, 0x98(%rbx)
xorl %r15d, %r15d
pushq $0x1
popq %rbp
cmpq %r12, %r15
jae 0x1950a9
xorl %edi, %edi
xorl %esi, %esi
movl %ebp, %edx
callq 0xc44b
movq 0x80(%rbx), %rcx
movq %rax, (%rcx,%r15,8)
callq 0x1588bc
movq 0x78(%rbx), %rcx
movq %rax, (%rcx,%r15,8)
incq %r15
movq 0x58(%r14), %r12
jmp 0x195078
movslq 0x38(%rbx), %rcx
leaq 0xd37f(%rip), %rsi      # 0x1a2433
movl %r12d, %edi
movq %rbx, %rdx
callq 0xc67c0
xorl %r12d, %r12d
xorl %r13d, %r13d
xorl %ebp, %ebp
xorl %r15d, %r15d
movq 0x80(%rbx), %rdi
cmpq 0x58(%r14), %r15
jae 0x1951a1
movq (%rdi,%r15,8), %rdi
movdqu 0xd0(%r14), %xmm0
paddq 0xf0(%rdi), %xmm0
movdqu %xmm0, 0xd0(%r14)
callq 0xc5d1
movq 0x88(%rbx), %rdi
addq %r13, %rdi
callq 0x15a8d7
movq 0x78(%rbx), %rax
movq (%rax,%r15,8), %rdi
callq 0x1588d8
movq 0x90(%rbx), %rdi
addq %r12, %rdi
callq 0x15a905
movq 0x60(%rbx), %rax
movq %r13, 0x10(%rsp)
movq %r12, %r13
movq %r14, %r12
movq 0x8(%rsp), %r14
movq (%rax,%r14), %rdi
callq 0x2220
movq 0x68(%rbx), %rax
movq 0x10(%rax,%rbp), %rdi
callq 0x2220
movq 0x98(%rbx), %rax
movq 0x10(%rax,%rbp,2), %rdi
callq 0x2220
movq 0x98(%rbx), %rax
movq 0x18(%rax,%rbp,2), %rdi
callq 0x2220
incq %r15
addq $0x18, %rbp
addq $0x10, %r14
movq %r14, 0x8(%rsp)
movq %r12, %r14
movq %r13, %r12
movq 0x10(%rsp), %r13
addq $0x68, %r13
addq $0xc0, %r12
jmp 0x1950ca
callq 0x2220
movq 0x88(%rbx), %rdi
callq 0x2220
movq 0x98(%rbx), %rdi
callq 0x2220
movq 0x78(%rbx), %rdi
callq 0x2220
movq 0x90(%rbx), %rdi
callq 0x2220
movq 0x60(%rbx), %rdi
callq 0x2220
movq 0x68(%rbx), %rdi
callq 0x2220
jmp 0x19533f
pushq $0x1
popq %rdi
movl $0xd0, %esi
callq 0x2120
movq %rax, %rbx
movups (%r14), %xmm0
movups %xmm0, 0x8(%rax)
movq 0x68(%r14), %rax
movq %rax, 0x50(%rbx)
movq 0x10(%r14), %rax
movq %rax, (%rbx)
movq 0x30(%r14), %rax
movq %rax, 0x30(%rbx)
movdqu 0x20(%r14), %xmm0
movdqu %xmm0, 0x20(%rbx)
movq 0x38(%r14), %rax
movq %rax, 0xa0(%rbx)
movq 0x48(%r14), %r13
movq %r13, %rdi
callq 0x1823fd
testl %eax, %eax
js 0x195323
movq 0x10(%r14), %rax
movq 0x48(%r14), %r13
movq 0x30(%r13), %r12
movslq 0x4(%rax), %rax
cmpq %rax, %r12
jb 0x195233
leaq 0xbe4f9(%rip), %rax     # 0x253758
movl 0x260(%rax), %eax
cmpq %rax, %r12
jb 0x195233
movslq 0x38(%rbx), %rbp
movq 0x48(%rbx), %rdi
movq 0x58(%rbx), %r13
cmpl 0x3c(%rbx), %ebp
jne 0x1952c1
movl %ebp, %eax
sarl %eax
addl %ebp, %eax
cmpl $0x10, %ebp
pushq $0x10
popq %rcx
cmovll %ecx, %eax
movl %eax, 0x3c(%rbx)
movslq %eax, %r12
shlq $0x3, %r12
movq %r12, %rsi
callq 0x2370
movq %rax, 0x8(%rsp)
movq %rax, 0x48(%rbx)
movq %r13, %rdi
movq %r12, %rsi
callq 0x2370
movq %rax, %r13
movq %rax, 0x58(%rbx)
movq 0x48(%r14), %rax
movq 0x30(%rax), %r12
jmp 0x1952c6
movq %rdi, 0x8(%rsp)
movq %r12, %rdi
callq 0x2280
movq %rax, (%r13,%rbp,8)
movl 0x40(%rbx), %r15d
addl %r12d, %r15d
movl %r15d, 0x40(%rbx)
movq 0x48(%r14), %r13
movq 0x40(%r13), %rsi
movq %rax, %rdi
movq %r12, %rdx
callq 0x2160
leal 0x1(%rbp), %eax
movl %eax, 0x38(%rbx)
movq 0x8(%rsp), %rcx
movq %r12, (%rcx,%rbp,8)
movslq %r15d, %rcx
cmpq %rcx, 0x50(%r14)
jg 0x195233
jmp 0x19532a
movq 0x48(%rbx), %rdi
callq 0x2220
movq 0x58(%rbx), %rdi
callq 0x2220
jmp 0x195335
movl 0x38(%rbx), %eax
movl 0x40(%rbx), %r15d
cltq
addq %rax, 0x68(%r14)
testl %r15d, %r15d
jne 0x19533f
movq %rbx, %rdi
callq 0x2220
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x61b9a(%rip), %rdi     # 0x1f6ef2
leaq 0x5c7c4(%rip), %rsi     # 0x1f1b23
leaq 0x61b96(%rip), %rcx     # 0x1f6efc
movl $0x332f, %edx           # imm = 0x332F
callq 0x2110