// File: /workspace/github_c_makefile_star2_O3/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 $0x28, %rsp
movq %rdi, %r14
testl %esi, %esi
je 0x6a04
movq %rdx, %rbx
cmpl $0x1, %esi
je 0x69e9
cmpl $0x2, %esi
jne 0x6aa1
cmpl $0x0, (%r14)
jle 0x675a
xorl %r15d, %r15d
movq 0x28(%rbx), %rax
movq (%rax,%r15,8), %rdi
callq 0x582a
incq %r15
movslq (%r14), %rax
cmpq %rax, %r15
jl 0x6742
movq 0x28(%rbx), %rdi
callq 0x2050
leaq 0x8(%rbx), %rax
movq %rax, 0x8(%rsp)
cmpl $0x0, 0x8(%rbx)
jle 0x69af
leaq 0x28(%r14), %rax
movq %rax, 0x10(%rsp)
xorl %r13d, %r13d
movq 0x18(%rbx), %rax
cmpl $0x0, (%rax,%r13,4)
jle 0x68c9
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
xorps %xmm3, %xmm3
cvtsi2sdl (%rcx), %xmm3
xorl %ebp, %ebp
movq %r13, %r10
shlq $0x5, %r10
xorl %r15d, %r15d
xorl %r12d, %r12d
movsd %xmm3, 0x20(%rsp)
movq %r10, 0x18(%rsp)
movq 0x10(%r14), %r9
movslq 0x5c(%r9), %rcx
cmpq %rcx, %r15
jge 0x68c4
movq 0x20(%rbx), %rcx
movq (%rcx,%r13,8), %r8
leaq (%r8,%rbp), %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 0x68b0
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
xorps %xmm1, %xmm1
cvtss2sd 0x50(%r9), %xmm1
mulsd %xmm3, %xmm1
ucomisd %xmm0, %xmm1
ja 0x68b0
movl 0x38(%r8,%rbp), %ecx
subl 0x34(%r8,%rbp), %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
movq 0x10(%rbx), %rcx
xorps %xmm1, %xmm1
cvtsi2sdl (%rcx,%r10), %xmm1
xorps %xmm2, %xmm2
cvtss2sd 0x54(%r9), %xmm2
mulsd %xmm1, %xmm2
ucomisd %xmm0, %xmm2
ja 0x68b0
addq %rbp, %r8
addq %r10, %rcx
movq 0x8(%r14), %rax
movq 0x20(%r14), %rdx
incq %rax
movq %rax, 0x8(%r14)
leal 0x1(%r15), %r10d
movq 0x10(%rsp), %rdi
xorl %esi, %esi
pushq %r10
pushq %rax
callq 0x108e6
addq $0x10, %rsp
movq 0x28(%r14), %rdx
movq 0x38(%r14), %rdi
movq 0x1272f(%rip), %rax     # 0x18fc0
movq (%rax), %rcx
movl $0x1, %esi
callq 0x22e0
movq 0x18(%rsp), %r10
movsd 0x20(%rsp), %xmm3
incl %r12d
movq 0x18(%rbx), %rax
incq %r15
movslq (%rax,%r13,4), %rcx
addq $0x68, %rbp
cmpq %rcx, %r15
jl 0x67cd
testl %r12d, %r12d
jne 0x6913
movq 0x10(%r14), %r9
movq 0x20(%r14), %rdx
movq %r13, %rcx
shlq $0x5, %rcx
addq 0x10(%rbx), %rcx
movq 0x10(%rsp), %rdi
xorl %esi, %esi
xorl %r8d, %r8d
pushq $0x0
pushq $0x0
callq 0x108e6
addq $0x10, %rsp
movq 0x28(%r14), %rdx
movq 0x38(%r14), %rdi
movq 0x126be(%rip), %rax     # 0x18fc0
movq (%rax), %rcx
movl $0x1, %esi
callq 0x22e0
movq 0x18(%rbx), %rax
cmpl $0x0, (%rax,%r13,4)
jle 0x6958
xorl %r15d, %r15d
xorl %r12d, %r12d
movq 0x20(%rbx), %rax
movq (%rax,%r13,8), %rax
movq 0x58(%rax,%r15), %rdi
callq 0x2050
movq 0x20(%rbx), %rax
movq (%rax,%r13,8), %rax
movq 0x60(%rax,%r15), %rdi
callq 0x2050
incq %r12
movq 0x18(%rbx), %rax
movslq (%rax,%r13,4), %rax
addq $0x68, %r15
cmpq %rax, %r12
jl 0x6920
movq 0x20(%rbx), %rax
movq (%rax,%r13,8), %rdi
callq 0x2050
movq 0x10(%rbx), %rax
movq %r13, %r15
shlq $0x5, %r15
movq 0x10(%rax,%r15), %rdi
callq 0x2050
movq 0x10(%rbx), %rax
movq 0x8(%rax,%r15), %rdi
callq 0x2050
movq 0x10(%rbx), %rax
movq 0x18(%rax,%r15), %rdi
testq %rdi, %rdi
je 0x699b
callq 0x2050
incq %r13
movq 0x8(%rsp), %rax
movslq (%rax), %rax
cmpq %rax, %r13
jl 0x6782
movq 0x20(%rbx), %rdi
callq 0x2050
movq 0x18(%rbx), %rdi
callq 0x2050
movq 0x10(%rbx), %rdi
callq 0x2050
leaq 0x12a0f(%rip), %rax     # 0x193e0
cmpl $0x3, (%rax)
jl 0x6a99
movq 0x8(%rsp), %rdi
callq 0x2b31
jmp 0x6a99
movl (%r14), %edi
movslq 0x8(%rbx), %rcx
leaq 0xbe(%rip), %rsi        # 0x6ab5
movq %rbx, %rdx
callq 0x8760
jmp 0x6aa3
movl $0x1, %esi
movl $0x30, %edx
xorl %edi, %edi
callq 0x8344
movq %rax, %rbx
movq 0x10(%r14), %rax
movq 0x18(%r14), %rdi
movq 0x8(%rax), %rsi
leaq 0x8(%rbx), %rcx
xorl %edx, %edx
callq 0xdac3
movq %rax, 0x10(%rbx)
testq %rax, %rax
je 0x6a99
movq %r14, (%rbx)
movslq (%r14), %rsi
movl $0x8, %edx
xorl %edi, %edi
callq 0x8344
movq %rax, 0x28(%rbx)
cmpl $0x0, (%r14)
jle 0x6a6f
xorl %r15d, %r15d
callq 0x57fc
movq 0x28(%rbx), %rcx
movq %rax, (%rcx,%r15,8)
incq %r15
movslq (%r14), %rax
cmpq %rax, %r15
jl 0x6a57
movslq 0x8(%rbx), %rsi
movl $0x4, %edx
xorl %edi, %edi
callq 0x8344
movq %rax, 0x18(%rbx)
movslq 0x8(%rbx), %rsi
movl $0x8, %edx
xorl %edi, %edi
callq 0x8344
movq %rax, 0x20(%rbx)
jmp 0x6aa3
movq %rbx, %rdi
callq 0x2050
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq