// File: /workspace/github_c_makefile_star2_O2/lh3[P]miniprot/map.c
// Function: worker_pipeline
static void *worker_pipeline(void *shared, int step, void *in)
{
	int32_t i;
    pipeline_t *p = (pipeline_t*)shared;
    if (step == 0) { // step 0: read sequences
        step_t *s;
        s = Kcalloc(0, step_t, 1);
		s->seq = mp_bseq_read(p->fp, p->opt->mini_batch_size, 0, &s->n_seq);
		if (s->seq) {
			s->p = p;
			s->buf = Kcalloc(0, mp_tbuf_t*, p->n_threads);
			for (i = 0; i < p->n_threads; ++i)
				s->buf[i] = mp_tbuf_init();
			s->n_reg = Kcalloc(0, int32_t, s->n_seq);
			s->reg = Kcalloc(0, mp_reg1_t*, s->n_seq);
			return s;
		} else free(s);
    } else if (step == 1) { // step 1: map
		kt_for(p->n_threads, worker_for, in, ((step_t*)in)->n_seq);
		return in;
    } else if (step == 2) { // step 2: output
        step_t *s = (step_t*)in;
		for (i = 0; i < p->n_threads; ++i) mp_tbuf_destroy(s->buf[i]);
		free(s->buf);
		for (i = 0; i < s->n_seq; ++i) {
			int32_t best_sc = -1, j, n_out;
			if (s->n_reg[i] > 0)
				best_sc = s->reg[i][0].p? s->reg[i][0].p->dp_max : s->reg[i][0].chn_sc;
			for (j = 0, n_out = 0; j < s->n_reg[i] && j < p->opt->out_n; ++j) {
				const mp_reg1_t *r = &s->reg[i][j];
				int32_t sc = r->p? r->p->dp_max : r->chn_sc;
				if (sc <= 0 || sc < (double)best_sc * p->opt->out_sim) continue;
				if (r->qe - r->qs < (double)s->seq[i].l_seq * p->opt->out_cov) continue;
				mp_write_output(&p->str, 0, p->mi, &s->seq[i], r, p->opt, ++p->id, j + 1);
				fwrite(p->str.s, 1, p->str.l, stdout);
				++n_out;
			}
			if (n_out == 0) {
				mp_write_output(&p->str, 0, p->mi, &s->seq[i], 0, p->opt, 0, 0);
				fwrite(p->str.s, 1, p->str.l, stdout);
			}
			for (j = 0; j < s->n_reg[i]; ++j) {
				free(s->reg[i][j].feat);
				free(s->reg[i][j].p);
			}
			free(s->reg[i]);
			free(s->seq[i].seq); free(s->seq[i].name);
			if (s->seq[i].comment) free(s->seq[i].comment);
		}
		free(s->reg); free(s->n_reg); free(s->seq);
		if (mp_verbose >= 3)
			fprintf(stderr, "[M::%s::%.3f*%.2f] mapped %d sequences\n", __func__, mp_realtime(), mp_cputime() / mp_realtime(), s->n_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 0x585e
movq %rdx, %rbx
cmpl $0x1, %esi
je 0x5843
cmpl $0x2, %esi
jne 0x5b06
xorl %r15d, %r15d
movslq (%r14), %rax
movq 0x28(%rbx), %rdi
cmpq %rax, %r15
jge 0x58c7
movq (%rdi,%r15,8), %rdi
callq 0x495a
incq %r15
jmp 0x5825
movl (%r14), %edi
movslq 0x8(%rbx), %rcx
leaq 0x342(%rip), %rsi       # 0x5b93
movq %rbx, %rdx
callq 0x775c
jmp 0x5b2e
pushq $0x1
popq %rsi
pushq $0x30
popq %rdx
xorl %edi, %edi
callq 0x72e4
movq %rax, %rbx
movq 0x10(%r14), %rax
movq 0x18(%r14), %rdi
movq 0x8(%rax), %rsi
leaq 0x8(%rbx), %rcx
xorl %edx, %edx
callq 0xc1af
movq %rax, 0x10(%rbx)
testq %rax, %rax
je 0x5afe
movq %r14, (%rbx)
movslq (%r14), %rsi
xorl %r15d, %r15d
pushq $0x8
popq %rdx
xorl %edi, %edi
callq 0x72e4
movq %rax, 0x28(%rbx)
movslq (%r14), %rax
cmpq %rax, %r15
jge 0x5b0a
callq 0x4930
movq 0x28(%rbx), %rcx
movq %rax, (%rcx,%r15,8)
incq %r15
jmp 0x58a9
callq 0x2050
leaq 0x28(%r14), %rax
movq %rax, 0x10(%rsp)
xorl %r13d, %r13d
movslq 0x8(%rbx), %rax
cmpq %rax, %r13
jge 0x5ad7
movq 0x18(%rbx), %rax
movl (%rax,%r13,4), %eax
movsd 0xce33(%rip), %xmm3     # 0x12728
testl %eax, %eax
jle 0x5918
movq 0x20(%rbx), %rcx
movq (%rcx,%r13,8), %rcx
movq 0x60(%rcx), %rdx
leaq 0x4(%rdx), %rsi
addq $0x24, %rcx
testq %rdx, %rdx
cmovneq %rsi, %rcx
cvtsi2sdl (%rcx), %xmm3
xorl %r12d, %r12d
movq %r13, %rbp
shlq $0x5, %rbp
xorl %r15d, %r15d
xorl %edi, %edi
movsd %xmm3, 0x8(%rsp)
movq %rbp, (%rsp)
movslq %eax, %rcx
cmpq %rcx, %r15
jge 0x5a1e
movq 0x10(%r14), %r9
movslq 0x5c(%r9), %rcx
cmpq %rcx, %r15
jge 0x5a1e
movq 0x20(%rbx), %rcx
movq (%rcx,%r13,8), %r8
leaq (%r8,%r12), %rcx
addq $0x24, %rcx
movq 0x3c(%rcx), %rdx
leaq 0x4(%rdx), %rsi
testq %rdx, %rdx
cmoveq %rcx, %rsi
movl (%rsi), %ecx
testl %ecx, %ecx
jle 0x5a12
cvtsi2sd %ecx, %xmm0
cvtss2sd 0x50(%r9), %xmm1
mulsd %xmm3, %xmm1
ucomisd %xmm0, %xmm1
ja 0x5a12
movl 0x38(%r8,%r12), %ecx
subl 0x34(%r8,%r12), %ecx
cvtsi2sd %ecx, %xmm0
movq 0x10(%rbx), %rcx
cvtsi2sdl (%rcx,%rbp), %xmm1
cvtss2sd 0x54(%r9), %xmm2
mulsd %xmm1, %xmm2
ucomisd %xmm0, %xmm2
ja 0x5a12
addq %r12, %r8
addq %rbp, %rcx
movq 0x8(%r14), %rax
movq 0x20(%r14), %rdx
incq %rax
movq %rax, 0x8(%r14)
leal 0x1(%r15), %r10d
movl %edi, %ebp
movq 0x10(%rsp), %rdi
xorl %esi, %esi
pushq %r10
pushq %rax
callq 0xea43
popq %rax
popq %rcx
movq 0x28(%r14), %rdx
movq 0x38(%r14), %rdi
movq 0x125cf(%rip), %rax     # 0x17fc0
movq (%rax), %rcx
pushq $0x1
popq %rsi
callq 0x2300
movl %ebp, %edi
movq (%rsp), %rbp
movsd 0x8(%rsp), %xmm3
incl %edi
movq 0x18(%rbx), %rax
movl (%rax,%r13,4), %eax
incq %r15
addq $0x68, %r12
jmp 0x5931
testl %edi, %edi
jne 0x5a60
movq 0x10(%r14), %r9
movq 0x20(%r14), %rdx
movq 0x10(%rbx), %rcx
addq %rbp, %rcx
movq 0x10(%rsp), %rdi
xorl %esi, %esi
xorl %r8d, %r8d
pushq $0x0
pushq $0x0
callq 0xea43
popq %rax
popq %rcx
movq 0x28(%r14), %rdx
movq 0x38(%r14), %rdi
movq 0x1256b(%rip), %rax     # 0x17fc0
movq (%rax), %rcx
pushq $0x1
popq %rsi
callq 0x2300
xorl %r15d, %r15d
xorl %r12d, %r12d
movq 0x18(%rbx), %rax
movq 0x20(%rbx), %rcx
movslq (%rax,%r13,4), %rax
movq (%rcx,%r13,8), %rdi
cmpq %rax, %r12
jge 0x5aa0
movq 0x58(%rdi,%r15), %rdi
callq 0x2050
movq 0x20(%rbx), %rax
movq (%rax,%r13,8), %rax
movq 0x60(%rax,%r15), %rdi
callq 0x2050
incq %r12
addq $0x68, %r15
jmp 0x5a66
callq 0x2050
movq 0x10(%rbx), %rax
movq 0x10(%rax,%rbp), %rdi
callq 0x2050
movq 0x10(%rbx), %rax
movq 0x8(%rax,%rbp), %rdi
callq 0x2050
movq 0x10(%rbx), %rax
movq 0x18(%rax,%rbp), %rdi
callq 0x2050
incq %r13
jmp 0x58d8
movq 0x20(%rbx), %rdi
callq 0x2050
movq 0x18(%rbx), %rdi
callq 0x2050
movq 0x10(%rbx), %rdi
callq 0x2050
leaq 0x128f7(%rip), %rax     # 0x183f0
cmpl $0x3, (%rax)
jge 0x5b40
movq %rbx, %rdi
callq 0x2050
xorl %ebx, %ebx
jmp 0x5b2e
movslq 0x8(%rbx), %rsi
pushq $0x4
popq %rdx
xorl %edi, %edi
callq 0x72e4
movq %rax, 0x18(%rbx)
movslq 0x8(%rbx), %rsi
pushq $0x8
popq %rdx
xorl %edi, %edi
callq 0x72e4
movq %rax, 0x20(%rbx)
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x124a9(%rip), %rax     # 0x17ff0
movq (%rax), %r14
callq 0x3801
movsd %xmm0, 0x8(%rsp)
callq 0x3798
movsd %xmm0, (%rsp)
callq 0x3801
movsd (%rsp), %xmm1
divsd %xmm0, %xmm1
movl 0x8(%rbx), %ecx
leaq 0xcc1b(%rip), %rsi      # 0x12792
leaq 0xcc3c(%rip), %rdx      # 0x127ba
movq %r14, %rdi
movsd 0x8(%rsp), %xmm0
movb $0x2, %al
callq 0x21e0
jmp 0x5afe