// File: SeTriones[P]Anubis/lru_cache.cpp
// Function: LRUCache::set(unsigned long, int*, int)
int* LRUCache::set(uint64_t key, int* pos, int overwrite){
	std::tr1::unordered_map<uint64_t, struct HashItem>::iterator it;
	it = hash.find(key);
	if (it != hash.end()) {
		if(overwrite) {
			it->second.pos = pos;
			mv_node_to_header(list, it->second.node, 0);
		}
		else {
			mv_node_to_header(list, it->second.node, 0);
		}
		return pos;
	}
	int* free_pos = pos;
	if (size == capacity) {
		node *n = pop_from_tail(list);
		it = hash.find(n->key);
		free_pos = it->second.pos;
		hash.erase(it);
		free(n);
		size--;
	}
	node *tmp = new_node();
	tmp->key = key;
	mv_node_to_header(list, tmp, 1);
	HashItem item;
	item.node = tmp;
	item.pos = free_pos;
	hash.insert(std::pair<uint64_t, struct HashItem>(key, item));
	size++;
	return free_pos;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x100(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x5550
movq -0x100(%rbp), %rdi
addq $0x10, %rdi
leaq -0x18(%rbp), %rsi
callq 0x5580
movq -0x100(%rbp), %rdi
movq %rax, -0x48(%rbp)
movq %rdx, -0x40(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x30(%rbp)
addq $0x10, %rdi
callq 0x5660
movq %rax, -0x58(%rbp)
movq %rdx, -0x50(%rbp)
leaq -0x38(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x56c0
testb $0x1, %al
jne 0x5288
jmp 0x5319
cmpl $0x0, -0x24(%rbp)
je 0x52df
movq -0x20(%rbp), %rax
movq %rax, -0x110(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x56a0
movq -0x110(%rbp), %rdx
movq %rax, %rcx
movq -0x100(%rbp), %rax
movq %rdx, 0x10(%rcx)
movq 0x8(%rax), %rax
movq %rax, -0x108(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x56a0
movq -0x108(%rbp), %rdi
movq 0x8(%rax), %rsi
xorl %edx, %edx
callq 0x2640
jmp 0x530c
movq -0x100(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x118(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x56a0
movq -0x118(%rbp), %rdi
movq 0x8(%rax), %rsi
xorl %edx, %edx
callq 0x2640
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x5495
movq -0x100(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rax, -0x60(%rbp)
movl (%rcx), %eax
cmpl 0x4(%rcx), %eax
jne 0x53d7
movq -0x100(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x2970
movq -0x100(%rbp), %rdi
movq %rax, -0x68(%rbp)
addq $0x10, %rdi
movq -0x68(%rbp), %rsi
callq 0x5580
movq %rax, -0x78(%rbp)
movq %rdx, -0x70(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0x30(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x56a0
movq -0x100(%rbp), %rdi
movq 0x10(%rax), %rax
movq %rax, -0x60(%rbp)
addq $0x10, %rdi
movq -0x38(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x88(%rbp), %rsi
movq -0x80(%rbp), %rdx
callq 0x56f0
movq %rax, -0x98(%rbp)
movq %rdx, -0x90(%rbp)
movq -0x68(%rbp), %rdi
callq 0x2270
movq -0x100(%rbp), %rax
movl (%rax), %ecx
addl $-0x1, %ecx
movl %ecx, (%rax)
callq 0x25f0
movq %rax, %rcx
movq -0x100(%rbp), %rax
movq %rcx, -0xa0(%rbp)
movq -0x18(%rbp), %rdx
movq -0xa0(%rbp), %rcx
movq %rdx, (%rcx)
movq 0x8(%rax), %rdi
movq -0xa0(%rbp), %rsi
movl $0x1, %edx
callq 0x2640
movq -0x100(%rbp), %rax
movq -0xa0(%rbp), %rcx
movq %rcx, -0xb0(%rbp)
movq -0x60(%rbp), %rcx
movq %rcx, -0xa8(%rbp)
addq $0x10, %rax
movq %rax, -0x120(%rbp)
leaq -0xe0(%rbp), %rdi
leaq -0x18(%rbp), %rsi
leaq -0xb0(%rbp), %rdx
callq 0x5770
leaq -0xc8(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x57b0
movq -0x120(%rbp), %rsi
leaq -0xf8(%rbp), %rdi
leaq -0xc8(%rbp), %rdx
callq 0x5740
movq -0x100(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq -0x60(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)