// File: /workspace/github_cpp_makefile_star2_O2/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, %r14
testl %esi, %esi
je 0x181d07
movq %rdx, %rbx
cmpl $0x1, %esi
je 0x181bf9
cmpl $0x2, %esi
jne 0x181f0d
addq $0x70, %r14
xorl %r15d, %r15d
pushq $0x1
popq %rbp
movslq 0x38(%rbx), %rax
movq 0x70(%rbx), %rdi
cmpq %rax, %r15
jae 0x181eec
movq (%rdi,%r15,8), %rsi
testq %rsi, %rsi
je 0x181bf4
movq %r14, %rdi
movl %ebp, %edx
callq 0x181643
movq 0x70(%rbx), %rax
movq (%rax,%r15,8), %rax
movq 0x18(%rax), %rdi
callq 0x2220
movq 0x70(%rbx), %rax
movq (%rax,%r15,8), %rax
movq 0x28(%rax), %rdi
callq 0x2220
movq 0x70(%rbx), %rax
movq (%rax,%r15,8), %rax
movq 0x20(%rax), %rdi
callq 0x2220
movq 0x70(%rbx), %rax
movq (%rax,%r15,8), %rdi
callq 0x2220
incq %r15
jmp 0x181b90
movq 0x58(%r14), %r12
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)
movslq 0x38(%rbx), %rdi
pushq $0x8
popq %r15
movq %r15, %rsi
callq 0x2120
movq %rax, 0x70(%rbx)
movq %r12, %rdi
movq %r15, %rsi
callq 0x2120
movq %rax, 0x78(%rbx)
xorl %r13d, %r13d
cmpq %r12, %r13
jae 0x181c5c
callq 0x1588bc
movq 0x78(%rbx), %rcx
movq %rax, (%rcx,%r13,8)
incq %r13
movq 0x58(%r14), %r12
jmp 0x181c41
movslq 0x38(%rbx), %rcx
leaq 0x2014e(%rip), %rsi     # 0x1a1db5
movl %r12d, %edi
movq %rbx, %rdx
callq 0xc67c0
xorl %r12d, %r12d
movslq 0x38(%rbx), %rax
movq 0x58(%rbx), %rdi
cmpq %rax, %r12
jae 0x181c9c
movq (%rdi,%r12,8), %rdi
callq 0x2220
movq 0x48(%rbx), %rax
movq (%rax,%r12,8), %rax
addq %rax, 0x60(%r14)
incq %r12
jmp 0x181c75
callq 0x2220
movq 0x48(%rbx), %rdi
callq 0x2220
pushq $0x2
popq %r12
xorl %r13d, %r13d
movq 0x78(%rbx), %rdi
cmpq 0x58(%r14), %r13
jae 0x181ceb
movq (%rdi,%r13,8), %rdi
callq 0x1588d8
movq 0x60(%rbx), %rax
movq (%rax,%r15), %rdi
callq 0x2220
movq 0x68(%rbx), %rax
movq (%rax,%r12,8), %rdi
callq 0x2220
incq %r13
addq $0x3, %r12
addq $0x10, %r15
jmp 0x181cb1
callq 0x2220
movq 0x60(%rbx), %rdi
callq 0x2220
movq 0x68(%rbx), %rdi
callq 0x2220
jmp 0x181f0f
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 0x28(%r14), %rax
movq %rax, 0x28(%rbx)
movups 0x18(%r14), %xmm0
movups %xmm0, 0x18(%rbx)
movq 0x48(%r14), %r15
movq %r15, %rdi
callq 0x1823fd
testl %eax, %eax
js 0x181ef3
movq 0x10(%r14), %rax
movq 0x48(%r14), %r15
movslq 0x4(%rax), %rax
cmpq %rax, 0x30(%r15)
jb 0x181d43
movslq 0x38(%rbx), %rbp
cmpl 0x3c(%rbx), %ebp
jne 0x181da7
movl %ebp, %eax
sarl %eax
addl %ebp, %eax
cmpl $0x10, %ebp
pushq $0x10
popq %rcx
cmovll %ecx, %eax
movl %eax, 0x3c(%rbx)
movq 0x48(%rbx), %rdi
movslq %eax, %r15
shlq $0x3, %r15
movq %r15, %rsi
callq 0x2370
movq %rax, 0x48(%rbx)
movq 0x58(%rbx), %rdi
movq %r15, %rsi
callq 0x2370
movq %rax, 0x58(%rbx)
movq 0x98(%r14), %rdx
movq 0xa8(%r14), %rax
cmpq 0xa0(%r14), %rdx
jne 0x181ded
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0xa0(%r14)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0xa8(%r14)
movq 0x98(%r14), %rdx
movq 0x48(%r14), %rcx
movq 0xb0(%r14), %rsi
addq (%rcx), %rsi
leaq 0x1(%rdx), %rdi
movq %rdi, 0x98(%r14)
movq %rsi, (%rax,%rdx,8)
movq 0xb0(%r14), %rdi
movq (%rcx), %rdx
leaq (%rdi,%rdx), %rsi
movq 0xc8(%r14), %rax
cmpq %rsi, 0xc0(%r14)
jae 0x181e83
decq %rsi
movq %rsi, %rcx
shrq %rcx
orq %rsi, %rcx
movq %rcx, %rdx
shrq $0x2, %rdx
orq %rcx, %rdx
movq %rdx, %rcx
shrq $0x4, %rcx
orq %rdx, %rcx
movq %rcx, %rdx
shrq $0x8, %rdx
orq %rcx, %rdx
movq %rdx, %rsi
shrq $0x10, %rsi
orq %rdx, %rsi
incq %rsi
movq %rsi, 0xc0(%r14)
movq %rax, %rdi
callq 0x2370
movq %rax, 0xc8(%r14)
movq 0x48(%r14), %rcx
movq 0xb0(%r14), %rdi
movq (%rcx), %rdx
addq %rax, %rdi
movq 0x10(%rcx), %rsi
callq 0x2160
movq 0x48(%r14), %rax
movq (%rax), %rcx
addq %rcx, 0xb0(%r14)
movq 0x30(%rax), %r12
movq %r12, %rdi
callq 0x2280
movq 0x58(%rbx), %rcx
movq %rax, (%rcx,%rbp,8)
movl 0x40(%rbx), %r13d
addl %r12d, %r13d
movl %r13d, 0x40(%rbx)
movq 0x48(%r14), %r15
movq 0x40(%r15), %rsi
movq %rax, %rdi
movq %r12, %rdx
callq 0x2160
movq 0x48(%rbx), %rcx
leal 0x1(%rbp), %eax
movl %eax, 0x38(%rbx)
movq %r12, (%rcx,%rbp,8)
movslq %r13d, %rcx
cmpq %rcx, 0x50(%r14)
jg 0x181d43
jmp 0x181efa
callq 0x2220
jmp 0x181f05
movl 0x38(%rbx), %eax
movl 0x40(%rbx), %r13d
cltq
addq %rax, 0x68(%r14)
testl %r13d, %r13d
jne 0x181f0f
movq %rbx, %rdi
callq 0x2220
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq