// File: /workspace/github_c_makefile_star2_O1/ToniWestbrook[P]paladin/uniprot.c
// Function: prepareUniprotLists
void prepareUniprotLists(UniprotList * retLists, int passPrimary) {
	UniprotList * globalLists;
	int listIdx, entryIdx, localIdx;
	int maxEntries, totalSize;

	globalLists = getGlobalLists(passPrimary);

	// Calculate maximum number of UniProt entries
	for (maxEntries = 0, listIdx = 0 ; listIdx < *getGlobalCount(passPrimary) ; listIdx++) {
		maxEntries += globalLists[listIdx].entryCount;
	}

	logMessage(__func__, LOG_LEVEL_MESSAGE, "Aggregating %d entries for UniProt report\n", maxEntries);

	// Stop processing if no entries, but ensure a list exists for easier post-processing
	if (maxEntries == 0) {
		if (globalLists == NULL) {
			if (passPrimary) uniprotPriEntryLists = malloc(sizeof(UniprotList));
			else uniprotSecEntryLists = malloc(sizeof(UniprotList));

			globalLists = getGlobalLists(passPrimary);
			globalLists[0].entries = NULL;
			globalLists[0].entryCount = 0;
			globalLists[0].unalignedCount = 0;
			*getGlobalCount(passPrimary) = 1;
		}

		return;
	}

	// Join each pipeline's individual list into one master list (at first list)
	for (listIdx = 0, totalSize = 0 ; listIdx < *getGlobalCount(passPrimary) ; listIdx++) {
		totalSize += globalLists[listIdx].entryCount;
	}

	globalLists[0].entries = realloc(globalLists[0].entries, sizeof(UniprotEntry) * totalSize);

	for (listIdx = 1, entryIdx = globalLists[0].entryCount ; listIdx < *getGlobalCount(passPrimary) ; listIdx++) {
		memcpy(globalLists[0].entries + entryIdx, globalLists[listIdx].entries, sizeof(UniprotEntry) * globalLists[listIdx].entryCount);
		entryIdx += globalLists[listIdx].entryCount;
		free(globalLists[listIdx].entries);
		globalLists[listIdx].entryCount = 0;
	}

	globalLists[0].entryCount = totalSize;

	// Aggregate each local list
	for (localIdx = 0 ; localIdx < 3 ; localIdx++) {
		aggregateUniprotList(retLists + localIdx, localIdx, passPrimary);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %esi, %ebx
testl %esi, %esi
leaq 0x26a29(%rip), %rcx     # 0x30e60
leaq 0x26a1a(%rip), %rax     # 0x30e58
cmoveq %rcx, %rax
movq %rdi, %r14
movq (%rax), %r12
leaq 0x26a1d(%rip), %rax     # 0x30e6c
leaq 0x26a12(%rip), %r15     # 0x30e68
cmoveq %rax, %r15
movslq (%r15), %rax
testq %rax, %rax
jle 0xa47a
shlq $0x4, %rax
xorl %ecx, %ecx
xorl %ebp, %ebp
addl 0x8(%r12,%rcx), %ebp
addq $0x10, %rcx
cmpq %rcx, %rax
jne 0xa46a
jmp 0xa47c
xorl %ebp, %ebp
leaq 0x1d3e7(%rip), %rdi     # 0x2786a
leaq 0x1d3f4(%rip), %rdx     # 0x2787e
xorl %r13d, %r13d
movl $0x3, %esi
movl %ebp, %ecx
xorl %eax, %eax
callq 0xdbeb
testl %ebp, %ebp
je 0xa57a
movl %ebx, 0xc(%rsp)
movslq (%r15), %rax
testq %rax, %rax
jle 0xa4c6
shlq $0x4, %rax
xorl %ecx, %ecx
xorl %r13d, %r13d
addl 0x8(%r12,%rcx), %r13d
addq $0x10, %rcx
cmpq %rcx, %rax
jne 0xa4b8
movq (%r12), %rdi
movslq %r13d, %rax
shlq $0x3, %rax
leaq (%rax,%rax,4), %rsi
callq 0x3610
movq %rax, (%r12)
cmpl $0x2, (%r15)
jl 0xa552
movq %r15, %rcx
movl 0x8(%r12), %ebp
leaq 0x18(%r12), %r15
movl $0x1, %ebx
movq %r12, 0x10(%rsp)
movslq %ebp, %rbp
leaq (,%rbp,4), %rdi
addq %rbp, %rdi
shlq $0x3, %rdi
addq (%r12), %rdi
movq -0x8(%r15), %rsi
movslq (%r15), %rax
shlq $0x3, %rax
leaq (%rax,%rax,4), %rdx
movq %rcx, %r12
callq 0x3260
addl (%r15), %ebp
movq -0x8(%r15), %rdi
callq 0x3390
movq %r12, %rcx
movq 0x10(%rsp), %r12
movl $0x0, (%r15)
incq %rbx
movslq (%rcx), %rax
addq $0x10, %r15
cmpq %rax, %rbx
jl 0xa4fb
movl %r13d, 0x8(%r12)
xorl %r15d, %r15d
movl 0xc(%rsp), %ebx
movq %r14, %rdi
movl %r15d, %esi
movl %ebx, %edx
callq 0xb946
incq %r15
addq $0x10, %r14
cmpq $0x3, %r15
jne 0xa55e
jmp 0xa5ad
testq %r12, %r12
jne 0xa5ad
movl $0x10, %edi
callq 0x3470
testl %ebx, %ebx
leaq 0x268ce(%rip), %rcx     # 0x30e60
leaq 0x268bf(%rip), %rdx     # 0x30e58
cmoveq %rcx, %rdx
movq %rax, (%rdx)
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movl $0x1, (%r15)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq