// File: /workspace/github_c_makefile_star2_O3/lh3[P]minimap/map.c
// Function: worker_pipeline
static void *worker_pipeline(void *shared, int step, void *in)
{
	int i, j;
    pipeline_t *p = (pipeline_t*)shared;
    if (step == 0) { // step 0: read sequences
        step_t *s;
        s = (step_t*)calloc(1, sizeof(step_t));
		s->seq = bseq_read(p->fp, p->batch_size, &s->n_seq);
		if (s->seq) {
			s->p = p;
			for (i = 0; i < s->n_seq; ++i)
				s->seq[i].rid = p->n_processed++;
			s->buf = (mm_tbuf_t**)calloc(p->n_threads, sizeof(mm_tbuf_t*));
			for (i = 0; i < p->n_threads; ++i)
				s->buf[i] = mm_tbuf_init();
			s->n_reg = (int*)calloc(s->n_seq, sizeof(int));
			s->reg = (mm_reg1_t**)calloc(s->n_seq, sizeof(mm_reg1_t*));
			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;
		const mm_idx_t *mi = p->mi;
		for (i = 0; i < p->n_threads; ++i) mm_tbuf_destroy(s->buf[i]);
		free(s->buf);
		for (i = 0; i < s->n_seq; ++i) {
			bseq1_t *t = &s->seq[i];
			for (j = 0; j < s->n_reg[i]; ++j) {
				mm_reg1_t *r = &s->reg[i][j];
				if (r->len < p->opt->min_match) continue;
				printf("%s\t%d\t%d\t%d\t%c\t", t->name, t->l_seq, r->qs, r->qe, "+-"[r->rev]);
				if (mi->name) fputs(mi->name[r->rid], stdout);
				else printf("%d", r->rid + 1);
				printf("\t%d\t%d\t%d\t%d\t%d\t255\tcm:i:%d\n", mi->len[r->rid], r->rs, r->re, r->len,
						r->re - r->rs > r->qe - r->qs? r->re - r->rs : r->qe - r->qs, r->cnt);
			}
			free(s->reg[i]);
			free(s->seq[i].seq); free(s->seq[i].name);
		}
		free(s->reg); free(s->n_reg); free(s->seq);
		free(s);
	}
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %rbx
cmpl $0x2, %esi
movq %rdi, 0x8(%rsp)
je 0x65d5
cmpl $0x1, %esi
je 0x65ba
testl %esi, %esi
jne 0x67b1
movq %rdi, %r12
movl $0x1, %edi
movl $0x30, %esi
callq 0x2150
movq %rax, %rbx
movq 0x18(%r12), %rdi
movl (%r12), %esi
leaq 0x8(%rax), %r15
movq %r15, %rdx
callq 0x34dc
movq %rax, 0x10(%rbx)
testq %rax, %rax
je 0x67a9
movq %r12, (%rbx)
movslq 0x8(%rbx), %r14
testq %r14, %r14
movq %r12, %rdi
jle 0x653b
movl 0x4(%rdi), %ecx
leaq (,%r14,8), %rdx
leaq (%rdx,%rdx,2), %rdx
xorl %esi, %esi
movl %ecx, 0x4(%rax,%rsi)
incl %ecx
addq $0x18, %rsi
cmpq %rsi, %rdx
jne 0x6529
movl %ecx, 0x4(%rdi)
movslq 0x8(%rdi), %r12
movl $0x8, %esi
movq %r12, %rdi
callq 0x2150
movq %rax, 0x28(%rbx)
testq %r12, %r12
jle 0x6590
xorl %r14d, %r14d
movq 0x8(%rsp), %r13
movl $0x1, %edi
movl $0xb8, %esi
callq 0x2150
movq %rax, %r12
callq 0x72f4
movq %rax, 0x78(%r12)
movq 0x28(%rbx), %rax
movq %r12, (%rax,%r14,8)
incq %r14
movslq 0x8(%r13), %rax
cmpq %rax, %r14
jl 0x655d
movl (%r15), %r14d
movslq %r14d, %r14
movl $0x4, %esi
movq %r14, %rdi
callq 0x2150
movq %rax, 0x18(%rbx)
movl $0x8, %esi
movq %r14, %rdi
callq 0x2150
movq %rax, 0x20(%rbx)
jmp 0x67b3
movl 0x8(%rdi), %edi
movslq 0x8(%rbx), %rcx
leaq 0x1fd(%rip), %rsi       # 0x67c5
movq %rbx, %rdx
callq 0x6870
jmp 0x67b3
movq 0x20(%rdi), %rax
movq %rax, 0x10(%rsp)
cmpl $0x0, 0x8(%rdi)
jle 0x6603
movq %rdi, %r15
xorl %r14d, %r14d
movq 0x28(%rbx), %rax
movq (%rax,%r14,8), %rdi
callq 0x4f19
incq %r14
movslq 0x8(%r15), %rax
cmpq %rax, %r14
jl 0x65ea
movq 0x28(%rbx), %rdi
callq 0x2040
cmpl $0x0, 0x8(%rbx)
jle 0x678e
xorl %r15d, %r15d
movq 0x18(%rbx), %rax
cmpl $0x0, (%rax,%r15,4)
movq 0x8(%rsp), %rsi
jle 0x6749
leaq (%r15,%r15,2), %r12
shlq $0x3, %r12
addq 0x10(%rbx), %r12
xorl %r13d, %r13d
xorl %r14d, %r14d
movq 0x20(%rbx), %rcx
movq (%rcx,%r15,8), %rbp
movl 0x8(%rbp,%r13), %ecx
movq 0x10(%rsi), %rdx
cmpl 0xc(%rdx), %ecx
jb 0x6735
movq 0x8(%r12), %rsi
movl (%r12), %edx
movl (%rbp,%r13), %eax
movl 0xc(%rbp,%r13), %ecx
movl 0x10(%rbp,%r13), %r8d
shrl $0x1f, %eax
leaq 0x228d(%rip), %rdi      # 0x8908
movsbl (%rax,%rdi), %r9d
leaq 0x2271(%rip), %rdi      # 0x88f8
xorl %eax, %eax
callq 0x20e0
movq 0x10(%rsp), %rax
movq 0x28(%rax), %rax
movl 0x4(%rbp,%r13), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
testq %rax, %rax
je 0x66bc
movq (%rax,%rsi,8), %rdi
movq 0x490e(%rip), %rax      # 0xafc0
movq (%rax), %rsi
callq 0x2120
jmp 0x66cc
incl %esi
leaq 0x2246(%rip), %rdi      # 0x890b
xorl %eax, %eax
callq 0x20e0
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rax
movq (%rbp,%r13), %rdi
movq %rdi, %rcx
shrq $0x1e, %rcx
movabsq $0x1fffffffc, %rdx      # imm = 0x1FFFFFFFC
andq %rdx, %rcx
movl (%rax,%rcx), %esi
movl 0x14(%rbp,%r13), %edx
movl 0x18(%rbp,%r13), %ecx
movl 0x8(%rbp,%r13), %r8d
movl %ecx, %eax
subl %edx, %eax
movl 0x10(%rbp,%r13), %r9d
subl 0xc(%rbp,%r13), %r9d
cmpl %r9d, %eax
cmovgl %eax, %r9d
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
movl %edi, (%rsp)
leaq 0x21e9(%rip), %rdi      # 0x890e
xorl %eax, %eax
callq 0x20e0
movq 0x18(%rbx), %rax
movq 0x8(%rsp), %rsi
incq %r14
movslq (%rax,%r15,4), %rcx
addq $0x1c, %r13
cmpq %rcx, %r14
jl 0x663f
movq 0x20(%rbx), %rax
movq (%rax,%r15,8), %rdi
callq 0x2040
movq 0x10(%rbx), %rax
leaq (,%r15,8), %rcx
leaq (%rcx,%rcx,2), %r14
movq 0x10(%rax,%r14), %rdi
callq 0x2040
movq 0x10(%rbx), %rax
movq 0x8(%rax,%r14), %rdi
callq 0x2040
incq %r15
movslq 0x8(%rbx), %rax
cmpq %rax, %r15
jl 0x6619
movq 0x20(%rbx), %rdi
callq 0x2040
movq 0x18(%rbx), %rdi
callq 0x2040
movq 0x10(%rbx), %rdi
callq 0x2040
movq %rbx, %rdi
callq 0x2040
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq