// File: /workspace/github_cpp_makefile_star2_O2/CMU-SAFARI[P]MQSim/src/ssd/Stats.cpp
// Function: SSD_Components::Stats::Init_stats(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int)
void Stats::Init_stats(unsigned int channel_no, unsigned int chip_no_per_channel, unsigned int die_no_per_chip, unsigned int plane_no_per_die, 
		unsigned int block_no_per_plane, unsigned int page_no_per_block, unsigned int max_allowed_block_erase_count)
	{
		Block_erase_histogram = new unsigned int ****[channel_no];
		for (unsigned int channel_cntr = 0; channel_cntr < channel_no; channel_cntr++) {
			Block_erase_histogram[channel_cntr] = new unsigned int***[chip_no_per_channel];
			for (unsigned int chip_cntr = 0; chip_cntr < chip_no_per_channel; chip_cntr++) {
				Block_erase_histogram[channel_cntr][chip_cntr] = new unsigned int**[die_no_per_chip];
				for (unsigned int die_cntr = 0; die_cntr < die_no_per_chip; die_cntr++) {
					Block_erase_histogram[channel_cntr][chip_cntr][die_cntr] = new unsigned int*[plane_no_per_die];
					for (unsigned int plane_cntr = 0; plane_cntr < plane_no_per_die; plane_cntr++) {
						Block_erase_histogram[channel_cntr][chip_cntr][die_cntr][plane_cntr] = new unsigned int[max_allowed_block_erase_count];
						Block_erase_histogram[channel_cntr][chip_cntr][die_cntr][plane_cntr][0] = block_no_per_plane * page_no_per_block; //At the start of the simulation all pages have zero erase count
						for (unsigned int i = 1; i < max_allowed_block_erase_count; ++i) {
							Block_erase_histogram[channel_cntr][chip_cntr][die_cntr][plane_cntr][i] = 0;
						}
					}
				}
			}
		}

		IssuedReadCMD = 0; IssuedCopybackReadCMD = 0; IssuedInterleaveReadCMD = 0; IssuedMultiplaneReadCMD = 0; IssuedMultiplaneCopybackReadCMD = 0;
		IssuedProgramCMD = 0; IssuedInterleaveProgramCMD = 0; IssuedMultiplaneProgramCMD = 0; IssuedMultiplaneCopybackProgramCMD = 0; IssuedInterleaveMultiplaneProgramCMD = 0; IssuedSuspendProgramCMD = 0; IssuedCopybackProgramCMD = 0;
		IssuedEraseCMD = 0; IssuedInterleaveEraseCMD = 0; IssuedMultiplaneEraseCMD = 0; IssuedInterleaveMultiplaneEraseCMD = 0;
		IssuedSuspendEraseCMD = 0;
		Total_flash_reads_for_mapping = 0; Total_flash_writes_for_mapping = 0; 
		CMT_hits = 0; readTR_CMT_hits = 0; writeTR_CMT_hits = 0;
		CMT_miss = 0; readTR_CMT_miss = 0; writeTR_CMT_miss = 0;
		total_CMT_queries = 0; total_readTR_CMT_queries = 0; total_writeTR_CMT_queries = 0;

		Total_gc_executions = 0;  Total_page_movements_for_gc = 0;
		Total_wl_executions = 0;  Total_page_movements_for_wl = 0;

		for (stream_id_type stream_id = 0; stream_id < MAX_SUPPORT_STREAMS; stream_id++) {
			Total_flash_reads_for_mapping_per_stream[stream_id] = 0;
			Total_flash_writes_for_mapping_per_stream[stream_id] = 0;
			CMT_hits_per_stream[stream_id] = 0; readTR_CMT_hits_per_stream[stream_id] = 0; writeTR_CMT_hits_per_stream[stream_id] = 0;
			CMT_miss_per_stream[stream_id] = 0; readTR_CMT_miss_per_stream[stream_id] = 0;  writeTR_CMT_miss_per_stream[stream_id] = 0;
			total_CMT_queries_per_stream[stream_id] = 0; total_readTR_CMT_queries_per_stream[stream_id] = 0; total_writeTR_CMT_queries_per_stream[stream_id] = 0;
			Total_gc_executions_per_stream[stream_id] = 0;
			Total_gc_page_movements_per_stream[stream_id] = 0;
			Total_wl_executions_per_stream[stream_id] = 0;
			Total_wl_page_movements_per_stream[stream_id] = 0;
		}
	}

	void Stats::Clear_stats(unsigned int channel_no, unsigned int chip_no_per_channel, unsigned int die_no_per_chip, unsigned int plane_no_per_die,
		unsigned int block_no_per_plane, unsigned int page_no_per_block, unsigned int max_allowed_block_erase_count)
	{
		for (unsigned int channel_cntr = 0; channel_cntr < channel_no; channel_cntr++) {
			for (unsigned int chip_cntr = 0; chip_cntr < chip_no_per_channel; chip_cntr++) {
				for (unsigned int die_cntr = 0; die_cntr < die_no_per_chip; die_cntr++) {
					for (unsigned int plane_cntr = 0; plane_cntr < plane_no_per_die; plane_cntr++) {
						delete[] Block_erase_histogram[channel_cntr][chip_cntr][die_cntr][plane_cntr];
					}
					delete[] Block_erase_histogram[channel_cntr][chip_cntr][die_cntr];
				}
				delete[] Block_erase_histogram[channel_cntr][chip_cntr];
			}
			delete[] Block_erase_histogram[channel_cntr];
		}
		delete[] Block_erase_histogram;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %r9d, %r13d
movl %r8d, %ebx
movl %ecx, %r12d
movl %edx, %r15d
movl %esi, %r14d
movl 0x80(%rsp), %ebp
movl %edi, %eax
movq %rax, 0x10(%rsp)
leaq (,%rax,8), %rdi
callq 0x7030
movq %rax, 0x27ce1(%rip)     # 0x63700
movl %r14d, %eax
movq %rax, 0x20(%rsp)
leaq (,%rax,8), %rax
movq %rax, 0x8(%rsp)
movl %r15d, %eax
movq %rax, 0x30(%rsp)
leaq (,%rax,8), %rax
movq %rax, 0x18(%rsp)
movl %r12d, %eax
movq %rax, 0x40(%rsp)
leaq (,%rax,8), %rax
movq %rax, 0x28(%rsp)
leaq (,%rbp,4), %rax
movq %rax, 0x38(%rsp)
imull %r13d, %ebx
movl %ebx, %r13d
xorl %r14d, %r14d
cmpq 0x10(%rsp), %r14
je 0x3bb59
movq 0x8(%rsp), %rdi
callq 0x7030
movq 0x27c6f(%rip), %rcx     # 0x63700
movq %rax, (%rcx,%r14,8)
xorl %r12d, %r12d
cmpq 0x20(%rsp), %r12
je 0x3bb51
movq 0x18(%rsp), %rdi
callq 0x7030
movq 0x27c4c(%rip), %rcx     # 0x63700
movq (%rcx,%r14,8), %rcx
movq %rax, (%rcx,%r12,8)
xorl %ebx, %ebx
cmpq 0x30(%rsp), %rbx
je 0x3bb49
movq 0x28(%rsp), %rdi
callq 0x7030
movq 0x27c26(%rip), %rcx     # 0x63700
movq (%rcx,%r14,8), %rcx
movq (%rcx,%r12,8), %rcx
movq %rax, (%rcx,%rbx,8)
xorl %r15d, %r15d
cmpq 0x40(%rsp), %r15
je 0x3bb41
movq 0x38(%rsp), %rdi
callq 0x7030
movq 0x27bff(%rip), %rcx     # 0x63700
movq (%rcx,%r14,8), %rcx
movq (%rcx,%r12,8), %rcx
movq (%rcx,%rbx,8), %rcx
movq %rax, (%rcx,%r15,8)
movq 0x27be8(%rip), %rax     # 0x63700
movq (%rax,%r14,8), %rax
movq (%rax,%r12,8), %rax
movq (%rax,%rbx,8), %rax
movq (%rax,%r15,8), %rax
movl %r13d, (%rax)
pushq $0x1
popq %rcx
cmpq %rbp, %rcx
jae 0x3bb3c
andl $0x0, (%rax,%rcx,4)
incq %rcx
jmp 0x3bb2e
incq %r15
jmp 0x3bae9
incq %rbx
jmp 0x3babe
incq %r12
jmp 0x3ba98
incq %r14
jmp 0x3ba75
andq $0x0, 0x26b07(%rip)     # 0x62668
andq $0x0, 0x26b07(%rip)     # 0x62670
andq $0x0, 0x26b07(%rip)     # 0x62678
andq $0x0, 0x26b07(%rip)     # 0x62680
andq $0x0, 0x26b07(%rip)     # 0x62688
andq $0x0, 0x26b07(%rip)     # 0x62690
andq $0x0, 0x26b07(%rip)     # 0x62698
andq $0x0, 0x26b07(%rip)     # 0x626a0
andq $0x0, 0x26b07(%rip)     # 0x626a8
andq $0x0, 0x26b07(%rip)     # 0x626b0
andq $0x0, 0x26b07(%rip)     # 0x626b8
andq $0x0, 0x26b07(%rip)     # 0x626c0
andq $0x0, 0x26b07(%rip)     # 0x626c8
andq $0x0, 0x26b07(%rip)     # 0x626d0
andq $0x0, 0x26b07(%rip)     # 0x626d8
andq $0x0, 0x26b07(%rip)     # 0x626e0
andq $0x0, 0x26b07(%rip)     # 0x626e8
andq $0x0, 0x26b07(%rip)     # 0x626f0
andq $0x0, 0x26b07(%rip)     # 0x626f8
andl $0x0, 0x27b10(%rip)     # 0x63708
andl $0x0, 0x27b0d(%rip)     # 0x6370c
andl $0x0, 0x27b0a(%rip)     # 0x63710
andl $0x0, 0x27b07(%rip)     # 0x63714
andl $0x0, 0x27b04(%rip)     # 0x63718
andl $0x0, 0x27b01(%rip)     # 0x6371c
andl $0x0, 0x27afe(%rip)     # 0x63720
andl $0x0, 0x27afb(%rip)     # 0x63724
andl $0x0, 0x27af8(%rip)     # 0x63728
andl $0x0, 0x27af5(%rip)     # 0x6372c
andl $0x0, 0x27ef2(%rip)     # 0x63b30
andl $0x0, 0x282fb(%rip)     # 0x63f40
andl $0x0, 0x28704(%rip)     # 0x64350
movq $-0x400, %rax           # imm = 0xFC00
xorl %ecx, %ecx
leaq 0x28f04(%rip), %r8      # 0x64b60
leaq 0x292fd(%rip), %r9      # 0x64f60
leaq 0x296f6(%rip), %r10     # 0x65360
leaq 0x29aef(%rip), %r11     # 0x65760
leaq 0x29ee8(%rip), %rbx     # 0x65b60
leaq 0x2a2e1(%rip), %r14     # 0x65f60
leaq 0x2a6da(%rip), %r15     # 0x66360
leaq 0x2aad3(%rip), %r12     # 0x66760
leaq 0x27a9c(%rip), %r13     # 0x63730
leaq 0x27ea5(%rip), %rbp     # 0x63b40
leaq 0x282ae(%rip), %rdx     # 0x63f50
leaq 0x286b7(%rip), %rsi     # 0x64360
testq %rax, %rax
je 0x3bd4e
leaq 0x26a47(%rip), %rdi     # 0x62700
andq $0x0, (%rcx,%rdi)
leaq 0x2723b(%rip), %rdi     # 0x62f00
andq $0x0, (%rcx,%rdi)
leaq 0x28a8f(%rip), %rdi     # 0x64760
andl $0x0, 0x400(%rax,%rdi)
andl $0x0, 0x400(%rax,%r8)
andl $0x0, 0x400(%rax,%r9)
andl $0x0, 0x400(%rax,%r10)
andl $0x0, 0x400(%rax,%r11)
andl $0x0, 0x400(%rax,%rbx)
andl $0x0, 0x400(%rax,%r14)
andl $0x0, 0x400(%rax,%r15)
andl $0x0, 0x400(%rax,%r12)
andl $0x0, 0x400(%rax,%r13)
andl $0x0, 0x400(%rax,%rbp)
andl $0x0, 0x400(%rax,%rdx)
andl $0x0, 0x400(%rax,%rsi)
addq $0x4, %rax
addq $0x8, %rcx
jmp 0x3bca9
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop