// File: /workspace/github_cpp_makefile_star2_O3/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 %rdx, %rbx
movq %rdi, %r14
movq (%rcx), %rax
movq 0x8(%rcx), %rdi
movq %rdi, %rcx
subq %rax, %rcx
sarq $0x3, %rcx
movabsq $-0x5555555555555555, %r10 # imm = 0xAAAAAAAAAAAAAAAB
imulq %r10, %rcx
movl 0x34(%r14), %edx
cmpq %rdx, %rcx
ja 0x3c702
movq 0x8(%r14), %rcx
movl (%rbx), %r8d
movl 0x4(%rbx), %r9d
movq (%rcx,%r8,8), %rcx
movq (%rcx,%r9,8), %rcx
movl 0x8(%rbx), %r8d
movq (%rcx,%r8,8), %r15
movl 0xc(%rbx), %ecx
imulq $0xe0, %rcx, %r8
movq 0x48(%r15,%r8), %rcx
movzwl %si, %r12d
movq (%rcx,%r12,8), %rcx
cmpl $0x0, 0x4(%rcx)
jne 0x3c721
addq %r8, %r15
cmpq %rax, %rdi
je 0x3c683
movq %r14, (%rsp)
movq %rbx, 0x8(%rsp)
xorl %ebp, %ebp
xorl %ebx, %ebx
movq 0x4(%r15), %xmm0
paddd 0x1d34c(%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
movq %r10, %r14
callq 0x3d4da
movq %r14, %r10
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 0x3c606
movq 0x8(%rsp), %rbx
movups (%rbx), %xmm0
movq 0x48(%r15), %rax
movq (%rax,%r12,8), %rcx
movl 0x4(%rcx), %eax
movq (%rsp), %r14
movl 0x34(%r14), %edx
jmp 0x3c688
movups (%rbx), %xmm0
xorl %eax, %eax
movaps %xmm0, 0x10(%rsp)
movq 0x10(%rbx), %rsi
movq %rsi, 0x20(%rsp)
cmpl %edx, %eax
jae 0x3c6de
leaq 0x10(%rsp), %r13
decl 0x4(%r15)
movl (%rcx), %edx
movl %edx, 0x20(%rsp)
leal 0x1(%rax), %edx
movl %edx, 0x4(%rcx)
movl %eax, 0x24(%rsp)
movq (%r14), %rax
movq %r14, %rdi
movl %r12d, %esi
movq %r13, %rdx
callq *0x38(%rax)
movq %r15, %rdi
movq %rbx, %rsi
callq 0x3d4da
movq 0x48(%r15), %rax
movq (%rax,%r12,8), %rcx
movl 0x4(%rcx), %eax
cmpl 0x34(%r14), %eax
jb 0x3c69f
movq %r15, %rdi
movl %r12d, %esi
xorl %edx, %edx
callq 0x3d1a2
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 0x328e7(%rip), %rbx     # 0x6eff0
leaq 0x19e98(%rip), %rsi     # 0x565a8
movq %rbx, %rdi
callq 0x7390
leaq 0x1d251(%rip), %rsi     # 0x59970
jmp 0x3c73e
movq 0x328c8(%rip), %rbx     # 0x6eff0
leaq 0x19e79(%rip), %rsi     # 0x565a8
movq %rbx, %rdi
callq 0x7390
leaq 0x1d2a1(%rip), %rsi     # 0x599df
movq %rbx, %rdi
callq 0x7390
movq %rax, %rdi
callq 0x71c0
movq 0x3287b(%rip), %rdi     # 0x6efd0
callq 0x7430
movl $0x1, %edi
callq 0x7440