// File: /workspace/github_c_makefile_star2_O0/ToniWestbrook[P]paladin/uniprot.c
// Function: cleanUniprotReferenceUniref
void cleanUniprotReferenceUniref(const char * passName, int passANN) {
	gzFile srcHandle, dstHandle;
	FILE * dstANNHandle;
	int searchIdx, searchIdx2, lineIdx;
	char * newName;
	char srcBuffer[4096], dstBuffer[16384];
	char target[] = "RepID=";

	// Prepare and open reference and temporary destination
	newName = malloc(strlen(passName) + 5);
	sprintf(newName, "%s.tmp", passName);

	srcHandle = xzopen(passName, "r");
	if (!passANN) dstHandle = xzopen(newName, "w");
	else dstANNHandle = err_xopen_core(__func__, newName, "w");
	lineIdx = 0;

	while (gzgets(srcHandle, srcBuffer, 4096)) {
		// For FASTA files, must start with ">".  For ANN, must be an odd line
		if (((passANN == 0) && (srcBuffer[0] == '>')) ||
				((passANN == 1) && (lineIdx % 2 == 1))) {
			// Alter header - strip CRLF
			for (searchIdx = strlen(srcBuffer) - 1 ; searchIdx >= 0 ; searchIdx--) {
				if ((srcBuffer[searchIdx] == 0x0A) || (srcBuffer[searchIdx] == 0x0D)) {
					srcBuffer[searchIdx] = 0x00;
				}
				else break;
			}

			// Find RepID
			for (searchIdx = 0 ; searchIdx < strlen(srcBuffer) - strlen(target) ; searchIdx++) {
				for (searchIdx2 = 0 ; searchIdx2 < strlen(target) ; searchIdx2++ ) {
					if (srcBuffer[searchIdx + searchIdx2] != target[searchIdx2]) break;
				}

				if (searchIdx2 == strlen(target)) {
					// RepID found, write new header
					if (!passANN) sprintf(dstBuffer, ">%s %s\n", srcBuffer + searchIdx + strlen(target), srcBuffer + 1);
					else sprintf(dstBuffer, "0 %s %s\n", srcBuffer + searchIdx + strlen(target), srcBuffer + 2);
					break;
				}
			}

			if (!passANN) gzwrite(dstHandle, dstBuffer, strlen(dstBuffer));
			else fwrite(dstBuffer, 1, strlen(dstBuffer), dstANNHandle);
		}
		else {
			// Copy sequence
			if (!passANN) gzwrite(dstHandle, srcBuffer, strlen(srcBuffer));
			else fwrite(srcBuffer, 1, strlen(srcBuffer), dstANNHandle);
		}

		lineIdx++;
	}

	err_gzclose(srcHandle);
	if (!passANN) err_gzclose(dstHandle);
	else fclose(dstANNHandle);

	// Delete original file and replace with new one
	unlink(passName);
	rename(newName, passName);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50c0, %rsp           # imm = 0x50C0
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl 0x2c392(%rip), %eax     # 0x3936a
movl %eax, -0x5047(%rbp)
movw 0x2c389(%rip), %ax      # 0x3936e
movw %ax, -0x5043(%rbp)
movb 0x2c37e(%rip), %al      # 0x39370
movb %al, -0x5041(%rbp)
movq -0x8(%rbp), %rdi
callq 0x30f0
movq %rax, %rdi
addq $0x5, %rdi
callq 0x3450
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
movq -0x8(%rbp), %rdx
leaq 0x2c351(%rip), %rsi     # 0x39371
movb $0x0, %al
callq 0x3070
movq -0x8(%rbp), %rsi
leaq 0x2c346(%rip), %rdi     # 0x39378
leaq 0x2bcc9(%rip), %rdx     # 0x38d02
callq 0x12990
movq %rax, -0x18(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0xd065
movq -0x40(%rbp), %rsi
leaq 0x2c325(%rip), %rdi     # 0x39378
leaq 0x2e2be(%rip), %rdx     # 0x3b318
callq 0x12990
movq %rax, -0x20(%rbp)
jmp 0xd080
movq -0x40(%rbp), %rsi
leaq 0x2c308(%rip), %rdi     # 0x39378
leaq 0x2e2a1(%rip), %rdx     # 0x3b318
callq 0x12740
movq %rax, -0x28(%rbp)
movl $0x0, -0x34(%rbp)
movq -0x18(%rbp), %rdi
leaq -0x1040(%rbp), %rsi
movl $0x1000, %edx           # imm = 0x1000
callq 0x3650
cmpq $0x0, %rax
je 0xd3c8
cmpl $0x0, -0xc(%rbp)
jne 0xd0b8
movsbl -0x1040(%rbp), %eax
cmpl $0x3e, %eax
je 0xd0d6
cmpl $0x1, -0xc(%rbp)
jne 0xd344
movl -0x34(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x1, %edx
jne 0xd344
leaq -0x1040(%rbp), %rdi
callq 0x30f0
subq $0x1, %rax
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jl 0xd12e
movslq -0x2c(%rbp), %rax
movsbl -0x1040(%rbp,%rax), %eax
cmpl $0xa, %eax
je 0xd111
movslq -0x2c(%rbp), %rax
movsbl -0x1040(%rbp,%rax), %eax
cmpl $0xd, %eax
jne 0xd11f
movslq -0x2c(%rbp), %rax
movb $0x0, -0x1040(%rbp,%rax)
jmp 0xd121
jmp 0xd12e
jmp 0xd123
movl -0x2c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xd0e9
movl $0x0, -0x2c(%rbp)
movslq -0x2c(%rbp), %rax
movq %rax, -0x5050(%rbp)
leaq -0x1040(%rbp), %rdi
callq 0x30f0
movq %rax, -0x5058(%rbp)
leaq -0x5047(%rbp), %rdi
callq 0x30f0
movq -0x5058(%rbp), %rcx
movq %rax, %rdx
movq -0x5050(%rbp), %rax
subq %rdx, %rcx
cmpq %rcx, %rax
jae 0xd2ce
movl $0x0, -0x30(%rbp)
movslq -0x30(%rbp), %rax
movq %rax, -0x5060(%rbp)
leaq -0x5047(%rbp), %rdi
callq 0x30f0
movq %rax, %rcx
movq -0x5060(%rbp), %rax
cmpq %rcx, %rax
jae 0xd1d8
movl -0x2c(%rbp), %eax
addl -0x30(%rbp), %eax
cltq
movsbl -0x1040(%rbp,%rax), %eax
movslq -0x30(%rbp), %rcx
movsbl -0x5047(%rbp,%rcx), %ecx
cmpl %ecx, %eax
je 0xd1cb
jmp 0xd1d8
jmp 0xd1cd
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0xd183
movslq -0x30(%rbp), %rax
movq %rax, -0x5068(%rbp)
leaq -0x5047(%rbp), %rdi
callq 0x30f0
movq %rax, %rcx
movq -0x5068(%rbp), %rax
cmpq %rcx, %rax
jne 0xd2be
cmpl $0x0, -0xc(%rbp)
jne 0xd263
leaq -0x5040(%rbp), %rax
movq %rax, -0x5070(%rbp)
leaq -0x1040(%rbp), %rax
movslq -0x2c(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x5078(%rbp)
leaq -0x5047(%rbp), %rdi
callq 0x30f0
movq -0x5078(%rbp), %rdx
movq -0x5070(%rbp), %rdi
addq %rax, %rdx
leaq -0x1040(%rbp), %rcx
addq $0x1, %rcx
leaq 0x2c13a(%rip), %rsi     # 0x39394
movb $0x0, %al
callq 0x3070
jmp 0xd2bc
leaq -0x5040(%rbp), %rax
movq %rax, -0x5080(%rbp)
leaq -0x1040(%rbp), %rax
movslq -0x2c(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x5088(%rbp)
leaq -0x5047(%rbp), %rdi
callq 0x30f0
movq -0x5088(%rbp), %rdx
movq -0x5080(%rbp), %rdi
addq %rax, %rdx
leaq -0x1040(%rbp), %rcx
addq $0x2, %rcx
leaq 0x2c0e7(%rip), %rsi     # 0x3939c
movb $0x0, %al
callq 0x3070
jmp 0xd2ce
jmp 0xd2c0
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xd135
cmpl $0x0, -0xc(%rbp)
jne 0xd310
movq -0x20(%rbp), %rax
movq %rax, -0x5098(%rbp)
leaq -0x5040(%rbp), %rax
movq %rax, -0x5090(%rbp)
leaq -0x5040(%rbp), %rdi
callq 0x30f0
movq -0x5098(%rbp), %rdi
movq -0x5090(%rbp), %rsi
movl %eax, %edx
callq 0x3510
jmp 0xd342
leaq -0x5040(%rbp), %rax
movq %rax, -0x50a0(%rbp)
leaq -0x5040(%rbp), %rdi
callq 0x30f0
movq -0x50a0(%rbp), %rdi
movq %rax, %rdx
movq -0x28(%rbp), %rcx
movl $0x1, %esi
callq 0x3770
jmp 0xd3ba
cmpl $0x0, -0xc(%rbp)
jne 0xd386
movq -0x20(%rbp), %rax
movq %rax, -0x50b0(%rbp)
leaq -0x1040(%rbp), %rax
movq %rax, -0x50a8(%rbp)
leaq -0x1040(%rbp), %rdi
callq 0x30f0
movq -0x50b0(%rbp), %rdi
movq -0x50a8(%rbp), %rsi
movl %eax, %edx
callq 0x3510
jmp 0xd3b8
leaq -0x1040(%rbp), %rax
movq %rax, -0x50b8(%rbp)
leaq -0x1040(%rbp), %rdi
callq 0x30f0
movq -0x50b8(%rbp), %rdi
movq %rax, %rdx
movq -0x28(%rbp), %rcx
movl $0x1, %esi
callq 0x3770
jmp 0xd3ba
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xd087
movq -0x18(%rbp), %rdi
callq 0x13200
cmpl $0x0, -0xc(%rbp)
jne 0xd3e2
movq -0x20(%rbp), %rdi
callq 0x13200
jmp 0xd3eb
movq -0x28(%rbp), %rdi
callq 0x32e0
movq -0x8(%rbp), %rdi
callq 0x3100
movq -0x40(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0x3170
addq $0x50c0, %rsp           # imm = 0x50C0
popq %rbp
retq
nopw (%rax,%rax)