// File: /workspace/github_c_makefile_star2_O3/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 0x1d359(%rip), %r14     # 0x271a2
leaq 0x1d01a(%rip), %rdx     # 0x26e6a
movq %r14, %rdi
callq 0xe1c4
movq %rax, %r15
leaq 0x1f6fd(%rip), %rdx     # 0x2955f
movq %r14, %rdi
movq %rbx, %rsi
callq 0xe023
movq %rax, %r14
movl $0x1, 0x2080(%rsp)
movq 0x2090(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x2080(%rsp), %xmm0
movups %xmm0, (%rsp)
movq %r14, %rdi
callq 0x57e4
movq %r15, 0x18(%rsp)
movq %r15, %rdi
callq 0xd7c8
movq %rax, %r15
movq %rax, %rdi
callq 0xd8a7
testl %eax, %eax
jle 0x9fe2
xorl %r12d, %r12d
movl $0x2, %ebx
xorl %r13d, %r13d
cmpq $0x2, %r13
ja 0x9f0d
movq %r13, 0x30(%rsp)
movq 0x30(%r15), %rcx
movq %rcx, %rax
movabsq $0x5555555555555556, %rdx # imm = 0x5555555555555556
imulq %rdx
movq %rdx, %rax
shrq $0x3f, %rax
addq %rdx, %rax
leaq (%rax,%rax,2), %rax
leaq (%rax,%r13), %rdx
decq %rdx
cmpq %rcx, %rdx
leaq -0x4(%r13,%rax), %rax
cmovlq %rdx, %rax
movw $0x1, %cx
jmp 0x9f51
movq 0x30(%r15), %rcx
movq %rcx, %rax
movabsq $0x5555555555555556, %rdx # imm = 0x5555555555555556
imulq %rdx
movq %rdx, %rax
shrq $0x3f, %rax
addq %rdx, %rax
leaq (%rax,%rax,2), %rdx
leaq (%rbx,%rcx), %rax
subq %rdx, %rcx
leal -0x3(%r13), %edx
subq %rdx, %rcx
leaq 0x3(%rcx), %rdx
testq %rcx, %rcx
cmovnsq %rcx, %rdx
movq %rdx, 0x30(%rsp)
movw $0xffff, %cx            # imm = 0xFFFF
movq %rax, 0x38(%rsp)
movw %cx, 0x40(%rsp)
movw $0x0, 0x42(%rsp)
movq 0x40(%r15), %rdi
leaq 0x30(%rsp), %rsi
xorl %edx, %edx
leaq 0x28(%rsp), %rcx
leaq 0x20(%rsp), %r8
callq 0x91ea
movq 0x10(%r15), %r8
movl 0x20(%rsp), %r9d
movq 0x28(%rsp), %rbp
movq %rbp, (%rsp)
movq %r14, %rdi
leaq 0x1d1f8(%rip), %rsi     # 0x27190
movq %r12, %rdx
movq %r13, %rcx
xorl %eax, %eax
callq 0x3500
movq %rbp, %rdi
callq 0x3390
leaq 0x2080(%rsp), %rax
cmpl $0x0, 0x4(%rax)
je 0x9fcf
leaq 0x1(%r13), %rax
decq %rbx
cmpq $0x5, %r13
movq %rax, %r13
jb 0x9ec7
incq %r12
movq %r15, %rdi
callq 0xd8a7
testl %eax, %eax
jg 0x9ebf
movq %r14, %rdi
callq 0x3370
movq 0x18(%rsp), %rdi
callq 0xe747
movq %r14, %rdi
callq 0xe71e
movq %r15, %rdi
callq 0xd84e
xorl %eax, %eax
addq $0x2048, %rsp           # imm = 0x2048
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq