// File: /workspace/github_cpp_makefile_star2_O1/gersteinlab[P]MUSIC/src/ms_genome_sequence_tools.cpp
// Function: get_forward_strand_RNA(char*, int, int)
char* get_forward_strand_RNA(char* cur_aln_line, int i_nuc_min, int i_nuc_max)
{
	char* forward_RNA = new char[i_nuc_max - i_nuc_min + 2];
	memset(forward_RNA, 0, sizeof(char) * (i_nuc_max - i_nuc_min + 2));

	//printf("Forward strand RNA for strand:\n");
	//for(int i_nuc = i_nuc_min; i_nuc <= i_nuc_max; i_nuc++)
	//{
	//	printf("%c", cur_aln_line[i_nuc]);
	//}
	//printf("\n");

	int i_rna_nuc = 0;

	// The forward strand RNA is transcribed from 3' end.
	for(int i_nuc = i_nuc_max; i_nuc >= i_nuc_min; i_nuc--)
	{
		if(cur_aln_line[i_nuc] == 'A')
		{
			forward_RNA[i_rna_nuc] = 'U';
			i_rna_nuc++;
		}
		else if(cur_aln_line[i_nuc] == 'T')
		{
			forward_RNA[i_rna_nuc] = 'A';
			i_rna_nuc++;
		}
		else if(cur_aln_line[i_nuc] == 'G')
		{
			forward_RNA[i_rna_nuc] = 'C';
			i_rna_nuc++;
		}
		else if(cur_aln_line[i_nuc] == 'C')
		{
			forward_RNA[i_rna_nuc] = 'G';
			i_rna_nuc++;
		}
		else if(cur_aln_line[i_nuc] == 'a')
		{
			forward_RNA[i_rna_nuc] = 'u';
			i_rna_nuc++;
		}
		else if(cur_aln_line[i_nuc] == 't')
		{
			forward_RNA[i_rna_nuc] = 'a';
			i_rna_nuc++;
		}
		else if(cur_aln_line[i_nuc] == 'g')
		{
			forward_RNA[i_rna_nuc] = 'c';
			i_rna_nuc++;
		}
		else if(cur_aln_line[i_nuc] == 'c')
		{
			forward_RNA[i_rna_nuc] = 'g';
			i_rna_nuc++;
		}
		else if(cur_aln_line[i_nuc] == '-')
		{
			forward_RNA[i_rna_nuc] = '-';
			i_rna_nuc++;
		}
		else
		{
			printf("Found %c in the alignment line @ %s(%d):\n%s\n",  cur_aln_line[i_nuc], __FILE__, __LINE__, cur_aln_line);
			//exit(0);
			forward_RNA[i_rna_nuc] = cur_aln_line[i_nuc];
			i_rna_nuc++;
		}
	} // i_nuc loop.

	//printf("%s", forward_RNA);
	//getc(stdin);
	
	return(forward_RNA);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edx, %ebp
movl %esi, %r15d
movq %rdi, %rbx
movl %edx, %eax
subl %esi, %eax
addl $0x2, %eax
movslq %eax, %r12
movq %r12, %rdi
callq 0x2040
movq %rax, %r14
movq %rax, %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x20f0
movl %ebp, %r13d
subl %r15d, %r13d
jl 0x231c9
movslq %ebp, %rbp
incl %r13d
addq %rbx, %rbp
leaq 0xc281(%rip), %r12      # 0x2f3b1
xorl %r15d, %r15d
movzbl (%rbp), %eax
cmpl $0x53, %eax
jle 0x23154
cmpl $0x62, %eax
jle 0x23175
cmpl $0x63, %eax
je 0x2318b
cmpl $0x67, %eax
je 0x23193
cmpl $0x74, %eax
jne 0x23197
movb $0x61, %cl
jmp 0x231b6
cmpl $0x42, %eax
jg 0x23167
cmpl $0x2d, %eax
je 0x23183
movb $0x55, %cl
cmpl $0x41, %eax
je 0x231b6
jmp 0x23197
cmpl $0x43, %eax
je 0x23187
cmpl $0x47, %eax
jne 0x23197
movb $0x43, %cl
jmp 0x231b6
cmpl $0x54, %eax
je 0x2318f
cmpl $0x61, %eax
jne 0x23197
movb $0x75, %cl
jmp 0x231b6
movb $0x2d, %cl
jmp 0x231b6
movb $0x47, %cl
jmp 0x231b6
movb $0x67, %cl
jmp 0x231b6
movb $0x41, %cl
jmp 0x231b6
movb $0x63, %cl
jmp 0x231b6
movsbl %al, %esi
leaq 0xc1e3(%rip), %rdi      # 0x2f384
movq %r12, %rdx
movl $0x2d0, %ecx            # imm = 0x2D0
movq %rbx, %r8
xorl %eax, %eax
callq 0x2050
movb (%rbp), %cl
movb %cl, (%r14,%r15)
incq %r15
decq %rbp
cmpq %r15, %r13
jne 0x23133
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop