// File: /workspace/github_cpp_makefile_star2_O2/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 $0x88, %rsp
movl %r9d, %r14d
movl %ecx, %r15d
movq %rdi, %rbx
movl 0xc0(%rsp), %r12d
movl 0xd0(%rsp), %r13d
movl 0xc8(%rsp), %ebp
movl 0xd8(%rsp), %eax
leaq 0x3035d(%rip), %rcx     # 0x613e0
movq %rcx, (%rdi)
movq %rsi, 0x10(%rdi)
movl %edx, 0x18(%rdi)
movl %r15d, 0x1c(%rdi)
movl %r8d, 0x20(%rdi)
movl %r9d, 0x24(%rdi)
movl %r12d, 0x28(%rdi)
movl %ebp, 0x2c(%rdi)
movl %r13d, 0x30(%rdi)
movl %eax, 0x34(%rdi)
movl %r8d, %eax
movq %rax, 0x30(%rsp)
leaq (,%rax,8), %rdi
callq 0x7030
movq %rbx, 0x8(%rsp)
movq %rax, 0x8(%rbx)
movl %r14d, %eax
movq %rax, 0x40(%rsp)
leaq (,%rax,8), %rax
movq %rax, 0x28(%rsp)
leaq (,%r12,8), %rax
movq %rax, 0x38(%rsp)
imulq $0xe0, %rbp, %rax
orq $0x8, %rax
movq %rax, 0x48(%rsp)
shlq $0x6, %r13
movl %r15d, %eax
movq %rax, 0x70(%rsp)
leaq (,%rax,8), %rax
movq %rax, 0x58(%rsp)
imulq $-0xe0, %rbp, %rax
movq %rax, 0x50(%rsp)
xorl %ebx, %ebx
movq %r13, 0x60(%rsp)
cmpq 0x30(%rsp), %rbx
je 0x3154c
movq 0x28(%rsp), %rdi
callq 0x7030
movq 0x8(%rsp), %rdx
movq 0x8(%rdx), %rcx
movq %rax, (%rcx,%rbx,8)
movq $0x0, 0x10(%rsp)
movq %rbx, %r13
movq %rbx, 0x20(%rsp)
movq 0x10(%rsp), %rax
cmpq 0x40(%rsp), %rax
je 0x31541
movq %rdx, %rbx
movq 0x38(%rsp), %rdi
callq 0x7030
movq %rbx, %rdx
movq 0x8(%rbx), %rcx
movq (%rcx,%r13,8), %rcx
movq 0x10(%rsp), %rsi
movq %rax, (%rcx,%rsi,8)
xorl %ecx, %ecx
movl 0xc0(%rsp), %eax
cmpq %rax, %rcx
je 0x31537
movq %rcx, 0x18(%rsp)
movq 0x48(%rsp), %rdi
callq 0x7030
movq %rax, %r15
leaq 0x8(%rax), %r14
movl 0xc8(%rsp), %eax
movq %rax, (%r15)
testl %eax, %eax
je 0x311df
movq %r14, %r12
xorl %ebx, %ebx
movq %r12, %rdi
callq 0x31ca8
addq $-0xe0, %rbx
addq $0xe0, %r12
cmpq %rbx, 0x50(%rsp)
jne 0x311c2
movq 0x8(%rsp), %rcx
movq 0x8(%rcx), %rax
movq (%rax,%r13,8), %rax
movq 0x10(%rsp), %rdx
movq (%rax,%rdx,8), %rax
movq 0x18(%rsp), %rdx
movq %r14, (%rax,%rdx,8)
movq %rcx, %rdx
xorl %esi, %esi
movl 0xc8(%rsp), %eax
cmpq %rax, %rsi
je 0x3152a
movl 0x34(%rdx), %eax
movl 0xd0(%rsp), %ecx
movq %rcx, %rbx
imull %ebx, %eax
movq %rdx, %r14
movq 0x8(%rdx), %rcx
movq (%rcx,%r13,8), %rcx
movq 0x10(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
movq 0x18(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
movq %rsi, 0x68(%rsp)
imulq $0xe0, %rsi, %r12
leaq (%rcx,%r12), %rdi
addq $0xb0, %rdi
movl %eax, -0xb0(%rdi)
movl %eax, -0xac(%rdi)
andq $0x0, -0xa8(%rdi)
callq 0x274a8
movq 0x60(%rsp), %r15
movq %r15, %rdi
callq 0x7030
testl %ebx, %ebx
je 0x31299
xorl %ecx, %ecx
movl $0xff, 0x20(%rax,%rcx)
movb $0x0, 0x30(%rax,%rcx)
addq $0x40, %rcx
cmpq %rcx, %r15
jne 0x31283
movq 0x8(%r14), %rcx
movq (%rcx,%r13,8), %rcx
movq 0x10(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
movq 0x18(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
movq %rax, 0x10(%rcx,%r12)
xorl %ecx, %ecx
movl 0xd0(%rsp), %eax
cmpq %rax, %rcx
je 0x313cc
movq 0x10(%rsp), %rbp
movq 0x8(%r14), %rdx
movq (%rdx,%r13,8), %rax
movq %rdx, 0x78(%rsp)
movq (%rax,%rbp,8), %rax
movq %r12, %rbx
movq 0x18(%rsp), %r12
movq (%rax,%r12,8), %rax
movq 0x10(%rax,%rbx), %rax
movq %rcx, %r15
shlq $0x6, %r15
movq %rcx, 0x80(%rsp)
movl %ecx, (%rax,%r15)
andw $0x0, 0x22(%rax,%r15)
andq $0x0, 0x28(%rax,%r15)
xorps %xmm0, %xmm0
movups %xmm0, 0x4(%rax,%r15)
movq (%rdx,%r13,8), %rax
movq (%rax,%rbp,8), %rax
movq (%rax,%r12,8), %rax
movq 0x10(%rax,%rbx), %rax
andq $0x0, 0x34(%rax,%r15)
movl 0x34(%r14), %eax
movl %eax, %r14d
shrl $0x6, %r14d
andl $0x3f, %eax
cmpl $0x1, %eax
sbbl $-0x1, %r14d
movl %r14d, 0x312bb(%rip)    # 0x62608
leal (,%r14,8), %edi
callq 0x7030
movq 0x78(%rsp), %rdx
movq (%rdx,%r13,8), %rcx
movq (%rcx,%rbp,8), %rcx
movq (%rcx,%r12,8), %rcx
movq 0x10(%rcx,%rbx), %rcx
movq %rax, 0x18(%rcx,%r15)
movq (%rdx,%r13,8), %rax
movq (%rax,%rbp,8), %rax
movq (%rax,%r12,8), %rdi
movq %rbx, %r12
leaq (%rdi,%rbx), %rax
addq $0x10, %rax
xorl %ecx, %ecx
cmpq %rcx, %r14
je 0x313a5
movq (%rax), %rdx
movq 0x18(%rdx,%r15), %rdx
andq $0x0, (%rdx,%rcx,8)
incq %rcx
jmp 0x3138e
addq 0x10(%rdi,%r12), %r15
addq %r12, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x31596
movq 0x80(%rsp), %rcx
incq %rcx
movq 0x8(%rsp), %r14
jmp 0x312ba
movq 0x58(%rsp), %r15
movq %r15, %rdi
callq 0x7030
movq 0x8(%rsp), %rcx
movq 0x8(%rcx), %rbx
movq (%rbx,%r13,8), %rcx
movq 0x10(%rsp), %rbp
movq (%rcx,%rbp,8), %rcx
movq 0x18(%rsp), %r14
movq (%rcx,%r14,8), %rcx
movq %rax, 0x48(%rcx,%r12)
movq %r15, %rdi
callq 0x7030
movq (%rbx,%r13,8), %rcx
movq (%rcx,%rbp,8), %rcx
movq (%rcx,%r14,8), %rcx
movq %rax, 0x58(%rcx,%r12)
movq %r15, %rdi
callq 0x7030
movq 0x8(%rsp), %rdx
movq (%rbx,%r13,8), %rcx
movq (%rcx,%rbp,8), %rcx
movq (%rcx,%r14,8), %rcx
movq %rax, 0x50(%rcx,%r12)
xorl %ebx, %ebx
cmpq %rbx, 0x70(%rsp)
je 0x31518
movq 0x8(%rdx), %rax
movq 0x20(%rsp), %r13
movq (%rax,%r13,8), %rax
movq 0x10(%rsp), %rbp
movq (%rax,%rbp,8), %rax
movq 0x18(%rsp), %r14
movq (%rax,%r14,8), %rdi
addq %r12, %rdi
movzwl %bx, %r15d
movl %r15d, %esi
xorl %edx, %edx
callq 0x315c8
movq 0x8(%rsp), %rcx
movq 0x8(%rcx), %rcx
movq (%rcx,%r13,8), %rcx
movq (%rcx,%rbp,8), %rcx
movq (%rcx,%r14,8), %rcx
movq 0x48(%rcx,%r12), %rcx
movq %rax, (%rcx,%rbx,8)
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rax
movq (%rax,%r13,8), %rax
movq (%rax,%rbp,8), %rax
movq (%rax,%r14,8), %rdi
addq %r12, %rdi
movl %r15d, %esi
pushq $0x1
popq %rdx
callq 0x315c8
movq 0x8(%rsp), %rcx
movq 0x8(%rcx), %rcx
movq (%rcx,%r13,8), %rcx
movq (%rcx,%rbp,8), %rcx
movq (%rcx,%r14,8), %rcx
movq 0x58(%rcx,%r12), %rcx
movq %rax, (%rcx,%rbx,8)
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rax
movq (%rax,%r13,8), %rax
movq (%rax,%rbp,8), %rax
movq (%rax,%r14,8), %rdi
addq %r12, %rdi
movl %r15d, %esi
xorl %edx, %edx
callq 0x315c8
movq 0x8(%rsp), %rdx
movq 0x8(%rdx), %rcx
movq (%rcx,%r13,8), %rcx
movq (%rcx,%rbp,8), %rcx
movq (%rcx,%r14,8), %rcx
movq 0x50(%rcx,%r12), %rcx
movq %rax, (%rcx,%rbx,8)
incq %rbx
jmp 0x31436
movq 0x68(%rsp), %rsi
incq %rsi
movq 0x20(%rsp), %r13
jmp 0x31203
movq 0x18(%rsp), %rcx
incq %rcx
jmp 0x31189
incq 0x10(%rsp)
jmp 0x31156
incq %r13
movq %r13, %rbx
jmp 0x31123
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
testq %rbx, %rbx
je 0x31585
negq %rbx
movq %r15, %r12
addq $-0xd8, %r12
leaq (%r12,%rbx), %rdi
callq 0x31d1e
addq $-0xe0, %rbx
jne 0x31573
movq %r15, %rdi
callq 0x7430
movq %r14, %rdi
callq 0x75d0
nop