// File: /workspace/github_c_makefile_star2_O3/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 0x8e26
movq %rdx, %rbx
movq 0x10(%r14), %r15
cmpl $0x1, %esi
je 0x8de9
cmpl $0x2, %esi
jne 0x8edf
cmpl $0x0, 0x8(%rbx)
jle 0x8ddb
xorl %r14d, %r14d
xorl %r12d, %r12d
movq 0x10(%rbx), %rax
movq 0x28(%rax,%r14), %rdi
testq %rdi, %rdi
je 0x8d89
movq 0x38(%r15), %rsi
callq 0xe631
movq 0x10(%rbx), %rax
movq 0x8(%rax,%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
movslq 0x8(%rbx), %rax
addq $0x30, %r14
cmpq %rax, %r12
jl 0x8d6e
movq 0x10(%rbx), %rdi
callq 0x3390
jmp 0x8ed7
movq 0x30(%r14), %r12
testb $0x4, 0x49(%r15)
jne 0x8ee6
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 0x1f227
addq $0x10, %rsp
jmp 0x9031
leaq 0x1cb51(%rip), %rdx     # 0x2597e
leaq 0x1deec(%rip), %r8      # 0x26d20
movl $0x1, %edi
movl $0x18, %esi
movl $0x1b, %ecx
callq 0x2319c
movq %rax, %rbx
movl 0x2c(%r14), %edi
leaq 0x8(%rax), %r15
movq (%r14), %rdx
movq 0x8(%r14), %rcx
movq %r15, %rsi
callq 0x11bac
movq %rax, 0x10(%rbx)
testq %rax, %rax
je 0x8ed7
cmpl $0x0, 0x28(%r14)
movl (%r15), %ecx
jne 0x8eab
testl %ecx, %ecx
jle 0x903b
movl $0x10, %r14d
xorl %r15d, %r15d
movq (%rax,%r14), %rdi
callq 0x3390
movq 0x10(%rbx), %rax
movq $0x0, (%rax,%r14)
incq %r15
movslq 0x8(%rbx), %rcx
addq $0x30, %r14
cmpq %rcx, %r15
jl 0x8e86
testl %ecx, %ecx
jle 0x903b
movl %ecx, %edx
shlq $0x4, %rdx
leaq (%rdx,%rdx,2), %rdx
xorl %esi, %esi
xorl %r8d, %r8d
movslq (%rax,%rsi), %rdi
addq %rdi, %r8
addq $0x30, %rsi
cmpq %rsi, %rdx
jne 0x8ec2
jmp 0x903e
movq %rbx, %rdi
callq 0x3390
xorl %ebx, %ebx
jmp 0x9058
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 0x11ef4
movl (%r15), %ecx
movl 0x4(%r15), %r8d
leaq 0x1de01(%rip), %rdi     # 0x26d20
leaq 0x1de29(%rip), %rdx     # 0x26d4f
xorl %r13d, %r13d
movl $0x3, %esi
xorl %eax, %eax
callq 0xde80
movl (%r15), %r9d
testl %r9d, %r9d
je 0x8fa7
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 0x1f227
addq $0x10, %rsp
movslq 0x8(%rsp), %r13
testq %r13, %r13
jle 0x8fa7
movq 0x10(%rbx), %rax
movq %r13, %rcx
shlq $0x4, %rcx
leaq (%rcx,%rcx,2), %rcx
xorl %edx, %edx
movq 0x10(%rsp), %rsi
movq 0x28(%rsi,%rdx), %rdi
movslq 0x4(%rsi,%rdx), %rsi
leaq (%rsi,%rsi,2), %rsi
shlq $0x4, %rsi
movq %rdi, 0x28(%rax,%rsi)
addq $0x30, %rdx
cmpq %rdx, %rcx
jne 0x8f82
movl 0xc(%rsp), %r9d
testl %r9d, %r9d
je 0x901d
leaq 0x28(%rsp), %rdi
orb $0x2, 0x48(%rdi)
movq (%r12), %rsi
movq 0x8(%r12), %rdx
movq 0x10(%r12), %rcx
movslq %r13d, %r8
addq 0x20(%r14), %r8
pushq 0x18(%r14)
pushq 0x20(%rsp)
callq 0x1f227
addq $0x10, %rsp
movslq 0xc(%rsp), %rcx
testq %rcx, %rcx
jle 0x901d
movq 0x10(%rbx), %rax
shlq $0x4, %rcx
leaq (%rcx,%rcx,2), %rcx
xorl %edx, %edx
movq 0x18(%rsp), %rsi
movq 0x28(%rsi,%rdx), %rdi
movslq 0x4(%rsi,%rdx), %rsi
leaq (%rsi,%rsi,2), %rsi
shlq $0x4, %rsi
movq %rdi, 0x28(%rax,%rsi)
addq $0x30, %rdx
cmpq %rdx, %rcx
jne 0x8ff8
movq 0x10(%rsp), %rdi
callq 0x3390
movq 0x18(%rsp), %rdi
callq 0x3390
movslq 0x8(%rbx), %rax
addq %rax, 0x20(%r14)
jmp 0x9058
xorl %r8d, %r8d
leaq 0x1dcdb(%rip), %rdi     # 0x26d20
leaq 0x1dcdc(%rip), %rdx     # 0x26d28
movl $0x3, %esi
xorl %eax, %eax
callq 0xde80
movq %rbx, %rax
addq $0x2d0, %rsp            # imm = 0x2D0
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq