// File: /workspace/github_cpp_makefile_star2_O3/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 0x23cca(%rip), %rsi     # 0x34cd5
leaq 0x68(%rsp), %rbx
movq %rbx, %rdi
movl $0x10, %edx
callq 0x5320
xorl %r14d, %r14d
leaq 0x22fef(%rip), %r12     # 0x34016
leaq 0x25f1c(%rip), %r13     # 0x36f4a
xorl %r15d, %r15d
movl $0x2, %edx
movq %rbx, %rdi
leaq 0x23ca7(%rip), %rsi     # 0x34ce7
callq 0x5360
leaq 0x343b4(%rip), %rax     # 0x45400
movq (%rax,%r14,8), %rbp
testq %rbp, %rbp
je 0x1106d
movq %rbp, %rdi
callq 0x5160
movq %rbx, %rdi
movq %rbp, %rsi
movq %rax, %rdx
callq 0x5360
jmp 0x11089
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 0x5360
leaq 0x34390(%rip), %rax     # 0x45430
movq (%rax,%r15,8), %rbp
testq %rbp, %rbp
je 0x110c1
movq %rbp, %rdi
callq 0x5160
movq %rbx, %rdi
movq %rbp, %rsi
movq %rax, %rdx
callq 0x5360
jmp 0x110dd
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 0x5360
incq %r15
cmpq $0x3, %r15
jne 0x11031
incq %r14
cmpq $0x5, %r14
jne 0x1102e
movq 0x68(%rsp), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x52c0
movsbl %al, %esi
leaq 0x68(%rsp), %r12
movq %r12, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x5200
movq 0x8(%rsp), %rcx
movq 0x3a8(%rcx), %rax
cmpq 0x3a0(%rcx), %rax
je 0x112fa
xorl %ebp, %ebp
movabsq $-0x5555555555555555, %rbx # imm = 0xAAAAAAAAAAAAAAAB
leaq 0x24b12(%rip), %r15     # 0x35c73
movl $0x1, %edx
movq %r12, %rdi
leaq 0x23b78(%rip), %rsi     # 0x34ce8
callq 0x5360
movl %ebp, %r14d
movl $0xaaaaaaab, %eax       # imm = 0xAAAAAAAB
imulq %rax, %r14
shrq $0x21, %r14
leaq 0x34274(%rip), %rax     # 0x45400
movq (%rax,%r14,8), %r13
testq %r13, %r13
je 0x111ad
movq %r13, %rdi
callq 0x5160
movq %r12, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x5360
jmp 0x111c9
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 0x22e3e(%rip), %rsi     # 0x34016
callq 0x5360
leal (%r14,%r14,2), %eax
movl %ebp, %ecx
subl %eax, %ecx
movl %ecx, %eax
leaq 0x34242(%rip), %rcx     # 0x45430
movq (%rcx,%rax,8), %r13
testq %r13, %r13
je 0x1120f
movq %r13, %rdi
callq 0x5160
movq %r12, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x5360
jmp 0x1122b
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 0x23ab0(%rip), %rsi     # 0x34cea
callq 0x5360
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 0x112ab
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 0x5360
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 0x11269
movq 0x68(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x52c0
movsbl %al, %esi
movq %r12, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x5200
movq 0x8(%rsp), %rcx
movq 0x3a8(%rcx), %rax
subq 0x3a0(%rcx), %rax
incl %ebp
sarq $0x3, %rax
imulq %rbx, %rax
cmpq %rbp, %rax
ja 0x11161
leaq 0x68(%rsp), %rdi
callq 0x5430
leaq 0x34c45(%rip), %rax     # 0x45f50
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
cmpb $0x1, 0xa9(%rax)
movq 0x20(%rsp), %r15
movq 0x30(%rsp), %r12
jne 0x11492
leaq 0x239ba(%rip), %rsi     # 0x34ced
leaq 0x268(%rsp), %rdi
movl $0x10, %edx
callq 0x5320
movq 0x8(%rsp), %rcx
movq 0x3b8(%rcx), %rax
cmpq %rax, 0x3c0(%rcx)
je 0x11439
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
movl $0x1, %ebp
xorl %ecx, %ecx
leaq 0x248fd(%rip), %r15     # 0x35c73
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 0x5360
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 0x52c0
movsbl %al, %esi
movq %r13, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x5200
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 0x11380
jmp 0x11443
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
leaq 0x268(%rsp), %rdi
callq 0x5430
movq 0x33b69(%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 0x5280
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 0x5360
movq %rax, %rbx
leaq 0x23858(%rip), %rsi     # 0x34d05
movl $0x20, %edx
movq %rax, %rdi
callq 0x5360
movq 0x8(%rsp), %rax
movl 0x374(%rax), %esi
movq %rbx, %rdi
callq 0x51f0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x52c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x5200
movq (%r12), %rsi
movq 0x8(%r12), %rdx
movq %r15, %rdi
callq 0x5360
movq %rax, %rbx
leaq 0x23814(%rip), %rsi     # 0x34d26
movl $0x27, %edx
movq %rax, %rdi
callq 0x5360
movq 0x8(%rsp), %rax
movl 0x370(%rax), %esi
movq %rbx, %rdi
callq 0x51f0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x52c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x5200
movq (%r12), %rsi
movq 0x8(%r12), %rdx
movq %r15, %rdi
callq 0x5360
movq %rax, %rbx
leaq 0x237d7(%rip), %rsi     # 0x34d4e
movl $0x20, %edx
movq %rax, %rdi
callq 0x5360
movq 0x8(%rsp), %rax
movq 0x380(%rax), %rsi
movq %rbx, %rdi
callq 0x51f0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x52c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x5200
movq (%r12), %rsi
movq 0x8(%r12), %rdx
movq %r15, %rdi
callq 0x5360
movq %rax, %rbx
leaq 0x23792(%rip), %rsi     # 0x34d6f
movl $0x1e, %edx
movq %rax, %rdi
callq 0x5360
movq 0x8(%rsp), %rax
movq 0x378(%rax), %rsi
movq %rbx, %rdi
callq 0x51f0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x52c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x5200
movq (%r12), %rsi
movq 0x8(%r12), %rdx
movq %r15, %rdi
callq 0x5360
movq %rax, %rbx
leaq 0x2374b(%rip), %rsi     # 0x34d8e
movl $0x1d, %edx
movq %rax, %rdi
callq 0x5360
movq 0x8(%rsp), %rax
movq 0x368(%rax), %rsi
movq %rbx, %rdi
callq 0x51f0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x52c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x5200
movq (%r12), %rsi
movq 0x8(%r12), %rdx
movq %r15, %rdi
callq 0x5360
movq %rax, %rbx
leaq 0x23703(%rip), %rsi     # 0x34dac
movl $0x1c, %edx
movq %rax, %rdi
callq 0x5360
movq 0x8(%rsp), %rax
movq 0x360(%rax), %rsi
movq %rbx, %rdi
callq 0x51f0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x52c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x5200
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 0x118d2
movq (%r12), %rsi
movq 0x8(%r12), %rdx
movq %r15, %rdi
callq 0x5360
movq %rax, %rbx
leaq 0x2368a(%rip), %rsi     # 0x34dc9
movl $0x1c, %edx
movq %rax, %rdi
callq 0x5360
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 0x52c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x5200
movq (%r12), %rsi
movq 0x8(%r12), %rdx
movq %r15, %rdi
callq 0x5360
movq %rax, %rbx
leaq 0x23647(%rip), %rsi     # 0x34de6
movl $0x21, %edx
movq %rax, %rdi
callq 0x5360
movq %rbx, %rdi
movapd 0x10(%rsp), %xmm0
callq 0x5500
movq %rax, %rbx
leaq 0x244af(%rip), %rsi     # 0x35c73
movl $0x1, %edx
movq %rax, %rdi
callq 0x5360
movapd 0x10(%rsp), %xmm0
mulsd 0x231b1(%rip), %xmm0    # 0x34990
divsd 0x20(%rsp), %xmm0
movq %rbx, %rdi
callq 0x5500
movq %rax, %rbx
leaq 0x23611(%rip), %rsi     # 0x34e08
movl $0x1, %edx
movq %rax, %rdi
callq 0x5360
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x52c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x5200
movq (%r12), %rsi
movq 0x8(%r12), %rdx
movq %r15, %rdi
callq 0x5360
movq %rax, %rbx
leaq 0x235c4(%rip), %rsi     # 0x34e0a
movl $0x22, %edx
movq %rax, %rdi
callq 0x5360
movq %rbx, %rdi
movapd 0x30(%rsp), %xmm0
callq 0x5500
movq %rax, %rbx
leaq 0x24408(%rip), %rsi     # 0x35c73
movl $0x1, %edx
movq %rax, %rdi
callq 0x5360
movapd 0x30(%rsp), %xmm0
mulsd 0x2310a(%rip), %xmm0    # 0x34990
divsd 0x20(%rsp), %xmm0
movq %rbx, %rdi
callq 0x5500
movq %rax, %rbx
leaq 0x2356a(%rip), %rsi     # 0x34e08
movl $0x1, %edx
movq %rax, %rdi
callq 0x5360
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x52c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5030
movq %rax, %rdi
callq 0x5200
leaq 0x58(%rsp), %r14
movq %r14, -0x10(%r14)
movq (%r12), %rsi
movq 0x8(%r12), %rdx
addq %rsi, %rdx
leaq 0x48(%rsp), %rdi
callq 0xcbd6
leaq 0x48(%rsp), %rdx
movq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x27a64
movq 0x48(%rsp), %rdi
cmpq %r14, %rdi
je 0x11912
callq 0x52b0
movq 0x336a7(%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 0x5280
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 0x11974
jmp 0x1198a
movq %rax, %rbx
movq 0x48(%rsp), %rdi
cmpq %r14, %rdi
je 0x1198d
callq 0x52b0
jmp 0x1198d
jmp 0x1198a
jmp 0x1198a
jmp 0x1198a
movq %rax, %rbx
leaq 0x268(%rsp), %rdi
callq 0x5628
jmp 0x1198d
jmp 0x1198a
jmp 0x1198a
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x5628
movq %rbx, %rdi
callq 0x55a0
nop