// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x2090, %rsp           # imm = 0x2090
leaq 0x10(%rbp), %rax
movq %rax, -0x2068(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rsi
leaq 0x2dbd7(%rip), %rdi     # 0x39020
leaq 0x2d8b2(%rip), %rdx     # 0x38d02
callq 0x12990
movq %rax, -0x2030(%rbp)
movq -0x10(%rbp), %rsi
leaq 0x2dbb9(%rip), %rdi     # 0x39020
leaq 0x2feaa(%rip), %rdx     # 0x3b318
callq 0x12740
movq %rax, %rcx
movq -0x2068(%rbp), %rax
movq %rcx, -0x2038(%rbp)
movl $0x1, (%rax)
movq -0x2038(%rbp), %rdi
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
callq 0x4bf0
movq -0x2030(%rbp), %rdi
callq 0x11a10
movq %rax, -0x2048(%rbp)
movq $0x0, -0x2058(%rbp)
movq -0x2048(%rbp), %rdi
callq 0x11b70
cmpl $0x0, %eax
jle 0xb670
movq $0x0, -0x2060(%rbp)
cmpq $0x6, -0x2060(%rbp)
jae 0xb659
cmpq $0x3, -0x2060(%rbp)
jae 0xb551
movq -0x2060(%rbp), %rax
movl $0x3, %ecx
xorl %edx, %edx
divq %rcx
movq %rdx, -0x2028(%rbp)
movq -0x2048(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x2060(%rbp), %rax
movl %eax, %esi
callq 0xa680
movq %rax, -0x2020(%rbp)
movw $0x1, -0x2018(%rbp)
movw $0x0, -0x2016(%rbp)
jmp 0xb5bb
movq -0x2048(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x2060(%rbp), %rax
movl %eax, %esi
callq 0xa680
movq %rax, -0x2028(%rbp)
movq -0x2048(%rbp), %rax
movq 0x30(%rax), %rax
subq $0x1, %rax
movq %rax, -0x2070(%rbp)
movq -0x2060(%rbp), %rax
movl $0x3, %ecx
xorl %edx, %edx
divq %rcx
movq -0x2070(%rbp), %rax
subq %rdx, %rax
movq %rax, -0x2020(%rbp)
movw $0xffff, -0x2018(%rbp)  # imm = 0xFFFF
movw $0x0, -0x2016(%rbp)
movq -0x2048(%rbp), %rax
movq 0x40(%rax), %rdi
leaq -0x2028(%rbp), %rsi
xorl %edx, %edx
leaq -0x2040(%rbp), %rcx
leaq -0x2050(%rbp), %r8
callq 0xa4f0
movq -0x2038(%rbp), %rdi
movq -0x2058(%rbp), %rdx
movq -0x2060(%rbp), %rcx
movq -0x2048(%rbp), %rax
movq 0x10(%rax), %r8
movq -0x2050(%rbp), %rax
movl %eax, %r9d
movq -0x2040(%rbp), %rax
leaq 0x2d9f4(%rip), %rsi     # 0x3900e
movq %rax, (%rsp)
movb $0x0, %al
callq 0x34e0
movq -0x2040(%rbp), %rdi
callq 0x3380
movq -0x2068(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jne 0xb640
jmp 0xb659
jmp 0xb642
movq -0x2060(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x2060(%rbp)
jmp 0xb4ed
movq -0x2058(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x2058(%rbp)
jmp 0xb4cd
movq -0x2038(%rbp), %rdi
callq 0x3360
movq -0x2030(%rbp), %rdi
callq 0x13200
movq -0x2038(%rbp), %rdi
callq 0x131b0
movq -0x2048(%rbp), %rdi
callq 0x11ad0
xorl %eax, %eax
addq $0x2090, %rsp           # imm = 0x2090
popq %rbp
retq
nopl (%rax,%rax)