// File: /workspace/github_c_makefile_star2_O3/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 0x4f5f
cmpl $0x1, %esi
je 0x4f41
testl %esi, %esi
jne 0x53d3
movl $0x1, %edi
movl $0x18, %esi
callq 0x2120
movq %rax, %rbx
movq 0x38(%r14), %rdi
movl 0x4(%r14), %esi
movq %rax, %rdx
callq 0x32d8
movq %rax, 0x8(%rbx)
testb $0x1, (%rbx)
jne 0x53e7
movq %r14, 0x10(%rbx)
testq %rax, %rax
jne 0x53d5
jmp 0x53cb
movl (%r14), %edi
movl (%rbx), %eax
sarl %eax
movslq %eax, %rcx
leaq 0x71b(%rip), %rsi       # 0x566d
movq %rbx, %rdx
callq 0x239c
jmp 0x53d5
cmpl $0x0, 0x2c(%r14)
je 0x4fa7
cmpl $0x0, (%rbx)
jle 0x53c2
movl $0x8, %r15d
leaq 0x1434(%rip), %r14      # 0x63b0
xorl %ebp, %ebp
movq 0x8(%rbx), %rax
movq (%rax,%r15), %rsi
movl -0x4(%rax,%r15), %edx
movq %r14, %rdi
xorl %eax, %eax
callq 0x20e0
movl (%rbx), %eax
addq $0x60, %r15
addl $0x2, %ebp
cmpl %ebp, %eax
jg 0x4f7e
jmp 0x537b
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movslq (%rbx), %rax
testq %rax, %rax
jle 0x533f
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 0x4fca
testl %eax, %eax
jle 0x533f
movl $0x20, %ebp
xorl %r12d, %r12d
movq 0x8(%rbx), %r15
testl $0x7fffffff, -0x20(%r15,%rbp) # imm = 0x7FFFFFFF
je 0x532c
cmpq $0x0, 0x40(%r14)
je 0x506f
cmpq $0x0, 0x48(%r14)
je 0x506f
movl -0x1c(%r15,%rbp), %eax
leal -0x1f(%rax), %ecx
cmpl $0x2, %ecx
jb 0x5144
leal -0x15(%rax), %ecx
cmpl $0x1, %ecx
ja 0x532c
xorl %ecx, %ecx
cmpq $0x0, -0x8(%r15,%rbp)
setne %cl
leal 0x3e(,%rcx,2), %esi
movq (%r15,%rbp), %r8
testq %r8, %r8
leaq 0x137a(%rip), %rcx      # 0x63c6
cmoveq %rcx, %r8
movq -0x18(%r15,%rbp), %rdx
movq -0x10(%r15,%rbp), %r9
leaq 0x1356(%rip), %rdi      # 0x63b7
movl %eax, %ecx
xorl %eax, %eax
callq 0x20e0
jmp 0x511d
movl -0x1c(%r15,%rbp), %ecx
cmpq $0x20, %rcx
ja 0x532c
movabsq $0x180600000, %rax      # imm = 0x180600000
btq %rcx, %rax
jae 0x532c
cmpl $0x0, 0x30(%r14)
jne 0x50a5
leal -0x1f(%rcx), %eax
cmpl $0x2, %eax
jb 0x532c
xorl %eax, %eax
cmpq $0x0, -0x8(%r15,%rbp)
setne %al
leal 0x3e(,%rax,2), %esi
movq -0x18(%r15,%rbp), %rdx
movq (%r15,%rbp), %r8
testq %r8, %r8
leaq 0x12fc(%rip), %rax      # 0x63c6
cmoveq %rax, %r8
leaq 0x12f5(%rip), %rdi      # 0x63ca
xorl %eax, %eax
callq 0x20e0
movl -0x1c(%r15,%rbp), %eax
addl $-0x15, %eax
cmpl $0x2, %eax
jb 0x5109
movl $0x2f, %edi
callq 0x2060
movl %r12d, %eax
andl $0x1, %eax
leaq 0x12d5(%rip), %rcx      # 0x63d5
movsbl (%rax,%rcx), %edi
callq 0x2060
movl $0xa, %edi
callq 0x2060
movq -0x10(%r15,%rbp), %rdi
callq 0x2090
cmpq $0x0, -0x8(%r15,%rbp)
je 0x532c
leaq 0x1298(%rip), %rdi      # 0x63c8
callq 0x2090
movq -0x8(%r15,%rbp), %rdi
callq 0x2090
jmp 0x532c
movl %r12d, %ecx
andl $0x1, %ecx
shll $0x4, %ecx
leaq (%rsp,%rcx), %r13
addq $0x40, %r13
xorl %ecx, %ecx
cmpq $0x0, -0x8(%r15,%rbp)
setne %cl
leal 0x3e(,%rcx,2), %edx
movq (%r15,%rbp), %r9
testq %r9, %r9
leaq 0x1251(%rip), %rcx      # 0x63c6
cmoveq %rcx, %r9
movq -0x18(%r15,%rbp), %rcx
movq -0x10(%r15,%rbp), %rsi
movq %rsi, (%rsp)
movq %r13, %rdi
leaq 0x1226(%rip), %rsi      # 0x63b7
movl %eax, %r8d
xorl %eax, %eax
callq 0x4dc3
cmpq $0x0, -0x8(%r15,%rbp)
je 0x532c
movl (%r13), %eax
movl 0x4(%r13), %ecx
movq %rax, 0x8(%rsp)
addl $0x3, %eax
cmpl %ecx, %eax
movq %r13, 0x28(%rsp)
jae 0x51cb
movq 0x8(%r13), %rax
movq %rcx, 0x10(%rsp)
jmp 0x5205
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(%r13)
movq 0x8(%r13), %rdi
movq %rsi, 0x10(%rsp)
callq 0x21d0
movq %rax, 0x8(%r13)
movq %rax, 0x20(%rsp)
movq 0x8(%rsp), %r13
movw $0xa2b, (%rax,%r13)     # imm = 0xA2B
leal 0x2(%r13), %ecx
movq %rcx, 0x38(%rsp)
movb $0x0, (%rax,%rcx)
movq -0x8(%r15,%rbp), %rdi
movq %rdi, 0x30(%rsp)
callq 0x20d0
movq %rax, %rdx
leal (%rax,%r13), %r15d
addl $0x3, %r15d
cmpl 0x10(%rsp), %r15d
movl %r15d, 0x1c(%rsp)
jae 0x5255
movq 0x28(%rsp), %r13
movq 0x20(%rsp), %rax
jmp 0x529c
movl %r15d, %eax
shrl %eax
orl %r15d, %eax
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
movq 0x28(%rsp), %r13
movl %esi, 0x4(%r13)
movq 0x20(%rsp), %rdi
movq %rdx, 0x10(%rsp)
callq 0x21d0
movq 0x10(%rsp), %rdx
movq %rax, 0x8(%r13)
movq 0x8(%rsp), %rcx
addl %edx, %ecx
addl $0x2, %ecx
movl %ecx, 0x8(%rsp)
movq 0x38(%rsp), %rdi
addq %rax, %rdi
movslq %edx, %rdx
movq %rax, %r15
movq 0x30(%rsp), %rsi
callq 0x2160
movq %r15, %rdi
movl 0x8(%rsp), %eax
movb $0x0, (%r15,%rax)
movl 0x1c(%rsp), %r15d
cmpl 0x4(%r13), %r15d
jb 0x5319
movq %rax, 0x8(%rsp)
movl %r15d, %eax
shrl %eax
orl %r15d, %eax
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(%r13)
callq 0x21d0
movq %rax, %rdi
movq 0x8(%rsp), %rax
movq %rdi, 0x8(%r13)
movl %r15d, (%r13)
movb $0xa, (%rdi,%rax)
movq 0x8(%r13), %rax
movl %r15d, %ecx
movb $0x0, (%rax,%rcx)
incq %r12
movslq (%rbx), %rax
addq $0x30, %rbp
cmpq %rax, %r12
jl 0x4fee
movq 0x40(%r14), %rdi
movq 0x48(%rsp), %r15
movl 0x40(%rsp), %edx
movq %r15, %rsi
callq 0x21c0
movq %r15, %rdi
callq 0x2050
movq 0x48(%r14), %rdi
movq 0x58(%rsp), %r14
movl 0x50(%rsp), %edx
movq %r14, %rsi
callq 0x21c0
movq %r14, %rdi
callq 0x2050
movl (%rbx), %eax
testl %eax, %eax
jle 0x53c2
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 0x5388
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 0xf7b(%rip), %rdi       # 0x6369
leaq 0xf89(%rip), %rsi       # 0x637e
leaq 0xf89(%rip), %rcx       # 0x6385
movl $0x24e, %edx            # imm = 0x24E
callq 0x2100