// File: /workspace/github_cpp_makefile_star2_O1/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 0x19e18
movq (%r14), %rsi
movl 0x8(%r14), %edx
leaq 0xc(%rsp), %rdi
callq 0x12baa
leaq 0xb4(%rsp), %rdi
callq 0x12bc0
leaq 0xc(%rsp), %rdi
leaq 0xb4(%rsp), %rsi
callq 0x12c2c
leaq 0x18(%rsp), %rdi
leaq 0xb4(%rsp), %rsi
callq 0x12d62
leaq 0x68(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0xb744(%rip), %rdx      # 0x22bec
leaq 0x58(%rsp), %rdi
movq %rdx, %rsi
callq 0xa6dc
leaq 0x90(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0xb724(%rip), %rdx      # 0x22bec
leaq 0x80(%rsp), %rdi
movq %rdx, %rsi
callq 0xa6dc
leaq 0x48(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0xb704(%rip), %rdx      # 0x22bec
leaq 0x38(%rsp), %rdi
movq %rdx, %rsi
callq 0xa6dc
leaq 0x8(%rbx), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x1afc0
movq %rax, %r13
leaq 0x10(%rbx), %rax
cmpq %rax, %r13
je 0x175b1
movq %r14, (%rsp)
movq %r13, %r12
addq $0x40, %r12
movq 0x48(%r13), %r14
cmpq 0x20(%rsp), %r14
jne 0x1754c
testq %r14, %r14
je 0x178ec
movq 0x18(%rsp), %rsi
movq (%r12), %rdi
movq %r14, %rdx
callq 0x6430
testl %eax, %eax
je 0x178ec
movq %r13, 0x78(%rsp)
leaq 0x38(%rbx), %rbp
movq %rbp, %rdi
movq %r12, %rsi
callq 0x1afc0
movq %rax, %r14
xorl %r13d, %r13d
movq %rbp, %rdi
movq %r12, %rsi
callq 0x1b04a
cmpq %r13, %rax
jbe 0x1775b
movq 0x48(%r14), %rdx
cmpq 0x8(%r15), %rdx
jne 0x175a1
testq %rdx, %rdx
je 0x17750
movq (%r15), %rsi
movq 0x40(%r14), %rdi
callq 0x6430
testl %eax, %eax
je 0x17750
movq %r14, %rdi
callq 0x62e0
movq %rax, %r14
incq %r13
jmp 0x17566
leaq 0xc8(%rsp), %rdi
leaq 0x18(%rsp), %rdx
movq %r15, %rsi
callq 0x17f96
movq %r14, %rbp
leaq 0xc8(%rsp), %rsi
movq %r12, %rdi
callq 0x1b39e
leaq 0xf8(%rsp), %r14
movq -0x10(%r14), %rdi
cmpq %r14, %rdi
je 0x175ef
callq 0x6400
leaq 0xd8(%rsp), %r13
movq -0x10(%r13), %rdi
cmpq %r13, %rdi
je 0x17605
callq 0x6400
leaq 0xc8(%rsp), %rdi
leaq 0x18(%rsp), %rsi
movq %r15, %rdx
callq 0x17f96
leaq 0x38(%rbx), %r15
leaq 0xc8(%rsp), %rsi
movq %r15, %rdi
callq 0x1b1e8
movq 0xe8(%rsp), %rdi
cmpq %r14, %rdi
je 0x17640
callq 0x6400
movq 0xc8(%rsp), %rdi
cmpq %r13, %rdi
je 0x17652
callq 0x6400
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 0xa64c
leaq 0x138(%rsp), %r13
movq %r13, -0x10(%r13)
movq (%rbp), %rsi
movq 0x8(%rbp), %rdx
addq %rsi, %rdx
leaq 0x128(%rsp), %rdi
callq 0xa64c
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 0x176d9
callq 0x6400
movq 0x108(%rsp), %rdi
leaq 0x118(%rsp), %rax
cmpq %rax, %rdi
je 0x176f3
callq 0x6400
testb %bpl, %bpl
je 0x17857
leaq 0x58(%rsp), %rsi
movq %r15, %rdi
callq 0x1afc0
movq %rax, %r13
addq $0x40, %rbx
leaq 0x58(%rsp), %r14
cmpq %rbx, %r13
je 0x17857
leaq 0x40(%r13), %rsi
movq %r12, %rdi
callq 0x1afc0
movq %r12, %rdi
movq %rax, %rsi
callq 0x1b1ae
movq %r15, %rdi
movq %r13, %rsi
callq 0x1b1ae
movq %r15, %rdi
movq %r14, %rsi
callq 0x1afc0
movq %rax, %r13
jmp 0x17715
movq %rbp, %rdi
movq %r14, %rsi
callq 0x1b1ae
leaq 0x18(%rsp), %rsi
movq %r12, %rdi
callq 0x6250
leaq 0xc8(%rsp), %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x17f96
movq 0x78(%rsp), %r15
leaq 0xc8(%rsp), %rsi
movq %rbp, %rdi
callq 0x1b1e8
leaq 0xf8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x177a6
callq 0x6400
leaq 0xd8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x177bc
callq 0x6400
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 0xa64c
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 0xa64c
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 0x17845
callq 0x6400
movq 0x1a8(%rsp), %rdi
cmpq %r14, %rdi
je 0x17857
callq 0x6400
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x1786b
callq 0x6400
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
leaq 0x68(%rsp), %rbx
je 0x1788a
callq 0x6400
movq 0x58(%rsp), %rdi
cmpq %rbx, %rdi
je 0x17899
callq 0x6400
leaq 0x28(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x178ac
callq 0x6400
leaq 0xb4(%rsp), %rdi
callq 0x12bdc
leaq 0xc(%rsp), %rdi
callq 0x12ba8
cmpb $0x1, 0xa8(%rsp)
jne 0x178da
movq 0xa0(%rsp), %rdi
callq 0x1ad4e
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)
movq (%r12), %rsi
addq %rsi, %r14
leaq 0x168(%rsp), %rdi
movq %r14, %rdx
callq 0xa64c
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 0xa64c
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 0x17977
callq 0x6400
movq 0x168(%rsp), %rdi
cmpq %r15, %rdi
jne 0x17852
jmp 0x17857
jmp 0x17a6b
movq %rax, %rbx
movq 0x148(%rsp), %rdi
cmpq %r14, %rdi
je 0x179ac
callq 0x6400
jmp 0x179ac
movq %rax, %rbx
movq 0x168(%rsp), %rdi
cmpq %r15, %rdi
jne 0x17a1e
jmp 0x17a6e
movq %rax, %rbx
movq 0x128(%rsp), %rdi
cmpq %r13, %rdi
je 0x179d8
callq 0x6400
jmp 0x179d8
movq %rax, %rbx
movq 0x108(%rsp), %rdi
leaq 0x118(%rsp), %rax
cmpq %rax, %rdi
jne 0x17a1e
jmp 0x17a6e
jmp 0x17a25
jmp 0x17a6b
jmp 0x17a25
jmp 0x17a6b
movq %rax, %rbx
movq 0x188(%rsp), %rdi
cmpq %r15, %rdi
je 0x17a11
callq 0x6400
jmp 0x17a11
movq %rax, %rbx
movq 0x1a8(%rsp), %rdi
cmpq %r14, %rdi
je 0x17a6e
callq 0x6400
jmp 0x17a6e
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
callq 0x17ff4
jmp 0x17a6e
jmp 0x17a6b
jmp 0x17a6b
movq %rax, %rdi
callq 0xdf17
jmp 0x17a6b
movq %rax, %rbx
jmp 0x17a82
movq %rax, %rbx
jmp 0x17a9c
movq %rax, %rbx
jmp 0x17ab0
jmp 0x17a56
movq %rax, %rbx
jmp 0x17ac3
movq %rax, %rbx
jmp 0x17ad0
movq %rax, %rbx
jmp 0x17ada
jmp 0x17a6b
jmp 0x17a6b
jmp 0x17a6b
movq %rax, %rbx
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x17a82
callq 0x6400
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x17a9c
callq 0x6400
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x17ab0
callq 0x6400
leaq 0x28(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x17ac3
callq 0x6400
leaq 0xb4(%rsp), %rdi
callq 0x12bdc
leaq 0xc(%rsp), %rdi
callq 0x12ba8
leaq 0xa0(%rsp), %rdi
callq 0x1801e
movq %rbx, %rdi
callq 0x6680
nop