// File: /workspace/github_c_makefile_star2_O2/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
movq %rdi, %r14
testl %esi, %esi
leaq 0x23f0c(%rip), %r15     # 0x2ce60
leaq 0x23efd(%rip), %rax     # 0x2ce58
cmoveq %r15, %rax
leaq 0x23f06(%rip), %rcx     # 0x2ce6c
leaq 0x23efb(%rip), %rdx     # 0x2ce68
cmoveq %rcx, %rdx
movq (%rax), %r12
movq %rdx, 0x8(%rsp)
movl (%rdx), %eax
xorl %ecx, %ecx
testl %eax, %eax
cmovlel %ecx, %eax
shlq $0x4, %rax
xorl %ebp, %ebp
cmpq %rcx, %rax
je 0x8f98
addl 0x8(%r12,%rcx), %ebp
addq $0x10, %rcx
jmp 0x8f88
leaq 0x198fb(%rip), %rdi     # 0x2289a
leaq 0x19908(%rip), %rdx     # 0x228ae
xorl %r13d, %r13d
pushq $0x3
popq %rsi
movl %ebp, %ecx
xorl %eax, %eax
callq 0xc78e
testl %ebp, %ebp
je 0x906d
movq 0x8(%rsp), %rax
movl (%rax), %eax
testl %eax, %eax
cmovlel %r13d, %eax
shlq $0x4, %rax
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x8fe0
addl 0x8(%r12,%rcx), %r13d
addq $0x10, %rcx
jmp 0x8fd0
movl %ebx, 0x14(%rsp)
movq (%r12), %rdi
movslq %r13d, %rax
imulq $0x28, %rax, %rsi
callq 0x3610
movq %rax, (%r12)
movl 0x8(%r12), %ebp
leaq 0x18(%r12), %rbx
pushq $0x1
popq %r15
movq 0x8(%rsp), %rax
movslq (%rax), %rax
cmpq %rax, %r15
jge 0x9045
movslq %ebp, %rbp
imulq $0x28, %rbp, %rdi
addq (%r12), %rdi
movq -0x8(%rbx), %rsi
movslq (%rbx), %rax
imulq $0x28, %rax, %rdx
callq 0x3260
addl (%rbx), %ebp
movq -0x8(%rbx), %rdi
callq 0x3390
andl $0x0, (%rbx)
incq %r15
addq $0x10, %rbx
jmp 0x9006
movl %r13d, 0x8(%r12)
xorl %r15d, %r15d
movl 0x14(%rsp), %ebx
cmpq $0x3, %r15
je 0x909b
movq %r14, %rdi
movl %r15d, %esi
movl %ebx, %edx
callq 0xa35a
incq %r15
addq $0x10, %r14
jmp 0x9051
testq %r12, %r12
jne 0x909b
pushq $0x10
popq %rdi
callq 0x3470
testl %ebx, %ebx
leaq 0x23dd5(%rip), %rcx     # 0x2ce58
cmoveq %r15, %rcx
movq %rax, (%rcx)
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq 0x8(%rsp), %rax
movl $0x1, (%rax)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq