// File: CMU-SAFARI[P]MQSim/src/ssd/Data_Cache_Flash.cpp
// Function: SSD_Components::Data_Cache_Flash::Insert_write_data(unsigned short, unsigned long, unsigned long, unsigned long, unsigned long)
void Data_Cache_Flash::Insert_write_data(const stream_id_type stream_id, const LPA_type lpn, const data_cache_content_type content,
		const data_timestamp_type timestamp, const page_status_type state_bitmap_of_write_sectors)
	{
		LPA_type key = LPN_TO_UNIQUE_KEY(stream_id, lpn);
		
		if (slots.find(key) != slots.end()) {
			throw std::logic_error("Duplicate lpn insertion into data cache!!");
		}
		
		if (slots.size() >= capacity_in_pages) {
			throw std::logic_error("Data cache overfull!");
		}

		Data_Cache_Slot_Type* cache_slot = new Data_Cache_Slot_Type();
		cache_slot->LPA = lpn;
		cache_slot->State_bitmap_of_existing_sectors = state_bitmap_of_write_sectors;
		cache_slot->Content = content;
		cache_slot->Timestamp = timestamp;
		cache_slot->Status = Cache_Slot_Status::DIRTY_NO_FLASH_WRITEBACK;
		lru_list.push_front(std::pair<LPA_type, Data_Cache_Slot_Type*>(key, cache_slot));
		cache_slot->lru_list_ptr = lru_list.begin();
		slots[key] = cache_slot;
	}

// Assembly:
subq $0xa8, %rsp
movw %si, %ax
movq %rdi, 0xa0(%rsp)
movw %ax, 0x9e(%rsp)
movq %rdx, 0x90(%rsp)
movq %rcx, 0x88(%rsp)
movq %r8, 0x80(%rsp)
movq %r9, 0x78(%rsp)
movq 0xa0(%rsp), %rdi
movq %rdi, 0x28(%rsp)
movzwl 0x9e(%rsp), %eax
shlq $0x38, %rax
orq 0x90(%rsp), %rax
movq %rax, 0x70(%rsp)
leaq 0x70(%rsp), %rsi
callq 0x65190
movq 0x28(%rsp), %rdi
movq %rax, 0x68(%rsp)
callq 0x651e0
movq %rax, 0x60(%rsp)
leaq 0x68(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x65240
testb $0x1, %al
jne 0x64c90
jmp 0x64ce8
movl $0x10, %edi
callq 0x8200
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x20(%rsp)
leaq 0x48400(%rip), %rsi     # 0xad0ac
callq 0x8610
jmp 0x64cb3
movq 0x20(%rsp), %rdi
movq 0x75301(%rip), %rsi     # 0xd9fc0
movq 0x752ca(%rip), %rdx     # 0xd9f90
callq 0x8710
movq 0x20(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x58(%rsp)
movl %eax, 0x54(%rsp)
callq 0x8330
jmp 0x64e4d
movq 0x28(%rsp), %rdi
callq 0x653b0
movq 0x28(%rsp), %rcx
movl 0x50(%rcx), %ecx
cmpq %rcx, %rax
jb 0x64d57
movl $0x10, %edi
callq 0x8200
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x18(%rsp)
leaq 0x4837c(%rip), %rsi     # 0xad097
callq 0x8610
jmp 0x64d22
movq 0x18(%rsp), %rdi
movq 0x75292(%rip), %rsi     # 0xd9fc0
movq 0x7525b(%rip), %rdx     # 0xd9f90
callq 0x8710
movq 0x18(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x58(%rsp)
movl %eax, 0x54(%rsp)
callq 0x8330
jmp 0x64e4d
movl $0x30, %edi
callq 0x8450
movq %rax, %rdi
movq %rdi, (%rsp)
xorl %esi, %esi
movl $0x30, %edx
callq 0x8260
movq (%rsp), %rdi
callq 0x65600
movq (%rsp), %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x48(%rsp)
movq 0x90(%rsp), %rdx
movq 0x48(%rsp), %rcx
movq %rdx, 0x8(%rcx)
movq 0x78(%rsp), %rdx
movq 0x48(%rsp), %rcx
movq %rdx, (%rcx)
movq 0x88(%rsp), %rdx
movq 0x48(%rsp), %rcx
movq %rdx, 0x10(%rcx)
movq 0x80(%rsp), %rdx
movq 0x48(%rsp), %rcx
movq %rdx, 0x18(%rcx)
movq 0x48(%rsp), %rcx
movl $0x2, 0x20(%rcx)
addq $0x38, %rax
movq %rax, 0x8(%rsp)
leaq 0x38(%rsp), %rdi
leaq 0x70(%rsp), %rsi
leaq 0x48(%rsp), %rdx
callq 0x65660
movq 0x8(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x65620
movq 0x28(%rsp), %rdi
addq $0x38, %rdi
callq 0x652d0
movq 0x28(%rsp), %rdi
movq %rax, 0x30(%rsp)
movq 0x48(%rsp), %rax
movq 0x30(%rsp), %rcx
movq %rcx, 0x28(%rax)
movq 0x48(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq 0x70(%rsp), %rsi
callq 0x65690
movq 0x10(%rsp), %rcx
movq %rcx, (%rax)
addq $0xa8, %rsp
retq
movq 0x58(%rsp), %rdi
callq 0x8770
nopw (%rax,%rax)