// File: /workspace/github_cpp_makefile_star2_O1/CMU-SAFARI[P]MQSim/src/ssd/Flash_Block_Manager.cpp
// Function: SSD_Components::Flash_Block_Manager::Allocate_Pages_in_block_and_invalidate_remaining_for_preconditioning(unsigned short, NVM::FlashMemory::Physical_Page_Address const&, std::vector<NVM::FlashMemory::Physical_Page_Address, std::allocator<NVM::FlashMemory::Physical_Page_Address>>&)
void Flash_Block_Manager::Allocate_Pages_in_block_and_invalidate_remaining_for_preconditioning(const stream_id_type stream_id, const NVM::FlashMemory::Physical_Page_Address& plane_address, std::vector<NVM::FlashMemory::Physical_Page_Address>& page_addresses)
	{
		if(page_addresses.size() > pages_no_per_block) {
			PRINT_ERROR("Error while precondition a physical block: the size of the address list is larger than the pages_no_per_block!")
		}
			
		PlaneBookKeepingType *plane_record = &plane_manager[plane_address.ChannelID][plane_address.ChipID][plane_address.DieID][plane_address.PlaneID];
		if (plane_record->Data_wf[stream_id]->Current_page_write_index > 0) {
			PRINT_ERROR("Illegal operation: the Allocate_Pages_in_block_and_invalidate_remaining_for_preconditioning function should be executed for an erased block!")
		}

		//Assign physical addresses
		for (int i = 0; i < page_addresses.size(); i++) {
			plane_record->Valid_pages_count++;
			plane_record->Free_pages_count--;
			page_addresses[i].BlockID = plane_record->Data_wf[stream_id]->BlockID;
			page_addresses[i].PageID = plane_record->Data_wf[stream_id]->Current_page_write_index++;
			plane_record->Check_bookkeeping_correctness(page_addresses[i]);
		}

		//Invalidate the remaining pages in the block
		NVM::FlashMemory::Physical_Page_Address target_address(plane_address);
		while (plane_record->Data_wf[stream_id]->Current_page_write_index < pages_no_per_block) {
			plane_record->Free_pages_count--;
			target_address.BlockID = plane_record->Data_wf[stream_id]->BlockID;
			target_address.PageID = plane_record->Data_wf[stream_id]->Current_page_write_index++;
			Invalidate_page_in_block_for_preconditioning(stream_id, target_address);
			plane_record->Check_bookkeeping_correctness(plane_address);
		}

		//Update the write frontier
		plane_record->Data_wf[stream_id] = plane_record->Get_a_free_block(stream_id, false);
	}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, %r13
movq 0x8(%rcx), %rax
subq (%rcx), %rax
sarq $0x3, %rax
movabsq $-0x5555555555555555, %r14 # imm = 0xAAAAAAAAAAAAAAAB
imulq %r14, %rax
movl 0x34(%rdi), %ecx
cmpq %rcx, %rax
ja 0x3d184
movq %rdi, (%rsp)
movq 0x8(%rdi), %rax
movl (%rdx), %ecx
movl 0x4(%rdx), %edi
movq (%rax,%rcx,8), %rax
movq (%rax,%rdi,8), %rax
movl 0x8(%rdx), %ecx
movq (%rax,%rcx,8), %r15
movq %rdx, 0x8(%rsp)
movl 0xc(%rdx), %eax
imulq $0xe0, %rax, %rax
movq 0x48(%r15,%rax), %rcx
movzwl %si, %r12d
movq (%rcx,%r12,8), %rcx
cmpl $0x0, 0x4(%rcx)
jne 0x3d1a3
addq %rax, %r15
movq (%r13), %rax
cmpq %rax, 0x8(%r13)
je 0x3d0f1
xorl %ebp, %ebp
xorl %ebx, %ebx
movq 0x4(%r15), %xmm0
paddd 0x1c8bb(%rip), %xmm0    # 0x59960
movq %xmm0, 0x4(%r15)
movq 0x48(%r15), %rcx
movq (%rcx,%r12,8), %rcx
movl (%rcx), %edx
leaq (%rax,%rbp), %rsi
movl %edx, 0x10(%rax,%rbp)
movl 0x4(%rcx), %edx
leal 0x1(%rdx), %edi
movl %edi, 0x4(%rcx)
movl %edx, 0x14(%rax,%rbp)
movq %r15, %rdi
callq 0x3df32
incq %rbx
movq (%r13), %rax
movq 0x8(%r13), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
imulq %r14, %rcx
addq $0x18, %rbp
cmpq %rbx, %rcx
ja 0x3d097
movq 0x8(%rsp), %rbx
movups (%rbx), %xmm0
movaps %xmm0, 0x10(%rsp)
movq 0x10(%rbx), %rax
movq %rax, 0x20(%rsp)
movq 0x48(%r15), %rax
movq (%rax,%r12,8), %rax
movl 0x4(%rax), %ecx
movq (%rsp), %r14
cmpl 0x34(%r14), %ecx
jae 0x3d160
leaq 0x10(%rsp), %r13
decl 0x4(%r15)
movl (%rax), %edx
movl %edx, 0x20(%rsp)
leal 0x1(%rcx), %edx
movl %edx, 0x4(%rax)
movl %ecx, 0x24(%rsp)
movq (%r14), %rax
movq %r14, %rdi
movl %r12d, %esi
movq %r13, %rdx
callq *0x38(%rax)
movq %r15, %rdi
movq %rbx, %rsi
callq 0x3df32
movq 0x48(%r15), %rax
movq (%rax,%r12,8), %rax
movl 0x4(%rax), %ecx
cmpl 0x34(%r14), %ecx
jb 0x3d121
movq %r15, %rdi
movl %r12d, %esi
xorl %edx, %edx
callq 0x3dbf4
movq 0x48(%r15), %rcx
movq %rax, (%rcx,%r12,8)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x31e65(%rip), %rbx     # 0x6eff0
leaq 0x19416(%rip), %rsi     # 0x565a8
movq %rbx, %rdi
callq 0x7390
leaq 0x1c7cf(%rip), %rsi     # 0x59970
jmp 0x3d1c0
movq 0x31e46(%rip), %rbx     # 0x6eff0
leaq 0x193f7(%rip), %rsi     # 0x565a8
movq %rbx, %rdi
callq 0x7390
leaq 0x1c81f(%rip), %rsi     # 0x599df
movq %rbx, %rdi
callq 0x7390
movq %rax, %rdi
callq 0x71c0
movq 0x31df9(%rip), %rdi     # 0x6efd0
callq 0x7430
movl $0x1, %edi
callq 0x7440