// File: /workspace/github_cpp_makefile_star2_O1/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 $0x58, %rsp
movl %r9d, 0x8(%rsp)
movl %r8d, %r14d
movl %ecx, 0x14(%rsp)
movl %edx, 0x10(%rsp)
movl %esi, 0xc(%rsp)
movl %edi, %r15d
movl 0x90(%rsp), %eax
movq %rax, 0x18(%rsp)
movl %edi, %eax
movq %rax, 0x28(%rsp)
leaq (,%rax,8), %rdi
callq 0x7030
movq %rax, 0x25d00(%rip)     # 0x70730
testl %r15d, %r15d
je 0x4ab92
movl 0xc(%rsp), %eax
movq %rax, 0x38(%rsp)
leaq (,%rax,8), %rax
movq %rax, 0x20(%rsp)
movl 0x10(%rsp), %eax
movq %rax, 0x48(%rsp)
leaq (,%rax,8), %rax
movq %rax, 0x30(%rsp)
movl 0x14(%rsp), %ebp
leaq (,%rbp,8), %rax
movq %rax, 0x40(%rsp)
movq 0x18(%rsp), %rcx
movl %ecx, %r12d
shlq $0x2, %r12
movl 0x8(%rsp), %eax
imull %r14d, %eax
movl %eax, 0x8(%rsp)
leal -0x1(%rcx), %eax
shlq $0x2, %rax
movq %rax, 0x50(%rsp)
xorl %r15d, %r15d
movq 0x20(%rsp), %rdi
callq 0x7030
movq 0x25c82(%rip), %rcx     # 0x70730
movq %rax, (%rcx,%r15,8)
cmpl $0x0, 0xc(%rsp)
je 0x4ab84
xorl %r14d, %r14d
movq 0x30(%rsp), %rdi
callq 0x7030
movq 0x25c5f(%rip), %rcx     # 0x70730
movq (%rcx,%r15,8), %rcx
movq %rax, (%rcx,%r14,8)
cmpl $0x0, 0x10(%rsp)
je 0x4ab76
xorl %ebx, %ebx
movq 0x40(%rsp), %rdi
callq 0x7030
movq 0x25c39(%rip), %rcx     # 0x70730
movq (%rcx,%r15,8), %rcx
movq (%rcx,%r14,8), %rcx
movq %rax, (%rcx,%rbx,8)
cmpl $0x0, 0x14(%rsp)
je 0x4ab68
xorl %r13d, %r13d
movq %r12, %rdi
callq 0x7030
movq 0x25c14(%rip), %rcx     # 0x70730
movq (%rcx,%r15,8), %rcx
movq (%rcx,%r14,8), %rcx
movq (%rcx,%rbx,8), %rcx
movq %rax, (%rcx,%r13,8)
movq 0x25bfd(%rip), %rax     # 0x70730
movq (%rax,%r15,8), %rax
movq (%rax,%r14,8), %rax
movq (%rax,%rbx,8), %rax
movq (%rax,%r13,8), %rdi
movl 0x8(%rsp), %eax
movl %eax, (%rdi)
cmpl $0x2, 0x18(%rsp)
jb 0x4ab60
addq $0x4, %rdi
xorl %esi, %esi
movq 0x50(%rsp), %rdx
callq 0x7230
incq %r13
cmpq %r13, %rbp
jne 0x4ab0d
incq %rbx
cmpq 0x48(%rsp), %rbx
jne 0x4aae6
incq %r14
cmpq 0x38(%rsp), %r14
jne 0x4aac0
incq %r15
cmpq 0x28(%rsp), %r15
jne 0x4aa9d
xorl %eax, %eax
movq %rax, 0x24afd(%rip)     # 0x6f698
movq %rax, 0x24afe(%rip)     # 0x6f6a0
movq %rax, 0x24aff(%rip)     # 0x6f6a8
movq %rax, 0x24b00(%rip)     # 0x6f6b0
movq %rax, 0x24b01(%rip)     # 0x6f6b8
movq %rax, 0x24b02(%rip)     # 0x6f6c0
movq %rax, 0x24b03(%rip)     # 0x6f6c8
movq %rax, 0x24b04(%rip)     # 0x6f6d0
movq %rax, 0x24b05(%rip)     # 0x6f6d8
movq %rax, 0x24b06(%rip)     # 0x6f6e0
movq %rax, 0x24b07(%rip)     # 0x6f6e8
movq %rax, 0x24b08(%rip)     # 0x6f6f0
movq %rax, 0x24b09(%rip)     # 0x6f6f8
movq %rax, 0x24b0a(%rip)     # 0x6f700
movq %rax, 0x24b0b(%rip)     # 0x6f708
movq %rax, 0x24b0c(%rip)     # 0x6f710
movq %rax, 0x24b0d(%rip)     # 0x6f718
movq %rax, 0x24b0e(%rip)     # 0x6f720
movq %rax, 0x24b0f(%rip)     # 0x6f728
movl %eax, 0x25b19(%rip)     # 0x70738
movl %eax, 0x25b17(%rip)     # 0x7073c
movl %eax, 0x25b15(%rip)     # 0x70740
movl %eax, 0x25b13(%rip)     # 0x70744
movl %eax, 0x25b11(%rip)     # 0x70748
movl %eax, 0x25b0f(%rip)     # 0x7074c
movl %eax, 0x25b0d(%rip)     # 0x70750
movl %eax, 0x25b0b(%rip)     # 0x70754
movl %eax, 0x25b09(%rip)     # 0x70758
movl %eax, 0x25b07(%rip)     # 0x7075c
movl %eax, 0x25f05(%rip)     # 0x70b60
movl %eax, 0x2630f(%rip)     # 0x70f70
movl %eax, 0x26719(%rip)     # 0x71380
leaq 0x24ac2(%rip), %rdi     # 0x6f730
movl $0x800, %edx            # imm = 0x800
xorl %esi, %esi
callq 0x7230
leaq 0x252af(%rip), %rdi     # 0x6ff30
movl $0x800, %edx            # imm = 0x800
xorl %esi, %esi
callq 0x7230
leaq 0x26afc(%rip), %rdi     # 0x71790
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x7230
leaq 0x26ee9(%rip), %rdi     # 0x71b90
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x7230
leaq 0x272d6(%rip), %rdi     # 0x71f90
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x7230
leaq 0x276c3(%rip), %rdi     # 0x72390
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x7230
leaq 0x27ab0(%rip), %rdi     # 0x72790
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x7230
leaq 0x27e9d(%rip), %rdi     # 0x72b90
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x7230
leaq 0x2828a(%rip), %rdi     # 0x72f90
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x7230
leaq 0x28677(%rip), %rdi     # 0x73390
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x7230
leaq 0x28a64(%rip), %rdi     # 0x73790
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x7230
leaq 0x25a21(%rip), %rdi     # 0x70760
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x7230
leaq 0x25e1e(%rip), %rdi     # 0x70b70
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x7230
leaq 0x2621b(%rip), %rdi     # 0x70f80
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x7230
leaq 0x26618(%rip), %rdi     # 0x71390
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7230