// File: /workspace/github_cpp_makefile_star2_O1/CMU-SAFARI[P]optimal-seed-solver/optimalSolverLN.cc
// Function: OptimalSolverLN::init(int, int)
void OptimalSolverLN::init(int readLength, int seedNum) {
	//Initialize the matrix
	if  (matrix != NULL) {
		delete [] matrix;
		matrix = NULL;
	}
	if  (base != NULL) {
		delete [] base;
		base = NULL;
	}
	if  (defaultMatrix != NULL) {
		delete [] defaultMatrix;
		defaultMatrix = NULL;
	}
	if  (defaultBase != NULL) {
		delete [] defaultBase;
		defaultBase = NULL;
	}

	this->readLength = readLength;

	if (readLength >= seedNum * minLength)
		this->seedNum = seedNum;
	else
		this->seedNum = readLength / minLength;

	//Position count for the level
	int lvPosCount;

	//Matrix and base overall size
	matrixSize = 0;
	baseSize = 0;

	//For the base case, we need to consider all possible seeds
	lvPosCount = readLength + 1 - minLength;
	baseSize = (lvPosCount + 1) * lvPosCount / 2;

	//For the matrix, we need to consider all cases, while leaving
	//the last minLength out (because we don't need to)
	if (seedNum > 1)
		matrixSize = (readLength + 1 - minLength * seedNum) * (seedNum - 1);
	else
		matrixSize = readLength + 1 - minLength;
	/*
	for (int i = 0; i < this->seedNum - 1; i++) {
		//Notice that for the rest levels, we do not need to consider the last
		//hashLength positions
		lvPosCount = readLength + 1 - minLength * (i + 2);
		matrixSize += lvPosCount;
	}
	*/

#ifdef DEBUG
	cout << "matrixSize: " << matrixSize << endl;
#endif
	//Allocate space for the base
	base = new Cell[baseSize];
	defaultBase = new Cell[baseSize];

	//Allocate space for the matrix
	matrix = new Cell[matrixSize];
	defaultMatrix = new Cell[matrixSize];

	//Fill the level0 pointers
	lvPosCount = readLength + 1 - minLength;
	level0.resize(lvPosCount);
	int levelIdx = 0;
	int baseProgress = 0;
	//Initialize the first one
	for (int i = lvPosCount; i > 0; i--) {
		level0[levelIdx] = base + baseProgress;
		baseProgress += i;
		levelIdx++;
	}

	//Just to check the baseSize
	assert (baseProgress == baseSize);

	if (seedNum > 1) {
		//Fill the level pointers. No need to have the last level
		level.resize(seedNum - 1);
		levelIdx = 0;
		int matrixProgress = 0;
		for (int i = 0; i < seedNum - 1; i++) {
			lvPosCount = readLength + 1 - minLength * seedNum;
			level[i] = matrix + matrixProgress;
			matrixProgress += lvPosCount;
		}

		//Just to check the matrixSize
		assert (matrixProgress == matrixSize);
	}
	else {
		level.resize(1);
		level[0] = matrix;
	}


	//Initialize all the seeds
	seeds.resize(seedNum);

	//Initialize statistics
	processedReads = 0;
	divTravel.resize(readLength, 0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %edx, %ebp
movl %esi, %r14d
movq %rdi, %rbx
movq 0x370(%rdi), %rdi
testq %rdi, %rdi
je 0x4850
callq 0x3340
movq $0x0, 0x370(%rbx)
movq 0x378(%rbx), %rdi
testq %rdi, %rdi
je 0x486c
callq 0x3340
movq $0x0, 0x378(%rbx)
movq 0x3b0(%rbx), %rdi
testq %rdi, %rdi
je 0x4888
callq 0x3340
movq $0x0, 0x3b0(%rbx)
movq 0x3b8(%rbx), %rdi
testq %rdi, %rdi
je 0x48a4
callq 0x3340
movq $0x0, 0x3b8(%rbx)
movl %r14d, 0x360(%rbx)
movl 0x368(%rbx), %esi
movl %esi, %ecx
imull %ebp, %ecx
movl %ebp, %eax
cmpl %r14d, %ecx
jle 0x48c3
movl %r14d, %eax
cltd
idivl %esi
movl %eax, 0x364(%rbx)
movq %r14, 0x10(%rsp)
leal 0x1(%r14), %r15d
movl %r15d, %r14d
subl %esi, %r14d
leal 0x1(%r14), %r13d
imull %r14d, %r13d
movl %r13d, %eax
shrl $0x1f, %eax
addl %r13d, %eax
sarl %eax
movl %eax, 0x3c4(%rbx)
movl %r15d, %r12d
subl %ecx, %r12d
leal -0x1(%rbp), %ecx
movq %rcx, 0x8(%rsp)
imull %ecx, %r12d
movq %rbp, 0x18(%rsp)
cmpl $0x2, %ebp
cmovll %r14d, %r12d
movl %r12d, 0x3c0(%rbx)
cltq
movl $0x28, %ecx
movq %rax, (%rsp)
mulq %rcx
movq $-0x1, %rbp
cmovnoq %rax, %rbp
movq %rbp, %rdi
callq 0x3030
incl %r13d
cmpl $0x3, %r13d
jb 0x4971
movq (%rsp), %rcx
leaq (%rcx,%rcx,4), %rcx
leaq (%rax,%rcx,8), %rcx
pcmpeqd %xmm0, %xmm0
movq %rax, %rdx
movq $-0x1, (%rdx)
movb $0x0, 0x8(%rdx)
movdqu %xmm0, 0xc(%rdx)
movdqu %xmm0, 0x18(%rdx)
addq $0x28, %rdx
cmpq %rcx, %rdx
jne 0x4953
movq %rax, 0x378(%rbx)
movq %rbp, %rdi
callq 0x3030
cmpl $0x3, %r13d
jb 0x49b7
movq (%rsp), %rcx
leaq (%rcx,%rcx,4), %rcx
leaq (%rax,%rcx,8), %rcx
pcmpeqd %xmm0, %xmm0
movq %rax, %rdx
movq $-0x1, (%rdx)
movb $0x0, 0x8(%rdx)
movdqu %xmm0, 0xc(%rdx)
movdqu %xmm0, 0x18(%rdx)
addq $0x28, %rdx
cmpq %rcx, %rdx
jne 0x4999
movq %rax, 0x3b8(%rbx)
movslq %r12d, %r13
movl $0x28, %ecx
movq %r13, %rax
mulq %rcx
movq $-0x1, %rbp
cmovnoq %rax, %rbp
movq %rbp, %rdi
callq 0x3030
testl %r12d, %r12d
je 0x4a18
leaq (,%r13,4), %rcx
addq %r13, %rcx
leaq (%rax,%rcx,8), %rcx
pcmpeqd %xmm0, %xmm0
movq %rax, %rdx
movq $-0x1, (%rdx)
movb $0x0, 0x8(%rdx)
movdqu %xmm0, 0xc(%rdx)
movdqu %xmm0, 0x18(%rdx)
addq $0x28, %rdx
cmpq %rcx, %rdx
jne 0x49fa
movq %rax, 0x370(%rbx)
movq %rbp, %rdi
callq 0x3030
testl %r12d, %r12d
je 0x4a60
leaq (,%r13,4), %rcx
addq %r13, %rcx
leaq (%rax,%rcx,8), %rcx
pcmpeqd %xmm0, %xmm0
movq %rax, %rdx
movq $-0x1, (%rdx)
movb $0x0, 0x8(%rdx)
movdqu %xmm0, 0xc(%rdx)
movdqu %xmm0, 0x18(%rdx)
addq $0x28, %rdx
cmpq %rcx, %rdx
jne 0x4a42
movq %rax, 0x3b0(%rbx)
leaq 0x398(%rbx), %rdi
movslq %r14d, %rsi
callq 0x614a
testl %r14d, %r14d
movq 0x18(%rsp), %r12
jle 0x4ab8
movl %r14d, %eax
shlq $0x3, %rax
xorl %edx, %edx
xorl %ecx, %ecx
movl %ecx, %esi
leaq (%rsi,%rsi,4), %rsi
shlq $0x3, %rsi
addq 0x378(%rbx), %rsi
movq 0x398(%rbx), %rdi
movq %rsi, (%rdi,%rdx)
addl %r14d, %ecx
addq $0x8, %rdx
decl %r14d
cmpq %rdx, %rax
jne 0x4a8b
jmp 0x4aba
xorl %ecx, %ecx
cmpl 0x3c4(%rbx), %ecx
jne 0x4ba5
leaq 0x380(%rbx), %rdi
cmpl $0x2, %r12d
jl 0x4b42
movq 0x8(%rsp), %r14
movq %r14, %rsi
callq 0x614a
movl 0x368(%rbx), %eax
imull %r12d, %eax
movl %r14d, %ecx
xorl %edx, %edx
xorl %esi, %esi
movslq %esi, %rsi
leaq (%rsi,%rsi,4), %rdi
shlq $0x3, %rdi
addq 0x370(%rbx), %rdi
movq 0x380(%rbx), %r8
movq %rdi, (%r8,%rdx,8)
addl %r15d, %esi
subl %eax, %esi
incq %rdx
cmpq %rdx, %rcx
jne 0x4af1
cmpl %esi, 0x3c0(%rbx)
je 0x4b5d
leaq 0x7637(%rip), %rdi      # 0xc161
leaq 0x75f8(%rip), %rsi      # 0xc129
leaq 0x7604(%rip), %rcx      # 0xc13c
movl $0x92, %edx
callq 0x3190
movl $0x1, %esi
callq 0x614a
movq 0x370(%rbx), %rax
movq 0x380(%rbx), %rcx
movq %rax, (%rcx)
leaq 0x3c8(%rbx), %rdi
movslq %r12d, %rsi
callq 0x617c
movl $0x0, 0x400(%rbx)
addq $0x3e8, %rbx            # imm = 0x3E8
movslq 0x10(%rsp), %rsi
leaq 0x20(%rsp), %rdx
movq $0x0, (%rdx)
movq %rbx, %rdi
callq 0x61c0
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x7564(%rip), %rdi      # 0xc110
leaq 0x7576(%rip), %rsi      # 0xc129
leaq 0x7582(%rip), %rcx      # 0xc13c
movl $0x84, %edx
callq 0x3190