// File: 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:
subq $0x28, %rsp
movq %rdi, 0x20(%rsp)
movl %esi, 0x1c(%rsp)
movl %edx, 0x18(%rsp)
movl 0x18(%rsp), %eax
subl 0x1c(%rsp), %eax
addl $0x2, %eax
movslq %eax, %rdi
callq 0x2040
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rdi
movl 0x18(%rsp), %eax
subl 0x1c(%rsp), %eax
addl $0x2, %eax
movslq %eax, %rdx
shlq $0x0, %rdx
xorl %esi, %esi
callq 0x2110
movl $0x0, 0xc(%rsp)
movl 0x18(%rsp), %eax
movl %eax, 0x8(%rsp)
movl 0x8(%rsp), %eax
cmpl 0x1c(%rsp), %eax
jl 0x3e2ef
movq 0x20(%rsp), %rax
movslq 0x8(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x41, %eax
jne 0x3e0f6
movq 0x10(%rsp), %rax
movslq 0xc(%rsp), %rcx
movb $0x55, (%rax,%rcx)
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x3e2dd
movq 0x20(%rsp), %rax
movslq 0x8(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x54, %eax
jne 0x3e127
movq 0x10(%rsp), %rax
movslq 0xc(%rsp), %rcx
movb $0x41, (%rax,%rcx)
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x3e2db
movq 0x20(%rsp), %rax
movslq 0x8(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x47, %eax
jne 0x3e158
movq 0x10(%rsp), %rax
movslq 0xc(%rsp), %rcx
movb $0x43, (%rax,%rcx)
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x3e2d9
movq 0x20(%rsp), %rax
movslq 0x8(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x43, %eax
jne 0x3e189
movq 0x10(%rsp), %rax
movslq 0xc(%rsp), %rcx
movb $0x47, (%rax,%rcx)
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x3e2d7
movq 0x20(%rsp), %rax
movslq 0x8(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x61, %eax
jne 0x3e1ba
movq 0x10(%rsp), %rax
movslq 0xc(%rsp), %rcx
movb $0x75, (%rax,%rcx)
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x3e2d5
movq 0x20(%rsp), %rax
movslq 0x8(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x74, %eax
jne 0x3e1eb
movq 0x10(%rsp), %rax
movslq 0xc(%rsp), %rcx
movb $0x61, (%rax,%rcx)
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x3e2d3
movq 0x20(%rsp), %rax
movslq 0x8(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x67, %eax
jne 0x3e21c
movq 0x10(%rsp), %rax
movslq 0xc(%rsp), %rcx
movb $0x63, (%rax,%rcx)
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x3e2d1
movq 0x20(%rsp), %rax
movslq 0x8(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x63, %eax
jne 0x3e24d
movq 0x10(%rsp), %rax
movslq 0xc(%rsp), %rcx
movb $0x67, (%rax,%rcx)
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x3e2cf
movq 0x20(%rsp), %rax
movslq 0x8(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2d, %eax
jne 0x3e27b
movq 0x10(%rsp), %rax
movslq 0xc(%rsp), %rcx
movb $0x2d, (%rax,%rcx)
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x3e2cd
movq 0x20(%rsp), %rax
movslq 0x8(%rsp), %rcx
movsbl (%rax,%rcx), %esi
movq 0x20(%rsp), %r8
leaq 0x184f0(%rip), %rdi     # 0x56785
leaq 0x18516(%rip), %rdx     # 0x567b2
movl $0x2d0, %ecx            # imm = 0x2D0
movb $0x0, %al
callq 0x2050
movq 0x20(%rsp), %rax
movslq 0x8(%rsp), %rcx
movb (%rax,%rcx), %dl
movq 0x10(%rsp), %rax
movslq 0xc(%rsp), %rcx
movb %dl, (%rax,%rcx)
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x3e2cf
jmp 0x3e2d1
jmp 0x3e2d3
jmp 0x3e2d5
jmp 0x3e2d7
jmp 0x3e2d9
jmp 0x3e2db
jmp 0x3e2dd
jmp 0x3e2df
movl 0x8(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x8(%rsp)
jmp 0x3e0b7
movq 0x10(%rsp), %rax
addq $0x28, %rsp
retq
nopl (%rax)