// File: /workspace/github_c_makefile_star2_O3/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 0xe77e
movsd %xmm0, 0x8(%rsp)
xorl %eax, %eax
callq 0xe7c1
movsd %xmm0, 0x10(%rsp)
movq %r15, 0x11d15(%rip)     # 0x30f80
movslq %ebx, %rdi
shlq $0x5, %rdi
leaq 0x9647(%rip), %rsi      # 0x288c0
leaq 0x9eb4(%rip), %rcx      # 0x29134
movl $0x50b, %edx            # imm = 0x50B
callq 0x23213
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 0x95ec(%rip), %rsi      # 0x288c0
movl $0x50f, %edx            # imm = 0x50F
leaq 0x9e54(%rip), %rcx      # 0x29134
callq 0x23213
movq %rax, 0x40(%rsp)
movl 0x94(%r14), %edi
testl %edi, %edi
jle 0x1f313
movq %rax, %r12
xorl %r15d, %r15d
callq 0x1f7c9
movq %rax, (%r12,%r15,8)
incq %r15
movslq 0x94(%r14), %rdi
cmpq %rdi, %r15
jl 0x1f2fb
movb 0x48(%r14), %cl
shrb %cl
andb $0x1, %cl
movl %ebx, %eax
sarl %cl, %eax
leaq 0x15c(%rip), %rsi       # 0x1f483
leaq 0x18(%rsp), %rdx
movl %eax, %ecx
callq 0xe7f8
cmpl $0x0, 0x94(%r14)
jle 0x1f35d
xorl %r15d, %r15d
movq 0x40(%rsp), %rax
movq (%rax,%r15,8), %rdi
callq 0x15695
incq %r15
movslq 0x94(%r14), %rax
cmpq %rax, %r15
jl 0x1f340
movq 0x40(%rsp), %rdi
callq 0x3390
testb $0x2, 0x48(%r14)
je 0x1f3a4
movq 0x4a8(%rsp), %rsi
testq %rsi, %rsi
je 0x1f38c
leaq 0x60(%rsp), %rdi
movl $0x400, %edx            # imm = 0x400
callq 0x3260
jmp 0x1f3a4
movq (%rbp), %rsi
movq 0x50(%rsp), %rcx
leaq 0x60(%rsp), %r8
movq %r14, %rdi
movl %ebx, %edx
callq 0x1f9ac
movl 0x4c(%r14), %edx
andl $0x10, %edx
leaq 0x18(%rsp), %r15
movq %r15, %rdi
movl %ebx, %esi
callq 0x1393b
movl 0x94(%r14), %edi
movb 0x48(%r14), %cl
shrb %cl
andb $0x1, %cl
movl %ebx, %eax
sarl %cl, %eax
leaq 0x271(%rip), %rsi       # 0x1f646
movq %r15, %rdx
movl %eax, %ecx
callq 0xe7f8
movq 0x38(%r14), %rax
movq 0x10bbe(%rip), %rcx     # 0x2ffa8
xorl %edx, %edx
cmpq (%rcx), %rax
setne %dl
movq %r15, %rdi
movl %ebx, %esi
callq 0xb666
xorl %eax, %eax
callq 0xe77e
subsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
xorl %eax, %eax
callq 0xe7c1
movapd %xmm0, %xmm1
subsd 0x10(%rsp), %xmm1
leaq 0x9d0d(%rip), %rdi      # 0x29134
leaq 0x9d17(%rip), %rdx      # 0x29145
movl $0x3, %esi
movl %ebx, %ecx
movsd 0x8(%rsp), %xmm0
movb $0x2, %al
callq 0xde80
testl %ebx, %ebx
jle 0x1f467
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 0x1f44f
movq 0x50(%rsp), %rdi
callq 0x3390
addq $0x468, %rsp            # imm = 0x468
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq