// File: /workspace/github_c_makefile_star2_O1/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 $0x2058, %rsp           # imm = 0x2058
movq %rsi, %rbx
movq %rdi, %rsi
leaq 0x1d546(%rip), %r14     # 0x27137
leaq 0x1d226(%rip), %rdx     # 0x26e1e
movq %r14, %rdi
callq 0xdf35
movq %rax, %r15
leaq 0x1f825(%rip), %rdx     # 0x2942f
movq %r14, %rdi
movq %rbx, %rsi
callq 0xdd8e
movq %rax, %rdi
movl $0x1, 0x2090(%rsp)
movq 0x20a0(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x2090(%rsp), %xmm0
movups %xmm0, (%rsp)
movq %rdi, 0x20(%rsp)
callq 0x5794
movq %r15, 0x28(%rsp)
movq %r15, %rdi
callq 0xd53f
movq %rax, %r15
movq %rax, %rdi
callq 0xd61e
testl %eax, %eax
jle 0x9dc3
xorl %r12d, %r12d
movq $-0x1, %rbx
xorl %r14d, %r14d
xorl %r13d, %r13d
movq %r13, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
mulq %rcx
shrq %rdx
leaq (%rdx,%rdx,2), %rsi
cmpq $0x2, %r13
ja 0x9ce5
movq $-0x4, %rdi
subq %rsi, %rdi
notq %rsi
movq %r13, 0x40(%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
addq %r13, %rax
addq %rax, %rsi
addq %rdi, %rax
cmpq %rcx, %rsi
cmovlq %rsi, %rax
movq %rax, 0x48(%rsp)
movw $0x1, 0x50(%rsp)
jmp 0x9d37
leaq (%rbx,%rsi), %rdi
addq %r14, %rsi
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
movq %rcx, %rdx
subq %rax, %rdx
leaq (%rsi,%rdx), %rax
addq $0x3, %rax
addq %rsi, %rdx
cmovnsq %rdx, %rax
movq %rax, 0x40(%rsp)
addq %rcx, %rdi
movq %rdi, 0x48(%rsp)
movw $0xffff, 0x50(%rsp)     # imm = 0xFFFF
movw $0x0, 0x52(%rsp)
movq 0x40(%r15), %rdi
leaq 0x40(%rsp), %rsi
xorl %edx, %edx
leaq 0x38(%rsp), %rcx
leaq 0x30(%rsp), %r8
callq 0x9002
movq 0x10(%r15), %r8
movl 0x30(%rsp), %r9d
movq 0x38(%rsp), %rbp
movq %rbp, (%rsp)
movq 0x20(%rsp), %rdi
leaq 0x1d3af(%rip), %rsi     # 0x27125
movq %r12, %rdx
movq %r13, %rcx
xorl %eax, %eax
callq 0x3500
movq %rbp, %rdi
callq 0x3390
leaq 0x2090(%rsp), %rax
cmpl $0x0, 0x4(%rax)
je 0x9db0
leaq 0x1(%r13), %rax
decq %rbx
decq %r14
cmpq $0x5, %r13
movq %rax, %r13
jb 0x9c76
incq %r12
movq %r15, %rdi
callq 0xd61e
testl %eax, %eax
jg 0x9c69
movq 0x20(%rsp), %rbx
movq %rbx, %rdi
callq 0x3370
movq 0x28(%rsp), %rdi
callq 0xe4b9
movq %rbx, %rdi
callq 0xe490
movq %r15, %rdi
callq 0xd5c5
xorl %eax, %eax
addq $0x2058, %rsp           # imm = 0x2058
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq