// File: /workspace/github_cpp_makefile_star2_O1/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 0x2ecd
movq %rdx, %r12
testq %rdx, %rdx
je 0x2ecd
cmpq $0x2001, %r12           # imm = 0x2001
jae 0x2f14
movq %r8, %r14
movq %rcx, 0x20(%rsp)
cmpq $0x3dfec, %r8           # imm = 0x3DFEC
jae 0x2f58
movl %r9d, %r13d
movq %rsi, %rbp
movl 0x60(%rsp), %ebx
leaq (%r12,%r14), %rdi
addq $0x15, %rdi
movq 0x519d(%rip), %rsi      # 0x7fa8
callq 0x22a0
movq %rax, %r15
movq 0x8(%rsp), %rax
movq %r15, (%rax)
testl %ebx, %ebx
je 0x2e25
shlq $0x20, %rbx
jmp 0x2e2d
callq 0x312a
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 0x2ea9
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 0x225c(%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 0x50e0(%rip), %rsi      # 0x7fe0
movq 0x50c1(%rip), %rdx      # 0x7fc8
movq %r14, %rdi
callq 0x2240
jmp 0x2f9a
leaq 0x2226(%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 0x5099(%rip), %rsi      # 0x7fe0
movq 0x507a(%rip), %rdx      # 0x7fc8
movq %r14, %rdi
callq 0x2240
jmp 0x2f9a
leaq 0x21f3(%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 0x5055(%rip), %rsi      # 0x7fe0
movq 0x5036(%rip), %rdx      # 0x7fc8
movq %r14, %rdi
callq 0x2240
jmp 0x2f9e
jmp 0x2f9e
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x22b8
movq %rbx, %rdi
callq 0x2250
nop