// File: /workspace/github_c_makefile_star2_O1/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 %r12
pushq %rbx
subq $0x2c8, %rsp            # imm = 0x2C8
movq %rdi, %r14
testl %esi, %esi
je 0x8c3a
movq %rdx, %rbx
movq 0x10(%r14), %r15
cmpl $0x1, %esi
je 0x8bfd
cmpl $0x2, %esi
jne 0x8cfb
cmpl $0x0, 0x8(%rbx)
jle 0x8bef
xorl %r14d, %r14d
xorl %r12d, %r12d
movq 0x10(%rbx), %rax
movq 0x28(%rax,%r14), %rdi
testq %rdi, %rdi
je 0x8b99
movq 0x38(%r15), %rsi
callq 0xe3a3
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 0x8b82
movq 0x10(%rbx), %rdi
callq 0x3390
jmp 0x8cf3
movq 0x30(%r14), %r12
testb $0x4, 0x49(%r15)
jne 0x8d02
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 0x1eb3c
addq $0x10, %rsp
jmp 0x8e49
leaq 0x1ccf1(%rip), %rdx     # 0x25932
leaq 0x1e08c(%rip), %r8      # 0x26cd4
movl $0x1, %edi
movl $0x18, %esi
movl $0x1b, %ecx
callq 0x22cb4
movq %rax, %rbx
movl 0x2c(%r14), %edi
leaq 0x8(%rax), %r15
movq (%r14), %rdx
movq 0x8(%r14), %rcx
movq %r15, %rsi
callq 0x118a8
movq %rax, 0x10(%rbx)
testq %rax, %rax
je 0x8cf3
cmpl $0x0, 0x28(%r14)
jne 0x8cbe
cmpl $0x0, (%r15)
jle 0x8cbe
movl $0x10, %r14d
xorl %r12d, %r12d
movq 0x10(%rbx), %rax
movq (%rax,%r14), %rdi
callq 0x3390
movq 0x10(%rbx), %rax
movq $0x0, (%rax,%r14)
incq %r12
movslq 0x8(%rbx), %rax
addq $0x30, %r14
cmpq %rax, %r12
jl 0x8c95
movslq (%r15), %rcx
testq %rcx, %rcx
jle 0x8e53
movq 0x10(%rbx), %rax
movq %rcx, %rdx
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 0x8cde
jmp 0x8e56
movq %rbx, %rdi
callq 0x3390
xorl %ebx, %ebx
jmp 0x8e70
leaq 0x20(%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 0x11bb2
movl (%r15), %ecx
movl 0x4(%r15), %r8d
leaq 0x1df99(%rip), %rdi     # 0x26cd4
leaq 0x1dfc1(%rip), %rdx     # 0x26d03
movl $0x3, %esi
xorl %eax, %eax
callq 0xdbeb
movl (%r15), %r9d
testl %r9d, %r9d
je 0x8dbd
leaq 0x20(%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 0x1eb3c
addq $0x10, %rsp
movslq 0x8(%rsp), %rcx
testq %rcx, %rcx
jle 0x8dbd
movq 0x10(%rbx), %rax
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 0x8d98
movl 0xc(%rsp), %r9d
testl %r9d, %r9d
je 0x8e35
leaq 0x20(%rsp), %rdi
orb $0x2, 0x48(%rdi)
movq (%r12), %rsi
movq 0x8(%r12), %rdx
movq 0x10(%r12), %rcx
movslq 0x8(%rsp), %r8
addq 0x20(%r14), %r8
pushq 0x18(%r14)
pushq 0x20(%rsp)
callq 0x1eb3c
addq $0x10, %rsp
movslq 0xc(%rsp), %rcx
testq %rcx, %rcx
jle 0x8e35
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 0x8e10
movq 0x10(%rsp), %rdi
callq 0x3390
movq 0x18(%rsp), %rdi
callq 0x3390
movslq 0x8(%rbx), %rax
addq %rax, 0x20(%r14)
jmp 0x8e70
xorl %r8d, %r8d
leaq 0x1de77(%rip), %rdi     # 0x26cd4
leaq 0x1de78(%rip), %rdx     # 0x26cdc
movl $0x3, %esi
xorl %eax, %eax
callq 0xdbeb
movq %rbx, %rax
addq $0x2c8, %rsp            # imm = 0x2C8
popq %rbx
popq %r12
popq %r14
popq %r15
retq
nop