// File: gersteinlab[P]MUSIC/src/ms_mapped_read_tools.cpp
// Function: preprocess_SAM_read_line(char*, char*, char*, int&, int&, char&, char*)
void preprocess_SAM_read_line(char* cur_line, 
	char* read_id,
	char* chrom, 
	int& chr_index, int& sequenced_length, 
	char& strand_char, 
	char* cigar_str)
{
	// Skip the comment and headers.
	if(cur_line[0] == '@')
	{
		chrom[0] = 0;
		chr_index = 0;
		return;
	}

	int flag;
	char flag_str[100];
	int _chr_index;
	char _chr_index_str[100];
	char fragment[100000];
	char phred_quality_str[100000];

	//t_string_tokens* cur_tokens = t_string::tokenize_by_chars(cur_line, "\t");
	//if(sscanf(cur_line, "%s %d %s %d %*s %s %*s %*s %*s %s %s", read_id, &flag, chrom, &_chr_index, cigar_str, fragment, phred_quality_str) == 7)
	//if(cur_tokens->size() >= 11)
	if(sscanf(cur_line, "%[^\t] %[^\t] %[^\t] %[^\t] %*[^\t] %[^\t] %*[^\t] %*[^\t] %*[^\t] %[^\t] %[^\t]", read_id, flag_str, chrom, _chr_index_str, cigar_str, fragment, phred_quality_str) == 7)
	{
		//t_string::copy(read_id, cur_tokens->at(0)->str());
		//flag = atoi(cur_tokens->at(1)->str());
		//t_string::copy(chrom, cur_tokens->at(2)->str());
		//_chr_index = atoi(cur_tokens->at(3)->str());
		//t_string::copy(cigar_str, cur_tokens->at(5)->str());
		//t_string::copy(fragment, cur_tokens->at(9)->str());
		//t_string::copy(phred_quality_str, cur_tokens->at(10)->str());

		_chr_index = atoi(_chr_index_str);
		flag = atoi(flag_str);

		// Translate the 0 based index in SAM file to ELAND's 1 based indexing.
		//chr_index += (CODEBASE_START_BASE - SAM_START_BASE);
		_chr_index = translate_coord(_chr_index, SAM_COORDS::start_base, CODEBASE_COORDS::start_base);

		// Check the flag and determine the strand.
		strand_char = 'F';
		if(flag & 0x10)
		{
			strand_char = 'R';
		}

		// Sanity check. Is this fragment mapped?
		if(flag & 0x04)
		{
			// The read is not mapping.
			chrom[0] = 0;
		}
		else
		{
			chr_index = _chr_index;
			sequenced_length = strlen(fragment);
		}
	}
	else
	{
		chrom[0] = 0;
	}

	//t_string::clean_tokens(cur_tokens);
}

// Assembly:
subq $0x30e68, %rsp          # imm = 0x30E68
movq 0x30e70(%rsp), %rax
movq %rdi, 0x30e60(%rsp)
movq %rsi, 0x30e58(%rsp)
movq %rdx, 0x30e50(%rsp)
movq %rcx, 0x30e48(%rsp)
movq %r8, 0x30e40(%rsp)
movq %r9, 0x30e38(%rsp)
movq 0x30e60(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x40, %eax
jne 0x1e63d
movq 0x30e50(%rsp), %rax
movb $0x0, (%rax)
movq 0x30e48(%rsp), %rax
movl $0x0, (%rax)
jmp 0x1e759
movq 0x30e60(%rsp), %rdi
movq 0x30e58(%rsp), %rdx
leaq 0x30dd0(%rsp), %rcx
movq 0x30e50(%rsp), %r8
leaq 0x30d60(%rsp), %r9
movq 0x30e70(%rsp), %r11
leaq 0x186c0(%rsp), %r10
leaq 0x20(%rsp), %rax
leaq 0x37176(%rip), %rsi     # 0x557f7
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movb $0x0, %al
callq 0x2170
cmpl $0x7, %eax
jne 0x1e74e
leaq 0x30d60(%rsp), %rdi
callq 0x2290
movl %eax, 0x30dcc(%rsp)
leaq 0x30dd0(%rsp), %rdi
callq 0x2290
movl %eax, 0x30e34(%rsp)
movl 0x30dcc(%rsp), %edi
movl $0x1, %edx
movl %edx, %esi
callq 0x1fd20
movl %eax, 0x30dcc(%rsp)
movq 0x30e38(%rsp), %rax
movb $0x46, (%rax)
movl 0x30e34(%rsp), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x1e706
movq 0x30e38(%rsp), %rax
movb $0x52, (%rax)
movl 0x30e34(%rsp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x1e722
movq 0x30e50(%rsp), %rax
movb $0x0, (%rax)
jmp 0x1e74c
movl 0x30dcc(%rsp), %ecx
movq 0x30e48(%rsp), %rax
movl %ecx, (%rax)
leaq 0x186c0(%rsp), %rdi
callq 0x20e0
movl %eax, %ecx
movq 0x30e40(%rsp), %rax
movl %ecx, (%rax)
jmp 0x1e759
movq 0x30e50(%rsp), %rax
movb $0x0, (%rax)
addq $0x30e68, %rsp          # imm = 0x30E68
retq
nopw %cs:(%rax,%rax)