// File: /workspace/github_cpp_makefile_star2_O1/gersteinlab[P]MUSIC/src/ms_annot_region_tools.cpp
// Function: extract_region_ends_by_l_extension(std::vector<t_annot_region*, std::allocator<t_annot_region*>>*, int, bool, bool)
vector<t_annot_region*>* extract_region_ends_by_l_extension(vector<t_annot_region*>* regions, int l_ext,
	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++)
	{
		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 %ecx, 0x10(%rsp)
movl %edx, 0x14(%rsp)
movl %esi, %r15d
movq %rdi, %r12
movl $0x18, %edi
callq 0x2180
movq %rax, %r13
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
movq (%r12), %r14
movq 0x8(%r12), %rbp
subq %r14, %rbp
sarq $0x3, %rbp
testl %ebp, %ebp
jle 0x15be7
xorl %ebx, %ebx
cmpb $0x0, 0x14(%rsp)
je 0x15add
movl $0x50, %edi
callq 0x2180
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movups %xmm0, 0x10(%rax)
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x30(%rax)
movups %xmm0, 0x40(%rax)
movq %rax, 0x8(%rsp)
cmpq %rbx, %rbp
jbe 0x15c05
movq (%r14,%rbx,8), %rax
movb 0x8(%rax), %bpl
movq (%rax), %rdi
callq 0x273e0
movq 0x8(%rsp), %rcx
movq %rax, (%rcx)
movq (%r12), %rax
movq 0x8(%r12), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpb $0x2b, %bpl
jne 0x15a93
cmpq %rbx, %rdx
jbe 0x15bf9
movq (%rax,%rbx,8), %rax
movl 0xc(%rax), %edx
subl %r15d, %edx
movl $0x1, %ecx
cmovlel %ecx, %edx
movq 0x8(%rsp), %rcx
movl %edx, 0xc(%rcx)
movl 0xc(%rax), %edx
jmp 0x15aae
cmpq %rbx, %rdx
jbe 0x15bf9
movq (%rax,%rbx,8), %rax
movl 0x20(%rax), %edx
movq 0x8(%rsp), %rcx
movl %edx, 0xc(%rcx)
addl %r15d, %edx
movl %edx, 0x20(%rcx)
movb 0x8(%rax), %al
movb %al, 0x8(%rcx)
movq 0x8(%r13), %rsi
cmpq 0x10(%r13), %rsi
je 0x15ad0
movq 0x8(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%r13)
jmp 0x15add
movq %r13, %rdi
leaq 0x8(%rsp), %rdx
callq 0xb976
cmpb $0x0, 0x10(%rsp)
je 0x15bc2
movl $0x50, %edi
callq 0x2180
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movups %xmm0, 0x10(%rax)
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x30(%rax)
movups %xmm0, 0x40(%rax)
movq %rax, 0x8(%rsp)
movq (%r12), %rax
movq 0x8(%r12), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpq %rbx, %rdx
jbe 0x15bf9
movq (%rax,%rbx,8), %rax
movb 0x8(%rax), %bpl
movq (%rax), %rdi
callq 0x273e0
movq 0x8(%rsp), %rcx
movq %rax, (%rcx)
movq (%r12), %rax
movq 0x8(%r12), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpb $0x2d, %bpl
jne 0x15b7c
cmpq %rbx, %rdx
jbe 0x15bf9
movq (%rax,%rbx,8), %rax
movl 0xc(%rax), %edx
subl %r15d, %edx
movl $0x1, %ecx
cmovlel %ecx, %edx
movq 0x8(%rsp), %rcx
movl %edx, 0xc(%rcx)
movl 0xc(%rax), %edx
jmp 0x15b93
cmpq %rbx, %rdx
jbe 0x15bf9
movq (%rax,%rbx,8), %rax
movl 0x20(%rax), %edx
movq 0x8(%rsp), %rcx
movl %edx, 0xc(%rcx)
addl %r15d, %edx
movl %edx, 0x20(%rcx)
movb 0x8(%rax), %al
movb %al, 0x8(%rcx)
movq 0x8(%r13), %rsi
cmpq 0x10(%r13), %rsi
je 0x15bb5
movq 0x8(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%r13)
jmp 0x15bc2
movq %r13, %rdi
leaq 0x8(%rsp), %rdx
callq 0xb976
incq %rbx
movq (%r12), %r14
movq 0x8(%r12), %rax
subq %r14, %rax
movq %rax, %rbp
sarq $0x3, %rbp
shrq $0x3, %rax
cltq
cmpq %rax, %rbx
jl 0x15a04
movq %r13, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x17cd6(%rip), %rdi     # 0x2d8d6
movq %rbx, %rsi
jmp 0x15c12
leaq 0x17cca(%rip), %rdi     # 0x2d8d6
movq %rbx, %rsi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x2270