// File: /workspace/github_c_makefile_star2_O2/ToniWestbrook[P]paladin/bwamem.c
// Function: mem_process_seqs
void mem_process_seqs(const mem_opt_t *opt, const bwt_t *bwt, const bntseq_t *bns, const uint8_t *pac, int64_t n_processed, int n, bseq1_t *seqs, const mem_pestat_t *pes0)
{
	extern void kt_for(int n_threads, void (*func)(void*,int,int), void *data, int n);
	worker_t w;
	mem_pestat_t pes[VALUE_DOMAIN];
	double ctime, rtime;
	int i;

	ctime = cputime(); rtime = realtime();
	global_bns = bns;
	w.regs = malloc(n * sizeof(mem_alnreg_v));
	w.opt = opt; w.bwt = bwt; w.bns = bns; w.pac = pac;
	w.seqs = seqs; w.n_processed = n_processed;
	w.pes = &pes[0];
	w.aux = malloc(opt->n_threads * sizeof(smem_aux_t));
	for (i = 0; i < opt->n_threads; ++i)
		w.aux[i] = smem_aux_init();
	kt_for(opt->n_threads, worker1, &w, (opt->flag&MEM_F_PE)? n>>1 : n); // find mapping positions
	for (i = 0; i < opt->n_threads; ++i)
		smem_aux_destroy(w.aux[i]);
	free(w.aux);
	if (opt->flag&MEM_F_PE) { // infer insert sizes if not provided
		if (pes0) memcpy(pes, pes0, VALUE_DOMAIN * sizeof(mem_pestat_t)); // if pes0 != NULL, set the insert-size distribution as pes0
		else mem_pestat(opt, bns->l_pac, n, w.regs, pes); // otherwise, infer the insert size distribution from data
	}

	// Filter competing alignments from multi-frame encoding during ORF detection process
    filterCompetingAln(&w, n, opt->proteinFlag & ALIGN_FLAG_MANUAL_PRO);

	kt_for(opt->n_threads, worker2, &w, (opt->flag&MEM_F_PE)? n>>1 : n);

	// Prepare Uniprot data (fully if requested)
	addUniprotList(&w, n, opt->outputStream != stdout);

	logMessage(__func__, LOG_LEVEL_MESSAGE, "Processed %d protein sequences in %.3f CPU sec, %.3f real sec\n", n, cputime() - ctime, realtime() - rtime);

	for (i = 0 ; i < n ; i++) {
		free(w.regs[i].a);
	}

	free(w.regs);

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x478, %rsp            # imm = 0x478
movl %r9d, %ebx
movq %r8, 0x18(%rsp)
movq %rcx, %rbp
movq %rdx, %r13
movq %rsi, %r15
movq %rdi, %r14
xorl %r12d, %r12d
xorl %eax, %eax
callq 0xd07b
movsd %xmm0, 0x8(%rsp)
xorl %eax, %eax
callq 0xd0be
movsd %xmm0, 0x20(%rsp)
movq %r13, 0x122a8(%rip)     # 0x2cf80
movslq %ebx, %rdi
shlq $0x5, %rdi
leaq 0x8b6a(%rip), %rsi      # 0x23850
leaq 0x93d7(%rip), %rcx      # 0x240c4
movl $0x50b, %edx            # imm = 0x50B
callq 0x1e045
movq %rax, 0x60(%rsp)
movq %r14, 0x28(%rsp)
movq %r15, 0x30(%rsp)
movq %r13, 0x10(%rsp)
movq %r13, 0x38(%rsp)
movq %rbp, 0x40(%rsp)
movq 0x4b0(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0x18(%rsp), %rax
movq %rax, 0x68(%rsp)
leaq 0x70(%rsp), %rax
movq %rax, 0x48(%rsp)
movslq 0x94(%r14), %rdi
shlq $0x6, %rdi
leaq 0x8b08(%rip), %rsi      # 0x23850
movl $0x50f, %edx            # imm = 0x50F
leaq 0x9370(%rip), %rcx      # 0x240c4
callq 0x1e045
movq %rax, %r15
movq %rax, 0x50(%rsp)
movslq 0x94(%r14), %rdi
cmpq %rdi, %r12
jge 0x1ad7b
callq 0x1b1f0
movq %rax, (%r15,%r12,8)
incq %r12
jmp 0x1ad61
movb 0x48(%r14), %cl
shrb %cl
andb $0x1, %cl
movl %ebx, %eax
sarl %cl, %eax
leaq 0x14e(%rip), %rsi       # 0x1aedd
leaq 0x28(%rsp), %rdx
movl %eax, %ecx
callq 0xd0f4
xorl %r15d, %r15d
movslq 0x94(%r14), %rax
movq 0x50(%rsp), %rdi
cmpq %rax, %r15
jge 0x1adbd
movq (%rdi,%r15,8), %rdi
callq 0x13375
incq %r15
jmp 0x1ad9e
callq 0x3390
testb $0x2, 0x48(%r14)
je 0x1ae03
movq 0x4b8(%rsp), %rsi
testq %rsi, %rsi
je 0x1ade7
leaq 0x70(%rsp), %rdi
movl $0x400, %edx            # imm = 0x400
callq 0x3260
jmp 0x1ae03
movq 0x10(%rsp), %rax
movq (%rax), %rsi
movq 0x60(%rsp), %rcx
leaq 0x70(%rsp), %r8
movq %r14, %rdi
movl %ebx, %edx
callq 0x1b44c
movl 0x4c(%r14), %edx
andl $0x10, %edx
leaq 0x28(%rsp), %r15
movq %r15, %rdi
movl %ebx, %esi
callq 0x11927
movl 0x94(%r14), %edi
movb 0x48(%r14), %cl
shrb %cl
andb $0x1, %cl
movl %ebx, %eax
sarl %cl, %eax
leaq 0x250(%rip), %rsi       # 0x1b084
movq %r15, %rdx
movl %eax, %ecx
callq 0xd0f4
movq 0x38(%r14), %rax
movq 0x1115f(%rip), %rcx     # 0x2bfa8
xorl %edx, %edx
cmpq (%rcx), %rax
setne %dl
movq %r15, %rdi
movl %ebx, %esi
callq 0x9e79
xorl %r14d, %r14d
xorl %eax, %eax
callq 0xd07b
subsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
xorl %eax, %eax
callq 0xd0be
movapd %xmm0, %xmm1
subsd 0x20(%rsp), %xmm1
leaq 0x923b(%rip), %rdi      # 0x240c4
leaq 0x9245(%rip), %rdx      # 0x240d5
pushq $0x3
popq %rsi
movl %ebx, %ecx
movsd 0x8(%rsp), %xmm0
movb $0x2, %al
callq 0xc78e
testl %ebx, %ebx
cmovlel %r14d, %ebx
shlq $0x5, %rbx
movq 0x60(%rsp), %rdi
cmpq %r14, %rbx
je 0x1aec6
movq 0x18(%rdi,%r14), %rdi
callq 0x3390
addq $0x20, %r14
jmp 0x1aeac
callq 0x3390
addq $0x478, %rsp            # imm = 0x478
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq