// File: /workspace/github_c_makefile_star2_O3/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
testl %esi, %esi
leaq 0x26817(%rip), %rcx     # 0x30e60
leaq 0x26808(%rip), %rbx     # 0x30e58
movq %rbx, %rax
cmoveq %rcx, %rax
movq (%rax), %r15
leaq 0x2680b(%rip), %rbp     # 0x30e6c
leaq 0x26800(%rip), %r13     # 0x30e68
movq %r13, %rax
cmoveq %rbp, %rax
movq %rax, %r12
movslq (%rax), %rax
testq %rax, %rax
jle 0xa790
movq %rdi, %r14
movl %esi, 0xc(%rsp)
shlq $0x4, %rax
xorl %ecx, %ecx
xorl %ebp, %ebp
addl 0x8(%r15,%rcx), %ebp
addq $0x10, %rcx
cmpq %rcx, %rax
jne 0xa68d
leaq 0x1d248(%rip), %rdi     # 0x278ea
leaq 0x1d255(%rip), %rdx     # 0x278fe
xorl %r13d, %r13d
movl $0x3, %esi
movl %ebp, %ecx
xorl %eax, %eax
callq 0xde80
testl %ebp, %ebp
je 0xa7dc
movslq (%r12), %rax
testq %rax, %rax
jle 0xa6e2
shlq $0x4, %rax
xorl %ecx, %ecx
xorl %r13d, %r13d
addl 0x8(%r15,%rcx), %r13d
addq $0x10, %rcx
cmpq %rcx, %rax
jne 0xa6d4
movq (%r15), %rdi
movslq %r13d, %rax
shlq $0x3, %rax
leaq (%rax,%rax,4), %rsi
callq 0x3610
movq %rax, (%r15)
cmpl $0x2, (%r12)
jl 0xa769
movq %r12, %rcx
movl 0x8(%r15), %ebp
leaq 0x18(%r15), %rbx
movl $0x1, %r12d
movq %r15, 0x10(%rsp)
movslq %ebp, %rbp
leaq (,%rbp,4), %rdi
addq %rbp, %rdi
shlq $0x3, %rdi
addq (%r15), %rdi
movq -0x8(%rbx), %rsi
movslq (%rbx), %rax
shlq $0x3, %rax
leaq (%rax,%rax,4), %rdx
movq %rcx, %r15
callq 0x3260
addl (%rbx), %ebp
movq -0x8(%rbx), %rdi
callq 0x3390
movq %r15, %rcx
movq 0x10(%rsp), %r15
movl $0x0, (%rbx)
incq %r12
movslq (%rcx), %rax
addq $0x10, %rbx
cmpq %rax, %r12
jl 0xa715
movl %r13d, 0x8(%r15)
xorl %r15d, %r15d
movl 0xc(%rsp), %ebx
movq %r14, %rdi
movl %r15d, %esi
movl %ebx, %edx
callq 0xbb5d
incq %r15
addq $0x10, %r14
cmpq $0x3, %r15
jne 0xa774
jmp 0xa7dc
movq %rcx, %r12
leaq 0x1d150(%rip), %rdi     # 0x278ea
movl %esi, %r14d
leaq 0x1d15a(%rip), %rdx     # 0x278fe
movl $0x3, %esi
xorl %ecx, %ecx
xorl %eax, %eax
callq 0xde80
testq %r15, %r15
jne 0xa7dc
movl $0x1, %edi
movl $0x10, %esi
callq 0x31b0
testl %r14d, %r14d
cmoveq %r12, %rbx
cmoveq %rbp, %r13
movq %rax, (%rbx)
movl $0x1, (%r13)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq