// File: /workspace/github_cpp_makefile_star2_O1/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rsi, %r14
leaq 0x119c8(%rip), %rsi     # 0x2baae
callq 0x26387
movq %rax, %r15
movq (%r14), %rax
movq 0x8(%r14), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
testl %edx, %edx
jle 0x1a3c9
leaq 0x14cb3(%rip), %rbp     # 0x2edbe
xorl %ebx, %ebx
cmpq %rbx, %rdx
jbe 0x1a3e0
movq (%rax,%rbx,8), %rax
movq 0x18(%rax), %r13
testq %r13, %r13
je 0x1a136
movq %r13, %rdi
leaq 0x13a71(%rip), %rsi     # 0x2db9e
callq 0x2240
testl %eax, %eax
jne 0x1a14e
leaq 0x10(%rsp), %r13
movq %r13, %rdi
leaq 0x14c59(%rip), %rsi     # 0x2ed9e
movl %ebx, %edx
xorl %eax, %eax
callq 0x2080
movq (%r14), %r12
movq 0x8(%r14), %rdx
subq %r12, %rdx
sarq $0x3, %rdx
cmpq %rbx, %rdx
jbe 0x1a3e0
movq (%r12,%rbx,8), %rax
cmpq $0x0, 0x30(%rax)
jne 0x1a1b8
movl $0x18, %edi
callq 0x2180
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
movq (%r12,%rbx,8), %rcx
movq %rax, 0x30(%rcx)
movq (%r12,%rbx,8), %rax
movq 0x30(%rax), %rax
movq %rax, (%rsp)
movq (%r12,%rbx,8), %rdi
callq 0x172ac
movq %rax, 0x8(%rsp)
movq (%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x10b7e
movq (%r14), %rax
movq 0x8(%r14), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpq %rbx, %rdx
jbe 0x1a3e0
movq (%rax,%rbx,8), %rax
movq (%rax), %rcx
movsbl 0x8(%rax), %r8d
movl 0xc(%rax), %r9d
decl %r9d
movl 0x20(%rax), %r10d
movq 0x30(%rax), %rax
movq 0x8(%rax), %r11
subq (%rax), %r11
sarq $0x3, %r11
movq %r15, %rdi
leaq 0x14bab(%rip), %rsi     # 0x2edaa
movq %r13, %rdx
xorl %eax, %eax
pushq %r11
pushq %r10
callq 0x2250
addq $0x10, %rsp
movq (%r14), %rax
movq 0x8(%r14), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpq %rbx, %rdx
leaq 0x11847(%rip), %r12     # 0x2ba70
jbe 0x1a3e0
movq (%rax,%rbx,8), %rax
movq 0x30(%rax), %rcx
movq (%rcx), %rax
cmpq %rax, 0x8(%rcx)
je 0x1a3fd
movq (%rax), %rax
movl 0xc(%rax), %edx
decl %edx
movq %r15, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0x2250
movq (%r14), %rax
movq 0x8(%r14), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpq %rbx, %rdx
jbe 0x1a3e0
movl $0x1, %r13d
movq (%rax,%rbx,8), %rax
movq 0x30(%rax), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rdx
subq %rax, %rdx
movq %rdx, %rcx
shrq $0x3, %rcx
movslq %ecx, %rcx
cmpq %rcx, %r13
jge 0x1a2d5
sarq $0x3, %rdx
cmpq %r13, %rdx
jbe 0x1a3ec
movq (%rax,%r13,8), %rax
movl 0xc(%rax), %edx
decl %edx
movq %r15, %rdi
movq %rbp, %rsi
xorl %eax, %eax
callq 0x2250
incq %r13
movq (%r14), %rax
movq 0x8(%r14), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpq %rbx, %rdx
ja 0x1a276
jmp 0x1a3e0
movl $0x9, %edi
movq %r15, %rsi
callq 0x2210
movq (%r14), %rax
movq 0x8(%r14), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpq %rbx, %rdx
jbe 0x1a3e0
movq (%rax,%rbx,8), %rax
movq 0x30(%rax), %rcx
movq (%rcx), %rax
cmpq %rax, 0x8(%rcx)
je 0x1a3fd
movq (%rax), %rax
movl 0x20(%rax), %edx
movq %r15, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0x2250
movq (%r14), %rax
movq 0x8(%r14), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpq %rbx, %rdx
jbe 0x1a3e0
movl $0x1, %r13d
movq (%rax,%rbx,8), %rax
movq 0x30(%rax), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rdx
subq %rax, %rdx
movq %rdx, %rcx
shrq $0x3, %rcx
movslq %ecx, %rcx
cmpq %rcx, %r13
jge 0x1a398
sarq $0x3, %rdx
cmpq %r13, %rdx
jbe 0x1a3ec
movq (%rax,%r13,8), %rax
movl 0x20(%rax), %edx
movq %r15, %rdi
movq %rbp, %rsi
xorl %eax, %eax
callq 0x2250
incq %r13
movq (%r14), %rax
movq 0x8(%r14), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpq %rbx, %rdx
ja 0x1a33e
jmp 0x1a3e0
movl $0xa, %edi
movq %r15, %rsi
callq 0x2210
incq %rbx
movq (%r14), %rax
movq 0x8(%r14), %rcx
subq %rax, %rcx
movq %rcx, %rdx
sarq $0x3, %rdx
shrq $0x3, %rcx
movslq %ecx, %rcx
cmpq %rcx, %rbx
jl 0x1a10d
movq %r15, %rdi
callq 0x2170
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x134ef(%rip), %rdi     # 0x2d8d6
movq %rbx, %rsi
jmp 0x1a3f6
leaq 0x134e3(%rip), %rdi     # 0x2d8d6
movq %r13, %rsi
xorl %eax, %eax
callq 0x2270
leaq 0x134d2(%rip), %rdi     # 0x2d8d6
xorl %esi, %esi
xorl %edx, %edx
jmp 0x1a3f6