// File: /workspace/github_cpp_makefile_star2_O1/gvaumour[P]cache-simulator/src/FeatureTable.cc
// Function: FeatureTable::finishSimu()
void 
FeatureTable::finishSimu()
{

	if(!simu_parameters.perceptron_drawFeatureMaps || stats_heatmap_allocation.size() == 0)
		return;
		
	int height = m_size;
	int width = stats_heatmap_allocation[0].size();


	if(width > IMG_WIDTH)
	{
		stats_heatmap_allocation = resize_image(stats_heatmap_allocation);
		stats_heatmap_weight = resize_image(stats_heatmap_weight);
		width = stats_heatmap_allocation[0].size();
	}	
	vector< vector<int> > red = vector< vector<int> >(width, vector<int>(height, 0));
	vector< vector<int> > blue  = red;
	vector< vector<int> > green = red;
	
	for(unsigned i = 0 ; i < stats_heatmap_allocation.size(); i++)
	{
		for(unsigned j = 0 ; j < stats_heatmap_allocation[i].size(); j++)
		{
			int value = stats_heatmap_allocation[i][j];
			
			if(value >= 0)
			{
				red[j][i] = 255;
				blue[j][i] = 255 - 255 * value / 32;			
				green[j][i] =  255 - 255 * value / 32; 
			}
			else
			{
				blue[j][i] = 255;
				red[j][i] = 255 - 255 * -value / 32;
				green[j][i] = 255 - 255 * -value / 32; 
			}
		}
	}

	writeBMPimage(string("allocation_" + m_name + ".bmp") , width , height , red, blue, green );
	
	for(unsigned i = 0 ; i < stats_heatmap_weight.size(); i++)
	{
		for(unsigned j = 0 ; j < stats_heatmap_weight[i].size(); j++)
		{
			int value = stats_heatmap_weight[i][j] - simu_parameters.perceptron_counter_size/2;
			
			if(value >= 0)
			{
				red[j][i] = 255;
				blue[j][i] = 255 - 255 * value / 32;			
				green[j][i] =  255 - 255 * value / 32; 
			}
			else
			{
				blue[j][i] = 255;
				red[j][i] = 255 - 255 * -value / 32;
				green[j][i] = 255 - 255 * -value / 32; 
			}
		}
	}

	writeBMPimage(string("weight_" + m_name + ".bmp") , width , height , red, blue, green );
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
leaq 0x311ba(%rip), %r13     # 0x45f50
cmpb $0x1, 0x1cc(%r13)
jne 0x1535d
movq %rdi, %r15
movq 0x60(%rdi), %rax
cmpq %rax, 0x68(%rdi)
je 0x1535d
movslq (%r15), %rbx
movq 0x8(%rax), %r14
subq (%rax), %r14
shrq $0x2, %r14
cmpl $0x7d1, %r14d           # imm = 0x7D1
jl 0x14eac
leaq 0x60(%r15), %rsi
leaq 0x40(%rsp), %r12
movq %r12, %rdi
callq 0x2f12a
xorl %ebp, %ebp
leaq 0x10(%rsp), %r14
movq %rbp, 0x10(%r14)
xorps %xmm0, %xmm0
movaps %xmm0, (%r14)
movups 0x60(%r15), %xmm0
movq 0x70(%r15), %rax
movaps (%r12), %xmm1
movups %xmm1, 0x60(%r15)
movq 0x10(%r12), %rcx
movq %rcx, 0x70(%r15)
movq 0x10(%r14), %rcx
movq %rax, 0x10(%r14)
movaps (%r14), %xmm1
movaps %xmm0, (%r14)
movaps %xmm1, (%r12)
movq %rcx, 0x10(%r12)
movq %r14, %rdi
callq 0xc642
movq %r12, %rdi
callq 0xc642
leaq 0x48(%r15), %rsi
leaq 0x40(%rsp), %r12
movq %r12, %rdi
callq 0x2f12a
movq %rbp, 0x10(%r14)
xorps %xmm0, %xmm0
movaps %xmm0, (%r14)
movups 0x48(%r15), %xmm0
movq 0x58(%r15), %rax
movaps (%r12), %xmm1
movups %xmm1, 0x48(%r15)
movq 0x10(%r12), %rcx
movq %rcx, 0x58(%r15)
movq 0x10(%r14), %rcx
movq %rax, 0x10(%r14)
movaps (%r14), %xmm1
movaps %xmm0, (%r14)
movaps %xmm1, (%r12)
movq %rcx, 0x10(%r12)
leaq 0x10(%rsp), %rdi
callq 0xc642
movq %r12, %rdi
callq 0xc642
movq 0x60(%r15), %rax
movq 0x8(%rax), %r14
subq (%rax), %r14
shrq $0x2, %r14
leaq 0x80(%rsp), %rdx
movl $0x0, (%rdx)
leaq 0x10(%rsp), %rdi
leaq 0x68(%rsp), %rcx
movq %rbx, %rsi
callq 0x15482
movslq %r14d, %rsi
leaq 0x40(%rsp), %rdi
leaq 0x10(%rsp), %rdx
leaq 0xf(%rsp), %rcx
callq 0xc5b2
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x14ef2
callq 0x52a0
leaq 0x80(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x15682
movq %r14, 0x58(%rsp)
movq %rbx, 0x60(%rsp)
leaq 0x68(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x15682
movq 0x60(%r15), %rax
movq %r15, 0xa0(%rsp)
movq 0x68(%r15), %rcx
subq %rax, %rcx
je 0x14fea
movq %rcx, %rdx
sarq $0x3, %rdx
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rdx
movq %rdx, 0x38(%rsp)
xorl %edx, %edx
movl $0xff, %esi
leaq (%rdx,%rdx,2), %r8
movq (%rax,%r8,8), %rdi
movq 0x8(%rax,%r8,8), %r8
subq %rdi, %r8
je 0x14fda
sarq $0x2, %r8
movq 0x80(%rsp), %r14
movq 0x40(%rsp), %rcx
movq 0x68(%rsp), %r11
xorl %r12d, %r12d
xorl %ebp, %ebp
movl (%rdi,%r12,4), %ebx
testl %ebx, %ebx
movq %r14, %r9
cmovnsq %rcx, %r9
movl $0xffffff01, %r15d      # imm = 0xFFFFFF01
cmovnsl %esi, %r15d
movq %rcx, %r10
cmovnsq %r14, %r10
movq (%r9,%rbp), %r9
movl %esi, (%r9,%rdx,4)
imull %ebx, %r15d
shrl $0x5, %r15d
movl $0xff, %r9d
subl %r15d, %r9d
movq (%r10,%rbp), %r10
movl %r9d, (%r10,%rdx,4)
movq (%r11,%rbp), %r10
movl %r9d, (%r10,%rdx,4)
incq %r12
movl %r12d, %r9d
addq $0x18, %rbp
cmpq %r9, %r8
ja 0x14f84
incq %rdx
movl %edx, %edi
cmpq %rdi, 0x38(%rsp)
ja 0x14f57
movq 0xa0(%rsp), %r15
leaq 0x8(%r15), %r12
leaq 0x2025f(%rip), %rsi     # 0x3525c
leaq 0x10(%rsp), %rdi
movq %r12, %rdx
callq 0x15714
leaq 0x20257(%rip), %rsi     # 0x35268
leaq 0x10(%rsp), %rdi
callq 0x55f0
movq 0x60(%rsp), %rbx
movq 0x58(%rsp), %r14
leaq 0xd8(%rsp), %rbp
movq %rbp, -0x10(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x15055
movq %rdx, 0xc8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0xd8(%rsp)
jmp 0x1505c
movups (%rcx), %xmm0
movups %xmm0, (%rbp)
movq 0x8(%rax), %rdx
movq %rdx, 0xd0(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x160(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x15682
leaq 0x148(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x15682
leaq 0x130(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x15682
leaq 0xc8(%rsp), %rdi
leaq 0x160(%rsp), %rcx
leaq 0x148(%rsp), %r8
leaq 0x130(%rsp), %r9
movl %r14d, %esi
movl %ebx, %edx
callq 0x2f2ec
leaq 0x130(%rsp), %rdi
callq 0xc642
leaq 0x148(%rsp), %rdi
callq 0xc642
leaq 0x160(%rsp), %rdi
callq 0xc642
movq 0xc8(%rsp), %rdi
cmpq %rbp, %rdi
je 0x15113
callq 0x52a0
movq %r12, 0x98(%rsp)
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1512e
callq 0x52a0
movq 0x48(%r15), %rax
movq 0x50(%r15), %rcx
subq %rax, %rcx
je 0x1520b
movq %rcx, %rdx
sarq $0x3, %rdx
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rdx
movq %rdx, 0x38(%rsp)
xorl %edx, %edx
movl $0xff, %esi
leaq (%rdx,%rdx,2), %r8
movq (%rax,%r8,8), %rdi
movq 0x8(%rax,%r8,8), %r8
subq %rdi, %r8
je 0x151fb
sarq $0x2, %r8
movq 0x80(%rsp), %r9
movq 0x40(%rsp), %rcx
movq 0x68(%rsp), %r11
xorl %r15d, %r15d
xorl %ebp, %ebp
movl (%rdi,%r15,4), %ebx
movl 0x1b0(%r13), %r12d
movl %r12d, %r14d
shrl $0x1f, %r14d
addl %r12d, %r14d
sarl %r14d
subl %r14d, %ebx
movq %r9, %r14
cmovnsq %rcx, %r14
movl $0xffffff01, %r12d      # imm = 0xFFFFFF01
cmovnsl %esi, %r12d
movq %rcx, %r10
cmovnsq %r9, %r10
movq (%r14,%rbp), %r14
movl %esi, (%r14,%rdx,4)
imull %ebx, %r12d
shrl $0x5, %r12d
movl $0xff, %ebx
subl %r12d, %ebx
movq (%r10,%rbp), %r10
movl %ebx, (%r10,%rdx,4)
movq (%r11,%rbp), %r10
movl %ebx, (%r10,%rdx,4)
incq %r15
movl %r15d, %r10d
addq $0x18, %rbp
cmpq %r10, %r8
ja 0x15191
incq %rdx
movl %edx, %edi
cmpq %rdi, 0x38(%rsp)
ja 0x15160
leaq 0x2005b(%rip), %rsi     # 0x3526d
leaq 0x10(%rsp), %rdi
movq 0x98(%rsp), %rdx
callq 0x15714
leaq 0x2003d(%rip), %rsi     # 0x35268
leaq 0x10(%rsp), %rdi
callq 0x55f0
leaq 0xb8(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x15265
movq %rdx, 0xa8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0xb8(%rsp)
jmp 0x1526c
movups (%rcx), %xmm0
movups %xmm0, (%r15)
movq 0x8(%rax), %rdx
movq %rdx, 0xb0(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x118(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x15682
leaq 0x100(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x15682
leaq 0xe8(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x15682
leaq 0xa8(%rsp), %rdi
leaq 0x118(%rsp), %rcx
leaq 0x100(%rsp), %r8
leaq 0xe8(%rsp), %r9
movq 0x58(%rsp), %rsi
movq 0x60(%rsp), %rdx
callq 0x2f2ec
leaq 0xe8(%rsp), %rdi
callq 0xc642
leaq 0x100(%rsp), %rdi
callq 0xc642
leaq 0x118(%rsp), %rdi
callq 0xc642
movq 0xa8(%rsp), %rdi
cmpq %r15, %rdi
je 0x15328
callq 0x52a0
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x1533c
callq 0x52a0
leaq 0x68(%rsp), %rdi
callq 0xc642
leaq 0x80(%rsp), %rdi
callq 0xc642
leaq 0x40(%rsp), %rdi
callq 0xc642
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0xe8(%rsp), %rdi
callq 0xc642
jmp 0x15384
movq %rax, %rbx
leaq 0x100(%rsp), %rdi
callq 0xc642
jmp 0x15396
movq %rax, %rbx
leaq 0x118(%rsp), %rdi
callq 0xc642
jmp 0x153a8
movq %rax, %rbx
movq 0xa8(%rsp), %rdi
cmpq %r15, %rdi
je 0x153bf
callq 0x52a0
jmp 0x153bf
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
jmp 0x15426
jmp 0x15432
movq %rax, %rbx
leaq 0x130(%rsp), %rdi
callq 0xc642
jmp 0x153e2
movq %rax, %rbx
leaq 0x148(%rsp), %rdi
callq 0xc642
jmp 0x153f4
movq %rax, %rbx
leaq 0x160(%rsp), %rdi
callq 0xc642
jmp 0x15406
movq %rax, %rbx
movq 0xc8(%rsp), %rdi
cmpq %rbp, %rdi
je 0x1541d
callq 0x52a0
jmp 0x1541d
movq %rax, %rbx
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x15435
callq 0x52a0
jmp 0x15435
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0xc642
leaq 0x80(%rsp), %rdi
callq 0xc642
leaq 0x40(%rsp), %rdi
callq 0xc642
movq %rbx, %rdi
callq 0x55a0
movq %rax, %rbx
jmp 0x1543f
movq %rax, %rbx
jmp 0x1544c
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x15456
callq 0x52a0
jmp 0x15456
movq %rax, %rbx
jmp 0x15456
nop