// File: 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:
subq $0xd8, %rsp
movq %rdi, 0xd0(%rsp)
movl $0x18, %edi
callq 0x2190
movq %rax, %rdi
movq %rdi, 0x18(%rsp)
xorl %esi, %esi
movl $0x18, %edx
callq 0x2110
movq 0x18(%rsp), %rdi
callq 0xc670
movq 0x18(%rsp), %rax
movq %rax, 0xc8(%rsp)
movq 0xd0(%rsp), %rdi
leaq 0x2882b(%rip), %rsi     # 0x550ce
callq 0x455f0
movq %rax, 0xc0(%rsp)
movq 0xc0(%rsp), %rdi
callq 0x45400
movq %rax, 0xb8(%rsp)
cmpq $0x0, 0xb8(%rsp)
je 0x2caa6
movq 0xb8(%rsp), %rdi
callq 0x2b460
andb $0x1, %al
movb %al, 0xb7(%rsp)
testb $0x1, 0xb7(%rsp)
jne 0x2ca6f
movq 0xb8(%rsp), %rdi
leaq 0x40(%rsp), %rdx
leaq 0x296ab(%rip), %rsi     # 0x55fb7
leaq 0xb0(%rsp), %rcx
leaq 0xac(%rsp), %r8
movb $0x0, %al
callq 0x2170
cmpl $0x3, %eax
je 0x2c945
movq 0xb8(%rsp), %rsi
leaq 0x29689(%rip), %rdi     # 0x55fc0
movb $0x0, %al
callq 0x2050
xorl %edi, %edi
callq 0x21f0
movb $0x2b, 0x3f(%rsp)
movq 0xb8(%rsp), %rdi
leaq 0x35(%rsp), %rdx
leaq 0x2969e(%rip), %rsi     # 0x55ffc
movb $0x0, %al
callq 0x2170
cmpl $0x1, %eax
je 0x2c971
movb $0x2b, 0x3f(%rsp)
jmp 0x2c98f
movsbl 0x35(%rsp), %eax
cmpl $0x2d, %eax
je 0x2c985
movsbl 0x35(%rsp), %eax
cmpl $0x2b, %eax
jne 0x2c98d
movb 0x35(%rsp), %al
movb %al, 0x3f(%rsp)
jmp 0x2c98f
movq 0xb8(%rsp), %rdi
callq 0x20e0
movq %rax, %rdi
addq $0x2, %rdi
callq 0x2040
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rdi
movq 0xb8(%rsp), %rsi
callq 0x2160
movl $0x50, %edi
callq 0x2190
movq %rax, %rdi
movq %rdi, 0x10(%rsp)
xorl %esi, %esi
movl $0x50, %edx
callq 0x2110
movq 0x10(%rsp), %rax
movq %rax, 0x20(%rsp)
movl 0xb0(%rsp), %edi
xorl %esi, %esi
movl $0x1, %edx
callq 0x1fd20
movl %eax, %ecx
movq 0x20(%rsp), %rax
movl %ecx, 0xc(%rax)
movl 0xac(%rsp), %edi
movl $0x1, %edx
movl %edx, %esi
callq 0x1fd20
movl %eax, %ecx
movq 0x20(%rsp), %rax
movl %ecx, 0x20(%rax)
leaq 0x40(%rsp), %rdi
callq 0x47b60
movq %rax, %rcx
movq 0x20(%rsp), %rax
movq %rcx, (%rax)
movq 0x20(%rsp), %rax
movq (%rax), %rdi
callq 0x22350
movb 0x3f(%rsp), %cl
movq 0x20(%rsp), %rax
movb %cl, 0x8(%rax)
movq 0x28(%rsp), %rcx
movq 0x20(%rsp), %rax
movq %rcx, 0x48(%rax)
movq 0xc8(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0xc8c0
movq 0xb8(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x2ca8c
movq 0x8(%rsp), %rdi
callq 0x2220
movq 0xc0(%rsp), %rdi
callq 0x45400
movq %rax, 0xb8(%rsp)
jmp 0x2c8c5
movq 0xc0(%rsp), %rdi
callq 0x2180
movq 0xc8(%rsp), %rax
addq $0xd8, %rsp
retq
nopw %cs:(%rax,%rax)