// File: /workspace/github_c_makefile_star2_O2/DReichLab[P]adna/trim.c
// Function: worker_pipeline
static void *worker_pipeline(void *shared, int step, void *_data)
{
	int i;
	lt_global_t *g = (lt_global_t*)shared;
	if (step == 0) {
		data_for_t *ret;
		ret = calloc(1, sizeof(data_for_t));
		ret->seqs = bseq_read(g->ks, g->opt.chunk_size, &ret->n_seqs);
		assert((ret->n_seqs&1) == 0);
		ret->g = g;
		if (ret->seqs) return ret;
		else free(ret);
	} else if (step == 1) {
		data_for_t *data = (data_for_t*)_data;
		kt_for(g->opt.n_threads, worker_for, data, data->n_seqs>>1);
		return data;
	} else if (step == 2) {
		data_for_t *data = (data_for_t*)_data;
		if (g->opt.tab_out) { // tabular output
			for (i = 0; i < data->n_seqs; i += 2) {
				bseq1_t *s = &data->seqs[i];
				printf("%s\t%d\n", s->name, s->type);
			}
		} else { // FASTQ output (FASTA not supported yet)
			kstring_t pe[2] = {{0,0,0},{0,0,0}};
			for (i = 0; i < data->n_seqs; i += 2)
				++g->types[data->seqs[i].type];
			for (i = 0; i < data->n_seqs; ++i) {
				bseq1_t *s = &data->seqs[i];
				if (s->l_seq <= 0) continue;
				if (g->fp_pe[0] && g->fp_pe[1]) {
					if (s->type == AD_PARTIAL_MERGE || s->type == AD_COMPLETE_MERGE) {
						printf("%c%s_%d:%s\n%s\n", s->qual? '@' : '>', s->name, s->type, s->bc? s->bc : "*", s->seq);
						if (s->qual) { puts("+"); puts(s->qual); }
					} else if (s->type == AD_NO_MERGE || s->type == AD_AMBI_MERGE) {
						kstring_t *str = &pe[i&1];
						ksprintf(str, "%c%s_%d:%s\n%s\n", s->qual? '@' : '>', s->name, s->type, s->bc? s->bc : "*", s->seq);
						if (s->qual) { kputs("+\n", str); kputs(s->qual, str); kputc('\n', str); }
					}
				} else {
					if (s->type == AD_PARTIAL_MERGE || s->type == AD_COMPLETE_MERGE || s->type == AD_NO_MERGE || s->type == AD_AMBI_MERGE) {
						if (!g->opt.retain_pe && (s->type == AD_NO_MERGE || s->type == AD_AMBI_MERGE)) continue;
						printf("%c%s_%d:%s", s->qual? '@' : '>', s->name, s->type, s->bc? s->bc : "*");
						if (s->type != AD_PARTIAL_MERGE && s->type != AD_COMPLETE_MERGE) {
							putchar('/'); putchar("12"[i&1]);
						}
						putchar('\n');
						puts(s->seq);
						if (s->qual) { puts("+"); puts(s->qual); }
					}
				}
			}
			for (i = 0; i < 2; ++i) {
				gzwrite(g->fp_pe[i], pe[i].s, pe[i].l);
				free(pe[i].s);
			}
		}
		for (i = 0; i < data->n_seqs; ++i) { // deallocate
			bseq1_t *s = &data->seqs[i];
			free(s->bc); free(s->seq); free(s->qual); free(s->name);
		}
		free(data->seqs); free(data);
	}
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdx, %rbx
movq %rdi, %r14
cmpl $0x2, %esi
je 0x482c
cmpl $0x1, %esi
je 0x480e
testl %esi, %esi
jne 0x4b72
pushq $0x1
popq %rdi
pushq $0x18
popq %rsi
callq 0x2120
movq %rax, %rbx
movq 0x38(%r14), %rdi
movl 0x4(%r14), %esi
movq %rax, %rdx
callq 0x328b
movq %rax, 0x8(%rbx)
testb $0x1, (%rbx)
jne 0x4b86
movq %r14, 0x10(%rbx)
testq %rax, %rax
jne 0x4b74
jmp 0x4b6a
movl (%r14), %edi
movl (%rbx), %eax
sarl %eax
movslq %eax, %rcx
leaq 0x626(%rip), %rsi       # 0x4e45
movq %rbx, %rdx
callq 0x239c
jmp 0x4b74
cmpl $0x0, 0x2c(%r14)
je 0x486e
pushq $0x8
popq %r15
leaq 0xb52(%rip), %r14       # 0x5390
xorl %r12d, %r12d
movslq (%rbx), %rax
cmpq %rax, %r12
jge 0x4b1f
movq 0x8(%rbx), %rax
movq (%rax,%r15), %rsi
movl -0x4(%rax,%r15), %edx
movq %r14, %rdi
xorl %eax, %eax
callq 0x20e0
addq $0x2, %r12
addq $0x60, %r15
jmp 0x4841
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movl (%rbx), %eax
movslq %eax, %rcx
pushq $0x4
popq %rdx
xorl %esi, %esi
cmpq %rcx, %rsi
jge 0x48a0
movq 0x8(%rbx), %rdi
movl (%rdi,%rdx), %edi
incq 0x50(%r14,%rdi,8)
addq $0x2, %rsi
addq $0x60, %rdx
jmp 0x4885
pushq $0x20
popq %rbp
xorl %r12d, %r12d
cltq
cmpq %rax, %r12
jge 0x4af1
movq 0x8(%rbx), %r13
testl $0x7fffffff, -0x20(%r13,%rbp) # imm = 0x7FFFFFFF
je 0x4ae3
cmpq $0x0, 0x40(%r14)
je 0x4933
cmpq $0x0, 0x48(%r14)
je 0x4933
movl -0x1c(%r13,%rbp), %eax
leal -0x1f(%rax), %ecx
cmpl $0x2, %ecx
jb 0x4a05
leal -0x15(%rax), %ecx
cmpl $0x1, %ecx
ja 0x4ae3
xorl %ecx, %ecx
cmpq $0x0, -0x8(%r13,%rbp)
setne %cl
leal 0x3e(,%rcx,2), %esi
movq (%r13,%rbp), %r8
testq %r8, %r8
leaq 0xa96(%rip), %rcx       # 0x53a6
cmoveq %rcx, %r8
movq -0x18(%r13,%rbp), %rdx
movq -0x10(%r13,%rbp), %r9
leaq 0xa72(%rip), %rdi       # 0x5397
movl %eax, %ecx
xorl %eax, %eax
callq 0x20e0
jmp 0x49de
movl -0x1c(%r13,%rbp), %ecx
cmpq $0x20, %rcx
ja 0x4ae3
movabsq $0x180600000, %rax      # imm = 0x180600000
btq %rcx, %rax
jae 0x4ae3
cmpl $0x0, 0x30(%r14)
jne 0x4969
leal -0x1f(%rcx), %eax
cmpl $0x2, %eax
jb 0x4ae3
xorl %eax, %eax
cmpq $0x0, -0x8(%r13,%rbp)
setne %al
leal 0x3e(,%rax,2), %esi
movq -0x18(%r13,%rbp), %rdx
movq (%r13,%rbp), %r8
testq %r8, %r8
leaq 0xa17(%rip), %rax       # 0x53a6
cmoveq %rax, %r8
leaq 0xa13(%rip), %rdi       # 0x53ad
xorl %eax, %eax
callq 0x20e0
movl -0x1c(%r13,%rbp), %eax
addl $-0x15, %eax
cmpl $0x2, %eax
jb 0x49cc
pushq $0x2f
popq %rdi
callq 0x2060
movl %r12d, %eax
andl $0x1, %eax
leaq 0x9f5(%rip), %rcx       # 0x53b8
movsbl (%rax,%rcx), %edi
callq 0x2060
pushq $0xa
popq %rdi
callq 0x2060
movq -0x10(%r13,%rbp), %rdi
callq 0x2090
cmpq $0x0, -0x8(%r13,%rbp)
je 0x4ae3
leaq 0x9b7(%rip), %rdi       # 0x53a8
callq 0x2090
movq -0x8(%r13,%rbp), %rdi
callq 0x2090
jmp 0x4ae3
movl %r12d, %ecx
andl $0x1, %ecx
shll $0x4, %ecx
leaq (%rsp,%rcx), %r15
addq $0x10, %r15
xorl %ecx, %ecx
cmpq $0x0, -0x8(%r13,%rbp)
setne %cl
leal 0x3e(,%rcx,2), %edx
movq (%r13,%rbp), %r9
testq %r9, %r9
leaq 0x96f(%rip), %rcx       # 0x53a6
cmoveq %rcx, %r9
movq -0x18(%r13,%rbp), %rcx
movq -0x10(%r13,%rbp), %rsi
movq %rsi, (%rsp)
movq %r15, %rdi
leaq 0x944(%rip), %rsi       # 0x5397
movl %eax, %r8d
xorl %eax, %eax
callq 0x4694
cmpq $0x0, -0x8(%r13,%rbp)
je 0x4ae3
leaq 0x93e(%rip), %rdi       # 0x53aa
movq %r15, %rsi
callq 0x4e59
movq -0x8(%r13,%rbp), %rdi
movq %r15, %rsi
callq 0x4e59
movl (%r15), %ecx
leal 0x1(%rcx), %r13d
cmpl 0x4(%r15), %r13d
jae 0x4a94
movq 0x8(%r15), %rax
jmp 0x4ad5
movl %r13d, %eax
shrl %eax
orl %r13d, %eax
movq %rcx, 0x8(%rsp)
movl %eax, %ecx
shrl $0x2, %ecx
orl %eax, %ecx
movl %ecx, %eax
shrl $0x4, %eax
orl %ecx, %eax
movl %eax, %ecx
shrl $0x8, %ecx
orl %eax, %ecx
movl %ecx, %esi
shrl $0x10, %esi
orl %ecx, %esi
incl %esi
movl %esi, 0x4(%r15)
movq 0x8(%r15), %rdi
callq 0x21d0
movq 0x8(%rsp), %rcx
movq %rax, 0x8(%r15)
movl %r13d, (%r15)
movb $0xa, (%rax,%rcx)
movl %r13d, %ecx
movb $0x0, (%rax,%rcx)
incq %r12
movl (%rbx), %eax
addq $0x30, %rbp
jmp 0x48a6
xorl %r12d, %r12d
cmpq $0x10, %r12
je 0x4b1f
movq 0x40(%r14,%r12), %rdi
movq 0x18(%rsp,%r12,2), %r15
movl 0x10(%rsp,%r12,2), %edx
movq %r15, %rsi
callq 0x21c0
movq %r15, %rdi
callq 0x2050
addq $0x8, %r12
jmp 0x4af4
pushq $0x20
popq %r15
xorl %r12d, %r12d
movslq (%rbx), %rax
movq 0x8(%rbx), %r14
cmpq %rax, %r12
jge 0x4b62
movq (%r14,%r15), %rdi
callq 0x2050
movq -0x10(%r14,%r15), %rdi
callq 0x2050
movq -0x8(%r14,%r15), %rdi
callq 0x2050
movq -0x18(%r14,%r15), %rdi
callq 0x2050
incq %r12
addq $0x30, %r15
jmp 0x4b26
movq %r14, %rdi
callq 0x2050
movq %rbx, %rdi
callq 0x2050
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x7bc(%rip), %rdi       # 0x5349
leaq 0x7ca(%rip), %rsi       # 0x535e
leaq 0x7ca(%rip), %rcx       # 0x5365
movl $0x24e, %edx            # imm = 0x24E
callq 0x2100