// File: 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:
subq $0x408, %rsp            # imm = 0x408
movq %rsi, 0xd8(%rsp)
movq %rdx, 0xe8(%rsp)
movq %rdi, 0x400(%rsp)
movq %rsi, 0x3f8(%rsp)
movq %rdx, 0x3f0(%rsp)
movq 0x400(%rsp), %rsi
movq %rsi, 0xe0(%rsp)
addq $0x70, %rsi
leaq 0x3e0(%rsp), %rdi
callq 0x388b0
movq 0xe8(%rsp), %rdi
callq 0x8180
movq 0xe8(%rsp), %rdi
movq %rax, 0xf0(%rsp)
callq 0x8730
movq 0xf0(%rsp), %rsi
movl %eax, %edx
leaq 0x3d4(%rsp), %rdi
callq 0x29c80
jmp 0x376cb
leaq 0x3b0(%rsp), %rdi
callq 0x29ce0
jmp 0x376da
leaq 0x3d4(%rsp), %rdi
leaq 0x3b0(%rsp), %rsi
callq 0x29e70
jmp 0x376f1
leaq 0x390(%rsp), %rdi
leaq 0x3b0(%rsp), %rsi
callq 0x2a120
jmp 0x37708
leaq 0x36f(%rsp), %rdi
movq %rdi, 0xd0(%rsp)
callq 0x8830
movq 0xd0(%rsp), %rdx
leaq 0x1b69a(%rip), %rsi     # 0x52dc6
leaq 0x370(%rsp), %rdi
callq 0x8680
jmp 0x3773b
leaq 0x36f(%rsp), %rdi
callq 0x8540
leaq 0x347(%rsp), %rdi
movq %rdi, 0xc8(%rsp)
callq 0x8830
movq 0xc8(%rsp), %rdx
leaq 0x1b65a(%rip), %rsi     # 0x52dc6
leaq 0x348(%rsp), %rdi
callq 0x8680
jmp 0x3777b
leaq 0x347(%rsp), %rdi
callq 0x8540
leaq 0x31f(%rsp), %rdi
movq %rdi, 0xc0(%rsp)
callq 0x8830
movq 0xc0(%rsp), %rdx
leaq 0x1b61a(%rip), %rsi     # 0x52dc6
leaq 0x320(%rsp), %rdi
callq 0x8680
jmp 0x377bb
leaq 0x31f(%rsp), %rdi
callq 0x8540
movq 0xe0(%rsp), %rdi
movq 0xd8(%rsp), %rsi
addq $0x8, %rdi
callq 0x388e0
movq %rax, 0xb8(%rsp)
jmp 0x377eb
movq 0xb8(%rsp), %rax
movq %rax, 0x310(%rsp)
leaq 0x308(%rsp), %rdi
callq 0x38910
movq 0xe0(%rsp), %rdi
addq $0x8, %rdi
callq 0x38950
movq %rax, 0x300(%rsp)
leaq 0x310(%rsp), %rdi
leaq 0x300(%rsp), %rsi
callq 0x38930
testb $0x1, %al
jne 0x3783f
jmp 0x37d3d
leaq 0x310(%rsp), %rdi
callq 0x38980
movq %rax, %rdi
addq $0x20, %rdi
leaq 0x390(%rsp), %rsi
callq 0x16d60
testb $0x1, %al
jne 0x37869
jmp 0x37c53
movq 0xe0(%rsp), %rax
addq $0x38, %rax
movq %rax, 0xa8(%rsp)
leaq 0x310(%rsp), %rdi
callq 0x38980
movq 0xa8(%rsp), %rdi
movq %rax, %rsi
addq $0x20, %rsi
callq 0x389a0
movq %rax, 0xb0(%rsp)
jmp 0x378a8
movq 0xb0(%rsp), %rax
movq %rax, 0x2f8(%rsp)
movq 0x2f8(%rsp), %rax
movq %rax, 0x308(%rsp)
movl $0x0, 0x2f4(%rsp)
movq 0xe0(%rsp), %rax
movslq 0x2f4(%rsp), %rcx
movq %rcx, 0x90(%rsp)
addq $0x38, %rax
movq %rax, 0x98(%rsp)
leaq 0x310(%rsp), %rdi
callq 0x38980
movq 0x98(%rsp), %rdi
movq %rax, %rsi
addq $0x20, %rsi
callq 0x389d0
movq %rax, 0xa0(%rsp)
jmp 0x37922
movq 0x90(%rsp), %rax
movq 0xa0(%rsp), %rcx
cmpq %rcx, %rax
jae 0x37ab0
leaq 0x308(%rsp), %rdi
callq 0x38980
movq 0xd8(%rsp), %rsi
movq %rax, %rdi
addq $0x20, %rdi
callq 0x21100
testb $0x1, %al
jne 0x37965
jmp 0x37a83
movq 0xe0(%rsp), %rdi
addq $0x38, %rdi
movq 0x308(%rsp), %rax
movq %rax, 0x2e8(%rsp)
movq 0x2e8(%rsp), %rsi
callq 0x38a00
movq %rax, 0x88(%rsp)
jmp 0x37998
movq 0x88(%rsp), %rax
movq %rax, 0x2e0(%rsp)
jmp 0x37ab0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3c8(%rsp)
movl %eax, 0x3c4(%rsp)
jmp 0x38176
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3c8(%rsp)
movl %eax, 0x3c4(%rsp)
jmp 0x38169
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3c8(%rsp)
movl %eax, 0x3c4(%rsp)
jmp 0x3815c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3c8(%rsp)
movl %eax, 0x3c4(%rsp)
leaq 0x36f(%rsp), %rdi
callq 0x8540
jmp 0x3814f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3c8(%rsp)
movl %eax, 0x3c4(%rsp)
leaq 0x347(%rsp), %rdi
callq 0x8540
jmp 0x38142
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3c8(%rsp)
movl %eax, 0x3c4(%rsp)
leaq 0x31f(%rsp), %rdi
callq 0x8540
jmp 0x38135
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3c8(%rsp)
movl %eax, 0x3c4(%rsp)
jmp 0x38128
leaq 0x308(%rsp), %rdi
xorl %esi, %esi
callq 0x38a40
movq %rax, 0x2d8(%rsp)
movl 0x2f4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2f4(%rsp)
jmp 0x378d3
leaq 0x310(%rsp), %rdi
callq 0x38980
movq %rax, %rdi
addq $0x20, %rdi
leaq 0x390(%rsp), %rsi
callq 0x8060
jmp 0x37ad3
movq 0xe0(%rsp), %rax
addq $0x38, %rax
movq %rax, 0x80(%rsp)
leaq 0x310(%rsp), %rdi
callq 0x38980
movq 0xd8(%rsp), %rdx
movq %rax, %rsi
addq $0x20, %rsi
leaq 0x298(%rsp), %rdi
callq 0x38ab0
jmp 0x37b12
movq 0x80(%rsp), %rdi
leaq 0x298(%rsp), %rsi
callq 0x38a80
movq %rax, 0x78(%rsp)
jmp 0x37b2e
movq 0x78(%rsp), %rax
movq %rax, 0x290(%rsp)
leaq 0x298(%rsp), %rdi
callq 0x38b20
movq 0xe0(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x70(%rsp)
leaq 0x310(%rsp), %rdi
callq 0x38980
movq %rax, %rsi
addq $0x20, %rsi
leaq 0x270(%rsp), %rdi
callq 0x81a0
jmp 0x37b7b
movq 0xe8(%rsp), %rsi
leaq 0x250(%rsp), %rdi
callq 0x81a0
jmp 0x37b92
movq 0x70(%rsp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
leaq 0x270(%rsp), %rsi
leaq 0x250(%rsp), %rdx
leaq 0x348(%rsp), %rcx
leaq 0x320(%rsp), %r8
xorl %r9d, %r9d
callq *%rax
jmp 0x37bc5
leaq 0x250(%rsp), %rdi
callq 0x8928
leaq 0x270(%rsp), %rdi
callq 0x8928
jmp 0x37d38
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3c8(%rsp)
movl %eax, 0x3c4(%rsp)
leaq 0x298(%rsp), %rdi
callq 0x38b20
jmp 0x38128
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3c8(%rsp)
movl %eax, 0x3c4(%rsp)
jmp 0x37c41
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3c8(%rsp)
movl %eax, 0x3c4(%rsp)
leaq 0x250(%rsp), %rdi
callq 0x8928
leaq 0x270(%rsp), %rdi
callq 0x8928
jmp 0x38128
movq 0xe0(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x68(%rsp)
leaq 0x310(%rsp), %rdi
callq 0x38980
movq %rax, %rsi
addq $0x20, %rsi
leaq 0x230(%rsp), %rdi
callq 0x81a0
jmp 0x37c86
movq 0xe8(%rsp), %rsi
leaq 0x210(%rsp), %rdi
callq 0x81a0
jmp 0x37c9d
movq 0x68(%rsp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
leaq 0x230(%rsp), %rsi
leaq 0x210(%rsp), %rdx
leaq 0x348(%rsp), %rcx
leaq 0x320(%rsp), %r8
movl $0x1, %r9d
callq *%rax
jmp 0x37cd3
leaq 0x210(%rsp), %rdi
callq 0x8928
leaq 0x230(%rsp), %rdi
callq 0x8928
jmp 0x37d38
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3c8(%rsp)
movl %eax, 0x3c4(%rsp)
jmp 0x37d26
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3c8(%rsp)
movl %eax, 0x3c4(%rsp)
leaq 0x210(%rsp), %rdi
callq 0x8928
leaq 0x230(%rsp), %rdi
callq 0x8928
jmp 0x38128
jmp 0x380c5
movq 0xd8(%rsp), %rsi
movq 0xe0(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x60(%rsp)
leaq 0x1d0(%rsp), %rdi
leaq 0x390(%rsp), %rdx
callq 0x38ab0
jmp 0x37d6d
movq 0x60(%rsp), %rdi
leaq 0x1d0(%rsp), %rsi
callq 0x38b50
movb %dl, 0x57(%rsp)
movq %rax, 0x58(%rsp)
jmp 0x37d8a
movb 0x57(%rsp), %al
movq 0x58(%rsp), %rcx
movq %rcx, 0x1c0(%rsp)
movb %al, 0x1c8(%rsp)
leaq 0x1d0(%rsp), %rdi
callq 0x38b20
movq 0xe0(%rsp), %rax
movq 0xd8(%rsp), %rdx
addq $0x38, %rax
movq %rax, 0x48(%rsp)
leaq 0x180(%rsp), %rdi
leaq 0x390(%rsp), %rsi
callq 0x38ab0
jmp 0x37ddf
movq 0x48(%rsp), %rdi
leaq 0x180(%rsp), %rsi
callq 0x38a80
movq %rax, 0x40(%rsp)
jmp 0x37df8
movq 0x40(%rsp), %rax
movq %rax, 0x178(%rsp)
leaq 0x180(%rsp), %rdi
callq 0x38b20
movq 0xe0(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x38(%rsp)
leaq 0x158(%rsp), %rdi
leaq 0x390(%rsp), %rsi
callq 0x81a0
jmp 0x37e39
movq 0xe8(%rsp), %rsi
leaq 0x138(%rsp), %rdi
callq 0x81a0
jmp 0x37e50
movq 0x38(%rsp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
leaq 0x158(%rsp), %rsi
leaq 0x138(%rsp), %rdx
leaq 0x370(%rsp), %rcx
leaq 0x320(%rsp), %r8
xorl %r9d, %r9d
callq *%rax
movb %al, 0x37(%rsp)
jmp 0x37e87
leaq 0x138(%rsp), %rdi
callq 0x8928
leaq 0x158(%rsp), %rdi
callq 0x8928
movb 0x37(%rsp), %al
testb $0x1, %al
jne 0x37eae
jmp 0x380c3
movq 0xe0(%rsp), %rdi
addq $0x38, %rdi
leaq 0x370(%rsp), %rsi
callq 0x389a0
movq %rax, 0x28(%rsp)
jmp 0x37ece
movq 0x28(%rsp), %rax
movq %rax, 0x130(%rsp)
movq 0x130(%rsp), %rax
movq %rax, 0x308(%rsp)
movq 0xe0(%rsp), %rdi
addq $0x38, %rdi
callq 0x38ba0
movq %rax, 0x128(%rsp)
leaq 0x308(%rsp), %rdi
leaq 0x128(%rsp), %rsi
callq 0x38930
testb $0x1, %al
jne 0x37f22
jmp 0x380c1
movq 0xe0(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x18(%rsp)
leaq 0x308(%rsp), %rdi
callq 0x38980
movq 0x18(%rsp), %rdi
movq %rax, %rsi
addq $0x20, %rsi
callq 0x388e0
movq %rax, 0x20(%rsp)
jmp 0x37f58
movq 0xe0(%rsp), %rdi
movq 0x20(%rsp), %rax
movq %rax, 0x120(%rsp)
movq 0x120(%rsp), %rax
movq %rax, 0x310(%rsp)
addq $0x8, %rdi
movq 0x310(%rsp), %rax
movq %rax, 0x118(%rsp)
movq 0x118(%rsp), %rsi
callq 0x38bd0
movq %rax, 0x10(%rsp)
jmp 0x37fa5
movq 0xe0(%rsp), %rdi
movq 0x10(%rsp), %rax
movq %rax, 0x110(%rsp)
addq $0x38, %rdi
movq 0x308(%rsp), %rax
movq %rax, 0x108(%rsp)
movq 0x108(%rsp), %rsi
callq 0x38a00
movq %rax, 0x8(%rsp)
jmp 0x37fe2
movq 0xe0(%rsp), %rdi
movq 0x8(%rsp), %rax
movq %rax, 0x100(%rsp)
addq $0x38, %rdi
leaq 0x370(%rsp), %rsi
callq 0x389a0
movq %rax, (%rsp)
jmp 0x3800e
movq (%rsp), %rax
movq %rax, 0xf8(%rsp)
movq 0xf8(%rsp), %rax
movq %rax, 0x308(%rsp)
jmp 0x37eeb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3c8(%rsp)
movl %eax, 0x3c4(%rsp)
leaq 0x1d0(%rsp), %rdi
callq 0x38b20
jmp 0x38128
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3c8(%rsp)
movl %eax, 0x3c4(%rsp)
leaq 0x180(%rsp), %rdi
callq 0x38b20
jmp 0x38128
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3c8(%rsp)
movl %eax, 0x3c4(%rsp)
jmp 0x380b2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3c8(%rsp)
movl %eax, 0x3c4(%rsp)
leaq 0x138(%rsp), %rdi
callq 0x8928
leaq 0x158(%rsp), %rdi
callq 0x8928
jmp 0x38128
jmp 0x380c3
jmp 0x380c5
leaq 0x320(%rsp), %rdi
callq 0x8928
leaq 0x348(%rsp), %rdi
callq 0x8928
leaq 0x370(%rsp), %rdi
callq 0x8928
leaq 0x390(%rsp), %rdi
callq 0x8928
leaq 0x3b0(%rsp), %rdi
callq 0x29d50
leaq 0x3d4(%rsp), %rdi
callq 0x29c70
leaq 0x3e0(%rsp), %rdi
callq 0x38c10
addq $0x408, %rsp            # imm = 0x408
retq
leaq 0x320(%rsp), %rdi
callq 0x8928
leaq 0x348(%rsp), %rdi
callq 0x8928
leaq 0x370(%rsp), %rdi
callq 0x8928
leaq 0x390(%rsp), %rdi
callq 0x8928
leaq 0x3b0(%rsp), %rdi
callq 0x29d50
leaq 0x3d4(%rsp), %rdi
callq 0x29c70
leaq 0x3e0(%rsp), %rdi
callq 0x38c10
movq 0x3c8(%rsp), %rdi
callq 0x8820