// File: /workspace/github_c_makefile_star2_O0/ToniWestbrook[P]paladin/protein.c
// Function: compileORFHistory
void compileORFHistory(long * passHistory[2][6], long passHistorySize[6], CDS * * retCDS, unsigned long * retCount) {
	unsigned long srcFrameIdx, srcHistoryIdx;
	unsigned long srcStart, srcEnd, totalSize;
	int relStart, validEntry;

	// Allocate potential CDS records per entry in history array
	totalSize = 0;
	for (srcFrameIdx = 0 ; srcFrameIdx < 6 ; srcFrameIdx++) totalSize += passHistorySize[srcFrameIdx];

	*retCDS = calloc(totalSize, sizeof(CDS));
	*retCount = 0;
	relStart = -1;

	// Iterate through each entry in each reading frame
	for (srcFrameIdx = 0 ; srcFrameIdx < 6 ; srcFrameIdx++) {
		for (srcHistoryIdx = 0 ; srcHistoryIdx < passHistorySize[srcFrameIdx] ; srcHistoryIdx++) {
			// Swap start/stop for reverse direction
			if (passHistory[0][srcFrameIdx][srcHistoryIdx] < passHistory[1][srcFrameIdx][srcHistoryIdx]) {
				srcStart = passHistory[0][srcFrameIdx][srcHistoryIdx];
				srcEnd = passHistory[1][srcFrameIdx][srcHistoryIdx];
			}
			else {
				srcStart = passHistory[1][srcFrameIdx][srcHistoryIdx];
				srcEnd = passHistory[0][srcFrameIdx][srcHistoryIdx];
			}

			validEntry = 1;

			// Filter minimum ORF size
			//if (srcLen < passMinORF) continue;

			// Add CDS record if valid (current strategy marks all as valid)
			if (validEntry) {
				if (relStart < 0) relStart = srcFrameIdx;

				(*retCDS)[*retCount].startIdx = srcStart;
				(*retCDS)[*retCount].endIdx = srcEnd;
				(*retCDS)[*retCount].strand = (srcFrameIdx < 3) ? 1 : -1;
				(*retCDS)[*retCount].relFrame = srcFrameIdx - relStart;

				(*retCount)++;
			}
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x28(%rbp)
cmpq $0x6, -0x28(%rbp)
jae 0xa981
movq -0x10(%rbp), %rax
movq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rax
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0xa958
movq -0x48(%rbp), %rdi
movl $0x2018, %esi           # imm = 0x2018
leaq 0x2e629(%rip), %rdx     # 0x38fba
movl $0xb9, %ecx
leaq 0x2e641(%rip), %r8      # 0x38fde
callq 0x31bf0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x20(%rbp), %rax
movq $0x0, (%rax)
movl $0xffffffff, -0x4c(%rbp) # imm = 0xFFFFFFFF
movq $0x0, -0x28(%rbp)
cmpq $0x6, -0x28(%rbp)
jae 0xab61
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
movq -0x28(%rbp), %rdx
cmpq (%rcx,%rdx,8), %rax
jae 0xab4e
movq -0x8(%rbp), %rax
movq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x8(%rbp), %rcx
movq -0x28(%rbp), %rdx
movq 0x30(%rcx,%rdx,8), %rcx
movq -0x30(%rbp), %rdx
cmpq (%rcx,%rdx,8), %rax
jge 0xaa4d
movq -0x8(%rbp), %rax
movq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq -0x28(%rbp), %rcx
movq 0x30(%rax,%rcx,8), %rax
movq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x40(%rbp)
jmp 0xaa7e
movq -0x8(%rbp), %rax
movq -0x28(%rbp), %rcx
movq 0x30(%rax,%rcx,8), %rax
movq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x40(%rbp)
movl $0x1, -0x50(%rbp)
cmpl $0x0, -0x50(%rbp)
je 0xab3b
cmpl $0x0, -0x4c(%rbp)
jge 0xaa9c
movq -0x28(%rbp), %rax
movl %eax, -0x4c(%rbp)
movq -0x38(%rbp), %rcx
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0x20(%rbp), %rdx
imulq $0x2018, (%rdx), %rdx   # imm = 0x2018
addq %rdx, %rax
movq %rcx, (%rax)
movq -0x40(%rbp), %rcx
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0x20(%rbp), %rdx
imulq $0x2018, (%rdx), %rdx   # imm = 0x2018
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq -0x28(%rbp), %rdx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl $0x1, %ecx
cmpq $0x3, %rdx
cmovbl %ecx, %eax
movw %ax, %cx
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0x20(%rbp), %rdx
imulq $0x2018, (%rdx), %rdx   # imm = 0x2018
addq %rdx, %rax
movw %cx, 0x10(%rax)
movq -0x28(%rbp), %rax
movslq -0x4c(%rbp), %rcx
subq %rcx, %rax
movw %ax, %cx
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0x20(%rbp), %rdx
imulq $0x2018, (%rdx), %rdx   # imm = 0x2018
addq %rdx, %rax
movw %cx, 0x14(%rax)
movq -0x20(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
jmp 0xab3d
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0xa9d9
jmp 0xab50
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0xa9c6
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)