// File: gersteinlab[P]MUSIC/src/ms_annot_region_tools.cpp
// Function: dump_Interval(char*, std::vector<t_annot_region*, std::allocator<t_annot_region*>>*)
void dump_Interval(char* interval_fp, vector<t_annot_region*>* annot_regions)
{
	FILE* f_Interval = open_f(interval_fp, "w");

//00021   tars = readTarsFromBedFile ("-");
//00022   for (i = 0; i < arrayMax (tars); i++) {
//00023     currTar = arrp (tars,i,Tar);
//00024     printf ("BED_%d\t%s\t.\t%d\t%d\t1\t%d\t%d\n",
//00025             i + 1,
					//currTar->targetName,
					//currTar->start,
					//currTar->end,
					//currTar->start,
					//currTar->end);
//00026   }
//00027   return 0;
//00028 }

	for(int i_reg = 0; i_reg < (int)annot_regions->size(); i_reg++)
	{
/*
1.   Name of the interval
2.   Chromosome 
3.   Strand
4.   Interval start (with respect to the "+")
5.   Interval end (with respect to the "+")
6.   Number of sub-intervals
7.   Sub-interval starts (with respect to the "+", comma-delimited)
8.   Sub-interval end (with respect to the "+", comma-delimited) 
*/
		char default_name_buffer[100];
		char* cur_int_name = NULL;
		if(annot_regions->at(i_reg)->name == NULL ||
			strcmp(annot_regions->at(i_reg)->name, ".") == 0)
		{
			sprintf(default_name_buffer, "Interval_%d", i_reg);
			cur_int_name = default_name_buffer;
		}
		else
		{
			cur_int_name = annot_regions->at(i_reg)->name;
		}

		// There needs to be interval information, if there is not, add it.
		if(annot_regions->at(i_reg)->intervals == NULL)
		{
			annot_regions->at(i_reg)->intervals = new vector<t_annot_region*>();
			annot_regions->at(i_reg)->intervals->push_back(duplicate_region(annot_regions->at(i_reg)));
		}

		//fprintf(f_Interval, "Interval_%d\t%s\t%c\t%d\t%d\t%d\t", 
		fprintf(f_Interval, "%s\t%s\t%c\t%d\t%d\t%ld\t", 
			cur_int_name, 
			annot_regions->at(i_reg)->chrom, 
			annot_regions->at(i_reg)->strand,
			translate_coord(annot_regions->at(i_reg)->start, CODEBASE_COORDS::start_base, INTERVAL_COORDS::start_base),
			translate_coord(annot_regions->at(i_reg)->end, CODEBASE_COORDS::end_base, INTERVAL_COORDS::end_base),
			annot_regions->at(i_reg)->intervals->size());

		int i_e = 0;
		fprintf(f_Interval, "%d", 
			translate_coord(annot_regions->at(i_reg)->intervals->at(i_e)->start, CODEBASE_COORDS::start_base, INTERVAL_COORDS::start_base));
		for(i_e = 1; i_e < (int)annot_regions->at(i_reg)->intervals->size(); i_e++)
		{
			fprintf(f_Interval, ",%d", 
				translate_coord(annot_regions->at(i_reg)->intervals->at(i_e)->start, CODEBASE_COORDS::start_base, INTERVAL_COORDS::start_base));
		} // i_e loop.

		fprintf(f_Interval, "\t");

		i_e = 0;
		fprintf(f_Interval, "%d", 
			translate_coord(annot_regions->at(i_reg)->intervals->at(i_e)->end, CODEBASE_COORDS::end_base, INTERVAL_COORDS::end_base));
		for(i_e = 1; i_e < (int)annot_regions->at(i_reg)->intervals->size(); i_e++)
		{
			//fprintf(f_Interval, ",%d", annot_regions->at(i_reg)->intervals->at(i_e)->end);
			fprintf(f_Interval, ",%d", 
				translate_coord(annot_regions->at(i_reg)->intervals->at(i_e)->end, CODEBASE_COORDS::end_base, INTERVAL_COORDS::end_base));
		} // i_e loop.

		fprintf(f_Interval, "\n");
	} // i_reg loop.

	fclose(f_Interval);
}

