// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x418, %rsp            # imm = 0x418
movq %r8, 0x28(%rsp)
movq %rcx, %r15
movq %rdx, 0x18(%rsp)
movq %rsi, %rax
movq %rdi, %r14
leaq 0x11516(%rip), %rsi     # 0x24aa8
movq %rax, %rdi
callq 0x2027c
movq %rax, %r13
xorl %r12d, %r12d
movq %r14, 0x8(%rsp)
movq %r15, 0x20(%rsp)
movq 0x8(%r14), %rax
subq (%r14), %rax
shrq $0x3, %rax
cltq
cmpq %rax, %r12
jge 0x13787
movq %r14, %rdi
movq %r12, %rsi
callq 0x7404
movq (%rax), %rax
cmpq $0x0, 0x18(%rax)
je 0x13610
movq %r14, %rdi
movq %r12, %rsi
callq 0x7404
movq (%rax), %rax
movq 0x18(%rax), %rax
cmpb $0x2e, (%rax)
jne 0x135f2
cmpb $0x0, 0x1(%rax)
je 0x13610
movq %r14, %rdi
movq %r12, %rsi
callq 0x7404
movq (%rax), %rax
movq 0x18(%rax), %rsi
leaq 0x30(%rsp), %rdi
callq 0x2140
jmp 0x13626
leaq 0x30(%rsp), %rdi
leaq 0x1437d(%rip), %rsi     # 0x27999
movl %r12d, %edx
xorl %eax, %eax
callq 0x2080
testq %r15, %r15
movq %r12, 0x10(%rsp)
je 0x136c0
movq %r14, %rdi
movq %r12, %rsi
callq 0x7404
movq (%rax), %rax
movq (%rax), %r14
movq 0x8(%rsp), %rdi
movq %r12, %rsi
callq 0x7404
movq (%rax), %rax
movl 0xc(%rax), %r12d
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x7404
movq (%rax), %rax
movl 0x20(%rax), %ebx
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x7404
movq (%rax), %rax
movsbl 0x8(%rax), %r10d
subq $0x8, %rsp
movq %r13, %rdi
leaq 0x14314(%rip), %rsi     # 0x279a7
movq %r14, %rdx
movq 0x10(%rsp), %r14
movq 0x20(%rsp), %rcx
movq %r15, %r8
movl %r12d, %r9d
movq 0x18(%rsp), %r12
xorl %eax, %eax
leaq 0x38(%rsp), %r11
pushq %r11
pushq %r10
pushq %rbx
callq 0x2240
addq $0x20, %rsp
movq %r14, %rdi
movq %r12, %rsi
callq 0x7404
movq (%rax), %rax
movq 0x30(%rax), %r12
xorl %r14d, %r14d
movq 0x8(%r12), %rax
subq (%r12), %rax
shrq $0x3, %rax
cltq
cmpq %rax, %r14
jge 0x13770
movq %r12, %rdi
movq %r14, %rsi
callq 0x7404
movq (%rax), %rax
movq (%rax), %rbp
movq %r12, %rdi
movq %r14, %rsi
callq 0x7404
movq (%rax), %rax
movl 0xc(%rax), %ebx
movq %r12, %rdi
movq %r14, %rsi
callq 0x7404
movq (%rax), %rax
movl 0x20(%rax), %r15d
movq %r12, %rdi
movq %r14, %rsi
callq 0x7404
movq (%rax), %rax
movsbl 0x8(%rax), %r10d
subq $0x8, %rsp
movq %r13, %rdi
leaq 0x14265(%rip), %rsi     # 0x279a7
movq %rbp, %rdx
movq 0x20(%rsp), %rcx
movq 0x30(%rsp), %r8
movl %ebx, %r9d
xorl %eax, %eax
leaq 0x38(%rsp), %r11
pushq %r11
pushq %r10
pushq %r15
callq 0x2240
addq $0x20, %rsp
incq %r14
jmp 0x136d5
movq 0x10(%rsp), %r12
incq %r12
movq 0x20(%rsp), %r15
movq 0x8(%rsp), %r14
jmp 0x135aa
movq %r13, %rdi
callq 0x2160
addq $0x418, %rsp            # imm = 0x418
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq