// File: /workspace/github_cpp_makefile_star2_O3/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 0x10dff(%rip), %rsi     # 0x2aaa8
callq 0x25d5a
movq %rax, %r15
movq (%r14), %r12
movq 0x8(%r14), %rdx
movq %rdx, %rax
subq %r12, %rax
sarq $0x3, %rax
testl %eax, %eax
jle 0x19f80
leaq 0x140ed(%rip), %r13     # 0x2ddbe
xorl %ebx, %ebx
cmpq %rbx, %rax
jbe 0x19fc1
movq (%r12,%rbx,8), %rax
movq 0x18(%rax), %rbp
testq %rbp, %rbp
je 0x19cf5
cmpb $0x2e, (%rbp)
jne 0x19d14
cmpb $0x0, 0x1(%rbp)
jne 0x19d14
leaq 0x10(%rsp), %rbp
movq %rbp, %rdi
leaq 0x1409a(%rip), %rsi     # 0x2dd9e
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 0x19f97
movq (%r12,%rbx,8), %rax
cmpq $0x0, 0x30(%rax)
jne 0x19d7c
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), %rdi
movq 0x30(%rdi), %r12
callq 0x16f1f
movq %rax, 0x8(%rsp)
movq %r12, %rdi
leaq 0x8(%rsp), %rsi
callq 0x108ac
movq (%r14), %r12
movq 0x8(%r14), %rdx
subq %r12, %rdx
sarq $0x3, %rdx
cmpq %rbx, %rdx
jbe 0x19f97
movq (%r12,%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 0x13ff5(%rip), %rsi     # 0x2ddaa
movq %rbp, %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
jbe 0x19f97
movq (%rax,%rbx,8), %rax
movq 0x30(%rax), %rcx
movq (%rcx), %rax
cmpq %rax, 0x8(%rcx)
leaq 0x10c76(%rip), %r12     # 0x2aa6a
je 0x19fb4
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 0x19f97
movl $0x1, %ebp
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, %rbp
jge 0x19e8a
sarq $0x3, %rdx
cmpq %rbp, %rdx
jbe 0x19fa3
movq (%rax,%rbp,8), %rax
movl 0xc(%rax), %edx
decl %edx
movq %r15, %rdi
movq %r13, %rsi
xorl %eax, %eax
callq 0x2250
incq %rbp
movq (%r14), %rax
movq 0x8(%r14), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpq %rbx, %rdx
ja 0x19e2b
jmp 0x19f97
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 0x19f97
movq (%rax,%rbx,8), %rax
movq 0x30(%rax), %rcx
movq (%rcx), %rax
cmpq %rax, 0x8(%rcx)
je 0x19fb4
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 0x19f97
movl $0x1, %ebp
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, %rbp
jge 0x19f4c
sarq $0x3, %rdx
cmpq %rbp, %rdx
jbe 0x19fa3
movq (%rax,%rbp,8), %rax
movl 0x20(%rax), %edx
movq %r15, %rdi
movq %r13, %rsi
xorl %eax, %eax
callq 0x2250
incq %rbp
movq (%r14), %rax
movq 0x8(%r14), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpq %rbx, %rdx
ja 0x19ef2
jmp 0x19f97
movl $0xa, %edi
movq %r15, %rsi
callq 0x2210
incq %rbx
movq (%r14), %r12
movq 0x8(%r14), %rdx
movq %rdx, %rcx
subq %r12, %rcx
movq %rcx, %rax
sarq $0x3, %rax
shrq $0x3, %rcx
movslq %ecx, %rcx
cmpq %rcx, %rbx
jl 0x19cd3
movq %r15, %rdi
callq 0x2170
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x12932(%rip), %rdi     # 0x2c8d0
movq %rbx, %rsi
jmp 0x19fad
leaq 0x12926(%rip), %rdi     # 0x2c8d0
movq %rbp, %rsi
xorl %eax, %eax
callq 0x2270
leaq 0x12915(%rip), %rdi     # 0x2c8d0
xorl %esi, %esi
xorl %edx, %edx
jmp 0x19fad
leaq 0x12908(%rip), %rdi     # 0x2c8d0
movq %rbx, %rsi
movq %rax, %rdx
jmp 0x19fad