// File: /workspace/github_cpp_makefile_star2_O3/CMU-SAFARI[P]optimal-seed-solver/optimalSolverLN.cc
// Function: OptimalSolverLN::fillMatrix(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&)
void OptimalSolverLN::fillMatrix(string& DNA) {
	//Load all substrings
	loadL0(DNA);

#ifdef DEBUG
	cout << "l-" << 0 << "  ";
#endif

	//Fill level 0
	int lvPosCount = readLength - minLength * seedNum;
	for (int pos = 0; pos <= lvPosCount; pos++) {
		level[0][pos].start = level0[pos][0].start;
		level[0][pos].end = level0[pos][0].end;
		level[0][pos].frequency = level0[pos][0].frequency;
		//Fill up again for tracing back
		level[0][pos].rstart = level0[pos][0].start;
		level[0][pos].rend = level0[pos][0].end;
		level[0][pos].rfreq = level0[pos][0].frequency;
#ifdef DEBUG
		cout << 0 << "-" << pos + minLength - 1 << ":" << level[0][pos].start << "-"
			<< level[0][pos].end << ":" << level[0][pos].frequency << " ";
#endif
	}
#ifdef DEBUG
	cout << endl;
#endif

	int opt_div;

	//Now calculate the rest levels
	for (int l = 1; l < seedNum - 1; l++) {

		lvPosCount = readLength - minLength * seedNum;
		opt_div = solveFirstOptimal(lvPosCount, lvPosCount, l);
#ifdef DEBUG
		cout << "lvPosCount: " << lvPosCount << " opt_div: " << opt_div << endl;
#endif
		level[l][lvPosCount].lstart = level[l-1][opt_div].start;
		level[l][lvPosCount].lend = level[l-1][opt_div].end;
		level[l][lvPosCount].lfreq = level[l-1][opt_div].frequency;
		level[l][lvPosCount].rstart = level0[lvPosCount - opt_div][opt_div + l * minLength].start;
		level[l][lvPosCount].rend = level0[lvPosCount - opt_div][opt_div + l * minLength].end;
		level[l][lvPosCount].rfreq = level0[lvPosCount - opt_div][opt_div + l * minLength].frequency;
		level[l][lvPosCount].start = level[l][lvPosCount].lstart;
		level[l][lvPosCount].end = level[l][lvPosCount].rend;
		level[l][lvPosCount].frequency = level[l][lvPosCount].lfreq + level[l][lvPosCount].rfreq;

		for (int pos = lvPosCount - 1; pos >= 0; pos--) {

			int prev_opt_div = level[l][pos+1].rstart - l * minLength;
#ifdef DEBUG
			cout << "prev_opt_div: " << prev_opt_div << endl;
#endif
			//Optimal Solution Forwarding
			if (true && prev_opt_div <= pos && level0[pos - prev_opt_div][prev_opt_div + l * minLength].frequency == level[l][pos+1].rfreq) {
#ifdef TEST
				cout << "same as previous; pos: " << pos << endl;
				cout.flush();
#endif
				level[l][pos].lstart = level[l][pos+1].lstart;
				level[l][pos].lend = level[l][pos+1].lend;
				level[l][pos].lfreq = level[l][pos+1].lfreq;
				level[l][pos].rstart = level0[pos - prev_opt_div][opt_div + l * minLength].start;
				level[l][pos].rend = level0[pos - prev_opt_div][prev_opt_div + l * minLength].end;
				level[l][pos].rfreq = level0[pos - prev_opt_div][prev_opt_div + l * minLength].frequency;
				level[l][pos].start = level[l][pos].lstart;
				level[l][pos].end = level[l][pos].rend;
				level[l][pos].frequency = level[l][pos].lfreq + level[l][pos].rfreq;
				divTravel[0]++;
			}
			else {
				if (opt_div > pos)
					opt_div = pos;

				opt_div = solveFirstOptimal(opt_div, pos, l);

				level[l][pos].lstart = level[l-1][opt_div].start;
				level[l][pos].lend = level[l-1][opt_div].end;
				level[l][pos].lfreq = level[l-1][opt_div].frequency;
				level[l][pos].rstart = level0[pos - opt_div][opt_div + l * minLength].start;
				level[l][pos].rend = level0[pos - opt_div][opt_div + l * minLength].end;
				level[l][pos].rfreq = level0[pos - opt_div][opt_div + l * minLength].frequency;
				level[l][pos].start = level[l][pos].lstart;
				level[l][pos].end = level[l][pos].rend;
				level[l][pos].frequency = level[l][pos].lfreq + level[l][pos].rfreq;
			}
		}

#ifdef TEST
		cout << "freq: ";
		for (int pos = 0; pos <= lvPosCount; pos++) {
			cout << level[l][pos].frequency << " ";
		}
		cout << endl;
		cout << "rstart: ";
		for (int pos = 0; pos <= lvPosCount; pos++) {
			cout << level[l][pos].rstart << " ";
		}
		cout << endl;
		cout << "rfreq: ";
		for (int pos = 0; pos <= lvPosCount; pos++) {
			cout << level[l][pos].rfreq << " ";
		}
		cout << endl;
#endif
#ifdef DEBUG
		cout << "l-" << l << "  ";
		for (int pos = 0; pos <= lvPosCount; pos++) {
			cout << 0 << "-" << pos + (l + 1) * minLength - 1 << ":" << level[l][pos].lstart << "-"
				<< level[l][pos].lend << "(" << level[l][pos].lfreq << ")"
				<< level[l][pos].rstart << "-" << level[l][pos].rend << "("
				<< level[l][pos].rfreq << "):" << level[l][pos].frequency << " ";

		}
		cout << endl;
#endif
	}

	L0Loaded = false;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %r12
callq 0x4d2a
movl 0x360(%r12), %ecx
movl 0x364(%r12), %eax
movl 0x368(%r12), %edx
imull %eax, %edx
subl %edx, %ecx
jl 0x526c
movq 0x380(%r12), %rsi
movq 0x398(%r12), %rdx
movq (%rsi), %rsi
incl %ecx
addq $0x24, %rsi
xorl %edi, %edi
movq (%rdx,%rdi,8), %r8
movl (%r8), %r9d
movl %r9d, -0x24(%rsi)
movl 0x4(%r8), %r10d
movl %r10d, -0x20(%rsi)
movl 0xc(%r8), %r8d
movl %r8d, -0x18(%rsi)
movl %r9d, -0x8(%rsi)
movl %r10d, -0x4(%rsi)
movl %r8d, (%rsi)
incq %rdi
addq $0x28, %rsi
cmpq %rdi, %rcx
jne 0x523a
cmpl $0x3, %eax
jl 0x57f7
movl $0x1, %r13d
movq %r12, (%rsp)
movl 0x360(%r12), %ebx
imull 0x368(%r12), %eax
subl %eax, %ebx
movq %r12, %rdi
movl %ebx, %esi
movl %ebx, %edx
movl %r13d, %ecx
callq 0x580c
movq 0x380(%r12), %r15
movslq %eax, %rcx
leaq (%rcx,%rcx,4), %rcx
movq -0x8(%r15,%r13,8), %rdx
movq (%r15,%r13,8), %rsi
movq %rbx, 0x10(%rsp)
movslq %ebx, %rdi
leaq (%rdi,%rdi,4), %r8
movq (%rdx,%rcx,8), %r9
movq %r9, 0x10(%rsi,%r8,8)
movl 0xc(%rdx,%rcx,8), %r10d
movl %r10d, 0x18(%rsi,%r8,8)
movl %edi, %ecx
subl %eax, %ecx
movslq %ecx, %rdx
movq 0x398(%r12), %rcx
movq (%rcx,%rdx,8), %r11
movl 0x368(%r12), %edx
movl %edx, %ebx
movq %r13, 0x8(%rsp)
imull %r13d, %ebx
movq %rax, 0x18(%rsp)
addl %eax, %ebx
movslq %ebx, %rbx
leaq (%rbx,%rbx,4), %rbx
movl (%r11,%rbx,8), %ebp
movl %ebp, 0x1c(%rsi,%r8,8)
movl 0x4(%r11,%rbx,8), %ebp
movl %ebp, 0x20(%rsi,%r8,8)
movl 0xc(%r11,%rbx,8), %r11d
movl %r11d, 0x24(%rsi,%r8,8)
movl %r9d, (%rsi,%r8,8)
movl %ebp, 0x4(%rsi,%r8,8)
addl %r10d, %r11d
movl %r11d, 0xc(%rsi,%r8,8)
testl %edi, %edi
jle 0x55a5
movl 0x10(%rsp), %eax
leaq (,%rax,8), %rsi
leaq (%rsi,%rsi,4), %r13
movl $0x1, %edi
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
xorl %r12d, %r12d
movq %rax, 0x20(%rsp)
movq %rdi, 0x38(%rsp)
leaq (%rax,%r12), %r9
leaq (%rax,%r12), %rsi
decq %rsi
movq %rsi, 0x28(%rsp)
leaq (%rax,%r14), %rbp
movq 0x8(%rsp), %r8
movq %rax, %rsi
movq (%r15,%r8,8), %rax
movslq 0x1c(%rax,%r13), %rdi
imull %r8d, %edx
movl %edi, %r15d
subl %edx, %r15d
cmpl %r9d, %r15d
jge 0x54cb
subl %edi, %edx
addl %esi, %edx
addl %r14d, %edx
movslq %edx, %r8
movq (%rcx,%r8,8), %rcx
leaq (%rdi,%rdi,4), %rdx
movl 0xc(%rcx,%rdx,8), %ecx
cmpl 0x24(%rax,%r13), %ecx
jne 0x54cb
movl $0x17, %edx
movq 0xbbf9(%rip), %rbx      # 0x10fc8
movq %rbx, %rdi
leaq 0x6ec4(%rip), %rsi      # 0xc29d
movq %r8, 0x40(%rsp)
callq 0x32e0
movq %rbx, %rdi
movl %ebp, %esi
callq 0x3450
movq %rax, %rbp
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x3260
movsbl %al, %esi
movq %rbp, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31c0
movq %rbx, %rdi
callq 0x31c0
movq (%rsp), %rax
movq 0x380(%rax), %rcx
movq 0x8(%rsp), %rbx
movq %rcx, 0x30(%rsp)
movq (%rcx,%rbx,8), %rsi
movl 0x28(%rsp), %ecx
leaq (%rcx,%rcx,4), %rdi
movq 0x10(%rsi,%r13), %r8
movq %r8, 0x10(%rsi,%rdi,8)
movl 0x18(%rsi,%r13), %r9d
movl %r9d, 0x18(%rsi,%rdi,8)
movq 0x398(%rax), %rcx
movq 0x40(%rsp), %rdx
movq (%rcx,%rdx,8), %r10
movl 0x368(%rax), %edx
movl %edx, %r11d
imull %ebx, %r11d
movq 0x18(%rsp), %rbx
leal (%r11,%rbx), %ebp
movslq %ebp, %rbp
leaq (%rbp,%rbp,4), %rbp
movl (%r10,%rbp,8), %ebp
movl %ebp, 0x1c(%rsi,%rdi,8)
addl %r15d, %r11d
movslq %r11d, %r11
leaq (%r11,%r11,4), %r11
movl 0x4(%r10,%r11,8), %ebp
movl %ebp, 0x20(%rsi,%rdi,8)
movl 0xc(%r10,%r11,8), %r10d
movl %r10d, 0x24(%rsi,%rdi,8)
movl %r8d, (%rsi,%rdi,8)
movl %ebp, 0x4(%rsi,%rdi,8)
addl %r9d, %r10d
movl %r10d, 0xc(%rsi,%rdi,8)
movq 0x3e8(%rax), %rsi
incq (%rsi)
movq 0x20(%rsp), %rax
jmp 0x5582
movq 0x18(%rsp), %rsi
cmpl %r9d, %esi
cmovgel %ebp, %esi
movq (%rsp), %r15
movq %r15, %rdi
movl %ebp, %edx
movq 0x8(%rsp), %rbx
movl %ebx, %ecx
callq 0x580c
movq 0x380(%r15), %rsi
movq %rax, 0x18(%rsp)
movslq %eax, %r8
leaq (%r8,%r8,4), %rcx
movq -0x8(%rsi,%rbx,8), %rdx
movq %rsi, 0x30(%rsp)
movq (%rsi,%rbx,8), %rsi
movl 0x28(%rsp), %edi
leaq (%rdi,%rdi,4), %rdi
movq (%rdx,%rcx,8), %r9
movq %r9, 0x10(%rsi,%rdi,8)
movl 0xc(%rdx,%rcx,8), %r10d
movl %r10d, 0x18(%rsi,%rdi,8)
movq 0x20(%rsp), %rax
leal (%rax,%r14), %ecx
subl %r8d, %ecx
movslq %ecx, %rdx
movq 0x398(%r15), %rcx
movq (%rcx,%rdx,8), %r11
movl 0x368(%r15), %edx
movl %edx, %ebp
imull %ebx, %ebp
addl %r8d, %ebp
movslq %ebp, %r8
leaq (%r8,%r8,4), %r8
movl (%r11,%r8,8), %ebp
movl %ebp, 0x1c(%rsi,%rdi,8)
movl 0x4(%r11,%r8,8), %ebp
movl %ebp, 0x20(%rsi,%rdi,8)
movl 0xc(%r11,%r8,8), %r8d
movl %r8d, 0x24(%rsi,%rdi,8)
movl %r9d, (%rsi,%rdi,8)
movl %ebp, 0x4(%rsi,%rdi,8)
addl %r10d, %r8d
movl %r8d, 0xc(%rsi,%rdi,8)
movq 0x38(%rsp), %rdi
addq $-0x28, %r13
decq %rdi
leal (%rdi,%rax), %esi
decq %r12
decq %r14
cmpl $0x1, %esi
movq 0x30(%rsp), %r15
jg 0x5365
movl $0x6, %edx
movq 0xba17(%rip), %r12      # 0x10fc8
movq %r12, %rdi
leaq 0x6d05(%rip), %rsi      # 0xc2c0
callq 0x32e0
movq 0x10(%rsp), %rbp
testl %ebp, %ebp
js 0x56b3
leal 0x1(%rbp), %ebx
movl $0xc, %r14d
movq %rbx, %r15
movq (%rsp), %r12
movq 0x8(%rsp), %r13
leaq 0x701d(%rip), %rbp      # 0xc606
movq 0x380(%r12), %rax
movq (%rax,%r13,8), %rax
movl (%rax,%r14), %esi
movq 0xb9c8(%rip), %rdi      # 0x10fc8
callq 0x31b0
movl $0x1, %edx
movq %rax, %rdi
movq %rbp, %rsi
callq 0x32e0
addq $0x28, %r14
decq %r15
jne 0x55e9
movq 0xb9a3(%rip), %r14      # 0x10fc8
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3260
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31c0
movl $0x8, %edx
movq %r14, %rdi
leaq 0x6c5a(%rip), %rsi      # 0xc2b5
callq 0x32e0
movq 0x10(%rsp), %rbp
testl %ebp, %ebp
js 0x577b
movq %r14, %r12
movl $0x1c, %r14d
leaq 0x6f89(%rip), %r15      # 0xc606
movq (%rsp), %rax
movq 0x380(%rax), %rax
movq (%rax,%r13,8), %rax
movl (%rax,%r14), %esi
movq %r12, %rdi
callq 0x31b0
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x32e0
addq $0x28, %r14
decq %rbx
jne 0x567d
jmp 0x56fb
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3260
movsbl %al, %esi
movq %r12, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31c0
movl $0x8, %edx
movq %r12, %rdi
leaq 0x6bcb(%rip), %rsi      # 0xc2b5
callq 0x32e0
movq 0x8(%rsp), %r13
leaq 0x6f0b(%rip), %r15      # 0xc606
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3260
movsbl %al, %esi
movq %r12, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31c0
movl $0x7, %edx
movq %r12, %rdi
leaq 0x6b96(%rip), %rsi      # 0xc2c8
callq 0x32e0
testl %ebp, %ebp
movq %r12, %r14
movq (%rsp), %r12
js 0x57b6
incl %ebp
movl $0x24, %ebx
movq 0x380(%r12), %rax
movq (%rax,%r13,8), %rax
movl (%rax,%rbx), %esi
movq %r14, %rdi
callq 0x31b0
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x32e0
addq $0x28, %rbx
decq %rbp
jne 0x5749
jmp 0x57b6
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3260
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31c0
movl $0x7, %edx
movq %r14, %rdi
leaq 0x6b17(%rip), %rsi      # 0xc2c8
callq 0x32e0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3260
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31c0
incq %r13
movslq 0x364(%r12), %rax
movq %rax, %rcx
decq %rcx
cmpq %rcx, %r13
jl 0x527f
movb $0x0, (%r12)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop