// File: /workspace/github_cpp_makefile_star2_O2/yangwanyuan[P]HLKVDS/src/ReadCache.cc
// Function: dslab::ReadCache::Put(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void ReadCache::Put(string key, string value){
	//get footprint
	WriteLock w_lock(myLock);
	hlkvds::Kvdb_Key input(value.c_str(),value.length());
	hlkvds::Kvdb_Digest result;
	em->CalcDigest(&input,result);
	string footprint = em->Tostring(&result);
	string tobeUpdate = "", lkey ="", lvalue = "";//useless key, useless value
	map<string, string>::iterator it_dedup = dedup_map.find(key);//old_footprint
	multimap<string, string>::iterator it_refer;
	if( it_dedup!=dedup_map.end() ){//key already exist
		if(it_dedup->second != footprint){//renew the value
			it_refer = refer_map.find(it_dedup->second);
			for(int i = 0; i < refer_map.count(it_dedup->second); i++){
				if(it_refer->second == key) {
					refer_map.erase(it_refer);
					break;
				}
				it_refer++;
			}
			it_dedup->second = footprint;
			refer_map.insert(pair<string, string>(it_dedup->second, key));
			cache_map->Put(it_dedup->second, value, lkey, lvalue);
		}else{ //same value same key
			cache_map->Put(it_dedup->second, value, lkey, lvalue, true);
		}
	}else{//key does not exist
		dedup_map.insert(pair<string,string>(key,footprint));
		refer_map.insert(pair<string,string>(footprint, key));
		if( cache_map->Put(footprint,value, tobeUpdate, lvalue) ){//cache has deleted an entry
			it_refer = refer_map.find(tobeUpdate);
			while(it_refer!=refer_map.end()){
				it_dedup = dedup_map.find(it_refer->second);
				dedup_map.erase(it_dedup);
				refer_map.erase(it_refer);
				it_refer= refer_map.find(tobeUpdate);
			}
		}
	}	
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1c8, %rsp            # imm = 0x1C8
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x70(%rdi), %rsi
leaq 0xd8(%rsp), %rdi
callq 0x155f8
movq (%r14), %rsi
movl 0x8(%r14), %edx
leaq 0xc(%rsp), %rdi
callq 0x10222
leaq 0x44(%rsp), %rdi
callq 0x10238
leaq 0xc(%rsp), %rdi
leaq 0x44(%rsp), %rsi
callq 0x10286
leaq 0x20(%rsp), %rdi
leaq 0x44(%rsp), %rsi
callq 0x103ac
leaq 0xaebd(%rip), %rsi      # 0x1fbfc
leaq 0xb8(%rsp), %rdi
leaq 0x58(%rsp), %rdx
callq 0x6150
leaq 0xaea4(%rip), %rsi      # 0x1fbfc
leaq 0xe8(%rsp), %rdi
leaq 0x58(%rsp), %rdx
callq 0x6150
leaq 0xae8b(%rip), %rsi      # 0x1fbfc
leaq 0x98(%rsp), %rdi
leaq 0x58(%rsp), %rdx
callq 0x6150
leaq 0x8(%rbx), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x17c6a
movq %rax, %r13
leaq 0x10(%rbx), %rax
cmpq %rax, %r13
je 0x14e09
addq $0x40, %r13
leaq 0x20(%rsp), %rsi
movq %r13, %rdi
callq 0xb492
testb %al, %al
je 0x14f30
movq %r14, 0x18(%rsp)
leaq 0x38(%rbx), %r12
movq %r12, %rdi
movq %r13, %rsi
callq 0x17c6a
movq %rax, %rbp
xorl %r14d, %r14d
movq %r12, %rdi
movq %r13, %rsi
callq 0x17cf4
cmpq %r14, %rax
jbe 0x14f8d
leaq 0x40(%rbp), %rdi
movq %r15, %rsi
callq 0xd211
testb %al, %al
jne 0x14f82
movq %rbp, %rdi
callq 0x62c0
movq %rax, %rbp
incq %r14
jmp 0x14dd1
leaq 0x58(%rsp), %rdi
leaq 0x20(%rsp), %rdx
movq %r15, %rsi
callq 0x15604
leaq 0x58(%rsp), %rsi
movq %r12, %rdi
callq 0x1802e
leaq 0x58(%rsp), %rdi
callq 0x1563a
leaq 0x58(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movq %r15, %rdx
callq 0x15604
leaq 0x38(%rbx), %r15
leaq 0x58(%rsp), %rsi
movq %r15, %rdi
callq 0x17e9e
leaq 0x58(%rsp), %rdi
callq 0x1563a
movq (%rbx), %r13
leaq 0x128(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x6530
leaq 0x108(%rsp), %rdi
movq %r14, %rsi
callq 0x6530
movq (%r13), %rax
leaq 0x128(%rsp), %rsi
leaq 0x108(%rsp), %rdx
leaq 0xb8(%rsp), %rcx
leaq 0x98(%rsp), %r8
movq %r13, %rdi
xorl %r9d, %r9d
callq *0x10(%rax)
movl %eax, %ebp
leaq 0x108(%rsp), %rdi
callq 0x6788
leaq 0x128(%rsp), %rdi
callq 0x6788
testb %bpl, %bpl
je 0x15022
leaq 0xb8(%rsp), %rsi
movq %r15, %rdi
callq 0x17c6a
movq %rax, %r13
addq $0x40, %rbx
leaq 0xb8(%rsp), %r14
cmpq %rbx, %r13
je 0x15022
leaq 0x40(%r13), %rsi
movq %r12, %rdi
callq 0x17c6a
movq %r12, %rdi
movq %rax, %rsi
callq 0x17e50
movq %r15, %rdi
movq %r13, %rsi
callq 0x17e50
movq %r15, %rdi
movq %r14, %rsi
callq 0x17c6a
movq %rax, %r13
jmp 0x14ef5
movq (%rbx), %r12
leaq 0x168(%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x6530
leaq 0x148(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x6530
movq (%r12), %rax
leaq 0xe8(%rsp), %rcx
leaq 0x98(%rsp), %r8
pushq $0x1
popq %r9
movq %r12, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq *0x10(%rax)
jmp 0x15012
movq %r12, %rdi
movq %rbp, %rsi
callq 0x17e50
leaq 0x20(%rsp), %rsi
movq %r13, %rdi
callq 0x6240
movq 0x18(%rsp), %r14
leaq 0x58(%rsp), %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x15604
leaq 0x58(%rsp), %rsi
movq %r12, %rdi
callq 0x17e9e
leaq 0x58(%rsp), %rdi
callq 0x1563a
movq (%rbx), %r12
leaq 0x1a8(%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x6530
leaq 0x188(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x6530
movq (%r12), %rax
leaq 0xe8(%rsp), %rcx
leaq 0x98(%rsp), %r8
movq %r12, %rdi
movq %rbx, %rsi
movq %r15, %rdx
xorl %r9d, %r9d
callq *0x10(%rax)
movq %r15, %rdi
callq 0x6788
movq %rbx, %rdi
callq 0x6788
leaq 0x98(%rsp), %rdi
callq 0x6788
leaq 0xe8(%rsp), %rdi
callq 0x6788
leaq 0xb8(%rsp), %rdi
callq 0x6788
leaq 0x20(%rsp), %rdi
callq 0x6788
leaq 0x44(%rsp), %rdi
callq 0x10252
leaq 0xc(%rsp), %rdi
callq 0x10220
leaq 0xd8(%rsp), %rdi
callq 0x15650
addq $0x1c8, %rsp            # imm = 0x1C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1513a
jmp 0x1513a
movq %rax, %rbx
leaq 0x188(%rsp), %rdi
callq 0x6788
jmp 0x150a5
movq %rax, %rbx
leaq 0x1a8(%rsp), %rdi
jmp 0x150f4
jmp 0x150ff
jmp 0x1513a
movq %rax, %rbx
leaq 0x148(%rsp), %rdi
callq 0x6788
jmp 0x150cb
movq %rax, %rbx
leaq 0x168(%rsp), %rdi
jmp 0x150f4
jmp 0x1513a
movq %rax, %rbx
leaq 0x108(%rsp), %rdi
callq 0x6788
jmp 0x150ec
movq %rax, %rbx
leaq 0x128(%rsp), %rdi
callq 0x6788
jmp 0x1513d
jmp 0x150ff
jmp 0x1513a
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x1563a
jmp 0x1513d
jmp 0x1513a
jmp 0x1513a
movq %rax, %rbx
jmp 0x1514a
movq %rax, %rbx
jmp 0x15157
movq %rax, %rbx
jmp 0x15164
jmp 0x15123
movq %rax, %rbx
jmp 0x1516e
movq %rax, %rbx
jmp 0x15178
movq %rax, %rbx
jmp 0x15182
jmp 0x1513a
jmp 0x1513a
jmp 0x1513a
jmp 0x1513a
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x6788
leaq 0xe8(%rsp), %rdi
callq 0x6788
leaq 0xb8(%rsp), %rdi
callq 0x6788
leaq 0x20(%rsp), %rdi
callq 0x6788
leaq 0x44(%rsp), %rdi
callq 0x10252
leaq 0xc(%rsp), %rdi
callq 0x10220
leaq 0xd8(%rsp), %rdi
callq 0x15650
movq %rbx, %rdi
callq 0x6680
nop