// File: gersteinlab[P]MUSIC/src/ms_annot_region_tools.cpp
// Function: dump_BED(char*, std::vector<t_annot_region*, std::allocator<t_annot_region*>>*)
void dump_BED(char* bed_fp, vector<t_annot_region*>* annot_regions)
{
	FILE* f_bed = open_f(bed_fp, "w");

	for(int i_reg = 0; i_reg < (int)annot_regions->size(); i_reg++)
	{
		if(annot_regions->at(i_reg)->strand == '-' ||
			annot_regions->at(i_reg)->strand == '+')
		{
			if(annot_regions->at(i_reg)->name == NULL)
			{
				annot_regions->at(i_reg)->name = new char[5];
				strcpy(annot_regions->at(i_reg)->name, ".");
			}

			// Translate the start and end to CODEBASE's start and end.
			fprintf(f_bed, "%s\t%d\t%d\t%s\t.\t%c\n", annot_regions->at(i_reg)->chrom, 
				translate_coord(annot_regions->at(i_reg)->start, CODEBASE_COORDS::start_base, BED_COORDS::start_base),
				translate_coord(annot_regions->at(i_reg)->end, CODEBASE_COORDS::end_base, BED_COORDS::end_base),
				annot_regions->at(i_reg)->name,
				annot_regions->at(i_reg)->strand);
		}
		else
		{
			fprintf(f_bed, "%s\t%d\t%d\n", annot_regions->at(i_reg)->chrom, 
				translate_coord(annot_regions->at(i_reg)->start, CODEBASE_COORDS::start_base, BED_COORDS::start_base),
				translate_coord(annot_regions->at(i_reg)->end, CODEBASE_COORDS::end_base, BED_COORDS::end_base));
		}
	} // i_ref loop.

	fclose(f_bed);
}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x60(%rsp)
movq %rsi, 0x58(%rsp)
movq 0x60(%rsp), %rdi
leaq 0x2a1ca(%rip), %rsi     # 0x52aa4
callq 0x455f0
movq %rax, 0x50(%rsp)
movl $0x0, 0x4c(%rsp)
movl 0x4c(%rsp), %eax
movl %eax, 0x48(%rsp)
movq 0x58(%rsp), %rdi
callq 0xc680
movq %rax, %rcx
movl 0x48(%rsp), %eax
cmpl %ecx, %eax
jge 0x28b14
movq 0x58(%rsp), %rdi
movslq 0x4c(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movsbl 0x8(%rax), %eax
cmpl $0x2d, %eax
je 0x28947
movq 0x58(%rsp), %rdi
movslq 0x4c(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movsbl 0x8(%rax), %eax
cmpl $0x2b, %eax
jne 0x28a79
movq 0x58(%rsp), %rdi
movslq 0x4c(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
cmpq $0x0, 0x18(%rax)
jne 0x289ac
movl $0x5, %edi
callq 0x2040
movq %rax, 0x40(%rsp)
movq 0x58(%rsp), %rdi
movslq 0x4c(%rsp), %rsi
callq 0xc800
movq 0x40(%rsp), %rcx
movq (%rax), %rax
movq %rcx, 0x18(%rax)
movq 0x58(%rsp), %rdi
movslq 0x4c(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movq 0x18(%rax), %rdi
leaq 0x2c5bd(%rip), %rsi     # 0x54f64
callq 0x2160
movq 0x50(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x58(%rsp), %rdi
movslq 0x4c(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movq (%rax), %rax
movq %rax, 0x28(%rsp)
movq 0x58(%rsp), %rdi
movslq 0x4c(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movl 0xc(%rax), %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x1fd20
movl %eax, 0x30(%rsp)
movq 0x58(%rsp), %rdi
movslq 0x4c(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movl 0x20(%rax), %edi
movl $0x1, %edx
movl %edx, %esi
callq 0x1fd20
movl %eax, 0x34(%rsp)
movq 0x58(%rsp), %rdi
movslq 0x4c(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movq 0x18(%rax), %rax
movq %rax, 0x38(%rsp)
movq 0x58(%rsp), %rdi
movslq 0x4c(%rsp), %rsi
callq 0xc800
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rdx
movl 0x30(%rsp), %ecx
movl 0x34(%rsp), %r8d
movq 0x38(%rsp), %r9
movq (%rax), %rax
movsbl 0x8(%rax), %eax
leaq 0x2d246(%rip), %rsi     # 0x55cb0
movl %eax, (%rsp)
movb $0x0, %al
callq 0x2250
jmp 0x28b02
movq 0x50(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x58(%rsp), %rdi
movslq 0x4c(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movq (%rax), %rax
movq %rax, 0x10(%rsp)
movq 0x58(%rsp), %rdi
movslq 0x4c(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movl 0xc(%rax), %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x1fd20
movl %eax, 0x1c(%rsp)
movq 0x58(%rsp), %rdi
movslq 0x4c(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movl 0x20(%rax), %edi
movl $0x1, %edx
movl %edx, %esi
callq 0x1fd20
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rdx
movl 0x1c(%rsp), %ecx
movl %eax, %r8d
leaq 0x2d1c7(%rip), %rsi     # 0x55cc2
movb $0x0, %al
callq 0x2250
jmp 0x28b04
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4c(%rsp)
jmp 0x288ec
movq 0x50(%rsp), %rdi
callq 0x2180
addq $0x68, %rsp
retq
nopw %cs:(%rax,%rax)