// File: /workspace/github_cpp_makefile_star2_O3/CMU-SAFARI[P]MQSim/src/ssd/Flash_Block_Manager_Base.cpp
// Function: SSD_Components::Flash_Block_Manager_Base::Flash_Block_Manager_Base(SSD_Components::GC_and_WL_Unit_Base*, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int)
Flash_Block_Manager_Base::Flash_Block_Manager_Base(GC_and_WL_Unit_Base* gc_and_wl_unit, unsigned int max_allowed_block_erase_count, unsigned int total_concurrent_streams_no,
		unsigned int channel_count, 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)
		: gc_and_wl_unit(gc_and_wl_unit), max_allowed_block_erase_count(max_allowed_block_erase_count), total_concurrent_streams_no(total_concurrent_streams_no),
		channel_count(channel_count), chip_no_per_channel(chip_no_per_channel), die_no_per_chip(die_no_per_chip), plane_no_per_die(plane_no_per_die),
		block_no_per_plane(block_no_per_plane), pages_no_per_block(page_no_per_block)
	{
		plane_manager = new PlaneBookKeepingType***[channel_count];
		for (unsigned int channelID = 0; channelID < channel_count; channelID++) {
			plane_manager[channelID] = new PlaneBookKeepingType**[chip_no_per_channel];
			for (unsigned int chipID = 0; chipID < chip_no_per_channel; chipID++) {
				plane_manager[channelID][chipID] = new PlaneBookKeepingType*[die_no_per_chip];
				for (unsigned int dieID = 0; dieID < die_no_per_chip; dieID++) {
					plane_manager[channelID][chipID][dieID] = new PlaneBookKeepingType[plane_no_per_die];

					//Initialize plane book keeping data structure
					for (unsigned int planeID = 0; planeID < plane_no_per_die; planeID++) {
						plane_manager[channelID][chipID][dieID][planeID].Total_pages_count = block_no_per_plane * pages_no_per_block;
						plane_manager[channelID][chipID][dieID][planeID].Free_pages_count = block_no_per_plane * pages_no_per_block;
						plane_manager[channelID][chipID][dieID][planeID].Valid_pages_count = 0;
						plane_manager[channelID][chipID][dieID][planeID].Invalid_pages_count = 0;
						plane_manager[channelID][chipID][dieID][planeID].Ongoing_erase_operations.clear();
						plane_manager[channelID][chipID][dieID][planeID].Blocks = new Block_Pool_Slot_Type[block_no_per_plane];
						
						//Initialize block pool for plane
						for (unsigned int blockID = 0; blockID < block_no_per_plane; blockID++) {
							plane_manager[channelID][chipID][dieID][planeID].Blocks[blockID].BlockID = blockID;
							plane_manager[channelID][chipID][dieID][planeID].Blocks[blockID].Current_page_write_index = 0;
							plane_manager[channelID][chipID][dieID][planeID].Blocks[blockID].Current_status = Block_Service_Status::IDLE;
							plane_manager[channelID][chipID][dieID][planeID].Blocks[blockID].Invalid_page_count = 0;
							plane_manager[channelID][chipID][dieID][planeID].Blocks[blockID].Erase_count = 0;
							plane_manager[channelID][chipID][dieID][planeID].Blocks[blockID].Holds_mapping_data = false;
							plane_manager[channelID][chipID][dieID][planeID].Blocks[blockID].Has_ongoing_gc_wl = false;
							plane_manager[channelID][chipID][dieID][planeID].Blocks[blockID].Erase_transaction = NULL;
							plane_manager[channelID][chipID][dieID][planeID].Blocks[blockID].Ongoing_user_program_count = 0;
							plane_manager[channelID][chipID][dieID][planeID].Blocks[blockID].Ongoing_user_read_count = 0;
							Block_Pool_Slot_Type::Page_vector_size = pages_no_per_block / (sizeof(uint64_t) * 8) + (pages_no_per_block % (sizeof(uint64_t) * 8) == 0 ? 0 : 1);
							plane_manager[channelID][chipID][dieID][planeID].Blocks[blockID].Invalid_page_bitmap = new uint64_t[Block_Pool_Slot_Type::Page_vector_size];
							for (unsigned int i = 0; i < Block_Pool_Slot_Type::Page_vector_size; i++) {
								plane_manager[channelID][chipID][dieID][planeID].Blocks[blockID].Invalid_page_bitmap[i] = All_VALID_PAGE;
							}
							plane_manager[channelID][chipID][dieID][planeID].Add_to_free_block_pool(&plane_manager[channelID][chipID][dieID][planeID].Blocks[blockID], false);
						}
						plane_manager[channelID][chipID][dieID][planeID].Data_wf = new Block_Pool_Slot_Type*[total_concurrent_streams_no];
						plane_manager[channelID][chipID][dieID][planeID].Translation_wf = new Block_Pool_Slot_Type*[total_concurrent_streams_no];
						plane_manager[channelID][chipID][dieID][planeID].GC_wf = new Block_Pool_Slot_Type*[total_concurrent_streams_no];
						for (unsigned int stream_cntr = 0; stream_cntr < total_concurrent_streams_no; stream_cntr++) {
							plane_manager[channelID][chipID][dieID][planeID].Data_wf[stream_cntr] = plane_manager[channelID][chipID][dieID][planeID].Get_a_free_block(stream_cntr, false);
							plane_manager[channelID][chipID][dieID][planeID].Translation_wf[stream_cntr] = plane_manager[channelID][chipID][dieID][planeID].Get_a_free_block(stream_cntr, true);
							plane_manager[channelID][chipID][dieID][planeID].GC_wf[stream_cntr] = plane_manager[channelID][chipID][dieID][planeID].Get_a_free_block(stream_cntr, false);
						}
					}
				}
			}
		}
	}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movl %r8d, %ebx
