// File: /workspace/github_c_makefile_star2_O3/ToniWestbrook[P]paladin/protein.c
// Function: writeIndexProtein
int writeIndexProtein(const char * passPrefix, const char * passProName, const char * passAnnName, IndexHeader passHeader) {
	CDS currentCDS;
	gzFile inputSeqPtr;
	FILE * inputAnnPtr, * outputPtr;
	char * outputBuffer;
	kseq_t * seq;
	unsigned long outputSize, currentLine, frameIdx;

	// Prepare file handles
	inputSeqPtr = xzopen(passPrefix, "r");
	inputAnnPtr = err_xopen_core(__func__, passAnnName, "r");
	outputPtr = err_xopen_core(__func__, passProName, "w");

	// Write index type header
	passHeader.nucleotide = 1;
	writeIndexHeader(outputPtr, passHeader);

	// Read in 1st sequence data
	seq = kseq_init(inputSeqPtr);
	kseq_read(seq);

	// Iterate through each CDS sequence in the annotation file
	currentLine = 0;
	while (getNextCDS(inputAnnPtr, &currentCDS, &currentLine)) {
		for (frameIdx = 0 ; frameIdx < 6 ; frameIdx++) {
			convertToAA(seq->seq.s, &currentCDS, 0, &outputBuffer, &outputSize);

			// Line ID of CDS : Frame : Sequence Header
			fprintf(outputPtr, ">%lu:%lu:%s\n%.*s\n", currentLine, frameIdx, currentCDS.description, (int) outputSize, outputBuffer);
			free(outputBuffer);

			currentCDS.startIdx++;
			currentCDS.endIdx++;
			if (frameIdx == 2) currentCDS.strand *= -1;

			if (!passHeader.multiFrame) break;
		}
	}

	// Close files
	fflush(outputPtr);
	err_gzclose(inputSeqPtr);
	err_fclose(inputAnnPtr);
	err_fclose(outputPtr);
	kseq_destroy(seq);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2058, %rsp           # imm = 0x2058
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %rsi
leaq 0x1d4ec(%rip), %r15     # 0x2717e
leaq 0x1d1d1(%rip), %r12     # 0x26e6a
movq %r15, %rdi
movq %r12, %rdx
callq 0xe1c4
movq %rax, %r13
movq %r15, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0xe023
movq %rax, %rbx
leaq 0x1f8a0(%rip), %rdx     # 0x2955f
movq %r15, %rdi
movq %r14, %rsi
callq 0xe023
movq %rax, %r15
movl $0x1, 0x2090(%rsp)
movq 0x20a0(%rsp), %rax
movq %rax, 0x10(%rsp)
movdqa 0x2090(%rsp), %xmm0
movdqu %xmm0, (%rsp)
movq %r15, %rdi
callq 0x57e4
movq %r13, 0x28(%rsp)
movq %r13, %rdi
callq 0xd7c8
movq %rax, %r12
movq %rax, %rdi
callq 0xd8a7
leaq 0x20(%rsp), %rdx
movq $0x0, (%rdx)
leaq 0x40(%rsp), %rsi
movq %rbx, 0x18(%rsp)
movq %rbx, %rdi
callq 0x9ace
testl %eax, %eax
je 0x9deb
leaq 0x1d450(%rip), %r13     # 0x27190
movq 0x20(%rsp), %rbx
xorl %r14d, %r14d
movq 0x40(%r12), %rdi
leaq 0x40(%rsp), %rsi
xorl %edx, %edx
leaq 0x38(%rsp), %rcx
leaq 0x30(%rsp), %r8
callq 0x91ea
movl 0x30(%rsp), %r9d
movq 0x38(%rsp), %rbp
movq %rbp, (%rsp)
movq %r15, %rdi
movq %r13, %rsi
movq %rbx, %rdx
movq %r14, %rcx
leaq 0x56(%rsp), %r8
xorl %eax, %eax
callq 0x3500
movq %rbp, %rdi
callq 0x3390
movdqa 0x40(%rsp), %xmm0
psubq 0x1d391(%rip), %xmm0    # 0x27130
movdqa %xmm0, 0x40(%rsp)
cmpq $0x2, %r14
jne 0x9db0
negw 0x50(%rsp)
leaq 0x2090(%rsp), %rax
cmpl $0x0, 0x4(%rax)
je 0x9dcf
leaq 0x1(%r14), %rax
cmpq $0x5, %r14
movq %rax, %r14
jb 0x9d48
movq 0x18(%rsp), %rdi
leaq 0x40(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x9ace
testl %eax, %eax
jne 0x9d40
movq %r15, %rdi
callq 0x3370
movq 0x28(%rsp), %rdi
callq 0xe747
movq 0x18(%rsp), %rdi
callq 0xe71e
movq %r15, %rdi
callq 0xe71e
movq %r12, %rdi
callq 0xd84e
xorl %eax, %eax
addq $0x2058, %rsp           # imm = 0x2058
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq