// File: /workspace/github_cpp_makefile_star2_O1/CMU-SAFARI[P]MQSim/src/ssd/Address_Mapping_Unit_Page_Level.cpp
// Function: SSD_Components::Address_Mapping_Unit_Page_Level::Set_barrier_for_accessing_physical_block(NVM::FlashMemory::Physical_Page_Address const&)
inline void Address_Mapping_Unit_Page_Level::Set_barrier_for_accessing_physical_block(const NVM::FlashMemory::Physical_Page_Address& block_address)
	{
		//The LPAs are actually not known until they are read one-by-one from flash storage. But, to reduce MQSim's complexity, we assume that LPAs are stored in DRAM and thus no read from flash storage is needed.
		Block_Pool_Slot_Type* block = &(block_manager->plane_manager[block_address.ChannelID][block_address.ChipID][block_address.DieID][block_address.PlaneID].Blocks[block_address.BlockID]);
		NVM::FlashMemory::Physical_Page_Address addr(block_address);
		for (flash_page_ID_type pageID = 0; pageID < block->Current_page_write_index; pageID++) {
			if (block_manager->Is_page_valid(block, pageID)) {
				addr.PageID = pageID;
				if (block->Holds_mapping_data) {
					MVPN_type mpvn = (MVPN_type)flash_controller->Get_metadata(addr.ChannelID, addr.ChipID, addr.DieID, addr.PlaneID, addr.BlockID, addr.PageID);
					if (domains[block->Stream_id]->GlobalTranslationDirectory[mpvn].MPPN != Convert_address_to_ppa(addr)) {
						PRINT_ERROR("Inconsistency in the global translation directory when locking an MPVN!")
						Set_barrier_for_accessing_mvpn(block->Stream_id, mpvn);
					}
				} else {
					LPA_type lpa = flash_controller->Get_metadata(addr.ChannelID, addr.ChipID, addr.DieID, addr.PlaneID, addr.BlockID, addr.PageID);
					LPA_type ppa = domains[block->Stream_id]->GlobalMappingTable[lpa].PPA;
					if (domains[block->Stream_id]->CMT->Exists(block->Stream_id, lpa)) {
						ppa = domains[block->Stream_id]->CMT->Retrieve_ppa(block->Stream_id, lpa);
					}
					if (ppa != Convert_address_to_ppa(addr)) {
						PRINT_ERROR("Inconsistency in the global mapping table when locking an LPA!")
					}
					Set_barrier_for_accessing_lpa(block->Stream_id, lpa);
				}
			}
		}
	}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
movq 0x40(%rdi), %rax
movq 0x8(%rax), %rax
movl (%rsi), %ecx
movl 0x4(%rsi), %edx
movq (%rax,%rcx,8), %rax
movq (%rax,%rdx,8), %rax
movq 0x8(%rsi), %rdi
movq %rdi, %xmm0
movl %edi, %edi
movq (%rax,%rdi,8), %rax
pshufd $0x55, %xmm0, %xmm1     # xmm1 = xmm0[1,1,1,1]
movd %xmm1, %edi
imulq $0xe0, %rdi, %rdi
movq 0x10(%rax,%rdi), %r14
movl %ecx, 0x10(%rsp)
movl %edx, 0x14(%rsp)
movq 0x10(%rsi), %rax
movq %rax, %xmm1
movl %eax, %eax
shlq $0x6, %rax
punpcklqdq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0]
movdqu %xmm0, 0x18(%rsp)
cmpl $0x0, 0x4(%r14,%rax)
je 0x30284
addq %rax, %r14
xorl %r15d, %r15d
movq 0x40(%rbx), %rdi
movq %r14, %rsi
movl %r15d, %edx
callq 0x3e338
testb %al, %al
je 0x30277
movl %r15d, 0x24(%rsp)
movl 0x10(%rsp), %esi
movl 0x14(%rsp), %edx
movl 0x18(%rsp), %ecx
movl 0x1c(%rsp), %r8d
movl 0x20(%rsp), %r9d
cmpb $0x1, 0x22(%r14)
jne 0x30188
movq 0x38(%rbx), %rdi
movq (%rdi), %rax
movl %r15d, (%rsp)
callq *0x38(%rax)
movq (%rbx), %rcx
movq 0xa8(%rbx), %rdx
movzwl 0x20(%r14), %esi
movq (%rdx,%rsi,8), %rdx
movq (%rdx), %rdx
movl %eax, %eax
shlq $0x4, %rax
movl (%rdx,%rax), %r12d
movq %rbx, %rdi
leaq 0x10(%rsp), %rsi
callq *0x90(%rcx)
cmpq %r12, %rax
je 0x30277
jmp 0x302b2
movq 0x38(%rbx), %rdi
movq (%rdi), %rax
movl %r15d, (%rsp)
callq *0x38(%rax)
movq %rax, %r13
movq 0xa8(%rbx), %rax
movzwl 0x20(%r14), %r9d
movq (%rax,%r9,8), %rax
movq 0x10(%rax), %rdi
movq 0x20(%rax), %rax
leaq (,%r13,2), %rcx
addq %r13, %rcx
movq (%rax,%rcx,8), %rbp
movq %r9, %rcx
shlq $0x38, %rcx
orq %r13, %rcx
movq (%rdi), %r8
movq 0x8(%rdi), %r10
movq %rcx, %rax
xorl %edx, %edx
divq %r10
movq %rdx, %rsi
movq (%r8,%rdx,8), %rdx
movl $0x0, %eax
testq %rdx, %rdx
je 0x30223
movq (%rdx), %r11
movq %rdx, %rax
cmpq 0x8(%r11), %rcx
je 0x30223
movq %r11, %r12
movq (%r11), %r11
testq %r11, %r11
je 0x30221
movq 0x8(%r11), %r8
movq %r8, %rax
xorl %edx, %edx
divq %r10
movl $0x0, %eax
cmpq %rsi, %rdx
jne 0x30223
movq %r12, %rax
cmpq %r8, %rcx
jne 0x301f6
jmp 0x30223
xorl %eax, %eax
testq %rax, %rax
je 0x3022d
movq (%rax), %rax
jmp 0x3022f
xorl %eax, %eax
testq %rax, %rax
je 0x3024d
movq 0x10(%rax), %rax
cmpl $0x2, 0x14(%rax)
jne 0x3024d
movzwl %r9w, %esi
movq %r13, %rdx
callq 0x29600
movq %rax, %rbp
movq (%rbx), %rax
movq %rbx, %rdi
leaq 0x10(%rsp), %rsi
callq *0x90(%rax)
cmpq %rax, %rbp
jne 0x30293
movzwl 0x20(%r14), %esi
movq (%rbx), %rax
movq %rbx, %rdi
movq %r13, %rdx
callq *0xa0(%rax)
incl %r15d
cmpl 0x4(%r14), %r15d
jb 0x30105
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x3ed56(%rip), %rbx     # 0x6eff0
leaq 0x26307(%rip), %rsi     # 0x565a8
movq %rbx, %rdi
callq 0x7390
leaq 0x28a64(%rip), %rsi     # 0x58d14
jmp 0x302cf
movq 0x3ed37(%rip), %rbx     # 0x6eff0
leaq 0x262e8(%rip), %rsi     # 0x565a8
movq %rbx, %rdi
callq 0x7390
leaq 0x289fd(%rip), %rsi     # 0x58ccc
movq %rbx, %rdi
callq 0x7390
movq %rax, %rdi
callq 0x71c0
movq 0x3ecea(%rip), %rdi     # 0x6efd0
callq 0x7430
movl $0x1, %edi
callq 0x7440
nop