// File: /workspace/github_cpp_makefile_star2_O3/gersteinlab[P]MUSIC/src/ms_annot_region_tools.cpp
// Function: extract_region_ends_by_fraction_extension(std::vector<t_annot_region*, std::allocator<t_annot_region*>>*, double, bool, bool)
vector<t_annot_region*>* extract_region_ends_by_fraction_extension(vector<t_annot_region*>* regions, double ext_fraction,
	bool extract_5p, 
	bool extract_3p)
{
	vector<t_annot_region*>* region_ends = new vector<t_annot_region*>();
	for(int i = 0; i < (int)regions->size(); i++)
	{
		int l_ext = (int)(ext_fraction * (regions->at(i)->end - regions->at(i)->start + 1));

		if(extract_5p)
		{
			t_annot_region* fp_end = get_empty_region();
			if(regions->at(i)->strand == '+')
			{
				fp_end->chrom = t_string::copy_me_str(regions->at(i)->chrom);
				fp_end->start = (regions->at(i)->start > l_ext)?(regions->at(i)->start - l_ext):(1);
				//fp_end->end = (regions->at(i)->start + l_ext);
				fp_end->end = (regions->at(i)->start);
				fp_end->strand = regions->at(i)->strand;
			}
			else
			{
				fp_end->chrom = t_string::copy_me_str(regions->at(i)->chrom);
				//fp_end->start = (regions->at(i)->end > l_ext)?(regions->at(i)->end - l_ext):(1);
				fp_end->start = regions->at(i)->end;
				fp_end->end = (regions->at(i)->end + l_ext);
				fp_end->strand = regions->at(i)->strand;
			}
			region_ends->push_back(fp_end);
		} // 5p extraction check.

		if(extract_3p)
		{
			t_annot_region* tp_end = get_empty_region();
			if(regions->at(i)->strand == '-')
			{
				tp_end->chrom = t_string::copy_me_str(regions->at(i)->chrom);
				tp_end->start = (regions->at(i)->start > l_ext)?(regions->at(i)->start - l_ext):(1);
				//tp_end->end = (regions->at(i)->start + l_ext);
				tp_end->end = regions->at(i)->start;
				tp_end->strand = regions->at(i)->strand;
			}
			else
			{
				tp_end->chrom = t_string::copy_me_str(regions->at(i)->chrom);
				//tp_end->start = (regions->at(i)->end > l_ext)?(regions->at(i)->end - l_ext):(1);
				tp_end->start = regions->at(i)->end;
				tp_end->end = (regions->at(i)->end + l_ext);
				tp_end->strand = regions->at(i)->strand;
			}
			region_ends->push_back(tp_end);
		} // 3p extraction check.
	} // i loop.

	return(region_ends);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, 0xc(%rsp)
movl %esi, %r14d
movsd %xmm0, 0x10(%rsp)
movq %rdi, %r15
movl $0x18, %edi
callq 0x2180
movq %rax, %r12
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
movq $0x0, 0x10(%rax)
movq (%r15), %rbp
movq 0x8(%r15), %rdx
subq %rbp, %rdx
sarq $0x3, %rdx
testl %edx, %edx
jle 0x15b0d
xorl %ebx, %ebx
cmpq %rbx, %rdx
jbe 0x15b1f
movq (%rbp,%rbx,8), %rax
movl 0x20(%rax), %ecx
subl 0xc(%rax), %ecx
incl %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
mulsd 0x10(%rsp), %xmm0
cvttsd2si %xmm0, %r13d
testb %r14b, %r14b
je 0x15a09
movl $0x50, %edi
callq 0x2180
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
movupd %xmm0, 0x10(%rax)
movupd %xmm0, 0x20(%rax)
movupd %xmm0, 0x30(%rax)
movupd %xmm0, 0x40(%rax)
movq %rax, (%rsp)
movq (%rbp,%rbx,8), %rax
movb 0x8(%rax), %bpl
movq (%rax), %rdi
callq 0x26db4
movq (%rsp), %rcx
movq %rax, (%rcx)
movq (%r15), %rax
movq 0x8(%r15), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpb $0x2b, %bpl
jne 0x159c4
cmpq %rbx, %rdx
jbe 0x15b1f
movq (%rax,%rbx,8), %rax
movl 0xc(%rax), %edx
subl %r13d, %edx
movl $0x1, %ecx
cmovlel %ecx, %edx
movq (%rsp), %rcx
movl %edx, 0xc(%rcx)
movl 0xc(%rax), %edx
jmp 0x159de
cmpq %rbx, %rdx
jbe 0x15b1f
movq (%rax,%rbx,8), %rax
movl 0x20(%rax), %edx
movq (%rsp), %rcx
movl %edx, 0xc(%rcx)
addl %r13d, %edx
movl %edx, 0x20(%rcx)
movb 0x8(%rax), %al
movb %al, 0x8(%rcx)
movq 0x8(%r12), %rsi
cmpq 0x10(%r12), %rsi
je 0x159fe
movq %rcx, (%rsi)
addq $0x8, 0x8(%r12)
jmp 0x15a09
movq %r12, %rdi
movq %rsp, %rdx
callq 0xb74c
cmpb $0x0, 0xc(%rsp)
je 0x15aea
movl $0x50, %edi
callq 0x2180
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
movupd %xmm0, 0x10(%rax)
movupd %xmm0, 0x20(%rax)
movupd %xmm0, 0x30(%rax)
movupd %xmm0, 0x40(%rax)
movq %rax, (%rsp)
movq (%r15), %rax
movq 0x8(%r15), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpq %rbx, %rdx
jbe 0x15b1f
movq (%rax,%rbx,8), %rax
movb 0x8(%rax), %bpl
movq (%rax), %rdi
callq 0x26db4
movq (%rsp), %rcx
movq %rax, (%rcx)
movq (%r15), %rax
movq 0x8(%r15), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpb $0x2d, %bpl
jne 0x15aa8
cmpq %rbx, %rdx
jbe 0x15b1f
movq (%rax,%rbx,8), %rax
movl 0xc(%rax), %edx
subl %r13d, %edx
movl $0x1, %ecx
cmovlel %ecx, %edx
movq (%rsp), %rcx
movl %edx, 0xc(%rcx)
movl 0xc(%rax), %r13d
jmp 0x15abe
cmpq %rbx, %rdx
jbe 0x15b1f
movq (%rax,%rbx,8), %rax
movl 0x20(%rax), %edx
movq (%rsp), %rcx
movl %edx, 0xc(%rcx)
addl %edx, %r13d
movl %r13d, 0x20(%rcx)
movb 0x8(%rax), %al
movb %al, 0x8(%rcx)
movq 0x8(%r12), %rsi
cmpq 0x10(%r12), %rsi
je 0x15adf
movq %rcx, (%rsi)
addq $0x8, 0x8(%r12)
jmp 0x15aea
movq %r12, %rdi
movq %rsp, %rdx
callq 0xb74c
incq %rbx
movq (%r15), %rbp
movq 0x8(%r15), %rax
subq %rbp, %rax
movq %rax, %rdx
sarq $0x3, %rdx
shrq $0x3, %rax
cltq
cmpq %rax, %rbx
jl 0x15916
movq %r12, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x16daa(%rip), %rdi     # 0x2c8d0
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2270