// File: /workspace/github_c_makefile_star2_O1/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
je 0x658d
cmpl $0x1, %esi
je 0x6572
testl %esi, %esi
jne 0x677d
movq %rdi, %r13
movl $0x1, %edi
movl $0x30, %esi
callq 0x2150
movq %rax, %rbx
movq 0x18(%r13), %rdi
movl (%r13), %esi
leaq 0x8(%rax), %rdx
callq 0x34f7
movq %rax, %r15
movq %rax, 0x10(%rbx)
testq %rax, %rax
je 0x6770
movq %r13, (%rbx)
movslq 0x8(%rbx), %rcx
testq %rcx, %rcx
jle 0x64fa
movl 0x4(%r13), %eax
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rcx
xorl %edx, %edx
movl %eax, 0x4(%r15,%rdx)
incl %eax
addq $0x18, %rdx
cmpq %rdx, %rcx
jne 0x64e6
movl %eax, 0x4(%r13)
movslq 0x8(%r13), %r12
movl $0x8, %esi
movq %r12, %rdi
callq 0x2150
movq %rax, 0x28(%rbx)
testq %r12, %r12
jle 0x6547
xorl %r14d, %r14d
movl $0x1, %edi
movl $0xb8, %esi
callq 0x2150
movq %rax, %r12
callq 0x72a8
movq %rax, 0x78(%r12)
movq 0x28(%rbx), %rax
movq %r12, (%rax,%r14,8)
incq %r14
movslq 0x8(%r13), %rax
cmpq %rax, %r14
jl 0x6517
movslq 0x8(%rbx), %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 0x6778
movl 0x8(%rdi), %edi
movslq 0x8(%rbx), %rcx
leaq 0x211(%rip), %rsi       # 0x6791
movq %rbx, %rdx
callq 0x683c
jmp 0x677f
movq 0x20(%rdi), %rax
movq %rax, 0x10(%rsp)
cmpl $0x0, 0x8(%rdi)
movq %rdi, %r15
jle 0x65bb
xorl %r14d, %r14d
movq 0x28(%rbx), %rax
movq (%rax,%r14,8), %rdi
callq 0x4edd
incq %r14
movslq 0x8(%r15), %rax
cmpq %rax, %r14
jl 0x65a2
movq %r15, 0x8(%rsp)
movq 0x28(%rbx), %rdi
callq 0x2040
cmpl $0x0, 0x8(%rbx)
jle 0x674b
xorl %r15d, %r15d
movq 0x18(%rbx), %rax
cmpl $0x0, (%rax,%r15,4)
movq 0x8(%rsp), %rdx
jle 0x6706
leaq (%r15,%r15,2), %r12
shlq $0x3, %r12
addq 0x10(%rbx), %r12
xorl %r13d, %r13d
xorl %r14d, %r14d
movq 0x20(%rbx), %rax
movq (%rax,%r15,8), %rbp
movl 0x8(%rbp,%r13), %eax
movq 0x10(%rdx), %rcx
cmpl 0xc(%rcx), %eax
jb 0x66ee
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 0x2300(%rip), %rdi      # 0x8938
movsbl (%rax,%rdi), %r9d
leaq 0x22e4(%rip), %rdi      # 0x8928
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 0x6679
movq (%rax,%rsi,8), %rdi
movq 0x4951(%rip), %rax      # 0xafc0
movq (%rax), %rsi
callq 0x2120
jmp 0x6689
incl %esi
leaq 0x22b9(%rip), %rdi      # 0x893b
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 0x225c(%rip), %rdi      # 0x893e
xorl %eax, %eax
callq 0x20e0
movq 0x8(%rsp), %rdx
incq %r14
movq 0x18(%rbx), %rax
movslq (%rax,%r15,4), %rax
addq $0x1c, %r13
cmpq %rax, %r14
jl 0x65fc
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 0x65d6
movq 0x20(%rbx), %rdi
callq 0x2040
movq 0x18(%rbx), %rdi
callq 0x2040
movq 0x10(%rbx), %rdi
callq 0x2040
movq %rbx, %rdi
callq 0x2040
jmp 0x677d
movq %rbx, %rdi
callq 0x2040
testq %r15, %r15
jne 0x677f
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq