// File: /workspace/github_c_makefile_star2_O2/ToniWestbrook[P]paladin/align.c
// Function: process
static void *process(void *shared, int step, void *_data) {
	ktp_aux_t *aux = (ktp_aux_t*)shared;
	ktp_data_t *data = (ktp_data_t*)_data;
	const mem_opt_t *opt = aux->opt;
	int i;

	if (step == 0) {
		ktp_data_t *ret;
		int64_t size = 0;
		ret = calloc(1, sizeof(ktp_data_t));
		ret->seqs = bseq_read(aux->actual_chunk_size, &ret->n_seqs, aux->ks, aux->ks2);
		if (ret->seqs == 0) {
			free(ret);
			return 0;
		}
		if (!aux->copy_comment)
			for (i = 0; i < ret->n_seqs; ++i) {
				free(ret->seqs[i].comment);
				ret->seqs[i].comment = 0;
			}
		for (i = 0; i < ret->n_seqs; ++i) size += ret->seqs[i].l_seq;

		logMessage(__func__, LOG_LEVEL_MESSAGE, "Read %d protein sequences (%ld AA)...\n", ret->n_seqs, (long)size);

		return ret;
	} else if (step == 1) {
		const bwaidx_t *idx = aux->idx;
		if (opt->flag & MEM_F_SMARTPE) {
			bseq1_t *sep[2];
			int n_sep[2];
			mem_opt_t tmp_opt = *opt;
			bseq_classify(data->n_seqs, data->seqs, n_sep, sep);

			logMessage(__func__, LOG_LEVEL_MESSAGE, "%d single-end sequences; %d paired-end sequences\n",  n_sep[0], n_sep[1]);

			if (n_sep[0]) {
				tmp_opt.flag &= ~MEM_F_PE;
				mem_process_seqs(&tmp_opt, idx->bwt, idx->bns, idx->pac, aux->n_processed, n_sep[0], sep[0], 0);
				for (i = 0; i < n_sep[0]; ++i)
					data->seqs[sep[0][i].id].sam = sep[0][i].sam;
			}
			if (n_sep[1]) {
				tmp_opt.flag |= MEM_F_PE;
				mem_process_seqs(&tmp_opt, idx->bwt, idx->bns, idx->pac, aux->n_processed + n_sep[0], n_sep[1], sep[1], aux->pes0);
				for (i = 0; i < n_sep[1]; ++i)
					data->seqs[sep[1][i].id].sam = sep[1][i].sam;
			}
			free(sep[0]); free(sep[1]);
		} else mem_process_seqs(opt, idx->bwt, idx->bns, idx->pac, aux->n_processed, data->n_seqs, data->seqs, aux->pes0);
		aux->n_processed += data->n_seqs;

		return data;
	} else if (step == 2) {
		for (i = 0; i < data->n_seqs; ++i) {
			if (data->seqs[i].sam) err_fputs(data->seqs[i].sam, opt->outputStream);
			free(data->seqs[i].name); free(data->seqs[i].comment);
			free(data->seqs[i].seq); free(data->seqs[i].qual); free(data->seqs[i].sam);
		}
		free(data->seqs); free(data);

		return 0;
	}
	return 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2d0, %rsp            # imm = 0x2D0
movq %rdi, %r14
testl %esi, %esi
je 0x7b4f
movq %rdx, %rbx
movq 0x10(%r14), %r15
cmpl $0x1, %esi
je 0x7b14
cmpl $0x2, %esi
jne 0x7bce
xorl %r14d, %r14d
xorl %r12d, %r12d
movslq 0x8(%rbx), %rax
movq 0x10(%rbx), %rdi
cmpq %rax, %r12
jge 0x7bc1
movq 0x28(%rdi,%r14), %rax
testq %rax, %rax
je 0x7ac9
movq 0x38(%r15), %rsi
movq %rax, %rdi
callq 0xcf2e
movq 0x10(%rbx), %rdi
movq 0x8(%rdi,%r14), %rdi
callq 0x3390
movq 0x10(%rbx), %rax
movq 0x10(%rax,%r14), %rdi
callq 0x3390
movq 0x10(%rbx), %rax
movq 0x18(%rax,%r14), %rdi
callq 0x3390
movq 0x10(%rbx), %rax
movq 0x20(%rax,%r14), %rdi
callq 0x3390
movq 0x10(%rbx), %rax
movq 0x28(%rax,%r14), %rdi
callq 0x3390
incq %r12
addq $0x30, %r14
jmp 0x7a9e
movq 0x30(%r14), %r12
testb $0x4, 0x49(%r15)
jne 0x7bf2
movq (%r12), %rsi
movq 0x8(%r12), %rdx
movq 0x10(%r12), %rcx
movq 0x20(%r14), %r8
movl 0x8(%rbx), %r9d
movq %r15, %rdi
pushq 0x18(%r14)
pushq 0x10(%rbx)
callq 0x1ac8f
popq %rax
popq %rcx
jmp 0x7d62
leaq 0x18ddc(%rip), %rdx     # 0x20932
leaq 0x1a177(%rip), %r8      # 0x21cd4
pushq $0x1
popq %rdi
pushq $0x18
popq %rsi
pushq $0x1b
popq %rcx
callq 0x1dfd0
movq %rax, %rbx
movl 0x2c(%r14), %edi
leaq 0x8(%rax), %r15
movq (%r14), %rdx
movq 0x8(%r14), %rcx
movq %r15, %rsi
callq 0x1004c
movq %rax, 0x10(%rbx)
testq %rax, %rax
je 0x7bc6
cmpl $0x0, 0x28(%r14)
je 0x7cb1
movl (%r15), %ecx
xorl %edx, %edx
testl %ecx, %ecx
movl $0x0, %esi
cmovgl %ecx, %esi
imulq $0x30, %rsi, %rsi
xorl %r8d, %r8d
cmpq %rdx, %rsi
je 0x7bd5
movslq (%rax,%rdx), %rdi
addq %rdi, %r8
addq $0x30, %rdx
jmp 0x7baf
callq 0x3390
movq %rbx, %rdi
callq 0x3390
xorl %ebx, %ebx
jmp 0x7d6a
leaq 0x1a0f8(%rip), %rdi     # 0x21cd4
leaq 0x1a0f9(%rip), %rdx     # 0x21cdc
pushq $0x3
popq %rsi
xorl %eax, %eax
callq 0xc78e
jmp 0x7d6a
leaq 0x28(%rsp), %rdi
movl $0x2a8, %edx            # imm = 0x2A8
movq %r15, %rsi
callq 0x3260
movl 0x8(%rbx), %edi
movq 0x10(%rbx), %rsi
leaq 0x8(%rsp), %r15
leaq 0x10(%rsp), %rcx
movq %r15, %rdx
callq 0x102c9
movl (%r15), %ecx
movl 0x4(%r15), %r8d
leaq 0x1a0a9(%rip), %rdi     # 0x21cd4
leaq 0x1a0d1(%rip), %rdx     # 0x21d03
xorl %r13d, %r13d
pushq $0x3
popq %rsi
xorl %eax, %eax
callq 0xc78e
movl (%r15), %r9d
testl %r9d, %r9d
je 0x7cdf
leaq 0x28(%rsp), %rdi
andb $-0x3, 0x48(%rdi)
movq (%r12), %rsi
movq 0x8(%r12), %rdx
movq 0x10(%r12), %rcx
movq 0x20(%r14), %r8
pushq $0x0
pushq 0x18(%rsp)
callq 0x1ac8f
addq $0x10, %rsp
movslq 0x8(%rsp), %r8
testl %r8d, %r8d
movl $0x0, %eax
cmovgl %r8d, %eax
imulq $0x30, %rax, %rax
cmpq %r13, %rax
je 0x7ce2
movq 0x10(%rsp), %rcx
movq 0x28(%rcx,%r13), %rdx
movq 0x10(%rbx), %rsi
movslq 0x4(%rcx,%r13), %rcx
imulq $0x30, %rcx, %rcx
movq %rdx, 0x28(%rsi,%rcx)
addq $0x30, %r13
jmp 0x7c8a
pushq $0x10
popq %r14
xorl %r12d, %r12d
movslq (%r15), %rcx
cmpq %rcx, %r12
jge 0x7b9c
movq (%rax,%r14), %rdi
callq 0x3390
movq 0x10(%rbx), %rax
andq $0x0, (%rax,%r14)
incq %r12
addq $0x30, %r14
jmp 0x7cb8
xorl %r8d, %r8d
movl 0xc(%rsp), %r9d
testl %r9d, %r9d
je 0x7d4e
leaq 0x28(%rsp), %rdi
orb $0x2, 0x48(%rdi)
movq (%r12), %rsi
movq 0x8(%r12), %rdx
movq 0x10(%r12), %rcx
addq 0x20(%r14), %r8
pushq 0x18(%r14)
pushq 0x20(%rsp)
callq 0x1ac8f
addq $0x10, %rsp
movl 0xc(%rsp), %ecx
xorl %eax, %eax
testl %ecx, %ecx
cmovlel %eax, %ecx
imulq $0x30, %rcx, %rcx
cmpq %rax, %rcx
je 0x7d4e
movq 0x18(%rsp), %rdx
movq 0x28(%rdx,%rax), %rsi
movq 0x10(%rbx), %rdi
movslq 0x4(%rdx,%rax), %rdx
imulq $0x30, %rdx, %rdx
movq %rsi, 0x28(%rdi,%rdx)
addq $0x30, %rax
jmp 0x7d27
movq 0x10(%rsp), %rdi
callq 0x3390
movq 0x18(%rsp), %rdi
callq 0x3390
movslq 0x8(%rbx), %rax
addq %rax, 0x20(%r14)
movq %rbx, %rax
addq $0x2d0, %rsp            # imm = 0x2D0
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
nop