// File: /workspace/github_cpp_makefile_star2_O2/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
movslq %ebp, %r13
movslq %r15d, %rbp
leaq 0xab86(%rip), %r15      # 0x28384
leaq 0xabac(%rip), %r12      # 0x283b1
movq %r14, (%rsp)
cmpq %rbp, %r13
jl 0x1d892
movzbl (%rbx,%r13), %eax
cmpl $0x2d, %eax
je 0x1d854
cmpl $0x41, %eax
je 0x1d864
cmpl $0x43, %eax
je 0x1d860
cmpl $0x47, %eax
je 0x1d848
cmpl $0x74, %eax
je 0x1d850
cmpl $0x61, %eax
je 0x1d85c
cmpl $0x63, %eax
je 0x1d858
cmpl $0x67, %eax
je 0x1d84c
cmpl $0x54, %eax
jne 0x1d868
movb $0x41, %al
jmp 0x1d884
movb $0x43, %al
jmp 0x1d884
movb $0x63, %al
jmp 0x1d884
movb $0x61, %al
jmp 0x1d884
movb $0x2d, %al
jmp 0x1d884
movb $0x67, %al
jmp 0x1d884
movb $0x75, %al
jmp 0x1d884
movb $0x47, %al
jmp 0x1d884
movb $0x55, %al
jmp 0x1d884
movsbl %al, %esi
movq %r15, %rdi
movq %r12, %rdx
movl $0x2d0, %ecx            # imm = 0x2D0
movq %rbx, %r8
xorl %eax, %eax
callq 0x2050
movb (%rbx,%r13), %al
movb %al, (%r14)
decq %r13
incq %r14
jmp 0x1d809
movq (%rsp), %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)