// File: /workspace/github_c_makefile_star2_O1/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 $0x18, %rsp
movq %rsi, %r15
movq %rdi, %r14
movq %rsi, %rdi
callq 0x3100
movq %rax, %r12
testl %r12d, %r12d
jle 0xaa5b
movl %r12d, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
xorl %edx, %edx
xorl %eax, %eax
xorl %esi, %esi
cmpb $0xa, (%r15,%rdx)
sete %sil
addl %esi, %eax
incq %rdx
cmpq %rdx, %rcx
jne 0xaa3b
movl %r12d, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
jmp 0xaa5f
xorl %eax, %eax
xorl %ecx, %ecx
xorl %edx, %edx
cmpb $0xa, -0x1(%r15,%rcx)
setne %dl
addl %eax, %edx
movl %edx, 0x4(%rsp)
movslq %edx, %r13
leaq (,%r13,8), %rdi
callq 0x3470
movq %rax, 0x8(%rsp)
movq %r15, (%rax)
testl %r12d, %r12d
jle 0xaad1
leal -0x1(%r12), %eax
cltq
andl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
leaq 0x1(%r15), %rcx
movl $0x1, %edx
xorl %esi, %esi
movq 0x8(%rsp), %r9
cmpb $0xa, (%r15,%rsi)
jne 0xaac9
movb $0x0, (%r15,%rsi)
cmpq %rax, %rsi
jge 0xaac9
leaq (%rcx,%rsi), %rdi
movslq %edx, %r8
incl %edx
movq %rdi, (%r9,%r8,8)
incq %rsi
cmpq %rsi, %r12
jne 0xaaab
leaq 0xfbe(%rip), %rcx       # 0xba96
movl $0x8, %edx
movq 0x8(%rsp), %rdi
movq %r13, %rsi
callq 0x3760
movl 0x8(%r14), %eax
movl %eax, 0x14(%rsp)
testl %eax, %eax
jle 0xab61
cmpl $0x2, 0x4(%rsp)
jl 0xab61
movq (%r14), %r13
movl $0x1, %ebp
xorl %ebx, %ebx
movslq %ebx, %rax
leaq (%rax,%rax,4), %r12
movq (%r13,%r12,8), %r15
movslq %ebp, %rax
movq 0x8(%rsp), %rcx
movq (%rcx,%rax,8), %r14
movq %r15, %rdi
callq 0x3100
movq %r15, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x3120
testl %eax, %eax
je 0xab3f
jle 0xab53
incl %ebp
jmp 0xab55
leaq (,%r12,8), %rax
addq %r13, %rax
incl %ebp
incl %ebx
movq %r14, (%rax)
jmp 0xab55
incl %ebx
cmpl 0x14(%rsp), %ebx
jge 0xab61
cmpl 0x4(%rsp), %ebp
jl 0xab07
movq 0x8(%rsp), %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3390