// File: /workspace/github_c_makefile_star2_O2/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 $0x28, %rsp
movq %rdx, %rbx
movq %rdi, %rax
cmpl $0x2, %esi
movq %rdi, 0x10(%rsp)
je 0x5d97
cmpl $0x1, %esi
je 0x5d7c
testl %esi, %esi
jne 0x5f55
pushq $0x1
popq %rdi
pushq $0x30
popq %rsi
movq %rax, %r14
callq 0x2150
movq %rax, %rbx
movq 0x18(%r14), %rdi
movl (%r14), %esi
leaq 0x8(%rax), %rdx
callq 0x325c
movq %rax, 0x10(%rbx)
testq %rax, %rax
je 0x5f4d
movq %r14, (%rbx)
movl 0x8(%rbx), %edx
xorl %ecx, %ecx
testl %edx, %edx
cmovlel %ecx, %edx
imulq $0x18, %rdx, %rdx
cmpq %rcx, %rdx
je 0x5f59
movl 0x4(%r14), %esi
leal 0x1(%rsi), %edi
movl %edi, 0x4(%r14)
movl %esi, 0x4(%rax,%rcx)
addq $0x18, %rcx
jmp 0x5d5e
movl 0x8(%rax), %edi
movslq 0x8(%rbx), %rcx
leaq 0x2ed(%rip), %rsi       # 0x6077
movq %rbx, %rdx
callq 0x611c
jmp 0x5fb3
movq 0x20(%rax), %rcx
movq %rcx, 0x18(%rsp)
xorl %r14d, %r14d
movslq 0x8(%rax), %rax
movq 0x28(%rbx), %rdi
cmpq %rax, %r14
jge 0x5dc3
movq (%rdi,%r14,8), %rdi
callq 0x4ad7
incq %r14
movq 0x10(%rsp), %rax
jmp 0x5da3
callq 0x2040
xorl %r15d, %r15d
movslq 0x8(%rbx), %rax
cmpq %rax, %r15
jge 0x5f32
imulq $0x18, %r15, %rax
movq 0x10(%rbx), %r13
movq %rax, 0x20(%rsp)
addq %rax, %r13
xorl %r14d, %r14d
xorl %r12d, %r12d
movq 0x10(%rsp), %rdx
movq 0x18(%rbx), %rax
movq 0x20(%rbx), %rcx
movslq (%rax,%r15,4), %rax
movq (%rcx,%r15,8), %rbp
cmpq %rax, %r12
jge 0x5f01
movl 0x8(%rbp,%r14), %eax
movq 0x10(%rdx), %rcx
cmpl 0xc(%rcx), %eax
jb 0x5ef5
movq 0x8(%r13), %rsi
movl (%r13), %edx
movl (%rbp,%r14), %eax
movl 0xc(%rbp,%r14), %ecx
movl 0x10(%rbp,%r14), %r8d
shrl $0x1f, %eax
leaq 0x2ac9(%rip), %rdi      # 0x8908
movsbl (%rax,%rdi), %r9d
leaq 0x2aad(%rip), %rdi      # 0x88f8
xorl %eax, %eax
callq 0x20e0
movq 0x18(%rsp), %rax
movq 0x28(%rax), %rax
movl 0x4(%rbp,%r14), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
testq %rax, %rax
je 0x5e80
movq (%rax,%rsi,8), %rdi
movq 0x514a(%rip), %rax      # 0xafc0
movq (%rax), %rsi
callq 0x2120
jmp 0x5e90
incl %esi
leaq 0x2a82(%rip), %rdi      # 0x890b
xorl %eax, %eax
callq 0x20e0
movq 0x18(%rsp), %rax
movq 0x20(%rax), %rax
movq (%rbp,%r14), %rdi
movq %rdi, %rcx
shrq $0x1e, %rcx
movabsq $0x1fffffffc, %rdx      # imm = 0x1FFFFFFFC
andq %rdx, %rcx
movl (%rax,%rcx), %esi
movl 0x14(%rbp,%r14), %edx
movl 0x18(%rbp,%r14), %ecx
movl 0x8(%rbp,%r14), %r8d
movl %ecx, %eax
subl %edx, %eax
movl 0x10(%rbp,%r14), %r9d
subl 0xc(%rbp,%r14), %r9d
cmpl %r9d, %eax
cmovgl %eax, %r9d
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
movl %edi, (%rsp)
leaq 0x2a25(%rip), %rdi      # 0x890e
xorl %eax, %eax
callq 0x20e0
movq 0x10(%rsp), %rdx
incq %r12
addq $0x1c, %r14
jmp 0x5df3
movq %rbp, %rdi
callq 0x2040
movq 0x10(%rbx), %rax
movq 0x20(%rsp), %r14
movq 0x10(%rax,%r14), %rdi
callq 0x2040
movq 0x10(%rbx), %rax
movq 0x8(%rax,%r14), %rdi
callq 0x2040
incq %r15
jmp 0x5dcb
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
jmp 0x5fb3
movl 0x8(%r14), %ebp
movslq %ebp, %rdi
pushq $0x8
popq %rsi
callq 0x2150
movq %rax, 0x28(%rbx)
xorl %r14d, %r14d
movslq %ebp, %rax
cmpq %rax, %r14
jge 0x5f91
callq 0x4ab8
movq 0x28(%rbx), %rcx
movq %rax, (%rcx,%r14,8)
incq %r14
movq 0x10(%rsp), %rax
movl 0x8(%rax), %ebp
jmp 0x5f6f
movslq 0x8(%rbx), %r14
pushq $0x4
popq %rsi
movq %r14, %rdi
callq 0x2150
movq %rax, 0x18(%rbx)
pushq $0x8
popq %rsi
movq %r14, %rdi
callq 0x2150
movq %rax, 0x20(%rbx)
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq