// File: 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:
subq $0x268, %rsp            # imm = 0x268
movq %rdi, 0x260(%rsp)
movq 0x260(%rsp), %rax
movq %rax, 0x78(%rsp)
leaq 0x6658d(%rip), %rax     # 0x93ff0
testb $0x1, 0x1cc(%rax)
je 0x2da80
movq 0x78(%rsp), %rdi
addq $0x60, %rdi
callq 0xfb20
cmpq $0x0, %rax
jne 0x2da85
jmp 0x2e4ef
movq 0x78(%rsp), %rdi
movl (%rdi), %eax
movl %eax, 0x25c(%rsp)
addq $0x60, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xef70
movq %rax, %rdi
callq 0x11020
movl %eax, 0x258(%rsp)
cmpl $0x7d0, 0x258(%rsp) # imm = 0x7D0
jle 0x2db53
movq 0x78(%rsp), %rsi
addq $0x60, %rsi
leaq 0x240(%rsp), %rdi
callq 0x66180
movq 0x78(%rsp), %rdi
addq $0x60, %rdi
leaq 0x240(%rsp), %rsi
callq 0xee50
leaq 0x240(%rsp), %rdi
callq 0xee90
movq 0x78(%rsp), %rsi
addq $0x48, %rsi
leaq 0x228(%rsp), %rdi
callq 0x66180
movq 0x78(%rsp), %rdi
addq $0x48, %rdi
leaq 0x228(%rsp), %rsi
callq 0xee50
leaq 0x228(%rsp), %rdi
callq 0xee90
movq 0x78(%rsp), %rdi
addq $0x60, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xef70
movq %rax, %rdi
callq 0x11020
movl %eax, 0x258(%rsp)
movslq 0x258(%rsp), %rax
movq %rax, 0x60(%rsp)
movslq 0x25c(%rsp), %rax
movq %rax, 0x68(%rsp)
movl $0x0, 0x1f4(%rsp)
leaq 0x1f3(%rsp), %rdi
movq %rdi, 0x70(%rsp)
callq 0xed30
movq 0x68(%rsp), %rsi
movq 0x70(%rsp), %rcx
leaq 0x1f8(%rsp), %rdi
leaq 0x1f4(%rsp), %rdx
callq 0xed40
jmp 0x2dbab
leaq 0x1e3(%rsp), %rdi
movq %rdi, 0x58(%rsp)
callq 0xedc0
movq 0x60(%rsp), %rsi
movq 0x58(%rsp), %rcx
leaq 0x210(%rsp), %rdi
leaq 0x1f8(%rsp), %rdx
callq 0xedd0
jmp 0x2dbde
leaq 0x1e3(%rsp), %rdi
callq 0xeef0
leaq 0x1f8(%rsp), %rdi
callq 0xef00
leaq 0x1f3(%rsp), %rdi
callq 0xef60
leaq 0x1c8(%rsp), %rdi
leaq 0x210(%rsp), %rsi
callq 0x2e9d0
jmp 0x2dc1c
leaq 0x1b0(%rsp), %rdi
leaq 0x210(%rsp), %rsi
callq 0x2e9d0
jmp 0x2dc33
movl $0x0, 0x1ac(%rsp)
movq 0x78(%rsp), %rdi
movl 0x1ac(%rsp), %eax
movq %rax, 0x50(%rsp)
addq $0x60, %rdi
callq 0xfb20
movq %rax, %rcx
movq 0x50(%rsp), %rax
cmpq %rcx, %rax
jae 0x2df42
movl $0x0, 0x1a8(%rsp)
movq 0x78(%rsp), %rdi
movl 0x1a8(%rsp), %eax
movq %rax, 0x48(%rsp)
addq $0x60, %rdi
movl 0x1ac(%rsp), %eax
movl %eax, %esi
callq 0xef70
movq %rax, %rdi
callq 0x11020
movq %rax, %rcx
movq 0x48(%rsp), %rax
cmpq %rcx, %rax
jae 0x2df2a
movq 0x78(%rsp), %rdi
addq $0x60, %rdi
movl 0x1ac(%rsp), %eax
movl %eax, %esi
callq 0xef70
movq %rax, %rdi
movl 0x1a8(%rsp), %eax
movl %eax, %esi
callq 0xef90
movl (%rax), %eax
movl %eax, 0x1a4(%rsp)
cmpl $0x0, 0x1a4(%rsp)
jl 0x2de43
movl 0x1a8(%rsp), %eax
movl %eax, %esi
leaq 0x210(%rsp), %rdi
callq 0xef70
movq %rax, %rdi
movl 0x1ac(%rsp), %eax
movl %eax, %esi
callq 0xef90
movl $0xff, (%rax)
imull $0xff, 0x1a4(%rsp), %eax
movl $0x20, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl $0xff, %eax
subl %ecx, %eax
movl %eax, 0x40(%rsp)
movl 0x1a8(%rsp), %eax
movl %eax, %esi
leaq 0x1c8(%rsp), %rdi
callq 0xef70
movq %rax, %rdi
movl 0x1ac(%rsp), %eax
movl %eax, %esi
callq 0xef90
movl 0x40(%rsp), %ecx
movl %ecx, (%rax)
imull $0xff, 0x1a4(%rsp), %eax
movl $0x20, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl $0xff, %eax
subl %ecx, %eax
movl %eax, 0x44(%rsp)
movl 0x1a8(%rsp), %eax
movl %eax, %esi
leaq 0x1b0(%rsp), %rdi
callq 0xef70
movq %rax, %rdi
movl 0x1ac(%rsp), %eax
movl %eax, %esi
callq 0xef90
movl 0x44(%rsp), %ecx
movl %ecx, (%rax)
jmp 0x2df12
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e8(%rsp)
movl %eax, 0x1e4(%rsp)
jmp 0x2ddff
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e8(%rsp)
movl %eax, 0x1e4(%rsp)
leaq 0x1e3(%rsp), %rdi
callq 0xeef0
leaq 0x1f8(%rsp), %rdi
callq 0xef00
leaq 0x1f3(%rsp), %rdi
callq 0xef60
jmp 0x2e5ce
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e8(%rsp)
movl %eax, 0x1e4(%rsp)
jmp 0x2e5c1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e8(%rsp)
movl %eax, 0x1e4(%rsp)
jmp 0x2e5b4
movl 0x1a8(%rsp), %eax
movl %eax, %esi
leaq 0x1c8(%rsp), %rdi
callq 0xef70
movq %rax, %rdi
movl 0x1ac(%rsp), %eax
movl %eax, %esi
callq 0xef90
movl $0xff, (%rax)
xorl %eax, %eax
subl 0x1a4(%rsp), %eax
imull $0xff, %eax, %eax
movl $0x20, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl $0xff, %eax
subl %ecx, %eax
movl %eax, 0x38(%rsp)
movl 0x1a8(%rsp), %eax
movl %eax, %esi
leaq 0x210(%rsp), %rdi
callq 0xef70
movq %rax, %rdi
movl 0x1ac(%rsp), %eax
movl %eax, %esi
callq 0xef90
movl 0x38(%rsp), %ecx
movl %ecx, (%rax)
xorl %eax, %eax
subl 0x1a4(%rsp), %eax
imull $0xff, %eax, %eax
movl $0x20, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl $0xff, %eax
subl %ecx, %eax
movl %eax, 0x3c(%rsp)
movl 0x1a8(%rsp), %eax
movl %eax, %esi
leaq 0x1b0(%rsp), %rdi
callq 0xef70
movq %rax, %rdi
movl 0x1ac(%rsp), %eax
movl %eax, %esi
callq 0xef90
movl 0x3c(%rsp), %ecx
movl %ecx, (%rax)
jmp 0x2df14
movl 0x1a8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1a8(%rsp)
jmp 0x2dc74
jmp 0x2df2c
movl 0x1ac(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1ac(%rsp)
jmp 0x2dc3e
movq 0x78(%rsp), %rdx
addq $0x8, %rdx
leaq 0x442ca(%rip), %rsi     # 0x7221c
leaq 0x160(%rsp), %rdi
callq 0x2ead0
jmp 0x2df61
leaq 0x442c0(%rip), %rdx     # 0x72228
leaq 0x180(%rsp), %rdi
leaq 0x160(%rsp), %rsi
callq 0x10180
jmp 0x2df7f
movl 0x258(%rsp), %eax
movl %eax, 0x30(%rsp)
movl 0x25c(%rsp), %eax
movl %eax, 0x34(%rsp)
leaq 0x148(%rsp), %rdi
leaq 0x210(%rsp), %rsi
callq 0x2e9d0
jmp 0x2dfac
leaq 0x130(%rsp), %rdi
leaq 0x1c8(%rsp), %rsi
callq 0x2e9d0
jmp 0x2dfc3
leaq 0x118(%rsp), %rdi
leaq 0x1b0(%rsp), %rsi
callq 0x2e9d0
jmp 0x2dfda
movl 0x34(%rsp), %edx
movl 0x30(%rsp), %esi
leaq 0x180(%rsp), %rdi
leaq 0x148(%rsp), %rcx
leaq 0x130(%rsp), %r8
leaq 0x118(%rsp), %r9
callq 0x66550
jmp 0x2e009
leaq 0x118(%rsp), %rdi
callq 0xee90
leaq 0x130(%rsp), %rdi
callq 0xee90
leaq 0x148(%rsp), %rdi
callq 0xee90
leaq 0x180(%rsp), %rdi
callq 0x5768
leaq 0x160(%rsp), %rdi
callq 0x5768
movl $0x0, 0x114(%rsp)
movq 0x78(%rsp), %rdi
movl 0x114(%rsp), %eax
movq %rax, 0x28(%rsp)
addq $0x48, %rdi
callq 0xfb20
movq %rax, %rcx
movq 0x28(%rsp), %rax
cmpq %rcx, %rax
jae 0x2e3c0
movl $0x0, 0x110(%rsp)
movq 0x78(%rsp), %rdi
movl 0x110(%rsp), %eax
movq %rax, 0x20(%rsp)
addq $0x48, %rdi
movl 0x114(%rsp), %eax
movl %eax, %esi
callq 0xef70
movq %rax, %rdi
callq 0x11020
movq %rax, %rcx
movq 0x20(%rsp), %rax
cmpq %rcx, %rax
jae 0x2e3a8
movq 0x78(%rsp), %rdi
addq $0x48, %rdi
movl 0x114(%rsp), %eax
movl %eax, %esi
callq 0xef70
movq %rax, %rdi
movl 0x110(%rsp), %eax
movl %eax, %esi
callq 0xef90
movl (%rax), %eax
movl %eax, 0x1c(%rsp)
leaq 0x65ef4(%rip), %rax     # 0x93ff0
movl 0x1b0(%rax), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl 0x1c(%rsp), %eax
subl %ecx, %eax
movl %eax, 0x10c(%rsp)
cmpl $0x0, 0x10c(%rsp)
jl 0x2e2c1
movl 0x110(%rsp), %eax
movl %eax, %esi
leaq 0x210(%rsp), %rdi
callq 0xef70
movq %rax, %rdi
movl 0x114(%rsp), %eax
movl %eax, %esi
callq 0xef90
movl $0xff, (%rax)
imull $0xff, 0x10c(%rsp), %eax
movl $0x20, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl $0xff, %eax
subl %ecx, %eax
movl %eax, 0x14(%rsp)
movl 0x110(%rsp), %eax
movl %eax, %esi
leaq 0x1c8(%rsp), %rdi
callq 0xef70
movq %rax, %rdi
movl 0x114(%rsp), %eax
movl %eax, %esi
callq 0xef90
movl 0x14(%rsp), %ecx
movl %ecx, (%rax)
imull $0xff, 0x10c(%rsp), %eax
movl $0x20, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl $0xff, %eax
subl %ecx, %eax
movl %eax, 0x18(%rsp)
movl 0x110(%rsp), %eax
movl %eax, %esi
leaq 0x1b0(%rsp), %rdi
callq 0xef70
movq %rax, %rdi
movl 0x114(%rsp), %eax
movl %eax, %esi
callq 0xef90
movl 0x18(%rsp), %ecx
movl %ecx, (%rax)
jmp 0x2e390
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e8(%rsp)
movl %eax, 0x1e4(%rsp)
jmp 0x2e5a7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e8(%rsp)
movl %eax, 0x1e4(%rsp)
jmp 0x2e2af
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e8(%rsp)
movl %eax, 0x1e4(%rsp)
jmp 0x2e2a2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e8(%rsp)
movl %eax, 0x1e4(%rsp)
jmp 0x2e295
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e8(%rsp)
movl %eax, 0x1e4(%rsp)
jmp 0x2e288
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e8(%rsp)
movl %eax, 0x1e4(%rsp)
leaq 0x118(%rsp), %rdi
callq 0xee90
leaq 0x130(%rsp), %rdi
callq 0xee90
leaq 0x148(%rsp), %rdi
callq 0xee90
leaq 0x180(%rsp), %rdi
callq 0x5768
leaq 0x160(%rsp), %rdi
callq 0x5768
jmp 0x2e5a7
movl 0x110(%rsp), %eax
movl %eax, %esi
leaq 0x1c8(%rsp), %rdi
callq 0xef70
movq %rax, %rdi
movl 0x114(%rsp), %eax
movl %eax, %esi
callq 0xef90
movl $0xff, (%rax)
xorl %eax, %eax
subl 0x10c(%rsp), %eax
imull $0xff, %eax, %eax
movl $0x20, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl $0xff, %eax
subl %ecx, %eax
movl %eax, 0xc(%rsp)
movl 0x110(%rsp), %eax
movl %eax, %esi
leaq 0x210(%rsp), %rdi
callq 0xef70
movq %rax, %rdi
movl 0x114(%rsp), %eax
movl %eax, %esi
callq 0xef90
movl 0xc(%rsp), %ecx
movl %ecx, (%rax)
xorl %eax, %eax
subl 0x10c(%rsp), %eax
imull $0xff, %eax, %eax
movl $0x20, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl $0xff, %eax
subl %ecx, %eax
movl %eax, 0x10(%rsp)
movl 0x110(%rsp), %eax
movl %eax, %esi
leaq 0x1b0(%rsp), %rdi
callq 0xef70
movq %rax, %rdi
movl 0x114(%rsp), %eax
movl %eax, %esi
callq 0xef90
movl 0x10(%rsp), %ecx
movl %ecx, (%rax)
jmp 0x2e392
movl 0x110(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x110(%rsp)
jmp 0x2e08b
jmp 0x2e3aa
movl 0x114(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x114(%rsp)
jmp 0x2e055
movq 0x78(%rsp), %rdx
addq $0x8, %rdx
leaq 0x43e5d(%rip), %rsi     # 0x7222d
leaq 0xc8(%rsp), %rdi
callq 0x2ead0
jmp 0x2e3df
leaq 0x43e42(%rip), %rdx     # 0x72228
leaq 0xe8(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0x10180
jmp 0x2e3fd
movl 0x258(%rsp), %eax
movl %eax, 0x4(%rsp)
movl 0x25c(%rsp), %eax
movl %eax, 0x8(%rsp)
leaq 0xb0(%rsp), %rdi
leaq 0x210(%rsp), %rsi
callq 0x2e9d0
jmp 0x2e42a
leaq 0x98(%rsp), %rdi
leaq 0x1c8(%rsp), %rsi
callq 0x2e9d0
jmp 0x2e441
leaq 0x80(%rsp), %rdi
leaq 0x1b0(%rsp), %rsi
callq 0x2e9d0
jmp 0x2e458
movl 0x8(%rsp), %edx
movl 0x4(%rsp), %esi
leaq 0xe8(%rsp), %rdi
leaq 0xb0(%rsp), %rcx
leaq 0x98(%rsp), %r8
leaq 0x80(%rsp), %r9
callq 0x66550
jmp 0x2e487
leaq 0x80(%rsp), %rdi
callq 0xee90
leaq 0x98(%rsp), %rdi
callq 0xee90
leaq 0xb0(%rsp), %rdi
callq 0xee90
leaq 0xe8(%rsp), %rdi
callq 0x5768
leaq 0xc8(%rsp), %rdi
callq 0x5768
leaq 0x1b0(%rsp), %rdi
callq 0xee90
leaq 0x1c8(%rsp), %rdi
callq 0xee90
leaq 0x210(%rsp), %rdi
callq 0xee90
addq $0x268, %rsp            # imm = 0x268
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e8(%rsp)
movl %eax, 0x1e4(%rsp)
jmp 0x2e59a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e8(%rsp)
movl %eax, 0x1e4(%rsp)
jmp 0x2e58d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e8(%rsp)
movl %eax, 0x1e4(%rsp)
jmp 0x2e580
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e8(%rsp)
movl %eax, 0x1e4(%rsp)
jmp 0x2e573
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e8(%rsp)
movl %eax, 0x1e4(%rsp)
leaq 0x80(%rsp), %rdi
callq 0xee90
leaq 0x98(%rsp), %rdi
callq 0xee90
leaq 0xb0(%rsp), %rdi
callq 0xee90
leaq 0xe8(%rsp), %rdi
callq 0x5768
leaq 0xc8(%rsp), %rdi
callq 0x5768
leaq 0x1b0(%rsp), %rdi
callq 0xee90
leaq 0x1c8(%rsp), %rdi
callq 0xee90
leaq 0x210(%rsp), %rdi
callq 0xee90
movq 0x1e8(%rsp), %rdi
callq 0x5690
nopl (%rax,%rax)