// Assembly:
subq $0x118, %rsp            # imm = 0x118
movq %rdi, 0x110(%rsp)
movq %rsi, 0x108(%rsp)
movq 0x110(%rsp), %rdi
leaq 0x247ce(%rip), %rsi     # 0x52aa4
callq 0x455f0
movq %rax, 0x100(%rsp)
movl $0x0, 0xfc(%rsp)
movl 0xfc(%rsp), %eax
movl %eax, 0x78(%rsp)
movq 0x108(%rsp), %rdi
callq 0xc680
movq %rax, %rcx
movl 0x78(%rsp), %eax
cmpl %ecx, %eax
jge 0x2e7dc
movq $0x0, 0x88(%rsp)
movq 0x108(%rsp), %rdi
movslq 0xfc(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
cmpq $0x0, 0x18(%rax)
je 0x2e36d
movq 0x108(%rsp), %rdi
movslq 0xfc(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movq 0x18(%rax), %rdi
leaq 0x26c01(%rip), %rsi     # 0x54f64
callq 0x2240
cmpl $0x0, %eax
jne 0x2e39c
leaq 0x90(%rsp), %rdi
movl 0xfc(%rsp), %edx
leaq 0x27e23(%rip), %rsi     # 0x561a6
movb $0x0, %al
callq 0x2090
leaq 0x90(%rsp), %rax
movq %rax, 0x88(%rsp)
jmp 0x2e3c0
movq 0x108(%rsp), %rdi
movslq 0xfc(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movq 0x18(%rax), %rax
movq %rax, 0x88(%rsp)
movq 0x108(%rsp), %rdi
movslq 0xfc(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
cmpq $0x0, 0x30(%rax)
jne 0x2e484
movl $0x18, %edi
callq 0x2190
movq %rax, %rdi
movq %rdi, 0x68(%rsp)
xorl %esi, %esi
movl $0x18, %edx
callq 0x2110
movq 0x68(%rsp), %rdi
callq 0xc670
movq 0x108(%rsp), %rdi
movslq 0xfc(%rsp), %rsi
callq 0xc800
movq 0x68(%rsp), %rcx
movq (%rax), %rax
movq %rcx, 0x30(%rax)
movq 0x108(%rsp), %rdi
movslq 0xfc(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movq 0x30(%rax), %rax
movq %rax, 0x70(%rsp)
movq 0x108(%rsp), %rdi
movslq 0xfc(%rsp), %rsi
callq 0xc800
movq (%rax), %rdi
callq 0x2a410
movq 0x70(%rsp), %rdi
movq %rax, 0x80(%rsp)
leaq 0x80(%rsp), %rsi
callq 0x1acc0
movq 0x100(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x88(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x108(%rsp), %rdi
movslq 0xfc(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movq (%rax), %rax
movq %rax, 0x48(%rsp)
movq 0x108(%rsp), %rdi
movslq 0xfc(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movsbl 0x8(%rax), %eax
movl %eax, 0x54(%rsp)
movq 0x108(%rsp), %rdi
movslq 0xfc(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movl 0xc(%rax), %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x1fd20
movl %eax, 0x58(%rsp)
movq 0x108(%rsp), %rdi
movslq 0xfc(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movl 0x20(%rax), %edi
movl $0x1, %edx
movl %edx, %esi
callq 0x1fd20
movl %eax, 0x5c(%rsp)
movq 0x108(%rsp), %rdi
movslq 0xfc(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movq 0x30(%rax), %rdi
callq 0xc680
movq 0x38(%rsp), %rdi
movq 0x40(%rsp), %rdx
movq 0x48(%rsp), %rcx
movl 0x54(%rsp), %r8d
movl 0x58(%rsp), %r9d
movl 0x5c(%rsp), %r10d
leaq 0x27c38(%rip), %rsi     # 0x561b2
movl %r10d, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0x2250
movl $0x0, 0x7c(%rsp)
movq 0x100(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x108(%rsp), %rdi
movslq 0xfc(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movq 0x30(%rax), %rdi
movslq 0x7c(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movl 0xc(%rax), %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x1fd20
movq 0x60(%rsp), %rdi
movl %eax, %edx
leaq 0x24481(%rip), %rsi     # 0x52a66
movb $0x0, %al
callq 0x2250
movl $0x1, 0x7c(%rsp)
movl 0x7c(%rsp), %eax
movl %eax, 0x34(%rsp)
movq 0x108(%rsp), %rdi
movslq 0xfc(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movq 0x30(%rax), %rdi
callq 0xc680
movq %rax, %rcx
movl 0x34(%rsp), %eax
cmpl %ecx, %eax
jge 0x2e692
movq 0x100(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x108(%rsp), %rdi
movslq 0xfc(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movq 0x30(%rax), %rdi
movslq 0x7c(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movl 0xc(%rax), %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x1fd20
movq 0x28(%rsp), %rdi
movl %eax, %edx
leaq 0x27b4b(%rip), %rsi     # 0x561c6
movb $0x0, %al
callq 0x2250
movl 0x7c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x7c(%rsp)
jmp 0x2e5f4
movq 0x100(%rsp), %rdi
leaq 0x27b23(%rip), %rsi     # 0x561c4
movb $0x0, %al
callq 0x2250
movl $0x0, 0x7c(%rsp)
movq 0x100(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x108(%rsp), %rdi
movslq 0xfc(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movq 0x30(%rax), %rdi
movslq 0x7c(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movl 0x20(%rax), %edi
movl $0x1, %edx
movl %edx, %esi
callq 0x1fd20
movq 0x20(%rsp), %rdi
movl %eax, %edx
leaq 0x24363(%rip), %rsi     # 0x52a66
movb $0x0, %al
callq 0x2250
movl $0x1, 0x7c(%rsp)
movl 0x7c(%rsp), %eax
movl %eax, 0x1c(%rsp)
movq 0x108(%rsp), %rdi
movslq 0xfc(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movq 0x30(%rax), %rdi
callq 0xc680
movq %rax, %rcx
movl 0x1c(%rsp), %eax
cmpl %ecx, %eax
jge 0x2e7b0
movq 0x100(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x108(%rsp), %rdi
movslq 0xfc(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movq 0x30(%rax), %rdi
movslq 0x7c(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movl 0x20(%rax), %edi
movl $0x1, %edx
movl %edx, %esi
callq 0x1fd20
movq 0x10(%rsp), %rdi
movl %eax, %edx
leaq 0x27a2d(%rip), %rsi     # 0x561c6
movb $0x0, %al
callq 0x2250
movl 0x7c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x7c(%rsp)
jmp 0x2e712
movq 0x100(%rsp), %rdi
leaq 0x23c0f(%rip), %rsi     # 0x523ce
movb $0x0, %al
callq 0x2250
movl 0xfc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xfc(%rsp)
jmp 0x2e2ee
movq 0x100(%rsp), %rdi
callq 0x2180
addq $0x118, %rsp            # imm = 0x118
retq
nopw %cs:(%rax,%rax)