// File: /workspace/github_cpp_makefile_star2_O1/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, %r15
movl 0xf0(%rsp), %r11d
movl 0xe8(%rsp), %r8d
movl 0xe0(%rsp), %r10d
movl 0xf8(%rsp), %eax
leaq 0x30e73(%rip), %rdi     # 0x6e408
movq %rdi, (%r15)
movq %rsi, 0x10(%r15)
movl %edx, 0x18(%r15)
movl %ecx, 0x1c(%rsp)
movl %ecx, 0x1c(%r15)
movl %ebx, 0x20(%r15)
movl %r9d, 0x18(%rsp)
movl %r9d, 0x24(%r15)
movl %r10d, 0x28(%r15)
movl %r8d, 0x2c(%r15)
movl %r11d, 0x30(%r15)
movl %eax, 0x34(%r15)
movl %ebx, %eax
movq %rax, 0x40(%rsp)
leaq (,%rax,8), %rdi
callq 0x7030
movq %rax, 0x8(%r15)
testl %ebx, %ebx
je 0x3db76
movl 0x18(%rsp), %eax
movq %rax, 0x48(%rsp)
leaq (,%rax,8), %rax
movq %rax, 0x38(%rsp)
movl 0xe0(%rsp), %eax
leaq (,%rax,8), %rax
movq %rax, 0x50(%rsp)
movl 0xe8(%rsp), %eax
imulq $0xe0, %rax, %rax
movq %rax, 0x60(%rsp)
addq $0x8, %rax
movq %rax, 0x58(%rsp)
movl 0xf0(%rsp), %eax
shlq $0x6, %rax
movq %rax, 0x30(%rsp)
movl 0x1c(%rsp), %ebx
leaq (,%rbx,8), %rax
movq %rax, 0x68(%rsp)
xorl %r13d, %r13d
movq %r15, 0x80(%rsp)
movq %rbx, 0x70(%rsp)
movq 0x38(%rsp), %rdi
callq 0x7030
movq 0x8(%r15), %rcx
movq %rax, (%rcx,%r13,8)
cmpl $0x0, 0x18(%rsp)
je 0x3db68
xorl %ebp, %ebp
movq %r13, 0x28(%rsp)
movq 0x50(%rsp), %rdi
callq 0x7030
movq 0x8(%r15), %rcx
movq (%rcx,%r13,8), %rcx
movq %rax, (%rcx,%rbp,8)
cmpl $0x0, 0xe0(%rsp)
je 0x3db5a
xorl %edx, %edx
movq %rbp, 0x10(%rsp)
movq %rdx, 0x8(%rsp)
movq 0x58(%rsp), %rdi
callq 0x7030
movq %rax, %r13
movl 0xe8(%rsp), %eax
movq %rax, (%r13)
cmpl $0x0, 0xe8(%rsp)
movl $0x0, %ecx
je 0x3d78c
xorl %ebp, %ebp
leaq 0x28(,%rbp), %rax
addq %r13, %rax
movl $0x0, 0x28(%r13,%rbp)
movq %rcx, 0x30(%r13,%rbp)
movq %rax, 0x38(%r13,%rbp)
movq %rax, 0x40(%r13,%rbp)
movq %rcx, 0x48(%r13,%rbp)
leaq 0x68(%r13,%rbp), %rdi
xorps %xmm0, %xmm0
movups %xmm0, 0x68(%r13,%rbp)
movups %xmm0, 0x78(%r13,%rbp)
movups %xmm0, 0x88(%r13,%rbp)
movups %xmm0, 0x98(%r13,%rbp)
movups %xmm0, 0xa8(%r13,%rbp)
xorl %esi, %esi
xorl %r14d, %r14d
callq 0x3e34e
leaq 0xc0(,%rbp), %rax
addq %r13, %rax
movl $0x0, 0xc0(%r13,%rbp)
movq %r14, 0xc8(%r13,%rbp)
movq %rax, 0xd0(%r13,%rbp)
movq %rax, 0xd8(%r13,%rbp)
movq %r14, 0xe0(%r13,%rbp)
addq $0xe0, %rbp
cmpq %rbp, 0x60(%rsp)
movl $0x0, %ecx
jne 0x3d6dd
addq $0x8, %r13
movq 0x8(%r15), %rax
movq 0x28(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x10(%rsp), %rbp
movq (%rax,%rbp,8), %rax
movq 0x8(%rsp), %rdx
movq %r13, (%rax,%rdx,8)
movq %rcx, %r13
cmpl $0x0, 0xe8(%rsp)
movl 0xf0(%rsp), %r14d
je 0x3db47
xorl %esi, %esi
movl 0x34(%r15), %eax
imull %r14d, %eax
movq 0x8(%r15), %rcx
movq (%rcx,%r13,8), %rcx
movq (%rcx,%rbp,8), %rcx
movq (%rcx,%rdx,8), %rcx
movq %rsi, 0x78(%rsp)
imulq $0xe0, %rsi, %rbx
leaq (%rcx,%rbx), %rdi
addq $0xb0, %rdi
movl %eax, -0xb0(%rdi)
movl %eax, -0xac(%rdi)
movq $0x0, -0xa8(%rdi)
callq 0x30eea
movq 0x30(%rsp), %r14
movq %r14, %rdi
callq 0x7030
movl 0xf0(%rsp), %edx
testl %edx, %edx
je 0x3d848
movq %r14, %rdi
xorl %ecx, %ecx
movl $0xff, 0x20(%rax,%rcx)
movb $0x0, 0x30(%rax,%rcx)
addq $0x40, %rcx
cmpq %rcx, %rdi
jne 0x3d832
movq 0x8(%r15), %rcx
movq (%rcx,%r13,8), %rcx
movq (%rcx,%rbp,8), %rcx
movq 0x8(%rsp), %rsi
movq %rsi, %r14
movq (%rcx,%rsi,8), %rcx
movq %rax, 0x10(%rcx,%rbx)
testl %edx, %edx
movq %rbp, %r12
je 0x3d9c4
xorl %ebp, %ebp
xorl %ecx, %ecx
movq %rbx, 0x88(%rsp)
movq %rbx, %rdx
movq 0x8(%r15), %rbx
movq (%rbx,%r13,8), %rax
movq (%rax,%r12,8), %rax
movq (%rax,%r14,8), %rax
movq 0x10(%rax,%rdx), %rax
movl %ecx, 0x20(%rsp)
movl %ecx, (%rax,%rbp)
movw $0x0, 0x22(%rax,%rbp)
xorl %ecx, %ecx
movq %rcx, 0x28(%rax,%rbp)
xorps %xmm0, %xmm0
movups %xmm0, 0x4(%rax,%rbp)
movq (%rbx,%r13,8), %rax
movq (%rax,%r12,8), %rax
movq (%rax,%r14,8), %rax
movq 0x10(%rax,%rdx), %rax
movq %rcx, 0x34(%rax,%rbp)
movl 0x34(%r15), %eax
movl %eax, %ecx
shrl $0x6, %ecx
xorl %r15d, %r15d
testb $0x3f, %al
setne %r15b
movq %rcx, 0x90(%rsp)
leal (%rcx,%r15), %r13d
movl %r13d, 0x31d4c(%rip)    # 0x6f638
leal (,%r13,8), %edi
callq 0x7030
movq 0x28(%rsp), %rcx
movq (%rbx,%rcx,8), %rcx
movq (%rcx,%r12,8), %rcx
movq (%rcx,%r14,8), %rcx
movq 0x88(%rsp), %rdx
movq 0x10(%rcx,%rdx), %rcx
movq %rax, 0x18(%rcx,%rbp)
testl %r13d, %r13d
movq 0x28(%rsp), %r13
movq %r14, %rcx
movq %rbx, %r14
movq %rdx, %rbx
je 0x3d966
movq (%r14,%r13,8), %rax
movq (%rax,%r12,8), %rax
movq (%rax,%rcx,8), %rax
movq 0x10(%rax,%rbx), %rax
movq 0x18(%rax,%rbp), %rdi
movq 0x90(%rsp), %rax
addl %r15d, %eax
decl %eax
leaq 0x8(,%rax,8), %rdx
xorl %esi, %esi
callq 0x7230
movq 0x8(%rsp), %rcx
movq (%r14,%r13,8), %rax
movq (%rax,%r12,8), %rax
movq (%rax,%rcx,8), %rax
leaq (%rax,%rbx), %rdi
addq $0x18, %rdi
movq -0x8(%rdi), %rax
addq %rbp, %rax
movl $0x0, 0x98(%rsp)
movq %rax, 0xa0(%rsp)
leaq 0x98(%rsp), %rsi
movq %rcx, %r14
callq 0x3e774
movl 0x20(%rsp), %ecx
incl %ecx
addq $0x40, %rbp
movq 0x30(%rsp), %rdi
cmpq %rbp, %rdi
movq 0x80(%rsp), %r15
jne 0x3d87c
movq 0x68(%rsp), %rbp
movq %rbp, %rdi
callq 0x7030
movq 0x8(%r15), %rcx
movq %rcx, 0x20(%rsp)
movq (%rcx,%r13,8), %rcx
movq (%rcx,%r12,8), %rcx
movq (%rcx,%r14,8), %rcx
movq %rax, 0x48(%rcx,%rbx)
movq %rbp, %rdi
callq 0x7030
movq 0x20(%rsp), %rcx
movq (%rcx,%r13,8), %rcx
movq (%rcx,%r12,8), %rcx
movq (%rcx,%r14,8), %rcx
movq %rax, 0x58(%rcx,%rbx)
movq %rbp, %rdi
callq 0x7030
movq 0x20(%rsp), %rcx
movq (%rcx,%r13,8), %rcx
movq (%rcx,%r12,8), %rcx
movq (%rcx,%r14,8), %rcx
movq %rax, 0x50(%rcx,%rbx)
cmpl $0x0, 0x1c(%rsp)
movq 0x70(%rsp), %rax
movq %r12, %rbp
movq %r14, %rdx
je 0x3db27
movq %rax, %r12
xorl %r14d, %r14d
movq 0x8(%r15), %rax
movq (%rax,%r13,8), %rax
movq (%rax,%rbp,8), %rax
movq (%rax,%rdx,8), %rdi
addq %rbx, %rdi
movzwl %r14w, %ebp
movl %ebp, %esi
xorl %edx, %edx
callq 0x3dbf4
movq 0x8(%r15), %rcx
movq (%rcx,%r13,8), %rcx
movq 0x10(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
movq 0x8(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
movq 0x48(%rcx,%rbx), %rcx
movq %rax, (%rcx,%r14,8)
movq 0x8(%r15), %rax
movq (%rax,%r13,8), %rax
movq 0x10(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x8(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
addq %rbx, %rdi
movl %ebp, %esi
movl $0x1, %edx
callq 0x3dbf4
movq 0x8(%r15), %rcx
movq (%rcx,%r13,8), %rcx
movq 0x10(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
movq 0x8(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
movq 0x58(%rcx,%rbx), %rcx
movq %rax, (%rcx,%r14,8)
movq 0x8(%r15), %rax
movq (%rax,%r13,8), %rax
movq 0x10(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x8(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
addq %rbx, %rdi
movl %ebp, %esi
movq 0x10(%rsp), %rbp
xorl %edx, %edx
callq 0x3dbf4
movq 0x8(%rsp), %rdx
movq 0x8(%r15), %rcx
movq (%rcx,%r13,8), %rcx
movq (%rcx,%rbp,8), %rcx
movq (%rcx,%rdx,8), %rcx
movq 0x50(%rcx,%rbx), %rcx
movq %rax, (%rcx,%r14,8)
incq %r14
cmpq %r14, %r12
jne 0x3da43
movq 0x78(%rsp), %rsi
incq %rsi
movl 0xe8(%rsp), %eax
cmpq %rax, %rsi
movl 0xf0(%rsp), %r14d
jne 0x3d7ca
incq %rdx
movl 0xe0(%rsp), %eax
cmpq %rax, %rdx
jne 0x3d6ab
incq %rbp
cmpq 0x48(%rsp), %rbp
jne 0x3d680
incq %r13
cmpq 0x40(%rsp), %r13
jne 0x3d65c
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x20(,%rbp), %rdi
addq %r13, %rdi
callq 0x3e4b6
testq %rbp, %rbp
je 0x3dbaf
addq $0x8, %rbp
movq %rbp, %rdi
movq %r13, %rsi
callq 0x7910
movq %r13, %rdi
callq 0x7480
movq %rbx, %rdi
callq 0x7620
nop