// File: /workspace/github_cpp_makefile_star2_O1/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
movl $0x18, %edi
callq 0x2180
movq %rax, %rbx
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
leaq 0x14e40(%rip), %rsi     # 0x2dd08
movq %r14, %rdi
callq 0x26387
movq %rax, %r14
movq %rax, %rdi
callq 0x26258
testq %rax, %rax
je 0x19007
movq %rax, %r15
leaq 0x20(%rsp), %r13
movq %r15, %rdi
callq 0x17dac
testb %al, %al
jne 0x18feb
movq %r15, %rdi
leaq 0x15cf1(%rip), %rsi     # 0x2ebf7
movq %r13, %rdx
leaq 0x10(%rsp), %rcx
leaq 0xc(%rsp), %r8
xorl %eax, %eax
callq 0x2160
cmpl $0x3, %eax
jne 0x19024
movq %r15, %rdi
leaq 0x15d0f(%rip), %rsi     # 0x2ec3c
leaq 0x16(%rsp), %rdx
xorl %eax, %eax
callq 0x2160
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 0x2150
movl $0x50, %edi
callq 0x2180
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 0x273e0
movq (%rsp), %rcx
movq %rax, (%rcx)
movq (%rsp), %rax
movq (%rax), %rdi
callq 0x12f1c
movq (%rsp), %rax
movb %r12b, 0x8(%rax)
movq %rbp, 0x48(%rax)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x18fe0
movq %rax, (%rsi)
addq $0x8, 0x8(%rbx)
jmp 0x18feb
movq %rbx, %rdi
movq %rsp, %rdx
callq 0xb976
movq %r15, %rdi
callq 0x2220
movq %r14, %rdi
callq 0x26258
movq %rax, %r15
testq %rax, %rax
jne 0x18eec
movq %r14, %rdi
callq 0x2170
movq %rbx, %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x15bd5(%rip), %rdi     # 0x2ec00
movq %r15, %rsi
xorl %eax, %eax
callq 0x2050
xorl %edi, %edi
callq 0x21e0