// File: /workspace/github_cpp_makefile_star2_O3/nmmmnu[P]HM3/hm3/pairblob.cc
// Function: hm3::PairBlob::create(char const*, unsigned long, char const*, unsigned long, unsigned int, unsigned int)
std::unique_ptr<PairBlob> PairBlob::create(	const char *key, size_t const keylen,
				const char *val, size_t const vallen,
				uint32_t const expires, uint32_t const created){
	if (key == nullptr || keylen == 0){
		std::logic_error exception("Key is zero size");
		throw exception;
	}

	if (keylen > MAX_KEY_SIZE){
		std::logic_error exception("Key is very long");
		throw exception;
	}

	if (vallen > MAX_VAL_SIZE){
		std::logic_error exception("Value is very long");
		throw exception;
	}

	size_t const size = sizeofBase__() + keylen + 1 + vallen + 1;

	std::unique_ptr<PairBlob>  pair{ new(size, std::nothrow) PairBlob };

	pair->created	= htobe64(getCreateTime_(created));
	pair->expires	= htobe32(expires);
	pair->vallen	= htobe32((uint32_t) vallen);
	pair->keylen	= htobe16((uint16_t) keylen);

	// memcpy so we can switch to blobs later...
	memcpy(& pair->buffer[0],		key, keylen);
	pair->buffer[keylen] = '\0';

	// this is safe with NULL pointer.
	memcpy(& pair->buffer[keylen + 1],	val, vallen);
	pair->buffer[keylen + 1 + vallen] = '\0';

	pair->checksum	= pair->calcChecksum();

	return pair;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, 0x8(%rsp)
testq %rsi, %rsi
je 0x2ec1
movq %rdx, %r12
testq %rdx, %rdx
je 0x2ec1
cmpq $0x2001, %r12           # imm = 0x2001
jae 0x2f08
movq %r8, %r14
movq %rcx, 0x20(%rsp)
cmpq $0x3dfec, %r8           # imm = 0x3DFEC
jae 0x2f4c
movl %r9d, %r13d
movq %rsi, %rbp
movl 0x60(%rsp), %ebx
leaq (%r12,%r14), %rdi
addq $0x15, %rdi
movq 0x51a9(%rip), %rsi      # 0x7fa8
callq 0x22a0
movq %rax, %r15
movq 0x8(%rsp), %rax
movq %r15, (%rax)
testl %ebx, %ebx
je 0x2e19
shlq $0x20, %rbx
jmp 0x2e21
callq 0x312e
movq %rax, %rbx
bswapq %rbx
movq %rbx, (%r15)
bswapl %r13d
movl %r13d, 0x8(%r15)
movl %r14d, %eax
bswapl %eax
movl %eax, 0xc(%r15)
movl %r12d, %eax
rolw $0x8, %ax
movw %ax, 0x10(%r15)
leaq 0x13(%r15), %r13
movq %r13, %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x2130
xorl %ebx, %ebx
movb %bl, 0x13(%r15,%r12)
leaq (%r15,%r12), %rdi
addq $0x14, %rdi
movq 0x20(%rsp), %rsi
movq %r14, %rdx
callq 0x2130
leaq (%r12,%r14), %rax
incq %rax
movb %bl, 0x13(%r15,%rax)
movzwl 0x10(%r15), %eax
rolw $0x8, %ax
movzwl %ax, %eax
movl 0xc(%r15), %ecx
bswapl %ecx
addq %r15, %rax
addq $0x13, %rax
addq %rcx, %rax
addq $0x2, %rax
xorb (%r13), %bl
incq %r13
cmpq %rax, %r13
jb 0x2e9d
movb %bl, 0x12(%r15)
movq 0x8(%rsp), %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2268(%rip), %rsi      # 0x5130
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
callq 0x21e0
movl $0x10, %edi
callq 0x20b0
movq %rax, %r14
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2110
movq 0x50ec(%rip), %rsi      # 0x7fe0
movq 0x50cd(%rip), %rdx      # 0x7fc8
movq %r14, %rdi
callq 0x2240
jmp 0x2f8e
leaq 0x2232(%rip), %rsi      # 0x5141
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
callq 0x21e0
movl $0x10, %edi
callq 0x20b0
movq %rax, %r14
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2110
movq 0x50a5(%rip), %rsi      # 0x7fe0
movq 0x5086(%rip), %rdx      # 0x7fc8
movq %r14, %rdi
callq 0x2240
jmp 0x2f8e
leaq 0x21ff(%rip), %rsi      # 0x5152
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
callq 0x21e0
movl $0x10, %edi
callq 0x20b0
movq %rax, %r14
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2110
movq 0x5061(%rip), %rsi      # 0x7fe0
movq 0x5042(%rip), %rdx      # 0x7fc8
movq %r14, %rdi
callq 0x2240
jmp 0x2f92
jmp 0x2f92
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x22b8
movq %rbx, %rdi
callq 0x2250
nop