// File: /workspace/github_cpp_makefile_star2_O3/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
subq $0x28, %rsp
movq %rdi, %r14
testl %esi, %esi
je 0x1cd83d
movq %rdx, %rbx
cmpl $0x1, %esi
je 0x1cd7ae
cmpl $0x2, %esi
jne 0x1cdaa7
movl 0x38(%rbx), %eax
testl %eax, %eax
je 0x1cd7a0
addq $0x70, %r14
xorl %r15d, %r15d
movq 0x70(%rbx), %rcx
movq (%rcx,%r15,8), %rsi
testq %rsi, %rsi
je 0x1cd795
movq %r14, %rdi
movl $0x1, %edx
callq 0x1cd21b
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
movl 0x38(%rbx), %eax
incq %r15
movslq %eax, %rcx
cmpq %rcx, %r15
jb 0x1cd738
movq 0x70(%rbx), %rdi
callq 0x2220
jmp 0x1cda9f
movq 0x58(%r14), %r12
movl $0x10, %esi
movq %r12, %rdi
callq 0x2120
movq %rax, 0x60(%rbx)
movl $0x18, %esi
movq %r12, %rdi
callq 0x2120
movq %rax, 0x68(%rbx)
movslq 0x38(%rbx), %r15
movl $0x8, %esi
movq %r15, %rdi
callq 0x2120
movq %rax, 0x70(%rbx)
movl $0x8, %esi
movq %r12, %rdi
callq 0x2120
movq %rax, 0x78(%rbx)
testq %r12, %r12
je 0x1cdaae
xorl %r12d, %r12d
movl $0x1, %edi
movl $0x10, %esi
callq 0x2120
movq %rax, %r15
callq 0x1edff7
movq %rax, (%r15)
movq 0x78(%rbx), %rax
movq %r15, (%rax,%r12,8)
incq %r12
movq 0x58(%r14), %rdi
cmpq %rdi, %r12
jb 0x1cd806
movslq 0x38(%rbx), %r15
jmp 0x1cdab0
movl $0x1, %edi
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), %rdi
callq 0x1ce059
testl %eax, %eax
js 0x1cda9f
xorl %r15d, %r15d
movq $0x0, 0x18(%rsp)
movq $0x0, 0x10(%rsp)
xorl %r12d, %r12d
movl $0x0, 0x8(%rsp)
movq 0x10(%r14), %rax
movq 0x48(%r14), %r13
movslq 0x4(%rax), %rax
cmpq %rax, 0x30(%r13)
jb 0x1cda7d
cmpl %r12d, 0x8(%rsp)
jne 0x1cd90c
movl %r12d, %ebp
sarl %ebp
addl %r12d, %ebp
cmpl $0x10, %r12d
movl $0x10, %eax
cmovll %eax, %ebp
movl %ebp, 0x3c(%rbx)
movslq %ebp, %r15
shlq $0x3, %r15
movq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x2370
movq %rax, 0x48(%rbx)
movq 0x58(%rbx), %rdi
movq %r15, %rsi
callq 0x2370
movq %rax, 0x18(%rsp)
movq %rax, 0x58(%rbx)
movl %ebp, %r12d
movq 0x98(%r14), %rdx
movq 0xa8(%r14), %rax
cmpq 0xa0(%r14), %rdx
jne 0x1cd954
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
movl $0x2, %ecx
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)
movl %r12d, 0xc(%rsp)
jae 0x1cd9ef
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), %rbp
movq %rbp, %rdi
callq 0x2280
movq %r14, %r12
movl 0x8(%rsp), %r14d
movslq %r14d, %rdx
movq %rdx, 0x20(%rsp)
movq 0x18(%rsp), %rcx
movq %rax, (%rcx,%rdx,8)
movl 0x40(%rbx), %r15d
addl %ebp, %r15d
movl %r15d, 0x40(%rbx)
movq 0x48(%r12), %r13
movq 0x40(%r13), %rsi
movq %rax, %rdi
movq %rbp, %rdx
callq 0x2160
movq 0x48(%rbx), %rcx
incl %r14d
movl %r14d, 0x8(%rsp)
movl %r14d, 0x38(%rbx)
movq %r12, %r14
movq %rcx, 0x10(%rsp)
movq 0x20(%rsp), %rax
movq %rbp, (%rcx,%rax,8)
movslq %r15d, %rax
cmpq %rax, 0x50(%r12)
movl 0xc(%rsp), %r12d
jle 0x1cda8d
movq %r13, %rdi
callq 0x1ce059
testl %eax, %eax
jns 0x1cd8a8
movslq 0x8(%rsp), %rax
addq %rax, 0x68(%r14)
testl %r15d, %r15d
jne 0x1cdb6b
movq %rbx, %rdi
callq 0x2220
xorl %ebx, %ebx
jmp 0x1cdb6b
xorl %edi, %edi
leaq 0x1f067(%rip), %rsi     # 0x1ecb1e
movq %rbx, %rdx
movq %r15, %rcx
callq 0x108f2c
cmpl $0x0, 0x38(%rbx)
je 0x1cdaf0
xorl %r15d, %r15d
movq 0x58(%rbx), %rax
movq (%rax,%r15,8), %rdi
callq 0x2220
movq 0x48(%rbx), %rax
movq (%rax,%r15,8), %rax
addq %rax, 0x60(%r14)
incq %r15
movslq 0x38(%rbx), %rax
cmpq %rax, %r15
jb 0x1cdacb
movq 0x58(%rbx), %rdi
callq 0x2220
movq 0x48(%rbx), %rdi
callq 0x2220
cmpq $0x0, 0x58(%r14)
je 0x1cdb50
movl $0x8, %r15d
xorl %r12d, %r12d
movl $0x8, %r13d
movq 0x78(%rbx), %rax
movq (%rax,%r12,8), %rdi
callq 0x19fca1
movq 0x60(%rbx), %rax
movq (%rax,%r13), %rdi
callq 0x2220
movq 0x68(%rbx), %rax
movq (%rax,%r15,2), %rdi
callq 0x2220
incq %r12
addq $0x10, %r13
addq $0xc, %r15
cmpq 0x58(%r14), %r12
jb 0x1cdb18
movq 0x78(%rbx), %rdi
callq 0x2220
movq 0x60(%rbx), %rdi
callq 0x2220
movq 0x68(%rbx), %rdi
callq 0x2220
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq