// File: deprekate[P]RepeatFinder/src/repeatfinder.cpp
// Function: check_extend(std::vector<repeat, std::allocator<repeat>>&, int, int, int)
int check_extend(vector<repeat> &rep, int fst, int n, int gap)
{
	int i, j, k;
        int len = (int)rep.size();
	int head, tail, mid;

	// binary search
	j = rep[fst].fst + rep[fst].len -1 +n;
	head = fst + 1;
	tail = len - 1;
	mid = (head + tail) / 2;
	while(rep[mid].fst!= j && head<=tail){
		mid = (head +tail) / 2;
		if(rep[mid].fst<j){
			head = mid+1;
		}else{
			tail = mid -1;
		}
	}
	i = mid-1;
	while(rep[mid].fst == rep[i].fst && i >-1){
		i--;
	}
	i++;
	k = rep[fst].sec+rep[fst].seclen -1;
	
	for(;rep[i].fst == j;i++){
		if(rep[i].visited == 0){
			if ( (rep[i].fst + rep[i].len -1) <rep[fst].sec || (rep[i].fst + rep[i].len -1)<(rep[i].sec)*(-1)-rep[i].seclen+1){
				//check for 2nd copy
				if(rep[i].sec-k <= gap && rep[i].sec-k >= 0){
					return i;
				}
			}
		}
	}
	return -1;
}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x58(%rsp)
movl %esi, 0x54(%rsp)
movl %edx, 0x50(%rsp)
movl %ecx, 0x4c(%rsp)
movq 0x58(%rsp), %rdi
callq 0x5aa0
movl %eax, 0x3c(%rsp)
movq 0x58(%rsp), %rdi
movslq 0x54(%rsp), %rsi
callq 0x5ac0
movl (%rax), %eax
movl %eax, 0x2c(%rsp)
movq 0x58(%rsp), %rdi
movslq 0x54(%rsp), %rsi
callq 0x5ac0
movq %rax, %rcx
movl 0x2c(%rsp), %eax
addl 0x8(%rcx), %eax
subl $0x1, %eax
addl 0x50(%rsp), %eax
movl %eax, 0x44(%rsp)
movl 0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
movl 0x3c(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x34(%rsp)
movl 0x38(%rsp), %eax
addl 0x34(%rsp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, 0x30(%rsp)
movq 0x58(%rsp), %rdi
movslq 0x30(%rsp), %rsi
callq 0x5ac0
movl (%rax), %ecx
xorl %eax, %eax
cmpl 0x44(%rsp), %ecx
movb %al, 0x2b(%rsp)
je 0x46e2
movl 0x38(%rsp), %eax
cmpl 0x34(%rsp), %eax
setle %al
movb %al, 0x2b(%rsp)
movb 0x2b(%rsp), %al
testb $0x1, %al
jne 0x46ec
jmp 0x4731
movl 0x38(%rsp), %eax
addl 0x34(%rsp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, 0x30(%rsp)
movq 0x58(%rsp), %rdi
movslq 0x30(%rsp), %rsi
callq 0x5ac0
movl (%rax), %eax
cmpl 0x44(%rsp), %eax
jge 0x4724
movl 0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
jmp 0x472f
movl 0x30(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x34(%rsp)
jmp 0x46b6
movl 0x30(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x48(%rsp)
movq 0x58(%rsp), %rdi
movslq 0x30(%rsp), %rsi
callq 0x5ac0
movl (%rax), %eax
movl %eax, 0x24(%rsp)
movq 0x58(%rsp), %rdi
movslq 0x48(%rsp), %rsi
callq 0x5ac0
movl 0x24(%rsp), %ecx
movq %rax, %rdx
xorl %eax, %eax
cmpl (%rdx), %ecx
movb %al, 0x2a(%rsp)
jne 0x477d
cmpl $-0x1, 0x48(%rsp)
setg %al
movb %al, 0x2a(%rsp)
movb 0x2a(%rsp), %al
testb $0x1, %al
jne 0x4787
jmp 0x4794
movl 0x48(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x48(%rsp)
jmp 0x473c
movl 0x48(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x48(%rsp)
movq 0x58(%rsp), %rdi
movslq 0x54(%rsp), %rsi
callq 0x5ac0
movl 0x4(%rax), %eax
movl %eax, 0x20(%rsp)
movq 0x58(%rsp), %rdi
movslq 0x54(%rsp), %rsi
callq 0x5ac0
movq %rax, %rcx
movl 0x20(%rsp), %eax
addl 0xc(%rcx), %eax
subl $0x1, %eax
movl %eax, 0x40(%rsp)
movq 0x58(%rsp), %rdi
movslq 0x48(%rsp), %rsi
callq 0x5ac0
movl (%rax), %eax
cmpl 0x44(%rsp), %eax
jne 0x4920
movq 0x58(%rsp), %rdi
movslq 0x48(%rsp), %rsi
callq 0x5ac0
cmpl $0x0, 0x10(%rax)
jne 0x490e
movq 0x58(%rsp), %rdi
movslq 0x48(%rsp), %rsi
callq 0x5ac0
movl (%rax), %eax
movl %eax, 0x18(%rsp)
movq 0x58(%rsp), %rdi
movslq 0x48(%rsp), %rsi
callq 0x5ac0
movq %rax, %rcx
movl 0x18(%rsp), %eax
addl 0x8(%rcx), %eax
subl $0x1, %eax
movl %eax, 0x1c(%rsp)
movq 0x58(%rsp), %rdi
movslq 0x54(%rsp), %rsi
callq 0x5ac0
movq %rax, %rcx
movl 0x1c(%rsp), %eax
cmpl 0x4(%rcx), %eax
jl 0x48c9
movq 0x58(%rsp), %rdi
movslq 0x48(%rsp), %rsi
callq 0x5ac0
movl (%rax), %eax
movl %eax, 0xc(%rsp)
movq 0x58(%rsp), %rdi
movslq 0x48(%rsp), %rsi
callq 0x5ac0
movq %rax, %rcx
movl 0xc(%rsp), %eax
addl 0x8(%rcx), %eax
subl $0x1, %eax
movl %eax, 0x14(%rsp)
movq 0x58(%rsp), %rdi
movslq 0x48(%rsp), %rsi
callq 0x5ac0
imull $-0x1, 0x4(%rax), %eax
movl %eax, 0x10(%rsp)
movq 0x58(%rsp), %rdi
movslq 0x48(%rsp), %rsi
callq 0x5ac0
movl 0x10(%rsp), %ecx
movq %rax, %rdx
movl 0x14(%rsp), %eax
subl 0xc(%rdx), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jge 0x490c
movq 0x58(%rsp), %rdi
movslq 0x48(%rsp), %rsi
callq 0x5ac0
movl 0x4(%rax), %eax
subl 0x40(%rsp), %eax
cmpl 0x4c(%rsp), %eax
jg 0x490a
movq 0x58(%rsp), %rdi
movslq 0x48(%rsp), %rsi
callq 0x5ac0
movl 0x4(%rax), %eax
subl 0x40(%rsp), %eax
cmpl $0x0, %eax
jl 0x490a
movl 0x48(%rsp), %eax
movl %eax, 0x64(%rsp)
jmp 0x4928
jmp 0x490c
jmp 0x490e
jmp 0x4910
movl 0x48(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x48(%rsp)
jmp 0x47d5
movl $0xffffffff, 0x64(%rsp) # imm = 0xFFFFFFFF
movl 0x64(%rsp), %eax
addq $0x68, %rsp
retq
nopw %cs:(%rax,%rax)