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

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

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

	// Iterate through each sequence
	seq = kseq_init(inputSeqPtr);
	currentLine = 0;

	while (kseq_read(seq) > 0) {
		for (frameIdx = 0 ; frameIdx < 6 ; frameIdx++) {
			if (frameIdx < 3) {
				currentCDS.startIdx = (frameIdx % 3);
				currentCDS.endIdx = getLastAlignedPos(seq->seq.l, frameIdx);
				currentCDS.strand = 1;
				currentCDS.phase = 0;
			}
			else {
				currentCDS.startIdx = getLastAlignedPos(seq->seq.l, frameIdx);
				currentCDS.endIdx = seq->seq.l - 1 - (frameIdx % 3);
				currentCDS.strand = -1;
				currentCDS.phase = 0;
			}

			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, seq->name.s, (int) outputSize, outputBuffer);
			free(outputBuffer);

			if (!passHeader.multiFrame) break;
		}

		currentLine++;
	}

	// Close files
	fflush(outputPtr);
	err_gzclose(inputSeqPtr);
	err_fclose(outputPtr);
	kseq_destroy(seq);

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2048, %rsp           # imm = 0x2048
movq %rsi, %rbx
movq %rdi, %rsi
leaq 0x2080(%rsp), %r15
leaq 0x19926(%rip), %r14     # 0x22152
leaq 0x195eb(%rip), %rdx     # 0x21e1e
movq %r14, %rdi
callq 0xcacc
movq %rax, %r12
leaq 0x1bc9a(%rip), %rdx     # 0x244df
movq %r14, %rdi
movq %rbx, %rsi
callq 0xc931
movq %rax, %r14
movl $0x1, (%r15)
movq 0x10(%r15), %rax
movq %rax, 0x10(%rsp)
movaps (%r15), %xmm0
movups %xmm0, (%rsp)
movq %r14, %rdi
callq 0x41e0
movq %r12, 0x18(%rsp)
movq %r12, %rdi
callq 0xc1ce
movq %rax, %r15
xorl %r12d, %r12d
movq %r15, %rdi
callq 0xc2aa
testl %eax, %eax
jle 0x895c
pushq $0x2
popq %rbx
xorl %r13d, %r13d
cmpq $0x6, %r13
je 0x8954
cmpq $0x2, %r13
ja 0x88c6
movq %r13, 0x30(%rsp)
movq 0x30(%r15), %rdi
movl %r13d, %esi
callq 0x7fe3
movq %rax, %rbp
movw $0x1, %ax
jmp 0x88e1
movq 0x30(%r15), %rbp
movq %rbp, %rdi
movl %r13d, %esi
callq 0x7fe3
movq %rax, 0x30(%rsp)
addq %rbx, %rbp
movw $0xffff, %ax            # imm = 0xFFFF
movq %rbp, 0x38(%rsp)
movw %ax, 0x40(%rsp)
andw $0x0, 0x42(%rsp)
movq 0x40(%r15), %rdi
leaq 0x30(%rsp), %rsi
xorl %edx, %edx
leaq 0x28(%rsp), %rcx
leaq 0x20(%rsp), %r8
callq 0x7f00
movq 0x10(%r15), %r8
movl 0x20(%rsp), %r9d
movq 0x28(%rsp), %rbp
movq %rbp, (%rsp)
movq %r14, %rdi
leaq 0x19819(%rip), %rsi     # 0x22140
movq %r12, %rdx
movq %r13, %rcx
xorl %eax, %eax
callq 0x3500
movq %rbp, %rdi
callq 0x3390
incq %r13
decq %rbx
leaq 0x2080(%rsp), %rax
cmpl $0x0, 0x4(%rax)
jne 0x889c
incq %r12
jmp 0x8886
movq %r14, %rdi
callq 0x3370
movq 0x18(%rsp), %rdi
callq 0xd044
movq %r14, %rdi
callq 0xd01b
movq %r15, %rdi
callq 0xc251
xorl %eax, %eax
addq $0x2048, %rsp           # imm = 0x2048
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq