// File: /workspace/github_c_makefile_star2_O2/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 0x2090(%rsp), %r13
leaq 0x19a9b(%rip), %r15     # 0x2212e
leaq 0x19784(%rip), %r12     # 0x21e1e
movq %r15, %rdi
movq %r12, %rdx
callq 0xcacc
movq %rax, %rbp
movq %r15, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0xc931
movq %rax, 0x18(%rsp)
leaq 0x1be1d(%rip), %rdx     # 0x244df
movq %r15, %rdi
movq %r14, %rsi
callq 0xc931
movq %rax, %r15
movl $0x1, (%r13)
movq 0x10(%r13), %rax
movq %rax, 0x10(%rsp)
movdqa (%r13), %xmm0
movdqu %xmm0, (%rsp)
movq %r15, %rdi
callq 0x41e0
movq %rbp, 0x28(%rsp)
movq %rbp, %rdi
callq 0xc1ce
movq %rax, %r12
movq %rax, %rdi
callq 0xc2aa
leaq 0x20(%rsp), %rax
andq $0x0, (%rax)
leaq 0x40(%rsp), %rbx
movq 0x18(%rsp), %rdi
movq %rbx, %rsi
leaq 0x20(%rsp), %rdx
callq 0x84f5
testl %eax, %eax
je 0x87c6
movq 0x20(%rsp), %r13
xorl %r14d, %r14d
cmpq $0x6, %r14
je 0x871a
movq 0x40(%r12), %rdi
movq %rbx, %rsi
xorl %edx, %edx
leaq 0x38(%rsp), %rcx
leaq 0x30(%rsp), %r8
callq 0x7f00
movl 0x30(%rsp), %r9d
movq 0x38(%rsp), %rbp
movq %rbp, (%rsp)
movq %r15, %rdi
leaq 0x199cd(%rip), %rsi     # 0x22140
movq %r13, %rdx
movq %r14, %rcx
leaq 0x56(%rsp), %r8
xorl %eax, %eax
callq 0x3500
movq %rbp, %rdi
callq 0x3390
movdqa 0x40(%rsp), %xmm0
psubq 0x19945(%rip), %xmm0    # 0x220e0
movdqa %xmm0, 0x40(%rsp)
cmpq $0x2, %r14
jne 0x87ac
negw 0x50(%rsp)
incq %r14
leaq 0x2090(%rsp), %rax
cmpl $0x0, 0x4(%rax)
jne 0x873c
jmp 0x871a
movq %r15, %rdi
callq 0x3370
movq 0x28(%rsp), %rdi
callq 0xd044
movq 0x18(%rsp), %rdi
callq 0xd01b
movq %r15, %rdi
callq 0xd01b
movq %r12, %rdi
callq 0xc251
xorl %eax, %eax
addq $0x2058, %rsp           # imm = 0x2058
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq