// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
leaq 0x1244f(%rip), %rsi     # 0x24aa8
callq 0x2027c
movq %rax, 0x10(%rsp)
xorl %ebp, %ebp
movq 0x8(%rbx), %rax
subq (%rbx), %rax
shrq $0x3, %rax
cltq
cmpq %rax, %rbp
jge 0x127c9
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x7404
movq (%rax), %rax
cmpb $0x2d, 0x8(%rax)
je 0x126a7
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x7404
movq (%rax), %rax
cmpb $0x2b, 0x8(%rax)
jne 0x12770
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x7404
movq (%rax), %rax
cmpq $0x0, 0x18(%rax)
jne 0x126f0
pushq $0x5
popq %rdi
callq 0x2040
movq %rax, %r15
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x7404
movq (%rax), %rax
movq %r15, 0x18(%rax)
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x7404
movq (%rax), %rax
movq 0x18(%rax), %rax
movw $0x2e, (%rax)
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x7404
movq (%rax), %rax
movq (%rax), %r13
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x7404
movq (%rax), %rax
movl 0xc(%rax), %r15d
decl %r15d
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x7404
movq (%rax), %rax
movl 0x20(%rax), %r12d
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x7404
movq (%rax), %rax
movq 0x18(%rax), %r14
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x7404
movq (%rax), %rax
movsbl 0x8(%rax), %eax
movl %eax, (%rsp)
movq 0x10(%rsp), %rdi
leaq 0x15195(%rip), %rsi     # 0x278f0
movq %r13, %rdx
movl %r15d, %ecx
movl %r12d, %r8d
movq %r14, %r9
xorl %eax, %eax
callq 0x2240
jmp 0x127c1
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x7404
movq (%rax), %rax
movq (%rax), %r14
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x7404
movq (%rax), %rax
movl 0xc(%rax), %r15d
decl %r15d
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x7404
movq (%rax), %rax
movl 0x20(%rax), %r8d
movq 0x10(%rsp), %rdi
leaq 0x1514e(%rip), %rsi     # 0x27902
movq %r14, %rdx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x2240
incq %rbp
jmp 0x12665
movq 0x10(%rsp), %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2160