// File: /workspace/github_cpp_makefile_star2_O1/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 0x15e6b
xorl %ebx, %ebx
cmpq %rbx, %rdx
jbe 0x15e7d
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 0x15d63
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 0x273e0
movq (%rsp), %rcx
movq %rax, (%rcx)
movq (%r15), %rax
movq 0x8(%r15), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpb $0x2b, %bpl
jne 0x15d1a
cmpq %rbx, %rdx
jbe 0x15e7d
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 0x15d34
cmpq %rbx, %rdx
jbe 0x15e7d
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 0x15d58
movq (%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%r12)
jmp 0x15d63
movq %r12, %rdi
movq %rsp, %rdx
callq 0xb976
cmpb $0x0, 0xc(%rsp)
je 0x15e48
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 0x15e7d
movq (%rax,%rbx,8), %rax
movb 0x8(%rax), %bpl
movq (%rax), %rdi
callq 0x273e0
movq (%rsp), %rcx
movq %rax, (%rcx)
movq (%r15), %rax
movq 0x8(%r15), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpb $0x2d, %bpl
jne 0x15e02
cmpq %rbx, %rdx
jbe 0x15e7d
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 0x15e18
cmpq %rbx, %rdx
jbe 0x15e7d
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 0x15e3d
movq (%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%r12)
jmp 0x15e48
movq %r12, %rdi
movq %rsp, %rdx
callq 0xb976
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 0x15c6c
movq %r12, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x17a52(%rip), %rdi     # 0x2d8d6
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2270