// File: /workspace/github_c_makefile_star2_O1/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 $0x468, %rsp            # imm = 0x468
movl %r9d, %ebx
movq %r8, %r12
movq %rcx, %r13
movq %rdx, %r15
movq %rsi, %rbp
movq %rdi, %r14
xorl %eax, %eax
callq 0xe4f0
movsd %xmm0, 0x8(%rsp)
xorl %eax, %eax
callq 0xe533
movsd %xmm0, 0x10(%rsp)
movq %r15, 0x12400(%rip)     # 0x30f80
movslq %ebx, %rdi
shlq $0x5, %rdi
leaq 0x9c42(%rip), %rsi      # 0x287d0
leaq 0xa4af(%rip), %rcx      # 0x29044
movl $0x50b, %edx            # imm = 0x50B
callq 0x22d2b
movq %rax, 0x50(%rsp)
movq %r14, 0x18(%rsp)
movq %rbp, 0x20(%rsp)
movq %r15, %rbp
movq %r15, 0x28(%rsp)
movq %r13, 0x30(%rsp)
movq 0x4a0(%rsp), %rax
movq %rax, 0x48(%rsp)
movq %r12, 0x58(%rsp)
leaq 0x60(%rsp), %rax
movq %rax, 0x38(%rsp)
movslq 0x94(%r14), %rdi
shlq $0x6, %rdi
leaq 0x9be7(%rip), %rsi      # 0x287d0
movl $0x50f, %edx            # imm = 0x50F
leaq 0xa44f(%rip), %rcx      # 0x29044
callq 0x22d2b
movq %rax, 0x40(%rsp)
movl 0x94(%r14), %edi
testl %edi, %edi
jle 0x1ec2a
xorl %r15d, %r15d
callq 0x1f0da
movq 0x40(%rsp), %rcx
movq %rax, (%rcx,%r15,8)
incq %r15
movslq 0x94(%r14), %rdi
cmpq %rdi, %r15
jl 0x1ec0d
movb 0x48(%r14), %cl
shrb %cl
andb $0x1, %cl
movl %ebx, %eax
sarl %cl, %eax
leaq 0x15c(%rip), %rsi       # 0x1ed9a
leaq 0x18(%rsp), %rdx
movl %eax, %ecx
callq 0xe568
cmpl $0x0, 0x94(%r14)
jle 0x1ec74
xorl %r15d, %r15d
movq 0x40(%rsp), %rax
movq (%rax,%r15,8), %rdi
callq 0x150e6
incq %r15
movslq 0x94(%r14), %rax
cmpq %rax, %r15
jl 0x1ec57
movq 0x40(%rsp), %rdi
callq 0x3390
testb $0x2, 0x48(%r14)
je 0x1ecbb
movq 0x4a8(%rsp), %rsi
testq %rsi, %rsi
je 0x1eca3
leaq 0x60(%rsp), %rdi
movl $0x400, %edx            # imm = 0x400
callq 0x3260
jmp 0x1ecbb
movq (%rbp), %rsi
movq 0x50(%rsp), %rcx
leaq 0x60(%rsp), %r8
movq %r14, %rdi
movl %ebx, %edx
callq 0x1f47c
movl 0x4c(%r14), %edx
andl $0x10, %edx
leaq 0x18(%rsp), %r15
movq %r15, %rdi
movl %ebx, %esi
callq 0x135d0
movl 0x94(%r14), %edi
movb 0x48(%r14), %cl
shrb %cl
andb $0x1, %cl
movl %ebx, %eax
sarl %cl, %eax
leaq 0x26b(%rip), %rsi       # 0x1ef57
movq %r15, %rdx
movl %eax, %ecx
callq 0xe568
movq 0x38(%r14), %rax
movq 0x112a7(%rip), %rcx     # 0x2ffa8
xorl %edx, %edx
cmpq (%rcx), %rax
setne %dl
movq %r15, %rdi
movl %ebx, %esi
callq 0xb442
xorl %eax, %eax
callq 0xe4f0
subsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
xorl %eax, %eax
callq 0xe533
movapd %xmm0, %xmm1
subsd 0x10(%rsp), %xmm1
leaq 0xa306(%rip), %rdi      # 0x29044
leaq 0xa310(%rip), %rdx      # 0x29055
movl $0x3, %esi
movl %ebx, %ecx
movsd 0x8(%rsp), %xmm0
movb $0x2, %al
callq 0xdbeb
testl %ebx, %ebx
jle 0x1ed7e
movl %ebx, %ebx
shlq $0x5, %rbx
xorl %r14d, %r14d
movq 0x50(%rsp), %rax
movq 0x18(%rax,%r14), %rdi
callq 0x3390
addq $0x20, %r14
cmpq %r14, %rbx
jne 0x1ed66
movq 0x50(%rsp), %rdi
callq 0x3390
addq $0x468, %rsp            # imm = 0x468
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq