// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/inter.cpp
// Function: worker_ul_pipeline(void*, int, void*)
static void *worker_ul_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->ug = p->ug; 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);
            }
			/**if(asm_opt.flag & HA_F_VERBOSE_GFA)**/ {
				kv_push(uint64_t, p->nn, p->ks->name.l+p->nn.tl);
				kv_resize(char, p->nn.cc, p->ks->name.l+p->nn.tl);
				memcpy(p->nn.cc.a+p->nn.tl, p->ks->name.s, p->ks->name.l);
				p->nn.tl += p->ks->name.l;
			}
            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);
            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
		uint64_t i;
        utepdat_t *s = (utepdat_t*)in;
        CALLOC(s->mzs, p->n_thread);
        CALLOC(s->sps, p->n_thread);
		CALLOC(s->gcs, s->n);

		s->buf = (mg_tbuf_t**)calloc(p->n_thread, sizeof(mg_tbuf_t*));
		for (i = 0; i < p->n_thread; ++i) s->buf[i] = mg_tbuf_init();
        
        kt_for(p->n_thread, worker_for_ul_alignment, s, s->n);
        for (i = 0; i < (uint64_t)s->n; ++i) {
            free(s->seq[i]);
            p->total_base += s->len[i];
        }
        free(s->seq); free(s->len); 
		
		for (i = 0; i < p->n_thread; ++i) {
			mg_tbuf_destroy(s->buf[i]);
			free(s->mzs[i].a); free(s->sps[i].a);
		}
		
		free(s->buf); free(s->mzs); free(s->sps);
		return s;
    }
    else if (step == 2) { // step 3: dump
        utepdat_t *s = (utepdat_t*)in;
		uint64_t i;
        for (i = 0; i < (uint64_t)s->n; ++i) {
            // if(s->pos[i].s == (uint64_t)-1) continue;
            // kv_push(pe_hit, p->hits.a, s->pos[i]);
			if(!s->gcs[i]) continue;
			dump_gaf(&(p->hits), s->gcs[i], 1);
			free(s->gcs[i]->gc); free(s->gcs[i]->a); free(s->gcs[i]->lc); free(s->gcs[i]);
        }
        free(s->gcs);
        free(s);
    }
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
testl %esi, %esi
je 0x1c3944
movq %rdx, %r14
cmpl $0x1, %esi
je 0x1c3804
cmpl $0x2, %esi
jne 0x1c3b72
cmpl $0x0, 0x38(%r14)
je 0x1c37f3
addq $0x70, %rbx
xorl %r15d, %r15d
movq 0x70(%r14), %rax
movq (%rax,%r15,8), %rsi
testq %rsi, %rsi
je 0x1c37e7
movq %rbx, %rdi
movl $0x1, %edx
callq 0x1c3294
movq 0x70(%r14), %rax
movq (%rax,%r15,8), %rax
movq 0x18(%rax), %rdi
callq 0x2220
movq 0x70(%r14), %rax
movq (%rax,%r15,8), %rax
movq 0x28(%rax), %rdi
callq 0x2220
movq 0x70(%r14), %rax
movq (%rax,%r15,8), %rax
movq 0x20(%rax), %rdi
callq 0x2220
movq 0x70(%r14), %rax
movq (%rax,%r15,8), %rdi
callq 0x2220
incq %r15
movslq 0x38(%r14), %rax
cmpq %rax, %r15
jb 0x1c378d
movq 0x70(%r14), %rdi
callq 0x2220
movq %r14, %r15
jmp 0x1c3b62
movq 0x58(%rbx), %r15
movl $0x10, %esi
movq %r15, %rdi
callq 0x2120
movq %rax, 0x60(%r14)
movl $0x18, %esi
movq %r15, %rdi
callq 0x2120
movq %rax, 0x68(%r14)
movslq 0x38(%r14), %rdi
movl $0x8, %esi
callq 0x2120
movq %rax, 0x70(%r14)
movl $0x8, %esi
movq %r15, %rdi
callq 0x2120
movq %rax, 0x78(%r14)
movq 0x58(%rbx), %rdi
testq %rdi, %rdi
je 0x1c3887
xorl %r12d, %r12d
movl $0x1, %edi
movl $0x10, %esi
callq 0x2120
movq %rax, %r15
callq 0x1e35d3
movq %rax, (%r15)
movq 0x78(%r14), %rax
movq %r15, (%rax,%r12,8)
incq %r12
movq 0x58(%rbx), %rdi
cmpq %rdi, %r12
jb 0x1c3859
movslq 0x38(%r14), %rcx
leaq 0x1e7ee(%rip), %rsi     # 0x1e2080
movq %r14, %rdx
callq 0x1047b4
cmpl $0x0, 0x38(%r14)
je 0x1c38c9
xorl %r15d, %r15d
movq 0x58(%r14), %rax
movq (%rax,%r15,8), %rdi
callq 0x2220
movq 0x48(%r14), %rax
movq (%rax,%r15,8), %rax
addq %rax, 0x60(%rbx)
incq %r15
movslq 0x38(%r14), %rax
cmpq %rax, %r15
jb 0x1c38a4
movq 0x58(%r14), %rdi
callq 0x2220
movq 0x48(%r14), %rdi
callq 0x2220
cmpq $0x0, 0x58(%rbx)
je 0x1c3929
movl $0x8, %r15d
xorl %r12d, %r12d
movl $0x8, %r13d
movq 0x78(%r14), %rax
movq (%rax,%r12,8), %rdi
callq 0x196f11
movq 0x60(%r14), %rax
movq (%rax,%r13), %rdi
callq 0x2220
movq 0x68(%r14), %rax
movq (%rax,%r15,2), %rdi
callq 0x2220
incq %r12
addq $0x10, %r13
addq $0xc, %r15
cmpq 0x58(%rbx), %r12
jb 0x1c38f1
movq 0x78(%r14), %rdi
callq 0x2220
movq 0x60(%r14), %rdi
callq 0x2220
movq 0x68(%r14), %r15
jmp 0x1c3b65
movl $0x1, %edi
movl $0xd0, %esi
callq 0x2120
movq %rax, %r15
movq (%rbx), %rax
movq %rax, 0x8(%r15)
movq 0x8(%rbx), %rax
movq %rax, 0x10(%r15)
movq 0x68(%rbx), %rax
movq %rax, 0x50(%r15)
movq 0x10(%rbx), %rax
movq %rax, (%r15)
movq 0x18(%rbx), %rax
movq %rax, 0x18(%r15)
movq 0x28(%rbx), %rax
movq %rax, 0x28(%r15)
movq 0x20(%rbx), %rax
movq %rax, 0x20(%r15)
movq 0x48(%rbx), %rdi
callq 0x1c406c
testl %eax, %eax
js 0x1c3b53
movl $0x2, %r12d
movq 0x10(%rbx), %rax
movq 0x48(%rbx), %rcx
movslq 0x4(%rax), %rax
cmpq %rax, 0x30(%rcx)
jb 0x1c3b42
movslq 0x38(%r15), %r13
movl 0x3c(%r15), %eax
cmpl %eax, %r13d
jne 0x1c3a03
movl %r13d, %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 0xa0(%rbx), %rax
cmpq %rax, 0x98(%rbx)
jne 0x1c3a3c
leaq (%rax,%rax), %rsi
testq %rax, %rax
cmoveq %r12, %rsi
movq %rsi, 0xa0(%rbx)
movq 0xa8(%rbx), %rdi
shlq $0x3, %rsi
callq 0x2370
movq %rax, 0xa8(%rbx)
movq 0xb0(%rbx), %rax
movq 0x48(%rbx), %rcx
movq 0x98(%rbx), %rdx
addq (%rcx), %rax
movq 0xa8(%rbx), %rsi
leaq 0x1(%rdx), %rdi
movq %rdi, 0x98(%rbx)
movq %rax, (%rsi,%rdx,8)
movq 0xb0(%rbx), %rax
addq (%rcx), %rax
cmpq %rax, 0xc0(%rbx)
jae 0x1c3acb
decq %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rsi
shrq $0x10, %rsi
orq %rax, %rsi
incq %rsi
movq %rsi, 0xc0(%rbx)
movq 0xc8(%rbx), %rdi
callq 0x2370
movq %rax, 0xc8(%rbx)
movq 0x48(%rbx), %rax
movq 0xc8(%rbx), %rdi
addq 0xb0(%rbx), %rdi
movq (%rax), %rdx
movq 0x10(%rax), %rsi
callq 0x2160
movq 0x48(%rbx), %rax
movq (%rax), %rcx
addq %rcx, 0xb0(%rbx)
movq 0x30(%rax), %r14
movq %r14, %rdi
callq 0x2280
movq 0x58(%r15), %rcx
movq %rax, (%rcx,%r13,8)
movl 0x40(%r15), %ebp
addl %r14d, %ebp
movl %ebp, 0x40(%r15)
movq 0x48(%rbx), %rcx
movq 0x40(%rcx), %rsi
movq %rax, %rdi
movq %r14, %rdx
callq 0x2160
movq 0x48(%r15), %rax
leal 0x1(%r13), %ecx
movl %ecx, 0x38(%r15)
movq %r14, (%rax,%r13,8)
movslq %ebp, %rax
cmpq %rax, 0x50(%rbx)
jle 0x1c3b53
movq 0x48(%rbx), %rdi
callq 0x1c406c
testl %eax, %eax
jns 0x1c39a3
movslq 0x38(%r15), %rax
addq %rax, 0x68(%rbx)
cmpl $0x0, 0x40(%r15)
jne 0x1c3b75
xorl %r14d, %r14d
movq %r15, %rdi
callq 0x2220
movq %r14, %r15
jmp 0x1c3b75
xorl %r15d, %r15d
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq