// File: /workspace/github_c_makefile_star2_O0/ToniWestbrook[P]paladin/protein.c
// Function: convertToAA
int convertToAA(char * passSequence, CDS * passCDS, int passTrans, char ** retSequence, unsigned long * retSize) {
	unsigned long nucIdx, aaIdx;
	unsigned long seqLen, seqStart;
	unsigned char currentCodon;

	// Calculate sequence length and loop control from CDS entry
	seqLen = passCDS->endIdx + 1 - passCDS->startIdx - passCDS->phase;
	seqStart = (passCDS->strand == 1) ? passCDS->startIdx : passCDS->endIdx;

	// Reserve memory for amino acid sequence
	*retSize = (seqLen + 2) / 3;
	*retSequence = malloc(*retSize);

	// Iterate through all codons in the nucleotide sequence
	for (nucIdx = 0, aaIdx = 0 ; nucIdx < seqLen ; nucIdx += 3, aaIdx++) {
		// If we've exhausted nucleotides premature to a full frame, assign ambiguous AA and exit
		if (nucIdx + 3 > seqLen) {
			(*retSequence)[aaIdx] = 'X';
			break;
		}

		// Encode codon
		currentCodon = encodeCodon(passSequence + seqStart + (passCDS->strand * nucIdx), passCDS->strand);

		if (currentCodon == 0xFF) {
            // If ambiguous nucleotides are present, assign ambiguous AA
			(*retSequence)[aaIdx] = 'X';
		}
        else {
            // Hash to amino acid IUPAC
            (*retSequence)[aaIdx] = codon_aa_hash[passTrans][currentCodon];
        }
	}

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
addq $0x1, %rax
movq -0x10(%rbp), %rcx
subq (%rcx), %rax
movq -0x10(%rbp), %rcx
movswq 0x12(%rcx), %rcx
subq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movswl 0x10(%rax), %eax
cmpl $0x1, %eax
jne 0xa548
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x58(%rbp)
jmp 0xa554
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rax
addq $0x2, %rax
movl $0x3, %ecx
xorl %edx, %edx
divq %rcx
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rax
movq (%rax), %rdi
leaq 0x2ea34(%rip), %rsi     # 0x38fba
movl $0x56, %edx
leaq 0x2ea32(%rip), %rcx     # 0x38fc4
callq 0x31ca0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x40(%rbp), %rax
jae 0xa66c
movq -0x30(%rbp), %rax
addq $0x3, %rax
cmpq -0x40(%rbp), %rax
jbe 0xa5e1
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0x38(%rbp), %rcx
movb $0x58, (%rax,%rcx)
jmp 0xa66c
movq -0x8(%rbp), %rdi
addq -0x48(%rbp), %rdi
movq -0x10(%rbp), %rax
movswq 0x10(%rax), %rax
imulq -0x30(%rbp), %rax
addq %rax, %rdi
movq -0x10(%rbp), %rax
movswl 0x10(%rax), %esi
callq 0xa450
movb %al, -0x49(%rbp)
movzbl -0x49(%rbp), %eax
cmpl $0xff, %eax
jne 0xa626
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0x38(%rbp), %rcx
movb $0x58, (%rax,%rcx)
jmp 0xa64d
movslq -0x14(%rbp), %rcx
leaq 0x35daf(%rip), %rax     # 0x403e0
shlq $0x6, %rcx
addq %rcx, %rax
movzbl -0x49(%rbp), %ecx
movb (%rax,%rcx), %dl
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0x38(%rbp), %rcx
movb %dl, (%rax,%rcx)
jmp 0xa64f
movq -0x30(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x30(%rbp)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0xa5b1
xorl %eax, %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)