// File: /workspace/github_cpp_makefile_star2_O1/gvaumour[P]cache-simulator/src/DBAMBPredictor.cc
// Function: DBAMBPredictor::printStats(std::ostream&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void 
DBAMBPredictor::printStats(std::ostream& out, string entete)
{	

	
	ofstream output_file(RAP_OUTPUT_FILE);
	
	for(int i = 0 ; i < NUM_RW_TYPE ;i++)
	{
		for(int j = 0 ; j < NUM_RD_TYPE ; j++)
			output_file << "\t[" << str_RW_status[i] << ","<< str_RD_status[j] << "]";
	}
	output_file << endl;
	
	for(unsigned i = 0 ; i < stats_ClassErrors.size() ; i++)
	{
		output_file << "[" << str_RW_status[i/NUM_RD_TYPE] << ","<< str_RD_status[i%NUM_RD_TYPE] << "]\t";
		for(unsigned j = 0 ; j < stats_ClassErrors[i].size() ; j++)
		{
			output_file << stats_ClassErrors[i][j] << "\t";
		}
		output_file << endl;
	}
	output_file.close();


	double migrationNVM=0, migrationSRAM = 0;

	if(simu_parameters.enableMigration)
	{

		ofstream file_migration_stats(RAP_MIGRATION_STATS);
		
		for(unsigned i = 0 ; i < stats_nbMigrationsFromNVM.size() ; i++)
		{
			migrationNVM += stats_nbMigrationsFromNVM[i][FROMNVM];
			migrationSRAM += stats_nbMigrationsFromNVM[i][FROMSRAM];			
			
			file_migration_stats << stats_nbMigrationsFromNVM[i][FROMNVM] << "\t" << stats_nbMigrationsFromNVM[i][FROMSRAM] << endl;	
		}
		file_migration_stats.close();
	}
	/*
	out << "\tRAP Table:" << endl;
	out << "\t\t NB Hits\t" << stats_RAP_hits << endl;
	out << "\t\t NB Miss\t" << stats_RAP_miss << endl;
	out << "\t\t Miss Ratio\t" << stats_RAP_miss*100.0/(double)(stats_RAP_hits+stats_RAP_miss)<< "%" << endl;
	*/
	
	/*out << "\tSource of Error, NVM error" << endl;
	out << "\t\tWrong Policy\t" << stats_error_wrongpolicy << endl;
	out << "\t\tWrong Allocation\t" << stats_error_wrongallocation << endl;
	out << "\t\tLearning\t" << stats_error_learning << endl;		
	*/
	/*
	if(simu_parameters.enableMigration)
		out << "\t\tMigration Error\t" << migrationSRAM << endl;		
	*/
	out << entete << ":DBAMBPredictor:NVM_medium_pred\t" << stats_NVM_medium_pred << endl;
	out << entete << ":DBAMBPredictor:NVM_medium_pred_errors\t" << stats_NVM_medium_pred_errors << endl;
	out << entete << ":DBAMBPredictor:BusynessMigrate\t" << stats_busyness_migrate_change << endl;
	out << entete << ":DBAMBPredictor:BusynessAlloc\t" << stats_busyness_alloc_change << endl;
	out << entete << ":DBAMBPredictor:AllocateSRAM\t" << stats_allocate_SRAM << endl;
	out << entete << ":DBAMBPredictor:AllocateNVM\t" << stats_allocate_NVM << endl;
	
//	out << "\tSource of Error, SRAM error" << endl;
//	out << "\t\tWrong Policy\t" << stats_error_SRAMwrongpolicy << endl;
//	out << "\t\tWrong Allocation\t" << stats_error_SRAMwrongallocation << endl;
//	out << "\t\tLearning\t" << stats_error_SRAMlearning << endl;		
	
	
	/*
	if(stats_nbSwitchDst.size() > 0)
	{
		double sum=0;
		for(auto d : stats_nbSwitchDst)
			sum+= d;
		out << "\t Average Switch\t" << sum / (double) stats_nbSwitchDst.size() << endl;	
	}*/
	


	double total = migrationNVM+migrationSRAM;

	if(total > 0){
		out << entete << ":DBAMBPredictor:NBMigration\t" << total << endl;
		out << entete << ":DBAMBPredictor:MigrationFromNVM\t" << migrationNVM << "\t" << migrationNVM*100/total << "%" << endl;
		out << entete << ":DBAMBPredictor:MigrationFromSRAM\t" << migrationSRAM << "\t" << migrationSRAM*100/total << "%" << endl;
	}
	
	Predictor::printStats(out, entete);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x468, %rsp            # imm = 0x468
movq %rdx, 0x30(%rsp)
movq %rsi, 0x20(%rsp)
movq %rdi, 0x8(%rsp)
leaq 0x23c78(%rip), %rsi     # 0x34cf5
leaq 0x68(%rsp), %rbx
movq %rbx, %rdi
movl $0x10, %edx
callq 0x5310
xorl %r14d, %r14d
leaq 0x22fa9(%rip), %r12     # 0x34042
leaq 0x25eb2(%rip), %r13     # 0x36f52
xorl %r15d, %r15d
movl $0x2, %edx
movq %rbx, %rdi
leaq 0x23c55(%rip), %rsi     # 0x34d07
callq 0x5350
leaq 0x34342(%rip), %rax     # 0x45400
movq (%rax,%r14,8), %rbp
testq %rbp, %rbp
je 0x110df
movq %rbp, %rdi
callq 0x5160
movq %rbx, %rdi
movq %rbp, %rsi
movq %rax, %rdx
callq 0x5350
jmp 0x110fb
movq 0x68(%rsp), %rax
movq -0x18(%rax), %rax
leaq (%rsp,%rax), %rdi
addq $0x68, %rdi
movl 0x20(%rdi), %esi
orl $0x1, %esi
callq 0x5560
movl $0x1, %edx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x5350
leaq 0x3431e(%rip), %rax     # 0x45430
movq (%rax,%r15,8), %rbp
testq %rbp, %rbp
je 0x11133
movq %rbp, %rdi
callq 0x5160
movq %rbx, %rdi
movq %rbp, %rsi
movq %rax, %rdx
callq 0x5350
jmp 0x1114f
movq 0x68(%rsp), %rax
movq -0x18(%rax), %rax
leaq (%rsp,%rax), %rdi
addq $0x68, %rdi
movl 0x20(%rdi), %esi
orl $0x1, %esi
callq 0x5560
movl $0x1, %edx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x5350
incq %r15
cmpq $0x3, %r15
jne 0x110a3
incq %r14
cmpq $0x5, %r14
jne 0x110a0
movq 0x68(%rsp), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x52b0
movsbl %al, %esi
leaq 0x68(%rsp), %r12
movq %r12, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x51f0
movq 0x8(%rsp), %rcx
movq 0x3a8(%rcx), %rax
cmpq 0x3a0(%rcx), %rax
je 0x1136c
xorl %ebp, %ebp
movabsq $-0x5555555555555555, %rbx # imm = 0xAAAAAAAAAAAAAAAB
leaq 0x24aa8(%rip), %r15     # 0x35c7b
movl $0x1, %edx
movq %r12, %rdi
leaq 0x23b26(%rip), %rsi     # 0x34d08
callq 0x5350
movl %ebp, %r14d
movl $0xaaaaaaab, %eax       # imm = 0xAAAAAAAB
imulq %rax, %r14
shrq $0x21, %r14
leaq 0x34202(%rip), %rax     # 0x45400
movq (%rax,%r14,8), %r13
testq %r13, %r13
je 0x1121f
movq %r13, %rdi
callq 0x5160
movq %r12, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x5350
jmp 0x1123b
movq 0x68(%rsp), %rax
movq -0x18(%rax), %rax
leaq (%rsp,%rax), %rdi
addq $0x68, %rdi
movl 0x20(%rdi), %esi
orl $0x1, %esi
callq 0x5560
movl $0x1, %edx
movq %r12, %rdi
leaq 0x22df8(%rip), %rsi     # 0x34042
callq 0x5350
leal (%r14,%r14,2), %eax
movl %ebp, %ecx
subl %eax, %ecx
movl %ecx, %eax
leaq 0x341d0(%rip), %rcx     # 0x45430
movq (%rcx,%rax,8), %r13
testq %r13, %r13
je 0x11281
movq %r13, %rdi
callq 0x5160
movq %r12, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x5350
jmp 0x1129d
movq 0x68(%rsp), %rax
movq -0x18(%rax), %rax
leaq (%rsp,%rax), %rdi
addq $0x68, %rdi
movl 0x20(%rdi), %esi
orl $0x1, %esi
callq 0x5560
movl $0x2, %edx
movq %r12, %rdi
leaq 0x23a5e(%rip), %rsi     # 0x34d0a
callq 0x5350
movq 0x8(%rsp), %rax
movq 0x3a0(%rax), %rcx
leaq (,%rbp,2), %r14
addq %rbp, %r14
movq (%rcx,%r14,8), %rax
cmpq %rax, 0x8(%rcx,%r14,8)
je 0x1131d
movl $0x1, %r13d
xorl %ecx, %ecx
movl (%rax,%rcx,4), %esi
movq %r12, %rdi
callq 0x5580
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x5350
movl %r13d, %ecx
movq 0x8(%rsp), %rax
movq 0x3a0(%rax), %rdx
movq (%rdx,%r14,8), %rax
movq 0x8(%rdx,%r14,8), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
incl %r13d
cmpq %rcx, %rdx
ja 0x112db
movq 0x68(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x52b0
movsbl %al, %esi
movq %r12, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x51f0
movq 0x8(%rsp), %rcx
movq 0x3a8(%rcx), %rax
subq 0x3a0(%rcx), %rax
incl %ebp
sarq $0x3, %rax
imulq %rbx, %rax
cmpq %rbp, %rax
ja 0x111d3
leaq 0x68(%rsp), %rdi
callq 0x5430
leaq 0x34bd3(%rip), %rax     # 0x45f50
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
cmpb $0x1, 0xa9(%rax)
movq 0x20(%rsp), %r15
movq 0x30(%rsp), %r12
jne 0x11504
leaq 0x23968(%rip), %rsi     # 0x34d0d
leaq 0x268(%rsp), %rdi
movl $0x10, %edx
callq 0x5310
movq 0x8(%rsp), %rcx
movq 0x3b8(%rcx), %rax
cmpq %rax, 0x3c0(%rcx)
je 0x114ab
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
movl $0x1, %ebp
xorl %ecx, %ecx
leaq 0x24893(%rip), %r15     # 0x35c7b
movabsq $-0x5555555555555555, %r14 # imm = 0xAAAAAAAAAAAAAAAB
leaq (%rcx,%rcx,2), %rbx
movq (%rax,%rbx,8), %rax
movq (%rax), %r12
leaq 0x268(%rsp), %rdi
movl %r12d, %esi
callq 0x5580
movq %rax, %r13
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x5350
movq 0x8(%rsp), %rax
movq 0x3b8(%rax), %rax
movq (%rax,%rbx,8), %rax
movl 0x4(%rax), %esi
movq %r13, %rdi
callq 0x5580
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x52b0
movsbl %al, %esi
movq %r13, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x51f0
movq %r12, %xmm0
cvtdq2pd %xmm0, %xmm0
movapd 0x10(%rsp), %xmm1
addpd %xmm0, %xmm1
movapd %xmm1, 0x10(%rsp)
movl %ebp, %ecx
movq 0x8(%rsp), %rdx
movq 0x3b8(%rdx), %rax
movq 0x3c0(%rdx), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
imulq %r14, %rdx
incl %ebp
cmpq %rcx, %rdx
ja 0x113f2
jmp 0x114b5
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
leaq 0x268(%rsp), %rdi
callq 0x5430
movq 0x33af7(%rip), %rax     # 0x44fc0
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x270(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x268(%rsp,%rcx)
callq 0x5270
leaq 0x360(%rsp), %rdi
callq 0x5120
movq 0x20(%rsp), %r15
movq 0x30(%rsp), %r12
movq (%r12), %rsi
movq 0x8(%r12), %rdx
movq %r15, %rdi
callq 0x5350
movq %rax, %rbx
leaq 0x23806(%rip), %rsi     # 0x34d25
movl $0x20, %edx
movq %rax, %rdi
callq 0x5350
movq 0x8(%rsp), %rax
movl 0x374(%rax), %esi
movq %rbx, %rdi
callq 0x51e0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x52b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x51f0
movq (%r12), %rsi
movq 0x8(%r12), %rdx
movq %r15, %rdi
callq 0x5350
movq %rax, %rbx
leaq 0x237c2(%rip), %rsi     # 0x34d46
movl $0x27, %edx
movq %rax, %rdi
callq 0x5350
movq 0x8(%rsp), %rax
movl 0x370(%rax), %esi
movq %rbx, %rdi
callq 0x51e0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x52b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x51f0
movq (%r12), %rsi
movq 0x8(%r12), %rdx
movq %r15, %rdi
callq 0x5350
movq %rax, %rbx
leaq 0x23785(%rip), %rsi     # 0x34d6e
movl $0x20, %edx
movq %rax, %rdi
callq 0x5350
movq 0x8(%rsp), %rax
movq 0x380(%rax), %rsi
movq %rbx, %rdi
callq 0x51e0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x52b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x51f0
movq (%r12), %rsi
movq 0x8(%r12), %rdx
movq %r15, %rdi
callq 0x5350
movq %rax, %rbx
leaq 0x23740(%rip), %rsi     # 0x34d8f
movl $0x1e, %edx
movq %rax, %rdi
callq 0x5350
movq 0x8(%rsp), %rax
movq 0x378(%rax), %rsi
movq %rbx, %rdi
callq 0x51e0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x52b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x51f0
movq (%r12), %rsi
movq 0x8(%r12), %rdx
movq %r15, %rdi
callq 0x5350
movq %rax, %rbx
leaq 0x236f9(%rip), %rsi     # 0x34dae
movl $0x1d, %edx
movq %rax, %rdi
callq 0x5350
movq 0x8(%rsp), %rax
movq 0x368(%rax), %rsi
movq %rbx, %rdi
callq 0x51e0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x52b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x51f0
movq (%r12), %rsi
movq 0x8(%r12), %rdx
movq %r15, %rdi
callq 0x5350
movq %rax, %rbx
leaq 0x236b1(%rip), %rsi     # 0x34dcc
movl $0x1c, %edx
movq %rax, %rdi
callq 0x5350
movq 0x8(%rsp), %rax
movq 0x360(%rax), %rsi
movq %rbx, %rdi
callq 0x51e0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x52b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x51f0
movapd 0x10(%rsp), %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
movapd %xmm0, %xmm2
movapd %xmm1, 0x30(%rsp)
addsd %xmm1, %xmm2
xorpd %xmm0, %xmm0
movapd %xmm2, 0x20(%rsp)
ucomisd %xmm0, %xmm2
jbe 0x11944
movq (%r12), %rsi
movq 0x8(%r12), %rdx
movq %r15, %rdi
callq 0x5350
movq %rax, %rbx
leaq 0x23638(%rip), %rsi     # 0x34de9
movl $0x1c, %edx
movq %rax, %rdi
callq 0x5350
movq %rbx, %rdi
movapd 0x20(%rsp), %xmm0
callq 0x5500
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x52b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x51f0
movq (%r12), %rsi
movq 0x8(%r12), %rdx
movq %r15, %rdi
callq 0x5350
movq %rax, %rbx
leaq 0x235f5(%rip), %rsi     # 0x34e06
movl $0x21, %edx
movq %rax, %rdi
callq 0x5350
movq %rbx, %rdi
movapd 0x10(%rsp), %xmm0
callq 0x5500
movq %rax, %rbx
leaq 0x24445(%rip), %rsi     # 0x35c7b
movl $0x1, %edx
movq %rax, %rdi
callq 0x5350
movapd 0x10(%rsp), %xmm0
mulsd 0x2315f(%rip), %xmm0    # 0x349b0
divsd 0x20(%rsp), %xmm0
movq %rbx, %rdi
callq 0x5500
movq %rax, %rbx
leaq 0x235bf(%rip), %rsi     # 0x34e28
movl $0x1, %edx
movq %rax, %rdi
callq 0x5350
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x52b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x51f0
movq (%r12), %rsi
movq 0x8(%r12), %rdx
movq %r15, %rdi
callq 0x5350
movq %rax, %rbx
leaq 0x23572(%rip), %rsi     # 0x34e2a
movl $0x22, %edx
movq %rax, %rdi
callq 0x5350
movq %rbx, %rdi
movapd 0x30(%rsp), %xmm0
callq 0x5500
movq %rax, %rbx
leaq 0x2439e(%rip), %rsi     # 0x35c7b
movl $0x1, %edx
movq %rax, %rdi
callq 0x5350
movapd 0x30(%rsp), %xmm0
mulsd 0x230b8(%rip), %xmm0    # 0x349b0
divsd 0x20(%rsp), %xmm0
movq %rbx, %rdi
callq 0x5500
movq %rax, %rbx
leaq 0x23518(%rip), %rsi     # 0x34e28
movl $0x1, %edx
movq %rax, %rdi
callq 0x5350
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x52b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x51f0
leaq 0x58(%rsp), %r14
movq %r14, -0x10(%r14)
movq (%r12), %rsi
movq 0x8(%r12), %rdx
addq %rsi, %rdx
leaq 0x48(%rsp), %rdi
callq 0xcc1c
leaq 0x48(%rsp), %rdx
movq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x27d9c
movq 0x48(%rsp), %rdi
cmpq %r14, %rdi
je 0x11984
callq 0x52a0
movq 0x33635(%rip), %rax     # 0x44fc0
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x70(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x68(%rsp,%rcx)
callq 0x5270
leaq 0x160(%rsp), %rdi
callq 0x5120
addq $0x468, %rsp            # imm = 0x468
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x119e6
jmp 0x119fc
movq %rax, %rbx
movq 0x48(%rsp), %rdi
cmpq %r14, %rdi
je 0x119ff
callq 0x52a0
jmp 0x119ff
jmp 0x119fc
jmp 0x119fc
jmp 0x119fc
movq %rax, %rbx
leaq 0x268(%rsp), %rdi
callq 0x5628
jmp 0x119ff
jmp 0x119fc
jmp 0x119fc
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x5628
movq %rbx, %rdi
callq 0x55a0
nop