// File: /workspace/github_c_makefile_star2_O2/ToniWestbrook[P]paladin/uniprot.c
// Function: joinOnlineLists
void joinOnlineLists(UniprotList * retList, char * passUniprotOutput) {
	char * * lineIndices;
	int parseIdx, entryIdx, lineIdx;
	int lineCount, outputSize, matchValue;

	// Count number of lines in output
	outputSize = strlen(passUniprotOutput);

	for (lineCount = 0, parseIdx = 0 ; parseIdx < outputSize ; parseIdx++) {
		if (passUniprotOutput[parseIdx] == '\n') lineCount++;
	}
	if (passUniprotOutput[parseIdx - 1] != '\n') lineCount++;

	// Index each line
	lineIndices = malloc(lineCount * sizeof(char *));
	lineIndices[0] = passUniprotOutput;

	for (lineIdx = 1, parseIdx = 0 ; parseIdx < outputSize ; parseIdx++) {
		// If EOL found, change to NULL and check for next valid line
		if (passUniprotOutput[parseIdx] == '\n') {
			passUniprotOutput[parseIdx] = 0;
			if (parseIdx < outputSize - 1) {
				lineIndices[lineIdx++] = passUniprotOutput + parseIdx + 1;
			}
		}
	}

	// Sort (hopefully temporarily)
	qsort(lineIndices, lineCount, sizeof(char *), uniprotEntryCompareOnline);

	// Now cross reference/join - both are ordered, so skip in lexicographical order if match not found
	for (entryIdx = 0, lineIdx = 1 ; (entryIdx < retList->entryCount) && (lineIdx < lineCount)  ; ) {
		matchValue = strncmp(retList->entries[entryIdx].id, lineIndices[lineIdx], strlen(retList->entries[entryIdx].id));

		if (matchValue == 0) {
			// Do not free existing string - global list handles this during cleanup
			retList->entries[entryIdx++].id = lineIndices[lineIdx++];
		}
		else if (matchValue > 0) lineIdx++;
		else entryIdx++; 
	}

	free(lineIndices);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r12
movq %rdi, 0x20(%rsp)
movq %rsi, %rdi
callq 0x3100
movq %rax, %r13
xorl %eax, %eax
testl %r13d, %r13d
movl %r13d, %ebp
cmovlel %eax, %ebp
xorl %r14d, %r14d
cmpq %rax, %rbp
je 0x94e1
xorl %ecx, %ecx
cmpb $0xa, (%r12,%rax)
sete %cl
addl %ecx, %r14d
incq %rax
jmp 0x94ca
xorl %eax, %eax
cmpb $0xa, -0x1(%r12,%rbp)
setne %al
addl %eax, %r14d
leaq (,%r14,8), %rdi
callq 0x3470
movq %rax, 0x8(%rsp)
movq %r12, (%rax)
leal -0x1(%r13), %eax
cltq
leaq 0x1(%r12), %rcx
pushq $0x1
popq %rdx
xorl %esi, %esi
movq 0x8(%rsp), %r9
cmpq %rsi, %rbp
je 0x9541
cmpb $0xa, (%r12,%rsi)
jne 0x953c
movb $0x0, (%r12,%rsi)
cmpq %rax, %rsi
jge 0x953c
leaq (%rcx,%rsi), %rdi
movslq %edx, %r8
incl %edx
movq %rdi, (%r9,%r8,8)
incq %rsi
jmp 0x9519
leaq 0xf7b(%rip), %rcx       # 0xa4c3
pushq $0x8
popq %rdx
movq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x3760
movq 0x20(%rsp), %rax
movl 0x8(%rax), %eax
movl %eax, 0x1c(%rsp)
xorl %r15d, %r15d
pushq $0x1
popq %rax
movq %r14, 0x10(%rsp)
movl %eax, 0x18(%rsp)
movslq %eax, %rcx
movslq %r15d, %rax
imulq $0x28, %rax, %rsi
cmpl 0x1c(%rsp), %r15d
jge 0x95e8
cmpl %r14d, %ecx
jge 0x95e8
movq 0x20(%rsp), %rax
movq (%rax), %r14
movq %rsi, %rbp
movq (%r14,%rsi), %r13
movq 0x8(%rsp), %rax
movq %rcx, %rbx
movq (%rax,%rcx,8), %r12
movq %r13, %rdi
callq 0x3100
movq %r13, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x3120
testl %eax, %eax
je 0x95d4
jg 0x95db
incl %r15d
movq %rbp, %rsi
addq $0x28, %rsi
movq 0x10(%rsp), %r14
movq %rbx, %rcx
jmp 0x957d
incl %r15d
movq %r12, (%r14,%rbp)
movq 0x10(%rsp), %r14
movl 0x18(%rsp), %eax
incl %eax
jmp 0x956f
movq 0x8(%rsp), %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3390