// File: 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:
subq $0x48, %rsp
movb %cl, %al
movb %dl, %cl
movq %rdi, 0x40(%rsp)
movl %esi, 0x3c(%rsp)
andb $0x1, %cl
movb %cl, 0x3b(%rsp)
andb $0x1, %al
movb %al, 0x3a(%rsp)
movl $0x18, %edi
callq 0x2190
movq %rax, %rdi
movq %rdi, 0x10(%rsp)
xorl %esi, %esi
movl $0x18, %edx
callq 0x2110
movq 0x10(%rsp), %rdi
callq 0xc670
movq 0x10(%rsp), %rax
movq %rax, 0x30(%rsp)
movl $0x0, 0x2c(%rsp)
movl 0x2c(%rsp), %eax
movl %eax, 0xc(%rsp)
movq 0x40(%rsp), %rdi
callq 0xc680
movq %rax, %rcx
movl 0xc(%rsp), %eax
cmpl %ecx, %eax
jge 0x27f1b
testb $0x1, 0x3b(%rsp)
je 0x27d91
callq 0x27b00
movq %rax, 0x20(%rsp)
movq 0x40(%rsp), %rdi
movslq 0x2c(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movsbl 0x8(%rax), %eax
cmpl $0x2b, %eax
jne 0x27d02
movq 0x40(%rsp), %rdi
movslq 0x2c(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movq (%rax), %rdi
callq 0x47b60
movq %rax, %rcx
movq 0x20(%rsp), %rax
movq %rcx, (%rax)
movq 0x40(%rsp), %rdi
movslq 0x2c(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movl 0xc(%rax), %eax
cmpl 0x3c(%rsp), %eax
jle 0x27cac
movq 0x40(%rsp), %rdi
movslq 0x2c(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movl 0xc(%rax), %eax
subl 0x3c(%rsp), %eax
movl %eax, 0x8(%rsp)
jmp 0x27cb7
movl $0x1, %eax
movl %eax, 0x8(%rsp)
jmp 0x27cb7
movl 0x8(%rsp), %ecx
movq 0x20(%rsp), %rax
movl %ecx, 0xc(%rax)
movq 0x40(%rsp), %rdi
movslq 0x2c(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movl 0xc(%rax), %ecx
movq 0x20(%rsp), %rax
movl %ecx, 0x20(%rax)
movq 0x40(%rsp), %rdi
movslq 0x2c(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movb 0x8(%rax), %cl
movq 0x20(%rsp), %rax
movb %cl, 0x8(%rax)
jmp 0x27d82
movq 0x40(%rsp), %rdi
movslq 0x2c(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movq (%rax), %rdi
callq 0x47b60
movq %rax, %rcx
movq 0x20(%rsp), %rax
movq %rcx, (%rax)
movq 0x40(%rsp), %rdi
movslq 0x2c(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movl 0x20(%rax), %ecx
movq 0x20(%rsp), %rax
movl %ecx, 0xc(%rax)
movq 0x40(%rsp), %rdi
movslq 0x2c(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movl 0x20(%rax), %ecx
addl 0x3c(%rsp), %ecx
movq 0x20(%rsp), %rax
movl %ecx, 0x20(%rax)
movq 0x40(%rsp), %rdi
movslq 0x2c(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movb 0x8(%rax), %cl
movq 0x20(%rsp), %rax
movb %cl, 0x8(%rax)
movq 0x30(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0xc8c0
testb $0x1, 0x3a(%rsp)
je 0x27f09
callq 0x27b00
movq %rax, 0x18(%rsp)
movq 0x40(%rsp), %rdi
movslq 0x2c(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movsbl 0x8(%rax), %eax
cmpl $0x2d, %eax
jne 0x27e7a
movq 0x40(%rsp), %rdi
movslq 0x2c(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movq (%rax), %rdi
callq 0x47b60
movq %rax, %rcx
movq 0x18(%rsp), %rax
movq %rcx, (%rax)
movq 0x40(%rsp), %rdi
movslq 0x2c(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movl 0xc(%rax), %eax
cmpl 0x3c(%rsp), %eax
jle 0x27e24
movq 0x40(%rsp), %rdi
movslq 0x2c(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movl 0xc(%rax), %eax
subl 0x3c(%rsp), %eax
movl %eax, 0x4(%rsp)
jmp 0x27e2f
movl $0x1, %eax
movl %eax, 0x4(%rsp)
jmp 0x27e2f
movl 0x4(%rsp), %ecx
movq 0x18(%rsp), %rax
movl %ecx, 0xc(%rax)
movq 0x40(%rsp), %rdi
movslq 0x2c(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movl 0xc(%rax), %ecx
movq 0x18(%rsp), %rax
movl %ecx, 0x20(%rax)
movq 0x40(%rsp), %rdi
movslq 0x2c(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movb 0x8(%rax), %cl
movq 0x18(%rsp), %rax
movb %cl, 0x8(%rax)
jmp 0x27efa
movq 0x40(%rsp), %rdi
movslq 0x2c(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movq (%rax), %rdi
callq 0x47b60
movq %rax, %rcx
movq 0x18(%rsp), %rax
movq %rcx, (%rax)
movq 0x40(%rsp), %rdi
movslq 0x2c(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movl 0x20(%rax), %ecx
movq 0x18(%rsp), %rax
movl %ecx, 0xc(%rax)
movq 0x40(%rsp), %rdi
movslq 0x2c(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movl 0x20(%rax), %ecx
addl 0x3c(%rsp), %ecx
movq 0x18(%rsp), %rax
movl %ecx, 0x20(%rax)
movq 0x40(%rsp), %rdi
movslq 0x2c(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movb 0x8(%rax), %cl
movq 0x18(%rsp), %rax
movb %cl, 0x8(%rax)
movq 0x30(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0xc8c0
jmp 0x27f0b
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
jmp 0x27bf8
movq 0x30(%rsp), %rax
addq $0x48, %rsp
retq
nopw %cs:(%rax,%rax)