// File: /workspace/github_c_makefile_star2_O1/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 0x66e8
movq %rdx, %rbx
cmpl $0x1, %esi
je 0x66cd
cmpl $0x2, %esi
jne 0x678d
cmpl $0x0, (%r14)
jle 0x643e
xorl %r15d, %r15d
movq 0x28(%rbx), %rax
movq (%rax,%r15,8), %rdi
callq 0x54f6
incq %r15
movslq (%r14), %rax
cmpq %rax, %r15
jl 0x6426
movq 0x28(%rbx), %rdi
callq 0x2050
cmpl $0x0, 0x8(%rbx)
jle 0x6695
leaq 0x28(%r14), %rax
movq %rax, (%rsp)
xorl %r12d, %r12d
movq 0x18(%rbx), %rax
cmpl $0x0, (%rax,%r12,4)
movsd 0xd26b(%rip), %xmm3     # 0x136d8
jle 0x6491
movq 0x20(%rbx), %rax
movq (%rax,%r12,8), %rax
movq 0x60(%rax), %rcx
leaq 0x4(%rcx), %rdx
addq $0x24, %rax
testq %rcx, %rcx
cmovneq %rdx, %rax
xorps %xmm3, %xmm3
cvtsi2sdl (%rax), %xmm3
movq 0x18(%rbx), %rax
cmpl $0x0, (%rax,%r12,4)
jle 0x65b4
xorl %ebp, %ebp
movq %r12, %rdi
shlq $0x5, %rdi
xorl %r13d, %r13d
xorl %r15d, %r15d
movsd %xmm3, 0x10(%rsp)
movq %rdi, 0x8(%rsp)
movq 0x10(%r14), %r9
movslq 0x5c(%r9), %rax
cmpq %rax, %r13
jge 0x65af
movq 0x20(%rbx), %rax
movq (%rax,%r12,8), %r8
leaq (%r8,%rbp), %rax
addq $0x24, %rax
movq 0x3c(%rax), %rcx
leaq 0x4(%rcx), %rdx
testq %rcx, %rcx
cmoveq %rax, %rdx
movl (%rdx), %eax
testl %eax, %eax
jle 0x6597
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
xorps %xmm1, %xmm1
cvtss2sd 0x50(%r9), %xmm1
mulsd %xmm3, %xmm1
ucomisd %xmm0, %xmm1
ja 0x6597
movl 0x38(%r8,%rbp), %eax
subl 0x34(%r8,%rbp), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movq 0x10(%rbx), %rcx
xorps %xmm1, %xmm1
cvtsi2sdl (%rcx,%rdi), %xmm1
xorps %xmm2, %xmm2
cvtss2sd 0x54(%r9), %xmm2
mulsd %xmm1, %xmm2
ucomisd %xmm0, %xmm2
ja 0x6597
addq %rbp, %r8
addq %rdi, %rcx
movq 0x8(%r14), %rax
movq 0x20(%r14), %rdx
incq %rax
movq %rax, 0x8(%r14)
leal 0x1(%r13), %r10d
movq (%rsp), %rdi
xorl %esi, %esi
pushq %r10
pushq %rax
callq 0x10588
addq $0x10, %rsp
movq 0x28(%r14), %rdx
movq 0x38(%r14), %rdi
movq 0x11a44(%rip), %rax     # 0x17fc0
movq (%rax), %rcx
movl $0x1, %esi
callq 0x22e0
movq 0x8(%rsp), %rdi
movsd 0x10(%rsp), %xmm3
incl %r15d
incq %r13
movq 0x18(%rbx), %rax
movslq (%rax,%r12,4), %rax
addq $0x68, %rbp
cmpq %rax, %r13
jl 0x64ba
testl %r15d, %r15d
jne 0x65f9
movq 0x10(%r14), %r9
movq 0x20(%r14), %rdx
movq %r12, %rcx
shlq $0x5, %rcx
addq 0x10(%rbx), %rcx
movq (%rsp), %rdi
xorl %esi, %esi
xorl %r8d, %r8d
pushq $0x0
pushq $0x0
callq 0x10588
addq $0x10, %rsp
movq 0x28(%r14), %rdx
movq 0x38(%r14), %rdi
movq 0x119d4(%rip), %rax     # 0x17fc0
movq (%rax), %rcx
movl $0x1, %esi
callq 0x22e0
movq 0x18(%rbx), %rax
cmpl $0x0, (%rax,%r12,4)
jle 0x6642
xorl %r15d, %r15d
xorl %r13d, %r13d
movq 0x20(%rbx), %rax
movq (%rax,%r12,8), %rax
movq 0x58(%rax,%r15), %rdi
callq 0x2050
movq 0x20(%rbx), %rax
movq (%rax,%r12,8), %rax
movq 0x60(%rax,%r15), %rdi
callq 0x2050
incq %r13
movq 0x18(%rbx), %rax
movslq (%rax,%r12,4), %rax
addq $0x68, %r15
cmpq %rax, %r13
jl 0x660a
movq 0x20(%rbx), %rax
movq (%rax,%r12,8), %rdi
callq 0x2050
movq 0x10(%rbx), %rax
movq %r12, %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 0x6685
callq 0x2050
incq %r12
movslq 0x8(%rbx), %rax
cmpq %rax, %r12
jl 0x645c
movq 0x20(%rbx), %rdi
callq 0x2050
movq 0x18(%rbx), %rdi
callq 0x2050
movq 0x10(%rbx), %rdi
callq 0x2050
leaq 0x11d29(%rip), %rax     # 0x183e0
cmpl $0x3, (%rax)
jge 0x67a1
movq %rbx, %rdi
callq 0x2050
jmp 0x678d
movl (%r14), %edi
movslq 0x8(%rbx), %rcx
leaq 0xd3(%rip), %rsi        # 0x67ae
movq %rbx, %rdx
callq 0x835c
jmp 0x678f
movl $0x1, %esi
movl $0x30, %edx
xorl %edi, %edi
callq 0x7f34
movq %rax, %rbx
movq 0x10(%r14), %rax
movq 0x18(%r14), %rdi
movq 0x8(%rax), %rsi
leaq 0x8(%rbx), %rcx
xorl %edx, %edx
callq 0xd886
movq %rax, %r15
movq %rax, 0x10(%rbx)
testq %rax, %rax
je 0x6780
movq %r14, (%rbx)
movslq (%r14), %rsi
movl $0x8, %edx
xorl %edi, %edi
callq 0x7f34
movq %rax, 0x28(%rbx)
cmpl $0x0, (%r14)
jle 0x6756
xorl %r12d, %r12d
callq 0x54c8
movq 0x28(%rbx), %rcx
movq %rax, (%rcx,%r12,8)
incq %r12
movslq (%r14), %rax
cmpq %rax, %r12
jl 0x673e
movslq 0x8(%rbx), %rsi
movl $0x4, %edx
xorl %edi, %edi
callq 0x7f34
movq %rax, 0x18(%rbx)
movslq 0x8(%rbx), %rsi
movl $0x8, %edx
xorl %edi, %edi
callq 0x7f34
movq %rax, 0x20(%rbx)
jmp 0x6788
movq %rbx, %rdi
callq 0x2050
testq %r15, %r15
jne 0x678f
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0x2b59
jmp 0x66c0