// File: /workspace/github_c_makefile_star2_O1/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 $0x68, %rsp
movq %rdx, %rbx
movq %rdi, %r14
cmpl $0x2, %esi
je 0x4cb7
cmpl $0x1, %esi
je 0x4c99
testl %esi, %esi
jne 0x50f7
movl $0x1, %edi
movl $0x18, %esi
callq 0x2120
movq %rax, %rbx
movq 0x38(%r14), %rdi
movl 0x4(%r14), %esi
movq %rax, %rdx
callq 0x3121
movq %rax, 0x8(%rbx)
testb $0x1, (%rbx)
jne 0x510b
movq %r14, 0x10(%rbx)
testq %rax, %rax
jne 0x50f9
jmp 0x50ef
movl (%r14), %edi
movl (%rbx), %eax
sarl %eax
movslq %eax, %rcx
leaq 0x8b1(%rip), %rsi       # 0x555b
movq %rbx, %rdx
callq 0x23ac
jmp 0x50f9
cmpl $0x0, 0x2c(%r14)
je 0x4cfd
cmpl $0x0, (%rbx)
jle 0x509e
movl $0x8, %r15d
leaq 0x16c2(%rip), %r14      # 0x6396
xorl %ebp, %ebp
movq 0x8(%rbx), %rax
movq (%rax,%r15), %rsi
movl -0x4(%rax,%r15), %edx
movq %r14, %rdi
xorl %eax, %eax
callq 0x20e0
addq $0x60, %r15
addl $0x2, %ebp
cmpl %ebp, (%rbx)
jg 0x4cd6
jmp 0x509e
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movslq (%rbx), %rax
testq %rax, %rax
jle 0x4d30
movq 0x8(%rbx), %rcx
addq $0x4, %rcx
xorl %edx, %edx
movl (%rcx), %esi
incq 0x50(%r14,%rsi,8)
addq $0x2, %rdx
addq $0x60, %rcx
cmpq %rax, %rdx
jb 0x4d1c
cmpl $0x0, (%rbx)
jle 0x5072
movl $0x20, %r12d
xorl %r13d, %r13d
movq 0x8(%rbx), %r15
testl $0x7fffffff, -0x20(%r15,%r12) # imm = 0x7FFFFFFF
je 0x505f
cmpq $0x0, 0x40(%r14)
je 0x4dc3
cmpq $0x0, 0x48(%r14)
je 0x4dc3
movl -0x1c(%r15,%r12), %eax
leal -0x1f(%rax), %ecx
cmpl $0x2, %ecx
jb 0x4e98
leal -0x15(%rax), %ecx
cmpl $0x1, %ecx
ja 0x505f
xorl %ecx, %ecx
cmpq $0x0, -0x8(%r15,%r12)
setne %cl
leal 0x3e(,%rcx,2), %esi
movq (%r15,%r12), %r8
testq %r8, %r8
leaq 0x160c(%rip), %rcx      # 0x63ac
cmoveq %rcx, %r8
movq -0x18(%r15,%r12), %rdx
movq -0x10(%r15,%r12), %r9
leaq 0x15e8(%rip), %rdi      # 0x639d
movl %eax, %ecx
xorl %eax, %eax
callq 0x20e0
jmp 0x4e71
movl -0x1c(%r15,%r12), %ecx
cmpq $0x20, %rcx
ja 0x505f
movabsq $0x180600000, %rax      # imm = 0x180600000
btq %rcx, %rax
jae 0x505f
leal -0x1f(%rcx), %eax
cmpl $0x1, %eax
ja 0x4df9
cmpl $0x0, 0x30(%r14)
je 0x505f
xorl %eax, %eax
cmpq $0x0, -0x8(%r15,%r12)
setne %al
leal 0x3e(,%rax,2), %esi
movq -0x18(%r15,%r12), %rdx
movq (%r15,%r12), %r8
testq %r8, %r8
leaq 0x158e(%rip), %rax      # 0x63ac
cmoveq %rax, %r8
leaq 0x1587(%rip), %rdi      # 0x63b0
xorl %eax, %eax
callq 0x20e0
movl -0x1c(%r15,%r12), %eax
addl $-0x15, %eax
cmpl $0x2, %eax
jb 0x4e5d
movl $0x2f, %edi
callq 0x2060
movl %r13d, %eax
andl $0x1, %eax
leaq 0x1567(%rip), %rcx      # 0x63bb
movsbl (%rax,%rcx), %edi
callq 0x2060
movl $0xa, %edi
callq 0x2060
movq -0x10(%r15,%r12), %rdi
callq 0x2090
cmpq $0x0, -0x8(%r15,%r12)
je 0x505f
leaq 0x152a(%rip), %rdi      # 0x63ae
callq 0x2090
movq -0x8(%r15,%r12), %rdi
callq 0x2090
jmp 0x505f
movl %r13d, %ecx
andl $0x1, %ecx
shll $0x4, %ecx
leaq (%rsp,%rcx), %rbp
addq $0x40, %rbp
xorl %ecx, %ecx
cmpq $0x0, -0x8(%r15,%r12)
setne %cl
leal 0x3e(,%rcx,2), %edx
movq (%r15,%r12), %r9
testq %r9, %r9
leaq 0x14e3(%rip), %rcx      # 0x63ac
cmoveq %rcx, %r9
movq -0x18(%r15,%r12), %rcx
movq -0x10(%r15,%r12), %rsi
movq %rsi, (%rsp)
movq %rbp, %rdi
leaq 0x14b8(%rip), %rsi      # 0x639d
movl %eax, %r8d
xorl %eax, %eax
callq 0x4b1b
cmpq $0x0, -0x8(%r15,%r12)
je 0x505f
movl (%rbp), %eax
movq %rax, 0x18(%rsp)
addl $0x3, %eax
cmpl 0x4(%rbp), %eax
jb 0x4f3f
movl %eax, %ecx
shrl %ecx
orl %eax, %ecx
movl %ecx, %eax
shrl $0x2, %eax
orl %ecx, %eax
movl %eax, %ecx
shrl $0x4, %ecx
orl %eax, %ecx
movl %ecx, %eax
shrl $0x8, %eax
orl %ecx, %eax
movl %eax, %esi
shrl $0x10, %esi
orl %eax, %esi
incl %esi
movl %esi, 0x4(%rbp)
movq 0x8(%rbp), %rdi
callq 0x21e0
movq %rax, 0x8(%rbp)
movq 0x8(%rbp), %rdx
movq %rbp, 0x10(%rsp)
movq 0x18(%rsp), %rbp
movw $0xa2b, (%rdx,%rbp)     # imm = 0xA2B
leal 0x2(%rbp), %eax
movq 0x10(%rsp), %rcx
movl %eax, (%rcx)
movq %rax, 0x20(%rsp)
movq %rdx, 0x28(%rsp)
movb $0x0, (%rdx,%rax)
movq -0x8(%r15,%r12), %rdi
movq %rdi, 0x30(%rsp)
callq 0x20d0
movq %rax, 0x38(%rsp)
addl %ebp, %eax
addl $0x3, %eax
movq 0x10(%rsp), %r15
cmpl 0x4(%r15), %eax
jb 0x4fc5
movl %eax, %ecx
shrl %ecx
orl %eax, %ecx
movl %ecx, %eax
shrl $0x2, %eax
orl %ecx, %eax
movl %eax, %ecx
shrl $0x4, %ecx
orl %eax, %ecx
movl %ecx, %eax
shrl $0x8, %eax
orl %ecx, %eax
movl %eax, %esi
shrl $0x10, %esi
orl %eax, %esi
incl %esi
movl %esi, 0x4(%r15)
movq 0x28(%rsp), %rdi
callq 0x21e0
movq %rax, 0x8(%r15)
movq 0x8(%r15), %rax
movq %rax, 0x18(%rsp)
movq 0x20(%rsp), %r15
movq %r15, %rdi
addq %rax, %rdi
movq 0x38(%rsp), %rbp
movslq %ebp, %rdx
movq 0x30(%rsp), %rsi
callq 0x2170
movq 0x18(%rsp), %rdi
leal (%r15,%rbp), %ecx
movq 0x10(%rsp), %rax
movl %ecx, (%rax)
movb $0x0, (%rdi,%rcx)
addl %ebp, %r15d
incl %r15d
movq 0x10(%rsp), %rbp
cmpl 0x4(%rbp), %r15d
jb 0x504c
movl %r15d, %eax
shrl %eax
orl %r15d, %eax
movq %rcx, 0x20(%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(%rbp)
callq 0x21e0
movq 0x20(%rsp), %rcx
movq %rax, 0x8(%rbp)
movq 0x8(%rbp), %rax
movl %r15d, (%rbp)
movb $0xa, (%rax,%rcx)
movl %r15d, %ecx
movb $0x0, (%rax,%rcx)
incq %r13
movslq (%rbx), %rax
addq $0x30, %r12
cmpq %rax, %r13
jl 0x4d42
xorl %r12d, %r12d
movq 0x40(%r14,%r12), %rdi
movq 0x48(%rsp,%r12,2), %r15
movl 0x40(%rsp,%r12,2), %edx
movq %r15, %rsi
callq 0x21d0
movq %r15, %rdi
callq 0x2050
addq $0x8, %r12
cmpq $0x8, %r12
je 0x5075
cmpl $0x0, (%rbx)
jle 0x50e6
movl $0x20, %r14d
xorl %r15d, %r15d
movq 0x8(%rbx), %r12
movq (%r12,%r14), %rdi
callq 0x2050
movq -0x10(%r12,%r14), %rdi
callq 0x2050
movq -0x8(%r12,%r14), %rdi
callq 0x2050
movq -0x18(%r12,%r14), %rdi
callq 0x2050
incq %r15
movslq (%rbx), %rax
addq $0x30, %r14
cmpq %rax, %r15
jl 0x50ac
movq 0x8(%rbx), %rdi
callq 0x2050
movq %rbx, %rdi
callq 0x2050
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x123d(%rip), %rdi      # 0x634f
leaq 0x124b(%rip), %rsi      # 0x6364
leaq 0x124b(%rip), %rcx      # 0x636b
movl $0x24e, %edx            # imm = 0x24E
callq 0x2100