// File: /workspace/github_cpp_makefile_star2_O2/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, 0x14(%rsp)
movl %edx, %ebp
movl %esi, %r14d
movq %rdi, %r15
pushq $0x18
popq %rdi
callq 0x2170
movq %rax, %r12
xorps %xmm0, %xmm0
andq $0x0, 0x10(%rax)
movups %xmm0, (%rax)
xorl %r13d, %r13d
movq 0x8(%r15), %rax
subq (%r15), %rax
shrq $0x3, %rax
cltq
cmpq %rax, %r13
jge 0x12099
testb %bpl, %bpl
je 0x11fb5
callq 0x11e71
movq %rax, 0x8(%rsp)
movq %r15, %rdi
movq %r13, %rsi
callq 0x7404
movq (%rax), %rax
movb 0x8(%rax), %bl
movq %r15, %rdi
movq %r13, %rsi
callq 0x7404
movq (%rax), %rax
movq (%rax), %rdi
callq 0x21062
movq 0x8(%rsp), %rcx
movq %rax, (%rcx)
movq %r15, %rdi
movq %r13, %rsi
callq 0x7404
movq (%rax), %rcx
cmpb $0x2b, %bl
jne 0x11f68
pushq $0x1
popq %rax
cmpl %r14d, 0xc(%rcx)
jle 0x11f4d
movq %r15, %rdi
movq %r13, %rsi
callq 0x7404
movq (%rax), %rax
movl 0xc(%rax), %eax
subl %r14d, %eax
movq 0x8(%rsp), %rcx
movl %eax, 0xc(%rcx)
movq %r15, %rdi
movq %r13, %rsi
callq 0x7404
movq (%rax), %rax
movl 0xc(%rax), %eax
jmp 0x11f87
movl 0x20(%rcx), %eax
movq 0x8(%rsp), %rcx
movl %eax, 0xc(%rcx)
movq %r15, %rdi
movq %r13, %rsi
callq 0x7404
movq (%rax), %rax
movl 0x20(%rax), %eax
addl %r14d, %eax
movq 0x8(%rsp), %rcx
movl %eax, 0x20(%rcx)
movq %r15, %rdi
movq %r13, %rsi
callq 0x7404
movq (%rax), %rax
movb 0x8(%rax), %al
movq 0x8(%rsp), %rcx
movb %al, 0x8(%rcx)
movq %r12, %rdi
leaq 0x8(%rsp), %rsi
callq 0x7448
cmpb $0x0, 0x14(%rsp)
je 0x12091
callq 0x11e71
movq %rax, 0x8(%rsp)
movq %r15, %rdi
movq %r13, %rsi
callq 0x7404
movq (%rax), %rax
movb 0x8(%rax), %bl
movq %r15, %rdi
movq %r13, %rsi
callq 0x7404
movq (%rax), %rax
movq (%rax), %rdi
callq 0x21062
movq 0x8(%rsp), %rcx
movq %rax, (%rcx)
movq %r15, %rdi
movq %r13, %rsi
callq 0x7404
movq (%rax), %rcx
cmpb $0x2d, %bl
jne 0x12044
pushq $0x1
popq %rax
cmpl %r14d, 0xc(%rcx)
jle 0x12029
movq %r15, %rdi
movq %r13, %rsi
callq 0x7404
movq (%rax), %rax
movl 0xc(%rax), %eax
subl %r14d, %eax
movq 0x8(%rsp), %rcx
movl %eax, 0xc(%rcx)
movq %r15, %rdi
movq %r13, %rsi
callq 0x7404
movq (%rax), %rax
movl 0xc(%rax), %eax
jmp 0x12063
movl 0x20(%rcx), %eax
movq 0x8(%rsp), %rcx
movl %eax, 0xc(%rcx)
movq %r15, %rdi
movq %r13, %rsi
callq 0x7404
movq (%rax), %rax
movl 0x20(%rax), %eax
addl %r14d, %eax
movq 0x8(%rsp), %rcx
movl %eax, 0x20(%rcx)
movq %r15, %rdi
movq %r13, %rsi
callq 0x7404
movq (%rax), %rax
movb 0x8(%rax), %al
movq 0x8(%rsp), %rcx
movb %al, 0x8(%rcx)
movq %r12, %rdi
leaq 0x8(%rsp), %rsi
callq 0x7448
incq %r13
jmp 0x11ec5
movq %r12, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq