// File: /workspace/github_cpp_makefile_star2_O2/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 $0x88, %rsp
movq %rsi, %rbx
leaq 0xeedc(%rip), %rsi      # 0x24aa8
callq 0x2027c
movq %rax, %r14
leaq 0x121e3(%rip), %r15     # 0x27dbe
xorl %r12d, %r12d
movq 0x8(%rbx), %rax
subq (%rbx), %rax
shrq $0x3, %rax
cltq
cmpq %rax, %r12
jge 0x15ea1
movq %rbx, %rdi
movq %r12, %rsi
callq 0x7404
movq (%rax), %rax
cmpq $0x0, 0x18(%rax)
je 0x15c3f
movq %rbx, %rdi
movq %r12, %rsi
callq 0x7404
movq (%rax), %rax
movq 0x18(%rax), %rax
cmpb $0x2e, (%rax)
jne 0x15c26
cmpb $0x0, 0x1(%rax)
je 0x15c3f
movq %rbx, %rdi
movq %r12, %rsi
callq 0x7404
movq (%rax), %rax
movq 0x18(%rax), %rax
movq %rax, 0x8(%rsp)
jmp 0x15c5d
leaq 0x20(%rsp), %r13
movq %r13, %rdi
leaq 0x12150(%rip), %rsi     # 0x27d9e
movl %r12d, %edx
xorl %eax, %eax
callq 0x2080
movq %r13, 0x8(%rsp)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x7404
movq (%rax), %rax
cmpq $0x0, 0x30(%rax)
jne 0x15cd1
pushq $0x18
popq %rdi
callq 0x2170
movq %rax, %r13
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
andq $0x0, 0x10(%rax)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x7404
movq (%rax), %rax
movq %r13, 0x30(%rax)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x7404
movq (%rax), %rax
movq 0x30(%rax), %r13
movq %rbx, %rdi
movq %r12, %rsi
callq 0x7404
movq (%rax), %rdi
callq 0x134b2
movq %rax, 0x18(%rsp)
movq %r13, %rdi
leaq 0x18(%rsp), %rsi
callq 0xd00a
movq %rbx, %rdi
movq %r12, %rsi
callq 0x7404
movq (%rax), %rax
movq (%rax), %rax
movq %rax, 0x10(%rsp)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x7404
movq (%rax), %rax
movsbl 0x8(%rax), %eax
movl %eax, 0x4(%rsp)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x7404
movq (%rax), %rax
movl 0xc(%rax), %ebp
decl %ebp
movq %rbx, %rdi
movq %r12, %rsi
callq 0x7404
movq (%rax), %rax
movl 0x20(%rax), %r13d
movq %rbx, %rdi
movq %r12, %rsi
callq 0x7404
movq (%rax), %rax
movq 0x30(%rax), %rax
movq 0x8(%rax), %r10
subq (%rax), %r10
sarq $0x3, %r10
movq %r14, %rdi
leaq 0x12061(%rip), %rsi     # 0x27daa
movq 0x8(%rsp), %rdx
movq 0x10(%rsp), %rcx
movl 0x4(%rsp), %r8d
movl %ebp, %r9d
xorl %eax, %eax
pushq %r10
pushq %r13
callq 0x2240
addq $0x10, %rsp
movq %rbx, %rdi
movq %r12, %rsi
callq 0x7404
movq (%rax), %rax
movq 0x30(%rax), %rdi
xorl %esi, %esi
callq 0x7404
movq (%rax), %rax
movl 0xc(%rax), %edx
decl %edx
movq %r14, %rdi
leaq 0xecd5(%rip), %rbp      # 0x24a6a
movq %rbp, %rsi
xorl %eax, %eax
callq 0x2240
pushq $0x1
popq %r13
movq %rbx, %rdi
movq %r12, %rsi
callq 0x7404
movq (%rax), %rax
movq 0x30(%rax), %rax
movq 0x8(%rax), %rcx
subq (%rax), %rcx
shrq $0x3, %rcx
movslq %ecx, %rax
cmpq %rax, %r13
jge 0x15dfc
movq %rbx, %rdi
movq %r12, %rsi
callq 0x7404
movq (%rax), %rax
movq 0x30(%rax), %rdi
movq %r13, %rsi
callq 0x7404
movq (%rax), %rax
movl 0xc(%rax), %edx
decl %edx
movq %r14, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x2240
incq %r13
jmp 0x15da3
pushq $0x9
popq %rdi
movq %r14, %rsi
callq 0x2200
movq %rbx, %rdi
movq %r12, %rsi
callq 0x7404
movq (%rax), %rax
movq 0x30(%rax), %rdi
xorl %esi, %esi
callq 0x7404
movq (%rax), %rax
movl 0x20(%rax), %edx
movq %r14, %rdi
movq %rbp, %rsi
xorl %eax, %eax
callq 0x2240
pushq $0x1
popq %r13
movq %rbx, %rdi
movq %r12, %rsi
callq 0x7404
movq (%rax), %rax
movq 0x30(%rax), %rax
movq 0x8(%rax), %rcx
subq (%rax), %rcx
shrq $0x3, %rcx
movslq %ecx, %rax
cmpq %rax, %r13
jge 0x15e8e
movq %rbx, %rdi
movq %r12, %rsi
callq 0x7404
movq (%rax), %rax
movq 0x30(%rax), %rdi
movq %r13, %rsi
callq 0x7404
movq (%rax), %rax
movl 0x20(%rax), %edx
movq %r14, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x2240
incq %r13
jmp 0x15e37
pushq $0xa
popq %rdi
movq %r14, %rsi
callq 0x2200
incq %r12
jmp 0x15bde
movq %r14, %rdi
callq 0x2160
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq