// File: gersteinlab[P]MUSIC/src/ms_annot_region_tools.cpp
// Function: dump_GFF_per_region_intervals(std::vector<t_annot_region*, std::allocator<t_annot_region*>>*, char*, char*, char*, char*)
void dump_GFF_per_region_intervals(vector<t_annot_region*>* regions, char* gff_fp, char* source_name, char* interval_parent_feature_str, char* interval_child_feature_str)
{
	FILE* f_gff = open_f(gff_fp, "w");
	for(int i_reg = 0; i_reg < (int)regions->size(); i_reg++)
	{
		char cur_transcript_name[1000];
		if(regions->at(i_reg)->name == NULL ||
			strcmp(regions->at(i_reg)->name, ".") == 0)
		{
			sprintf(cur_transcript_name, "transcript_%d", i_reg);
		}
		else
		{
			sprintf(cur_transcript_name, "%s", regions->at(i_reg)->name);
		}

		if(interval_parent_feature_str != NULL)
		{
			fprintf(f_gff, "%s\t%s\t%s\t%d\t%d\t.\t%c\t.\t%s\n", regions->at(i_reg)->chrom, source_name, interval_parent_feature_str, 
				regions->at(i_reg)->start, regions->at(i_reg)->end, regions->at(i_reg)->strand, cur_transcript_name);
		}

		vector<t_annot_region*>* exons = regions->at(i_reg)->intervals;

		for(int i_int = 0; i_int < (int)exons->size(); i_int++)
		{
			fprintf(f_gff, "%s\t%s\t%s\t%d\t%d\t.\t%c\t.\t%s\n", exons->at(i_int)->chrom, source_name, interval_child_feature_str,
				exons->at(i_int)->start, exons->at(i_int)->end, exons->at(i_int)->strand, cur_transcript_name);
		} // i_int loop.
	} // i_reg loop.
	fclose(f_gff);
}

// Assembly:
subq $0x4b8, %rsp            # imm = 0x4B8
movq %rdi, 0x4b0(%rsp)
movq %rsi, 0x4a8(%rsp)
movq %rdx, 0x4a0(%rsp)
movq %rcx, 0x498(%rsp)
movq %r8, 0x490(%rsp)
movq 0x4a8(%rsp), %rdi
leaq 0x284f6(%rip), %rsi     # 0x52aa4
callq 0x455f0
movq %rax, 0x488(%rsp)
movl $0x0, 0x484(%rsp)
movl 0x484(%rsp), %eax
movl %eax, 0x80(%rsp)
movq 0x4b0(%rsp), %rdi
callq 0xc680
movq %rax, %rcx
movl 0x80(%rsp), %eax
cmpl %ecx, %eax
jge 0x2a8f5
movq 0x4b0(%rsp), %rdi
movslq 0x484(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
cmpq $0x0, 0x18(%rax)
je 0x2a63f
movq 0x4b0(%rsp), %rdi
movslq 0x484(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movq 0x18(%rax), %rdi
leaq 0x2a92f(%rip), %rsi     # 0x54f64
callq 0x2240
cmpl $0x0, %eax
jne 0x2a65e
leaq 0x90(%rsp), %rdi
movl 0x484(%rsp), %edx
leaq 0x2b704(%rip), %rsi     # 0x55d59
movb $0x0, %al
callq 0x2090
jmp 0x2a69a
leaq 0x90(%rsp), %rax
movq %rax, 0x78(%rsp)
movq 0x4b0(%rsp), %rdi
movslq 0x484(%rsp), %rsi
callq 0xc800
movq 0x78(%rsp), %rdi
movq (%rax), %rax
movq 0x18(%rax), %rdx
leaq 0x2b26b(%rip), %rsi     # 0x558fe
movb $0x0, %al
callq 0x2090
cmpq $0x0, 0x498(%rsp)
je 0x2a78d
movq 0x488(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x4b0(%rsp), %rdi
movslq 0x484(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movq (%rax), %rax
movq %rax, 0x58(%rsp)
movq 0x4a0(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x498(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x4b0(%rsp), %rdi
movslq 0x484(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movl 0xc(%rax), %eax
movl %eax, 0x70(%rsp)
movq 0x4b0(%rsp), %rdi
movslq 0x484(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movl 0x20(%rax), %eax
movl %eax, 0x74(%rsp)
movq 0x4b0(%rsp), %rdi
movslq 0x484(%rsp), %rsi
callq 0xc800
movq 0x50(%rsp), %rdi
movq 0x58(%rsp), %rdx
movq 0x60(%rsp), %rcx
movq 0x68(%rsp), %r8
movl 0x70(%rsp), %r9d
movl 0x74(%rsp), %r11d
movq (%rax), %rax
movsbl 0x8(%rax), %r10d
leaq 0x90(%rsp), %rax
leaq 0x2b5ef(%rip), %rsi     # 0x55d67
movl %r11d, (%rsp)
movl %r10d, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movb $0x0, %al
callq 0x2250
movq 0x4b0(%rsp), %rdi
movslq 0x484(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movq 0x30(%rax), %rax
movq %rax, 0x88(%rsp)
movl $0x0, 0x84(%rsp)
movl 0x84(%rsp), %eax
movl %eax, 0x4c(%rsp)
movq 0x88(%rsp), %rdi
callq 0xc680
movq %rax, %rcx
movl 0x4c(%rsp), %eax
cmpl %ecx, %eax
jge 0x2a8dd
movq 0x488(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x88(%rsp), %rdi
movslq 0x84(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movq (%rax), %rax
movq %rax, 0x28(%rsp)
movq 0x4a0(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x490(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x88(%rsp), %rdi
movslq 0x84(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movl 0xc(%rax), %eax
movl %eax, 0x44(%rsp)
movq 0x88(%rsp), %rdi
movslq 0x84(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movl 0x20(%rax), %eax
movl %eax, 0x48(%rsp)
movq 0x88(%rsp), %rdi
movslq 0x84(%rsp), %rsi
callq 0xc800
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rdx
movq 0x30(%rsp), %rcx
movq 0x38(%rsp), %r8
movl 0x44(%rsp), %r9d
movl 0x48(%rsp), %r11d
movq (%rax), %rax
movsbl 0x8(%rax), %r10d
leaq 0x90(%rsp), %rax
leaq 0x2b4b5(%rip), %rsi     # 0x55d67
movl %r11d, (%rsp)
movl %r10d, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movb $0x0, %al
callq 0x2250
movl 0x84(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x84(%rsp)
jmp 0x2a7bc
jmp 0x2a8df
movl 0x484(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x484(%rsp)
jmp 0x2a5c6
movq 0x488(%rsp), %rdi
callq 0x2180
addq $0x4b8, %rsp            # imm = 0x4B8
retq
nopw (%rax,%rax)