// File: /workspace/github_cpp_makefile_star2_O3/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), %rax
leaq 0xa0(%rsp), %rdi
movq %rax, (%rdi)
movb $0x0, 0x8(%rdi)
callq 0x19e42
movq (%r14), %rsi
movl 0x8(%r14), %edx
leaq 0xc(%rsp), %rdi
callq 0x12cce
leaq 0xb4(%rsp), %rdi
callq 0x12ce4
leaq 0xc(%rsp), %rdi
leaq 0xb4(%rsp), %rsi
callq 0x12d50
leaq 0x18(%rsp), %rdi
leaq 0xb4(%rsp), %rsi
callq 0x12e86
leaq 0x68(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0xb654(%rip), %rdx      # 0x22bec
leaq 0x58(%rsp), %rdi
movq %rdx, %rsi
callq 0xa862
leaq 0x90(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0xb634(%rip), %rdx      # 0x22bec
leaq 0x80(%rsp), %rdi
movq %rdx, %rsi
callq 0xa862
leaq 0x48(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0xb614(%rip), %rdx      # 0x22bec
leaq 0x38(%rsp), %rdi
movq %rdx, %rsi
callq 0xa862
leaq 0x8(%rbx), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x1afe0
movq %rax, %r13
leaq 0x10(%rbx), %rax
cmpq %rax, %r13
je 0x176a4
movq %r14, (%rsp)
movq %r13, %r12
addq $0x40, %r12
movq 0x48(%r13), %r14
cmpq 0x20(%rsp), %r14
jne 0x1763f
movq (%r12), %rbp
testq %r14, %r14
je 0x179df
movq 0x18(%rsp), %rsi
movq %rbp, %rdi
movq %r14, %rdx
callq 0x6420
testl %eax, %eax
je 0x179df
movq %r13, 0x78(%rsp)
leaq 0x38(%rbx), %rbp
movq %rbp, %rdi
movq %r12, %rsi
callq 0x1afe0
movq %rax, %r14
xorl %r13d, %r13d
movq %rbp, %rdi
movq %r12, %rsi
callq 0x1b06a
cmpq %r13, %rax
jbe 0x1784e
movq 0x48(%r14), %rdx
cmpq 0x8(%r15), %rdx
jne 0x17694
testq %rdx, %rdx
je 0x17843
movq (%r15), %rsi
movq 0x40(%r14), %rdi
callq 0x6420
testl %eax, %eax
je 0x17843
movq %r14, %rdi
callq 0x62d0
movq %rax, %r14
incq %r13
jmp 0x17659
leaq 0xc8(%rsp), %rdi
leaq 0x18(%rsp), %rdx
movq %r15, %rsi
callq 0x18088
movq %r14, %rbp
leaq 0xc8(%rsp), %rsi
movq %r12, %rdi
callq 0x1b3cc
leaq 0xf8(%rsp), %r14
movq -0x10(%r14), %rdi
cmpq %r14, %rdi
je 0x176e2
callq 0x63f0
leaq 0xd8(%rsp), %r13
movq -0x10(%r13), %rdi
cmpq %r13, %rdi
je 0x176f8
callq 0x63f0
leaq 0xc8(%rsp), %rdi
leaq 0x18(%rsp), %rsi
movq %r15, %rdx
callq 0x18088
leaq 0x38(%rbx), %r15
leaq 0xc8(%rsp), %rsi
movq %r15, %rdi
callq 0x1b214
movq 0xe8(%rsp), %rdi
cmpq %r14, %rdi
je 0x17733
callq 0x63f0
movq 0xc8(%rsp), %rdi
cmpq %r13, %rdi
je 0x17745
callq 0x63f0
movq (%rbx), %r14
leaq 0x118(%rsp), %rax
movq %rax, -0x10(%rax)
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
addq %rsi, %rdx
leaq 0x108(%rsp), %rdi
callq 0xa7cc
leaq 0x138(%rsp), %r13
movq %r13, -0x10(%r13)
movq (%rbp), %rsi
movq 0x8(%rbp), %rdx
addq %rsi, %rdx
leaq 0x128(%rsp), %rdi
callq 0xa7cc
movq (%r14), %rax
leaq 0x108(%rsp), %rsi
leaq 0x128(%rsp), %rdx
leaq 0x58(%rsp), %rcx
leaq 0x38(%rsp), %r8
movq %r14, %rdi
xorl %r9d, %r9d
callq *0x10(%rax)
movl %eax, %ebp
movq 0x128(%rsp), %rdi
cmpq %r13, %rdi
je 0x177cc
callq 0x63f0
movq 0x108(%rsp), %rdi
leaq 0x118(%rsp), %rax
cmpq %rax, %rdi
je 0x177e6
callq 0x63f0
testb %bpl, %bpl
je 0x1794a
leaq 0x58(%rsp), %rsi
movq %r15, %rdi
callq 0x1afe0
movq %rax, %r13
addq $0x40, %rbx
leaq 0x58(%rsp), %r14
cmpq %rbx, %r13
je 0x1794a
leaq 0x40(%r13), %rsi
movq %r12, %rdi
callq 0x1afe0
movq %r12, %rdi
movq %rax, %rsi
callq 0x1b1da
movq %r15, %rdi
movq %r13, %rsi
callq 0x1b1da
movq %r15, %rdi
movq %r14, %rsi
callq 0x1afe0
movq %rax, %r13
jmp 0x17808
movq %rbp, %rdi
movq %r14, %rsi
callq 0x1b1da
leaq 0x18(%rsp), %rsi
movq %r12, %rdi
callq 0x6240
leaq 0xc8(%rsp), %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x18088
movq 0x78(%rsp), %r15
leaq 0xc8(%rsp), %rsi
movq %rbp, %rdi
callq 0x1b214
leaq 0xf8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x17899
callq 0x63f0
leaq 0xd8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x178af
callq 0x63f0
movq (%rbx), %rbx
leaq 0x1b8(%rsp), %r14
movq %r14, -0x10(%r14)
movq 0x40(%r15), %rsi
movq 0x48(%r15), %rdx
addq %rsi, %rdx
leaq 0x1a8(%rsp), %rdi
callq 0xa7cc
leaq 0x198(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0x188(%rsp), %rdi
callq 0xa7cc
movq (%rbx), %rax
leaq 0x1a8(%rsp), %rsi
leaq 0x188(%rsp), %rdx
leaq 0x80(%rsp), %rcx
leaq 0x38(%rsp), %r8
movq %rbx, %rdi
xorl %r9d, %r9d
callq *0x10(%rax)
movq 0x188(%rsp), %rdi
cmpq %r15, %rdi
je 0x17938
callq 0x63f0
movq 0x1a8(%rsp), %rdi
cmpq %r14, %rdi
je 0x1794a
callq 0x63f0
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x1795e
callq 0x63f0
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
leaq 0x68(%rsp), %rbx
je 0x1797d
callq 0x63f0
movq 0x58(%rsp), %rdi
cmpq %rbx, %rdi
je 0x1798c
callq 0x63f0
leaq 0x28(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1799f
callq 0x63f0
leaq 0xb4(%rsp), %rdi
callq 0x12d00
leaq 0xc(%rsp), %rdi
callq 0x12ccc
cmpb $0x1, 0xa8(%rsp)
jne 0x179cd
movq 0xa0(%rsp), %rdi
callq 0x1ad6e
addq $0x1c8, %rsp            # imm = 0x1C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rbx), %rbx
leaq 0x178(%rsp), %r15
movq %r15, -0x10(%r15)
addq %rbp, %r14
leaq 0x168(%rsp), %rdi
movq %rbp, %rsi
movq %r14, %rdx
callq 0xa7cc
leaq 0x158(%rsp), %r14
movq %r14, -0x10(%r14)
movq (%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0x148(%rsp), %rdi
callq 0xa7cc
movq (%rbx), %rax
leaq 0x168(%rsp), %rsi
leaq 0x148(%rsp), %rdx
leaq 0x80(%rsp), %rcx
leaq 0x38(%rsp), %r8
movq %rbx, %rdi
movl $0x1, %r9d
callq *0x10(%rax)
movq 0x148(%rsp), %rdi
cmpq %r14, %rdi
je 0x17a69
callq 0x63f0
movq 0x168(%rsp), %rdi
cmpq %r15, %rdi
jne 0x17945
jmp 0x1794a
jmp 0x17b5d
movq %rax, %rbx
movq 0x148(%rsp), %rdi
cmpq %r14, %rdi
je 0x17a9e
callq 0x63f0
jmp 0x17a9e
movq %rax, %rbx
movq 0x168(%rsp), %rdi
cmpq %r15, %rdi
jne 0x17b10
jmp 0x17b60
movq %rax, %rbx
movq 0x128(%rsp), %rdi
cmpq %r13, %rdi
je 0x17aca
callq 0x63f0
jmp 0x17aca
movq %rax, %rbx
movq 0x108(%rsp), %rdi
leaq 0x118(%rsp), %rax
cmpq %rax, %rdi
jne 0x17b10
jmp 0x17b60
jmp 0x17b17
jmp 0x17b5d
jmp 0x17b17
jmp 0x17b5d
movq %rax, %rbx
movq 0x188(%rsp), %rdi
cmpq %r15, %rdi
je 0x17b03
callq 0x63f0
jmp 0x17b03
movq %rax, %rbx
movq 0x1a8(%rsp), %rdi
cmpq %r14, %rdi
je 0x17b60
callq 0x63f0
jmp 0x17b60
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
callq 0x180e6
jmp 0x17b60
jmp 0x17b5d
jmp 0x17b5d
movq %rax, %rdi
callq 0xe09d
jmp 0x17b5d
movq %rax, %rbx
jmp 0x17b74
movq %rax, %rbx
jmp 0x17b8e
movq %rax, %rbx
jmp 0x17ba2
jmp 0x17b48
movq %rax, %rbx
jmp 0x17bb5
movq %rax, %rbx
jmp 0x17bc2
movq %rax, %rbx
jmp 0x17bcc
jmp 0x17b5d
jmp 0x17b5d
jmp 0x17b5d
movq %rax, %rbx
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x17b74
callq 0x63f0
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x17b8e
callq 0x63f0
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x17ba2
callq 0x63f0
leaq 0x28(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x17bb5
callq 0x63f0
leaq 0xb4(%rsp), %rdi
callq 0x12d00
leaq 0xc(%rsp), %rdi
callq 0x12ccc
leaq 0xa0(%rsp), %rdi
callq 0x18110
movq %rbx, %rdi
callq 0x6670
nop