// File: /workspace/github_c_makefile_star2_O1/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 0x1d6c9(%rip), %r15     # 0x27113
leaq 0x1d3cd(%rip), %r12     # 0x26e1e
movq %r15, %rdi
movq %r12, %rdx
callq 0xdf35
movq %rax, %r13
movq %r15, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0xdd8e
movq %rax, %rbx
leaq 0x1f9b8(%rip), %rdx     # 0x2942f
movq %r15, %rdi
movq %r14, %rsi
callq 0xdd8e
movq %rax, %r15
movl $0x1, 0x2090(%rsp)
movq 0x20a0(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x2090(%rsp), %xmm0
movups %xmm0, (%rsp)
movq %r15, %rdi
callq 0x5794
movq %r13, 0x28(%rsp)
movq %r13, %rdi
callq 0xd53f
movq %rax, %r12
movq %rax, %rdi
callq 0xd61e
leaq 0x20(%rsp), %rdx
movq $0x0, (%rdx)
leaq 0x40(%rsp), %rsi
movq %rbx, 0x18(%rsp)
movq %rbx, %rdi
callq 0x9884
testl %eax, %eax
je 0x9b93
leaq 0x1d62f(%rip), %r13     # 0x27125
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 0x9002
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
incq 0x40(%rsp)
incq 0x48(%rsp)
cmpq $0x2, %r14
jne 0x9b5c
negw 0x50(%rsp)
leaq 0x2090(%rsp), %rax
cmpl $0x0, 0x4(%rax)
je 0x9b77
leaq 0x1(%r14), %rax
cmpq $0x5, %r14
movq %rax, %r14
jb 0x9afe
movq 0x18(%rsp), %rdi
leaq 0x40(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x9884
testl %eax, %eax
jne 0x9af6
movq %r15, %rdi
callq 0x3370
movq 0x28(%rsp), %rdi
callq 0xe4b9
movq 0x18(%rsp), %rdi
callq 0xe490
movq %r15, %rdi
callq 0xe490
movq %r12, %rdi
callq 0xd5c5
xorl %eax, %eax
addq $0x2058, %rsp           # imm = 0x2058
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq