// File: /workspace/github_cpp_makefile_star2_O3/CMU-SAFARI[P]MQSim/src/ssd/Address_Mapping_Unit_Page_Level.cpp
// Function: SSD_Components::Address_Mapping_Unit_Page_Level::query_cmt(SSD_Components::NVM_Transaction_Flash*)
bool Address_Mapping_Unit_Page_Level::query_cmt(NVM_Transaction_Flash* transaction)
	{
		stream_id_type stream_id = transaction->Stream_id;
		Stats::total_CMT_queries++;
		Stats::total_CMT_queries_per_stream[stream_id]++;

		if (domains[stream_id]->Mapping_entry_accessible(ideal_mapping_table, stream_id, transaction->LPA))//Either limited or unlimited CMT
		{
			Stats::CMT_hits_per_stream[stream_id]++;
			Stats::CMT_hits++;
			if (transaction->Type == Transaction_Type::READ) {
				Stats::total_readTR_CMT_queries_per_stream[stream_id]++;
				Stats::total_readTR_CMT_queries++;
				Stats::readTR_CMT_hits_per_stream[stream_id]++;
				Stats::readTR_CMT_hits++;
			} else {
				//This is a write transaction
				Stats::total_writeTR_CMT_queries++;
				Stats::total_writeTR_CMT_queries_per_stream[stream_id]++;
				Stats::writeTR_CMT_hits++;
				Stats::writeTR_CMT_hits_per_stream[stream_id]++;
			}

			if (translate_lpa_to_ppa(stream_id, transaction)) {
				return true;
			} else {
				mange_unsuccessful_translation(transaction);
				return false;
			}
		} else {//Limited CMT
			//Maybe we can catch mapping data from an on-the-fly write back request
			if (request_mapping_entry(stream_id, transaction->LPA)) {
				Stats::CMT_miss++;
				Stats::CMT_miss_per_stream[stream_id]++;
				if (transaction->Type == Transaction_Type::READ) {
					Stats::total_readTR_CMT_queries++;
					Stats::total_readTR_CMT_queries_per_stream[stream_id]++;
					Stats::readTR_CMT_miss++;
					Stats::readTR_CMT_miss_per_stream[stream_id]++;
				} else { //This is a write transaction
					Stats::total_writeTR_CMT_queries++;
					Stats::total_writeTR_CMT_queries_per_stream[stream_id]++;
					Stats::writeTR_CMT_miss++;
					Stats::writeTR_CMT_miss_per_stream[stream_id]++;
				}
				if (translate_lpa_to_ppa(stream_id, transaction)) {
					return true;
				} else {
					mange_unsuccessful_translation(transaction);
					return false;
				}
			} else {
				if (transaction->Type == Transaction_Type::READ) {
					Stats::total_readTR_CMT_queries++;
					Stats::total_readTR_CMT_queries_per_stream[stream_id]++;
					Stats::readTR_CMT_miss++;
					Stats::readTR_CMT_miss_per_stream[stream_id]++;
					domains[stream_id]->Waiting_unmapped_read_transactions.insert(std::pair<LPA_type, NVM_Transaction_Flash*>(transaction->LPA, transaction));
				} else {//This is a write transaction
					Stats::total_writeTR_CMT_queries++;
					Stats::total_writeTR_CMT_queries_per_stream[stream_id]++;
					Stats::writeTR_CMT_miss++;
					Stats::writeTR_CMT_miss_per_stream[stream_id]++;
					domains[stream_id]->Waiting_unmapped_program_transactions.insert(std::pair<LPA_type, NVM_Transaction_Flash*>(transaction->LPA, transaction));
				}
			}

			return false;
		}
	}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rsi, %rbx
