// File: /workspace/github_cpp_makefile_star2_O3/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, (%rsp)
movl %r8d, %r14d
movl %ecx, 0xc(%rsp)
movl %edx, 0x8(%rsp)
movl %esi, 0x4(%rsp)
movl %edi, %r15d
movl 0x90(%rsp), %eax
movq %rax, 0x10(%rsp)
movl %edi, %eax
movq %rax, 0x20(%rsp)
leaq (,%rax,8), %rdi
callq 0x7030
movq %rax, 0x26779(%rip)     # 0x70730
testl %r15d, %r15d
je 0x4a11f
movl 0x4(%rsp), %eax
movq %rax, 0x30(%rsp)
leaq (,%rax,8), %rax
movq %rax, 0x18(%rsp)
movl 0x8(%rsp), %eax
movq %rax, 0x40(%rsp)
leaq (,%rax,8), %rax
movq %rax, 0x28(%rsp)
movl 0xc(%rsp), %eax
movq %rax, 0x50(%rsp)
leaq (,%rax,8), %rax
movq %rax, 0x38(%rsp)
movq 0x10(%rsp), %rcx
movl %ecx, %r12d
shlq $0x2, %r12
movl (%rsp), %eax
imull %r14d, %eax
movl %eax, (%rsp)
leal -0x1(%rcx), %eax
shlq $0x2, %rax
movq %rax, 0x48(%rsp)
xorl %r15d, %r15d
movq 0x18(%rsp), %rdi
callq 0x7030
movq 0x266f8(%rip), %rcx     # 0x70730
movq %rax, (%rcx,%r15,8)
cmpl $0x0, 0x4(%rsp)
je 0x4a111
xorl %r14d, %r14d
movq 0x28(%rsp), %rdi
callq 0x7030
movq 0x266d5(%rip), %rcx     # 0x70730
movq (%rcx,%r15,8), %rcx
movq %rax, (%rcx,%r14,8)
cmpl $0x0, 0x8(%rsp)
je 0x4a103
xorl %ebx, %ebx
movq 0x38(%rsp), %rdi
callq 0x7030
movq 0x266af(%rip), %rcx     # 0x70730
movq (%rcx,%r15,8), %rcx
movq (%rcx,%r14,8), %rcx
movq %rax, (%rcx,%rbx,8)
cmpl $0x0, 0xc(%rsp)
je 0x4a0f5
movq 0x26695(%rip), %rbp     # 0x70730
xorl %r13d, %r13d
movq %r12, %rdi
callq 0x7030
movq (%rbp,%r15,8), %rcx
movq (%rcx,%r14,8), %rcx
movq (%rcx,%rbx,8), %rcx
movq %rax, (%rcx,%r13,8)
movq 0x26672(%rip), %rbp     # 0x70730
movq (%rbp,%r15,8), %rax
movq (%rax,%r14,8), %rax
movq (%rax,%rbx,8), %rax
movq (%rax,%r13,8), %rdi
movl (%rsp), %eax
movl %eax, (%rdi)
cmpl $0x2, 0x10(%rsp)
jb 0x4a0eb
addq $0x4, %rdi
xorl %esi, %esi
movq 0x48(%rsp), %rdx
callq 0x7230
incq %r13
cmpq %r13, 0x50(%rsp)
jne 0x4a09e
incq %rbx
cmpq 0x40(%rsp), %rbx
jne 0x4a070
incq %r14
cmpq 0x30(%rsp), %r14
jne 0x4a04a
incq %r15
cmpq 0x20(%rsp), %r15
jne 0x4a027
xorl %eax, %eax
movq %rax, 0x25570(%rip)     # 0x6f698
movq %rax, 0x25571(%rip)     # 0x6f6a0
movq %rax, 0x25572(%rip)     # 0x6f6a8
movq %rax, 0x25573(%rip)     # 0x6f6b0
movq %rax, 0x25574(%rip)     # 0x6f6b8
movq %rax, 0x25575(%rip)     # 0x6f6c0
movq %rax, 0x25576(%rip)     # 0x6f6c8
movq %rax, 0x25577(%rip)     # 0x6f6d0
movq %rax, 0x25578(%rip)     # 0x6f6d8
movq %rax, 0x25579(%rip)     # 0x6f6e0
movq %rax, 0x2557a(%rip)     # 0x6f6e8
movq %rax, 0x2557b(%rip)     # 0x6f6f0
movq %rax, 0x2557c(%rip)     # 0x6f6f8
movq %rax, 0x2557d(%rip)     # 0x6f700
movq %rax, 0x2557e(%rip)     # 0x6f708
movq %rax, 0x2557f(%rip)     # 0x6f710
movq %rax, 0x25580(%rip)     # 0x6f718
movq %rax, 0x25581(%rip)     # 0x6f720
movq %rax, 0x25582(%rip)     # 0x6f728
movl %eax, 0x2658c(%rip)     # 0x70738
movl %eax, 0x2658a(%rip)     # 0x7073c
movl %eax, 0x26588(%rip)     # 0x70740
movl %eax, 0x26586(%rip)     # 0x70744
movl %eax, 0x26584(%rip)     # 0x70748
movl %eax, 0x26582(%rip)     # 0x7074c
movl %eax, 0x26580(%rip)     # 0x70750
movl %eax, 0x2657e(%rip)     # 0x70754
movl %eax, 0x2657c(%rip)     # 0x70758
movl %eax, 0x2657a(%rip)     # 0x7075c
movl %eax, 0x26978(%rip)     # 0x70b60
movl %eax, 0x26d82(%rip)     # 0x70f70
movl %eax, 0x2718c(%rip)     # 0x71380
leaq 0x25535(%rip), %rdi     # 0x6f730
movl $0x800, %edx            # imm = 0x800
xorl %esi, %esi
callq 0x7230
leaq 0x25d22(%rip), %rdi     # 0x6ff30
movl $0x800, %edx            # imm = 0x800
xorl %esi, %esi
callq 0x7230
leaq 0x2756f(%rip), %rdi     # 0x71790
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x7230
leaq 0x2795c(%rip), %rdi     # 0x71b90
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x7230
leaq 0x27d49(%rip), %rdi     # 0x71f90
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x7230
leaq 0x28136(%rip), %rdi     # 0x72390
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x7230
leaq 0x28523(%rip), %rdi     # 0x72790
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x7230
leaq 0x28910(%rip), %rdi     # 0x72b90
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x7230
leaq 0x28cfd(%rip), %rdi     # 0x72f90
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x7230
leaq 0x290ea(%rip), %rdi     # 0x73390
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x7230
leaq 0x294d7(%rip), %rdi     # 0x73790
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x7230
leaq 0x26494(%rip), %rdi     # 0x70760
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x7230
leaq 0x26891(%rip), %rdi     # 0x70b70
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x7230
leaq 0x26c8e(%rip), %rdi     # 0x70f80
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x7230
leaq 0x2708b(%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
nop