// File: /workspace/github_cpp_makefile_star2_O2/gersteinlab[P]MUSIC/src/ms_annot_region_tools.cpp
// Function: load_BED_with_line_information(char*)
vector<t_annot_region*>* load_BED_with_line_information(char* bed_fp)
{
	vector<t_annot_region*>* bed_regions = new vector<t_annot_region*>();

	FILE* f_bed = open_f(bed_fp, "r");
	
	char* cur_line = getline(f_bed);
	while(cur_line != NULL)
	{
		bool skip_line = check_line_skip(cur_line);

		if(!skip_line)
		{
			// Read the mandatory fields.
			int start;
			int end;
			char chrom[100];
			if(sscanf(cur_line, "%s %d %d", chrom, &start, &end) != 3)
			{
				printf("Could not read the mandatory fields from BED file line:\n%s\n", cur_line);
				exit(0);
			}

			// Read the strand information if it is there otherwise set to positive strand.
			char strand = '+';
			char strand_str[10]; 
			if(sscanf(cur_line, "%*s %*d %*d %*s %*s %s", strand_str) != 1)
			{
				// Could not read the strand from file, set it to '+' by default.
				strand = '+';
			} 
			else if(strand_str[0] == '-' || // Verify the read strand information.
				strand_str[0] == '+')
			{
				strand = strand_str[0];
			}

			char* bed_line = new char[strlen(cur_line) + 2];
			strcpy(bed_line, cur_line);

			t_annot_region* new_region = new t_annot_region();
			// Translate the start and end of the BED coordinates to the codebase coordinates.
			new_region->start = translate_coord(start, BED_COORDS::start_base, CODEBASE_COORDS::start_base);
			new_region->end = translate_coord(end, BED_COORDS::end_base, CODEBASE_COORDS::end_base);
			new_region->chrom = t_string::copy_me_str(chrom);
			normalize_chr_id(new_region->chrom);
			new_region->strand = strand;
			new_region->data = (void*)bed_line;
		
			bed_regions->push_back(new_region);
		} // line skip check.

		delete [] cur_line;

		// Read the next line.
		cur_line = getline(f_bed);
	} // file reading loop.

	fclose(f_bed);

	//printf("Loaded %d regions from %s\n", bed_regions->size(), bed_fp);

	return(bed_regions);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdi, %r14
pushq $0x18
popq %rdi
callq 0x2170
movq %rax, %rbx
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
andq $0x0, 0x10(%rax)
leaq 0x1216b(%rip), %rsi     # 0x26d08
movq %r14, %rdi
callq 0x2027c
movq %rax, %r14
movq %rax, %rdi
callq 0x2017f
movq %rax, %r15
leaq 0x20(%rsp), %r13
testq %r15, %r15
je 0x14cc2
movq %r15, %rdi
callq 0x13e9f
testb %al, %al
jne 0x14caa
movq %r15, %rdi
leaq 0x1301c(%rip), %rsi     # 0x27bf7
movq %r13, %rdx
leaq 0x10(%rsp), %rcx
leaq 0xc(%rsp), %r8
xorl %eax, %eax
callq 0x2150
cmpl $0x3, %eax
jne 0x14cdf
movq %r15, %rdi
leaq 0x1303a(%rip), %rsi     # 0x27c3c
leaq 0x16(%rsp), %rdx
xorl %eax, %eax
callq 0x2150
cmpl $0x1, %eax
sete %al
cmpb $0x2d, 0x16(%rsp)
sete %r12b
andb %al, %r12b
addb %r12b, %r12b
addb $0x2b, %r12b
movq %r15, %rdi
callq 0x20d0
leaq 0x2(%rax), %rdi
callq 0x2040
movq %rax, %rbp
movq %rax, %rdi
movq %r15, %rsi
callq 0x2140
pushq $0x50
popq %rdi
callq 0x2170
xorps %xmm0, %xmm0
movaps %xmm0, (%rax)
movaps %xmm0, 0x10(%rax)
movaps %xmm0, 0x20(%rax)
movaps %xmm0, 0x30(%rax)
movaps %xmm0, 0x40(%rax)
movq %rax, (%rsp)
movl 0x10(%rsp), %ecx
incl %ecx
movl %ecx, 0xc(%rax)
movl 0xc(%rsp), %ecx
movl %ecx, 0x20(%rax)
movq %r13, %rdi
callq 0x21062
movq (%rsp), %rcx
movq %rax, (%rcx)
movq (%rsp), %rax
movq (%rax), %rdi
callq 0xf63c
movq (%rsp), %rax
movb %r12b, 0x8(%rax)
movq %rbp, 0x48(%rax)
movq %rbx, %rdi
movq %rsp, %rsi
callq 0x7448
movq %r15, %rdi
callq 0x2210
movq %r14, %rdi
callq 0x2017f
movq %rax, %r15
jmp 0x14bb8
movq %r14, %rdi
callq 0x2160
movq %rbx, %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x12f1a(%rip), %rdi     # 0x27c00
movq %r15, %rsi
xorl %eax, %eax
callq 0x2050
xorl %edi, %edi
callq 0x21d0