// File: nmmmnu[P]HM3/hm3/linklist.cc
// Function: bool hm3::LinkList::putT_<hm3::Pair>(hm3::Pair&&)
bool LinkList::putT_(UPAIR&& newdata){
	const StringRef &key = newdata.getKey();

	Node *prev = nullptr;
	for(Node *node = head_; node; node = node->next){
		Pair & olddata = node->data;

		int const cmp = olddata.cmp(key);

		if (cmp == 0){
			// handle overwrite,
			// keep the node, overwrite the data

			// check if the data in database is valid
			if (! newdata.valid(olddata)){
				// newdata will be magically destroyed.
				return false;
			}

			dataSize_ = dataSize_
					- olddata.getBytes()
					+ newdata.getBytes();

			// copy assignment
			olddata = std::forward<UPAIR>(newdata);

			return true;
		}

		if (cmp > 0)
			break;

		prev = node;
	}

	size_t const size = newdata.getBytes();

	Node *newnode = new(std::nothrow) Node(std::forward<UPAIR>(newdata));
	if (newnode == nullptr){
		// newdata will be magically destroyed.
		return false;
	}

	// put new pair here...
	if (prev){
		// we are at the middle
		newnode->next = prev->next;
		prev->next = newnode;
	}else{
		newnode->next = head_;
		head_ = newnode;
	}

	dataSize_ += size;
	dataCount_++;

	return true;
}

// Assembly:
subq $0xa8, %rsp
movq %rdi, 0x98(%rsp)
movq %rsi, 0x90(%rsp)
movq 0x98(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x90(%rsp), %rdi
callq 0x14c40
movq %rax, %rcx
movq 0x20(%rsp), %rax
movq %rcx, 0x78(%rsp)
movq %rdx, 0x80(%rsp)
leaq 0x78(%rsp), %rcx
movq %rcx, 0x88(%rsp)
movq $0x0, 0x70(%rsp)
movq (%rax), %rax
movq %rax, 0x68(%rsp)
cmpq $0x0, 0x68(%rsp)
je 0x12bbe
movq 0x68(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x60(%rsp), %rdi
movq 0x88(%rsp), %rsi
callq 0xebb0
movl %eax, 0x5c(%rsp)
cmpl $0x0, 0x5c(%rsp)
jne 0x12b98
movq 0x90(%rsp), %rdi
movq 0x60(%rsp), %rsi
xorl %edx, %edx
callq 0xfcc0
testb $0x1, %al
jne 0x12b30
movb $0x0, 0xa7(%rsp)
jmp 0x12cd4
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
movq 0x60(%rsp), %rdi
callq 0x15050
movq %rax, %rcx
movq 0x10(%rsp), %rax
subq %rcx, %rax
movq %rax, 0x18(%rsp)
movq 0x90(%rsp), %rdi
callq 0x15050
movq 0x18(%rsp), %rcx
movq %rax, %rdx
movq 0x20(%rsp), %rax
addq %rdx, %rcx
movq %rcx, 0x10(%rax)
movq 0x90(%rsp), %rsi
movq 0x60(%rsp), %rdi
callq 0x14aa0
movb $0x1, 0xa7(%rsp)
jmp 0x12cd4
cmpl $0x0, 0x5c(%rsp)
jle 0x12ba1
jmp 0x12bbe
movq 0x68(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x68(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x68(%rsp)
jmp 0x12ad4
movq 0x90(%rsp), %rdi
callq 0x15050
movq %rax, 0x50(%rsp)
movl $0x10, %edi
movq 0xc3e4(%rip), %rsi      # 0x1efc0
callq 0x2230
movq %rax, %rcx
movq %rcx, (%rsp)
movb $0x0, 0x3f(%rsp)
xorl %eax, %eax
cmpq $0x0, %rcx
movq %rax, 0x8(%rsp)
je 0x12c22
movq (%rsp), %rdi
movq %rdi, 0x40(%rsp)
movb $0x1, 0x3f(%rsp)
movq 0x90(%rsp), %rsi
callq 0x12cf0
jmp 0x12c17
movq (%rsp), %rax
movq %rax, 0x8(%rsp)
jmp 0x12c22
movq 0x8(%rsp), %rax
movq %rax, 0x48(%rsp)
cmpq $0x0, 0x48(%rsp)
jne 0x12c6b
movb $0x0, 0xa7(%rsp)
jmp 0x12cd4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x30(%rsp)
movl %eax, 0x2c(%rsp)
testb $0x1, 0x3f(%rsp)
jne 0x12c58
jmp 0x12c69
movq 0x40(%rsp), %rdi
movq 0xc35c(%rip), %rsi      # 0x1efc0
callq 0x20e0
jmp 0x12ce5
cmpq $0x0, 0x70(%rsp)
je 0x12c95
movq 0x70(%rsp), %rax
movq 0x8(%rax), %rcx
movq 0x48(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x48(%rsp), %rcx
movq 0x70(%rsp), %rax
movq %rcx, 0x8(%rax)
jmp 0x12cae
movq 0x20(%rsp), %rax
movq (%rax), %rdx
movq 0x48(%rsp), %rcx
movq %rdx, 0x8(%rcx)
movq 0x48(%rsp), %rcx
movq %rcx, (%rax)
movq 0x20(%rsp), %rax
movq 0x50(%rsp), %rcx
addq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
movq 0x8(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x8(%rax)
movb $0x1, 0xa7(%rsp)
movb 0xa7(%rsp), %al
andb $0x1, %al
addq $0xa8, %rsp
retq
movq 0x30(%rsp), %rdi
callq 0x2220
nop