// 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::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 %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
movzwl (%rsi), %r15d
leaq 0x45635(%rip), %rax     # 0x70750
incl (%rax)
leaq 0x47e6c(%rip), %rax     # 0x72f90
incl (%rax,%r15,4)
movq %rdi, %r14
cmpb $0x0, 0x4c(%rdi)
jne 0x2b1c6
movq 0x58(%rbx), %rcx
movq 0xa8(%r14), %rax
movq (%rax,%r15,8), %rax
movq 0x10(%rax), %rax
movq %r15, %rsi
shlq $0x38, %rsi
orq %rcx, %rsi
movq (%rax), %r8
movq 0x8(%rax), %r9
xorl %r11d, %r11d
movq %rsi, %rax
xorl %edx, %edx
divq %r9
movq (%r8,%rdx,8), %rax
testq %rax, %rax
je 0x2b1ab
movq (%rax), %r10
movq %rax, %r11
cmpq 0x8(%r10), %rsi
je 0x2b1ab
movq %rdx, %rdi
movq %r10, %r12
movq (%r10), %r10
testq %r10, %r10
je 0x2b1a8
movq 0x8(%r10), %r8
movq %r8, %rax
xorl %edx, %edx
divq %r9
movl $0x0, %r11d
cmpq %rdi, %rdx
jne 0x2b1ab
movq %r12, %r11
cmpq %r8, %rsi
jne 0x2b17c
jmp 0x2b1ab
xorl %r11d, %r11d
testq %r11, %r11
je 0x2b1b5
movq (%r11), %rax
jmp 0x2b1b7
xorl %eax, %eax
testq %rax, %rax
je 0x2b214
movq 0x10(%rax), %rax
cmpl $0x2, 0x14(%rax)
jne 0x2b214
leaq 0x465c3(%rip), %rax     # 0x71790
incl (%rax,%r15,4)
leaq 0x45560(%rip), %rax     # 0x70738
incl (%rax)
cmpl $0x0, 0x8(%rbx)
je 0x2b291
leaq 0x4556d(%rip), %rax     # 0x70758
incl (%rax)
leal (,%r15,4), %eax
leaq 0x48594(%rip), %rcx     # 0x73790
incl (%rcx,%rax)
leaq 0x4553a(%rip), %rcx     # 0x70740
incl (%rcx)
addq 0x43d71(%rip), %rax     # 0x6ef80
jmp 0x2b2bd
movq %r14, %rdi
movl %r15d, %esi
movq %rcx, %rdx
callq 0x2b4c4
testb %al, %al
je 0x2b312
leaq 0x45513(%rip), %rax     # 0x70744
incl (%rax)
leal (,%r15,4), %eax
leaq 0x4714e(%rip), %rcx     # 0x72390
incl (%rcx,%rax)
cmpl $0x0, 0x8(%rbx)
leaq 0x45508(%rip), %rcx     # 0x70758
cmoveq 0x43d20(%rip), %rcx     # 0x6ef78
leaq 0x48531(%rip), %rdx     # 0x73790
cmoveq 0x43cd9(%rip), %rdx     # 0x6ef40
leaq 0x454de(%rip), %rsi     # 0x7074c
cmoveq 0x43d32(%rip), %rsi     # 0x6efa8
leaq 0x47913(%rip), %rdi     # 0x72b90
cmoveq 0x43d13(%rip), %rdi     # 0x6ef98
incl (%rcx)
incl (%rdx,%rax)
incl (%rsi)
incl (%rdi,%rax)
jmp 0x2b2bf
leal (,%r15,4), %eax
leaq 0x480f0(%rip), %rcx     # 0x73390
incl (%rcx,%rax)
leaq 0x454aa(%rip), %rcx     # 0x70754
incl (%rcx)
leaq 0x468dd(%rip), %rcx     # 0x71b90
incl (%rcx,%rax)
leaq 0x4547f(%rip), %rax     # 0x7073c
incl (%rax)
movq %r14, %rdi
movl %r15d, %esi
movq %rbx, %rdx
callq 0x2b3b8
movl %eax, %ecx
movb $0x1, %al
testb %cl, %cl
jne 0x2b3ab
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
leaq 0x8(%rsp), %rsi
movq %rbx, (%rsi)
callq 0x31bb8
jmp 0x2b3a9
cmpl $0x0, 0x8(%rbx)
je 0x2b357
leaq 0x45439(%rip), %rax     # 0x70758
incl (%rax)
leal (,%r15,4), %eax
leaq 0x48460(%rip), %rcx     # 0x73790
incl (%rcx,%rax)
leaq 0x45412(%rip), %rcx     # 0x7074c
incl (%rcx)
leaq 0x4784d(%rip), %rcx     # 0x72b90
incl (%rcx,%rax)
movq 0xa8(%r14), %rax
movq (%rax,%r15,8), %rdi
addq $0x58, %rdi
jmp 0x2b394
leaq 0x453f6(%rip), %rax     # 0x70754
incl (%rax)
leal (,%r15,4), %eax
leaq 0x48021(%rip), %rcx     # 0x73390
incl (%rcx,%rax)
leaq 0x453cf(%rip), %rcx     # 0x70748
incl (%rcx)
leaq 0x4740e(%rip), %rcx     # 0x72790
incl (%rcx,%rax)
movq 0xa8(%r14), %rax
movq (%rax,%r15,8), %rdi
addq $0x28, %rdi
movq 0x58(%rbx), %rax
leaq 0x8(%rsp), %rsi
movq %rax, (%rsi)
movq %rbx, 0x8(%rsi)
callq 0x315e2
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
nop