// File: 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:
subq $0x58, %rsp
movb %dl, %al
movb %sil, %cl
movq %rdi, 0x50(%rsp)
movsd %xmm0, 0x48(%rsp)
andb $0x1, %cl
movb %cl, 0x47(%rsp)
andb $0x1, %al
movb %al, 0x46(%rsp)
movl $0x18, %edi
callq 0x2190
movq %rax, %rdi
movq %rdi, 0x18(%rsp)
xorl %esi, %esi
movl $0x18, %edx
callq 0x2110
movq 0x18(%rsp), %rdi
callq 0xc670
movq 0x18(%rsp), %rax
movq %rax, 0x38(%rsp)
movl $0x0, 0x34(%rsp)
movl 0x34(%rsp), %eax
movl %eax, 0x14(%rsp)
movq 0x50(%rsp), %rdi
callq 0xc680
movq %rax, %rcx
movl 0x14(%rsp), %eax
cmpl %ecx, %eax
jge 0x28305
movsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x50(%rsp), %rdi
movslq 0x34(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movl 0x20(%rax), %eax
movl %eax, 0x10(%rsp)
movq 0x50(%rsp), %rdi
movslq 0x34(%rsp), %rsi
callq 0xc800
movsd 0x8(%rsp), %xmm0
movq %rax, %rcx
movl 0x10(%rsp), %eax
movq (%rcx), %rcx
subl 0xc(%rcx), %eax
addl $0x1, %eax
cvtsi2sd %eax, %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x30(%rsp)
testb $0x1, 0x47(%rsp)
je 0x2817e
callq 0x27b00
movq %rax, 0x28(%rsp)
movq 0x50(%rsp), %rdi
movslq 0x34(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movsbl 0x8(%rax), %eax
cmpl $0x2b, %eax
jne 0x280ef
movq 0x50(%rsp), %rdi
movslq 0x34(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movq (%rax), %rdi
callq 0x47b60
movq %rax, %rcx
movq 0x28(%rsp), %rax
movq %rcx, (%rax)
movq 0x50(%rsp), %rdi
movslq 0x34(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movl 0xc(%rax), %eax
cmpl 0x30(%rsp), %eax
jle 0x28099
movq 0x50(%rsp), %rdi
movslq 0x34(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movl 0xc(%rax), %eax
subl 0x30(%rsp), %eax
movl %eax, 0x4(%rsp)
jmp 0x280a4
movl $0x1, %eax
movl %eax, 0x4(%rsp)
jmp 0x280a4
movl 0x4(%rsp), %ecx
movq 0x28(%rsp), %rax
movl %ecx, 0xc(%rax)
movq 0x50(%rsp), %rdi
movslq 0x34(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movl 0xc(%rax), %ecx
movq 0x28(%rsp), %rax
movl %ecx, 0x20(%rax)
movq 0x50(%rsp), %rdi
movslq 0x34(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movb 0x8(%rax), %cl
movq 0x28(%rsp), %rax
movb %cl, 0x8(%rax)
jmp 0x2816f
movq 0x50(%rsp), %rdi
movslq 0x34(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movq (%rax), %rdi
callq 0x47b60
movq %rax, %rcx
movq 0x28(%rsp), %rax
movq %rcx, (%rax)
movq 0x50(%rsp), %rdi
movslq 0x34(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movl 0x20(%rax), %ecx
movq 0x28(%rsp), %rax
movl %ecx, 0xc(%rax)
movq 0x50(%rsp), %rdi
movslq 0x34(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movl 0x20(%rax), %ecx
addl 0x30(%rsp), %ecx
movq 0x28(%rsp), %rax
movl %ecx, 0x20(%rax)
movq 0x50(%rsp), %rdi
movslq 0x34(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movb 0x8(%rax), %cl
movq 0x28(%rsp), %rax
movb %cl, 0x8(%rax)
movq 0x38(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0xc8c0
testb $0x1, 0x46(%rsp)
je 0x282f3
callq 0x27b00
movq %rax, 0x20(%rsp)
movq 0x50(%rsp), %rdi
movslq 0x34(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movsbl 0x8(%rax), %eax
cmpl $0x2d, %eax
jne 0x28264
movq 0x50(%rsp), %rdi
movslq 0x34(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movq (%rax), %rdi
callq 0x47b60
movq %rax, %rcx
movq 0x20(%rsp), %rax
movq %rcx, (%rax)
movq 0x50(%rsp), %rdi
movslq 0x34(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movl 0xc(%rax), %eax
cmpl 0x30(%rsp), %eax
jle 0x28210
movq 0x50(%rsp), %rdi
movslq 0x34(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movl 0xc(%rax), %eax
subl 0x30(%rsp), %eax
movl %eax, (%rsp)
jmp 0x2821a
movl $0x1, %eax
movl %eax, (%rsp)
jmp 0x2821a
movl (%rsp), %ecx
movq 0x20(%rsp), %rax
movl %ecx, 0xc(%rax)
movq 0x50(%rsp), %rdi
movslq 0x34(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movl 0xc(%rax), %ecx
movq 0x20(%rsp), %rax
movl %ecx, 0x20(%rax)
movq 0x50(%rsp), %rdi
movslq 0x34(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movb 0x8(%rax), %cl
movq 0x20(%rsp), %rax
movb %cl, 0x8(%rax)
jmp 0x282e4
movq 0x50(%rsp), %rdi
movslq 0x34(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movq (%rax), %rdi
callq 0x47b60
movq %rax, %rcx
movq 0x20(%rsp), %rax
movq %rcx, (%rax)
movq 0x50(%rsp), %rdi
movslq 0x34(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movl 0x20(%rax), %ecx
movq 0x20(%rsp), %rax
movl %ecx, 0xc(%rax)
movq 0x50(%rsp), %rdi
movslq 0x34(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movl 0x20(%rax), %ecx
addl 0x30(%rsp), %ecx
movq 0x20(%rsp), %rax
movl %ecx, 0x20(%rax)
movq 0x50(%rsp), %rdi
movslq 0x34(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movb 0x8(%rax), %cl
movq 0x20(%rsp), %rax
movb %cl, 0x8(%rax)
movq 0x38(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0xc8c0
jmp 0x282f5
movl 0x34(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x34(%rsp)
jmp 0x27f8b
movq 0x38(%rsp), %rax
addq $0x58, %rsp
retq
nop