movzwl (%rsi), %r15d
leaq 0x45b27(%rip), %rax     # 0x70750
incl (%rax)
leaq 0x4835e(%rip), %rax     # 0x72f90
incl (%rax,%r15,4)
movq %rdi, %r14
cmpb $0x0, 0x4c(%rdi)
jne 0x2ac73
movq 0xa8(%r14), %rax
movq (%rax,%r15,8), %rax
movq 0x10(%rax), %rdi
movq %r15, %rax
shlq $0x38, %rax
orq 0x58(%rbx), %rax
movq %rsp, %rsi
movq %rax, (%rsi)
callq 0x30a0c
testq %rax, %rax
je 0x2acc1
movq 0x10(%rax), %rax
cmpl $0x2, 0x14(%rax)
jne 0x2acc1
leaq 0x46b16(%rip), %rax     # 0x71790
incl (%rax,%r15,4)
leaq 0x45ab3(%rip), %rax     # 0x70738
incl (%rax)
cmpl $0x0, 0x8(%rbx)
je 0x2ad3f
leaq 0x45ac0(%rip), %rax     # 0x70758
incl (%rax)
leal (,%r15,4), %eax
leaq 0x48ae7(%rip), %rcx     # 0x73790
incl (%rcx,%rax)
leaq 0x45a8d(%rip), %rcx     # 0x70740
incl (%rcx)
addq 0x442bc(%rip), %rax     # 0x6ef78
jmp 0x2ad6b
movq 0x58(%rbx), %rdx
movq %r14, %rdi
movl %r15d, %esi
callq 0x2af6c
testb %al, %al
je 0x2adbe
leaq 0x45a65(%rip), %rax     # 0x70744
incl (%rax)
leal (,%r15,4), %eax
leaq 0x476a0(%rip), %rcx     # 0x72390
incl (%rcx,%rax)
cmpl $0x0, 0x8(%rbx)
leaq 0x45a5a(%rip), %rcx     # 0x70758
cmoveq 0x4426a(%rip), %rcx     # 0x6ef70
leaq 0x48a83(%rip), %rdx     # 0x73790
cmoveq 0x44223(%rip), %rdx     # 0x6ef38
leaq 0x45a30(%rip), %rsi     # 0x7074c
cmoveq 0x4427c(%rip), %rsi     # 0x6efa0
leaq 0x47e65(%rip), %rdi     # 0x72b90
cmoveq 0x4425d(%rip), %rdi     # 0x6ef90
incl (%rcx)
incl (%rdx,%rax)
incl (%rsi)
incl (%rdi,%rax)
jmp 0x2ad6d
leal (,%r15,4), %eax
leaq 0x48642(%rip), %rcx     # 0x73390
incl (%rcx,%rax)
leaq 0x459fc(%rip), %rcx     # 0x70754
incl (%rcx)
leaq 0x46e2f(%rip), %rcx     # 0x71b90
incl (%rcx,%rax)
leaq 0x459d1(%rip), %rax     # 0x7073c
incl (%rax)
movq %r14, %rdi
movl %r15d, %esi
movq %rbx, %rdx
callq 0x2ae60
movl %eax, %ecx
movb $0x1, %al
testb %cl, %cl
jne 0x2ae55
movq 0xb8(%r14), %rax
movl 0x38(%rbx), %ecx
movl 0x3c(%rbx), %edx
movq (%rax,%rcx,8), %rax
movq (%rax,%rdx,8), %rax
movl 0x40(%rbx), %ecx
movl 0x44(%rbx), %edx
leaq (%rdx,%rdx,2), %rdi
shlq $0x4, %rdi
addq (%rax,%rcx,8), %rdi
movq %rsp, %rsi
movq %rbx, (%rsi)
callq 0x3139c
jmp 0x2ae53
cmpl $0x0, 0x8(%rbx)
je 0x2ae03
leaq 0x4598d(%rip), %rax     # 0x70758
incl (%rax)
leal (,%r15,4), %eax
leaq 0x489b4(%rip), %rcx     # 0x73790
incl (%rcx,%rax)
leaq 0x45966(%rip), %rcx     # 0x7074c
incl (%rcx)
leaq 0x47da1(%rip), %rcx     # 0x72b90
incl (%rcx,%rax)
movq 0xa8(%r14), %rax
movq (%rax,%r15,8), %rdi
addq $0x58, %rdi
jmp 0x2ae40
leaq 0x4594a(%rip), %rax     # 0x70754
incl (%rax)
leal (,%r15,4), %eax
leaq 0x48575(%rip), %rcx     # 0x73390
incl (%rcx,%rax)
leaq 0x45923(%rip), %rcx     # 0x70748
incl (%rcx)
leaq 0x47962(%rip), %rcx     # 0x72790
incl (%rcx,%rax)
movq 0xa8(%r14), %rax
movq (%rax,%r15,8), %rdi
addq $0x28, %rdi
movq 0x58(%rbx), %rax
movq %rsp, %rsi
movq %rax, (%rsi)
movq %rbx, 0x8(%rsi)
callq 0x30dc2
xorl %eax, %eax
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
nop