// File: /workspace/github_cpp_makefile_star2_O3/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 $0x408, %rsp            # imm = 0x408
movq %r8, %rbx
movq %rcx, 0x10(%rsp)
movq %rdx, %r15
movq %rsi, %rax
movq %rdi, %r14
leaq 0x13aa6(%rip), %rsi     # 0x2aaa8
movq %rax, %rdi
callq 0x25d5a
movq %rax, %r13
movq (%r14), %rdi
movq %r14, 0x8(%rsp)
movq 0x8(%r14), %r12
movq %r12, %rdx
subq %rdi, %rdx
sarq $0x3, %rdx
testl %edx, %edx
jle 0x171ae
xorl %ebp, %ebp
cmpq %rbp, %rdx
jbe 0x171dc
movq (%rdi,%rbp,8), %rax
movq 0x18(%rax), %rsi
testq %rsi, %rsi
je 0x17060
cmpb $0x2e, (%rsi)
jne 0x1704e
cmpb $0x0, 0x1(%rsi)
je 0x17060
movq %rdi, %r14
leaq 0x20(%rsp), %rdi
callq 0x2150
movq %r14, %rdi
jmp 0x17081
leaq 0x20(%rsp), %rdi
leaq 0x1692d(%rip), %rsi     # 0x2d999
movl %ebp, %edx
xorl %eax, %eax
callq 0x2080
movq 0x8(%rsp), %rax
movq (%rax), %rdi
movq 0x8(%rax), %r12
cmpq $0x0, 0x10(%rsp)
je 0x170e5
subq %rdi, %r12
sarq $0x3, %r12
cmpq %rbp, %r12
jbe 0x171e8
movq (%rdi,%rbp,8), %rax
movq (%rax), %rdx
movl 0xc(%rax), %r9d
movl 0x20(%rax), %r10d
movsbl 0x8(%rax), %r11d
subq $0x8, %rsp
movq %r13, %rdi
leaq 0x168ec(%rip), %rsi     # 0x2d9a7
movq %r15, %rcx
movq 0x18(%rsp), %r8
xorl %eax, %eax
leaq 0x28(%rsp), %r14
pushq %r14
pushq %r11
pushq %r10
callq 0x2250
addq $0x20, %rsp
movq 0x8(%rsp), %rax
movq (%rax), %rdi
movq 0x8(%rax), %r12
movq %r12, %rdx
subq %rdi, %rdx
sarq $0x3, %rdx
cmpq %rbp, %rdx
jbe 0x171dc
movq (%rdi,%rbp,8), %rax
movq 0x30(%rax), %r14
movq (%r14), %rcx
movq 0x8(%r14), %rax
subq %rcx, %rax
sarq $0x3, %rax
testl %eax, %eax
jle 0x1719f
movq %rbp, 0x18(%rsp)
xorl %r12d, %r12d
cmpq %r12, %rax
jbe 0x171c8
movq (%rcx,%r12,8), %rax
movq (%rax), %rdx
movl 0xc(%rax), %r9d
movl 0x20(%rax), %r10d
movsbl 0x8(%rax), %r11d
subq $0x8, %rsp
movq %r13, %rdi
leaq 0x1685e(%rip), %rsi     # 0x2d9a7
movq %r15, %rcx
movq %rbx, %r8
xorl %eax, %eax
leaq 0x28(%rsp), %rbp
pushq %rbp
pushq %r11
pushq %r10
callq 0x2250
addq $0x20, %rsp
incq %r12
movq (%r14), %rcx
movq 0x8(%r14), %rdx
subq %rcx, %rdx
movq %rdx, %rax
sarq $0x3, %rax
shrq $0x3, %rdx
movslq %edx, %rdx
cmpq %rdx, %r12
jl 0x1711e
movq 0x8(%rsp), %rax
movq (%rax), %rdi
movq 0x8(%rax), %r12
movq %r12, %rdx
subq %rdi, %rdx
sarq $0x3, %rdx
movq 0x18(%rsp), %rbp
incq %rbp
movslq %edx, %rax
cmpq %rax, %rbp
jl 0x1702d
movq %r13, %rdi
callq 0x2170
addq $0x408, %rsp            # imm = 0x408
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x15701(%rip), %rdi     # 0x2c8d0
movq %r12, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x2270
leaq 0x156ed(%rip), %rdi     # 0x2c8d0
movq %rbp, %rsi
jmp 0x171d5
leaq 0x156e1(%rip), %rdi     # 0x2c8d0
movq %rbp, %rsi
movq %r12, %rdx
jmp 0x171d5