movq %rdi, %r14
movl 0xf0(%rsp), %r11d
movl 0xe8(%rsp), %edi
movl 0xe0(%rsp), %r8d
movl 0xf8(%rsp), %eax
leaq 0x318f0(%rip), %r10     # 0x6e400
movq %r10, (%r14)
movq %rsi, 0x10(%r14)
movl %edx, 0x18(%r14)
movl %ecx, 0x24(%rsp)
movl %ecx, 0x1c(%r14)
movl %ebx, 0x20(%r14)
movl %r9d, 0x20(%rsp)
movl %r9d, 0x24(%r14)
movl %r8d, 0x28(%r14)
movl %edi, 0x2c(%r14)
movl %r11d, 0x30(%r14)
movl %eax, 0x34(%r14)
movl %ebx, %eax
movq %rax, 0x50(%rsp)
leaq (,%rax,8), %rdi
callq 0x7030
movq %rax, 0x8(%r14)
testl %ebx, %ebx
je 0x3d128
movq %r14, %r13
movl 0x20(%rsp), %eax
movq %rax, 0x58(%rsp)
leaq (,%rax,8), %rax
movq %rax, 0x48(%rsp)
movl 0xe0(%rsp), %eax
leaq (,%rax,8), %rax
movq %rax, 0x60(%rsp)
movl 0xe8(%rsp), %eax
imulq $0xe0, %rax, %rax
movq %rax, 0x70(%rsp)
addq $0x8, %rax
movq %rax, 0x68(%rsp)
movl 0xf0(%rsp), %ebx
shlq $0x6, %rbx
movl 0x24(%rsp), %ebp
leaq (,%rbp,8), %rax
movq %rax, 0x30(%rsp)
xorl %r15d, %r15d
xorl %r14d, %r14d
movq %r13, 0x18(%rsp)
movq %rbx, 0x38(%rsp)
movq %rbp, 0x80(%rsp)
movq 0x48(%rsp), %rdi
callq 0x7030
movq 0x8(%r13), %rcx
movq %r14, 0x8(%rsp)
movq %rax, (%rcx,%r14,8)
cmpl $0x0, 0x20(%rsp)
je 0x3d115
xorl %r12d, %r12d
movq 0x60(%rsp), %rdi
callq 0x7030
movq 0x8(%r13), %rcx
movq 0x8(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
movq %rax, (%rcx,%r12,8)
cmpl $0x0, 0xe0(%rsp)
je 0x3d107
xorl %ecx, %ecx
movq %r12, 0x28(%rsp)
movq %rcx, 0x10(%rsp)
movq 0x68(%rsp), %rdi
callq 0x7030
movq %rax, %rbx
leaq 0x8(%rax), %r14
movl 0xe8(%rsp), %eax
movq %rax, (%rbx)
cmpl $0x0, 0xe8(%rsp)
je 0x3d0cf
xorl %ebp, %ebp
leaq (%rbx,%rbp), %rax
addq $0x28, %rax
movl $0x0, 0x28(%rbx,%rbp)
movq %r15, 0x30(%rbx,%rbp)
movq %rax, 0x38(%rbx,%rbp)
movq %rax, 0x40(%rbx,%rbp)
movq %r15, 0x48(%rbx,%rbp)
leaq 0x68(%rbx,%rbp), %rdi
xorps %xmm0, %xmm0
movups %xmm0, 0x68(%rbx,%rbp)
movups %xmm0, 0x78(%rbx,%rbp)
movups %xmm0, 0x88(%rbx,%rbp)
movups %xmm0, 0x98(%rbx,%rbp)
movups %xmm0, 0xa8(%rbx,%rbp)
xorl %esi, %esi
callq 0x3d8f6
leaq (%rbx,%rbp), %rax
addq $0xc0, %rax
movl $0x0, 0xc0(%rbx,%rbp)
movq %r15, 0xc8(%rbx,%rbp)
movq %rax, 0xd0(%rbx,%rbp)
movq %rax, 0xd8(%rbx,%rbp)
movq %r15, 0xe0(%rbx,%rbp)
addq $0xe0, %rbp
cmpq %rbp, 0x70(%rsp)
jne 0x3cc62
movq %r13, %rsi
movq 0x8(%r13), %rax
movq 0x8(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq (%rax,%r12,8), %rax
movq 0x10(%rsp), %rcx
movq %r14, (%rax,%rcx,8)
cmpl $0x0, 0xe8(%rsp)
je 0x3d0ec
xorl %edx, %edx
movl 0x34(%rsi), %eax
movl 0xf0(%rsp), %ecx
imull %ecx, %eax
movq 0x8(%rsi), %rcx
movq %r12, %r14
movq 0x8(%rsp), %rdi
movq (%rcx,%rdi,8), %rcx
movq (%rcx,%r12,8), %rcx
movq 0x10(%rsp), %r12
movq (%rcx,%r12,8), %rcx
movq %rdx, 0x78(%rsp)
imulq $0xe0, %rdx, %rbx
leaq (%rcx,%rbx), %rdi
addq $0xb0, %rdi
movl %eax, -0xb0(%rdi)
movl %eax, -0xac(%rdi)
movq $0x0, -0xa8(%rdi)
movq %rsi, %r13
callq 0x306cc
movq 0x38(%rsp), %rdi
callq 0x7030
cmpl $0x0, 0xf0(%rsp)
je 0x3cf49
xorl %ecx, %ecx
movq 0x38(%rsp), %rdx
movl $0xff, 0x20(%rax,%rcx)
movb $0x0, 0x30(%rax,%rcx)
addq $0x40, %rcx
cmpq %rcx, %rdx
jne 0x3cdaa
movq 0x8(%r13), %rsi
movq 0x8(%rsp), %rdx
movq (%rsi,%rdx,8), %rcx
movq 0x28(%rsp), %r14
movq (%rcx,%r14,8), %rcx
movq 0x10(%rsp), %r12
movq (%rcx,%r12,8), %rcx
movq %rax, 0x10(%rcx,%rbx)
cmpl $0x0, 0xf0(%rsp)
je 0x3cf63
xorl %ebp, %ebp
xorl %ecx, %ecx
movq 0x8(%r13), %rdx
movq 0x8(%rsp), %r14
movq (%rdx,%r14,8), %rax
movq %rdx, %rsi
movq %rdx, 0x90(%rsp)
movq 0x28(%rsp), %rdx
movq (%rax,%rdx,8), %rax
movq 0x10(%rsp), %r12
movq (%rax,%r12,8), %rax
movq 0x10(%rax,%rbx), %rax
movl %ecx, 0x44(%rsp)
movl %ecx, (%rax,%rbp)
movw $0x0, 0x22(%rax,%rbp)
movq %r15, 0x28(%rax,%rbp)
xorps %xmm0, %xmm0
movups %xmm0, 0x4(%rax,%rbp)
movq (%rsi,%r14,8), %rax
movq (%rax,%rdx,8), %rax
movq (%rax,%r12,8), %rax
movq 0x10(%rax,%rbx), %rax
movq %r15, 0x34(%rax,%rbp)
movl 0x34(%r13), %eax
movl %eax, %ecx
shrl $0x6, %ecx
xorl %r15d, %r15d
testb $0x3f, %al
setne %r15b
movq %rcx, 0x88(%rsp)
leal (%rcx,%r15), %r13d
movl %r13d, 0x327bd(%rip)    # 0x6f638
leal (,%r13,8), %edi
callq 0x7030
movq 0x90(%rsp), %rdx
movq (%rdx,%r14,8), %rcx
movq 0x28(%rsp), %rsi
movq (%rcx,%rsi,8), %rcx
movq (%rcx,%r12,8), %rcx
movq 0x10(%rcx,%rbx), %rcx
movq %rax, 0x18(%rcx,%rbp)
movq (%rdx,%r14,8), %rax
movq (%rax,%rsi,8), %rax
movq (%rax,%r12,8), %r12
testl %r13d, %r13d
je 0x3cee2
movq 0x10(%r12,%rbx), %rax
movq 0x18(%rax,%rbp), %rdi
movq 0x88(%rsp), %rax
addl %r15d, %eax
decl %eax
leaq 0x8(,%rax,8), %rdx
xorl %esi, %esi
callq 0x7230
leaq (%r12,%rbx), %rdi
addq $0x18, %rdi
movq -0x8(%rdi), %rax
addq %rbp, %rax
movl $0x0, 0x98(%rsp)
movq %rax, 0xa0(%rsp)
leaq 0x98(%rsp), %rsi
callq 0x3dd22
movl 0x44(%rsp), %ecx
incl %ecx
addq $0x40, %rbp
movq 0x38(%rsp), %rax
cmpq %rbp, %rax
movq 0x18(%rsp), %r13
movl $0x0, %r15d
jne 0x3cdf6
movq 0x8(%r13), %rsi
movq 0x8(%rsp), %rdx
movq 0x28(%rsp), %r14
movq 0x10(%rsp), %r12
jmp 0x3cf63
movq 0x8(%r13), %rsi
movq 0x8(%rsp), %rdx
movq (%rsi,%rdx,8), %rcx
movq (%rcx,%r14,8), %rcx
movq (%rcx,%r12,8), %rcx
movq %rax, 0x10(%rcx,%rbx)
movq 0x30(%rsp), %rdi
movq %r12, %r13
movq %rdx, %r12
movq %rsi, %r15
callq 0x7030
movq (%r15,%r12,8), %rcx
movq (%rcx,%r14,8), %rcx
movq (%rcx,%r13,8), %rcx
movq %rax, 0x48(%rcx,%rbx)
movq 0x30(%rsp), %rdi
callq 0x7030
movq (%r15,%r12,8), %rcx
movq (%rcx,%r14,8), %rcx
movq (%rcx,%r13,8), %rcx
movq %rax, 0x58(%rcx,%rbx)
movq 0x30(%rsp), %rdi
callq 0x7030
movq 0x18(%rsp), %rsi
movq (%r15,%r12,8), %rcx
movq (%rcx,%r14,8), %rcx
movq (%rcx,%r13,8), %rcx
movq %rax, 0x50(%rcx,%rbx)
cmpl $0x0, 0x24(%rsp)
movq %r12, %r15
movq %r14, %r12
je 0x3d0af
movq %r13, %rdx
xorl %r14d, %r14d
movq 0x8(%rsi), %rax
movq (%rax,%r15,8), %rax
movq (%rax,%r12,8), %rax
movq (%rax,%rdx,8), %rdi
addq %rbx, %rdi
movzwl %r14w, %ebp
movl %ebp, %esi
xorl %edx, %edx
callq 0x3d1a2
movq 0x18(%rsp), %rcx
movq 0x8(%rcx), %rcx
movq (%rcx,%r15,8), %rcx
movq (%rcx,%r12,8), %rcx
movq (%rcx,%r13,8), %rcx
movq 0x48(%rcx,%rbx), %rcx
movq %rax, (%rcx,%r14,8)
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rax
movq (%rax,%r15,8), %rax
movq (%rax,%r12,8), %rax
movq (%rax,%r13,8), %rdi
addq %rbx, %rdi
movl %ebp, %esi
movl $0x1, %edx
callq 0x3d1a2
movq 0x18(%rsp), %rcx
movq 0x8(%rcx), %rcx
movq (%rcx,%r15,8), %rcx
movq (%rcx,%r12,8), %rcx
movq (%rcx,%r13,8), %rcx
movq 0x58(%rcx,%rbx), %rcx
movq %rax, (%rcx,%r14,8)
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rax
movq (%rax,%r15,8), %rax
movq (%rax,%r12,8), %rax
movq (%rax,%r13,8), %rdi
addq %rbx, %rdi
movl %ebp, %esi
movq 0x80(%rsp), %rbp
xorl %edx, %edx
callq 0x3d1a2
movq %r13, %rdx
movq 0x18(%rsp), %rsi
movq 0x8(%rsi), %rcx
movq (%rcx,%r15,8), %rcx
movq (%rcx,%r12,8), %rcx
movq (%rcx,%r13,8), %rcx
movq 0x50(%rcx,%rbx), %rcx
movq %rax, (%rcx,%r14,8)
incq %r14
cmpq %r14, %rbp
jne 0x3cfd9
movq 0x78(%rsp), %rdx
incq %rdx
movl 0xe8(%rsp), %eax
cmpq %rax, %rdx
movl $0x0, %r15d
jne 0x3cd2b
jmp 0x3d0ec
movq %r13, %rsi
movq 0x8(%r13), %rax
movq 0x8(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq (%rax,%r12,8), %rax
movq 0x10(%rsp), %rcx
movq %r14, (%rax,%rcx,8)
movq %rsi, %r13
movq 0x10(%rsp), %rcx
incq %rcx
movl 0xe0(%rsp), %eax
cmpq %rax, %rcx
jne 0x3cc32
incq %r12
cmpq 0x58(%rsp), %r12
jne 0x3cc02
movq 0x8(%rsp), %r14
incq %r14
cmpq 0x50(%rsp), %r14
jne 0x3cbdd
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
leaq (%rbx,%rbp), %rdi
addq $0x20, %rdi
callq 0x3da5e
testq %rbp, %rbp
je 0x3d15e
addq $0x8, %rbp
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x78e0
movq %rbx, %rdi
callq 0x7480
movq %r14, %rdi
callq 0x7620