// File: /workspace/github_cpp_makefile_star2_O2/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 $0x18, %rsp
testq %rsi, %rsi
je 0x2d6e
movq %rdx, %r15
testq %rdx, %rdx
je 0x2d6e
cmpq $0x2001, %r15           # imm = 0x2001
jae 0x2dae
movq %r8, %r14
movq %rcx, 0x10(%rsp)
cmpq $0x3dfec, %r8           # imm = 0x3DFEC
jae 0x2dee
movl %r9d, %r12d
movq %rsi, %r13
movq %rdi, %rbx
leaq (%r15,%r14), %rdi
addq $0x15, %rdi
movq 0x52c3(%rip), %rsi      # 0x7fa8
callq 0x22b0
movq %rax, %rbp
movq %rax, (%rbx)
movl 0x50(%rsp), %edi
callq 0x2e44
bswapq %rax
movq %rax, (%rbp)
bswapl %r12d
movl %r12d, 0x8(%rbp)
movl %r14d, %eax
bswapl %eax
movl %eax, 0xc(%rbp)
movl %r15d, %eax
rolw $0x8, %ax
movw %ax, 0x10(%rbp)
leaq 0x13(%rbp), %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x2140
xorl %r12d, %r12d
leaq (%r15,%rbp), %rdi
addq $0x14, %rdi
movb %r12b, -0x1(%rdi)
movq 0x10(%rsp), %rsi
movq %r14, %rdx
callq 0x2140
leaq (%r15,%r14), %rax
incq %rax
movb %r12b, 0x13(%rbp,%rax)
movq %rbp, %rdi
callq 0x2f5e
movb %al, 0x12(%rbp)
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x23bb(%rip), %rsi      # 0x5130
movq %rsp, %rbx
movq %rbx, %rdi
callq 0x21f0
pushq $0x10
popq %rdi
callq 0x20c0
movq %rax, %r14
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2120
movq 0x5243(%rip), %rsi      # 0x7fe0
movq 0x5224(%rip), %rdx      # 0x7fc8
movq %r14, %rdi
callq 0x2250
jmp 0x2e2c
leaq 0x238c(%rip), %rsi      # 0x5141
movq %rsp, %rbx
movq %rbx, %rdi
callq 0x21f0
pushq $0x10
popq %rdi
callq 0x20c0
movq %rax, %r14
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2120
movq 0x5203(%rip), %rsi      # 0x7fe0
movq 0x51e4(%rip), %rdx      # 0x7fc8
movq %r14, %rdi
callq 0x2250
jmp 0x2e2c
leaq 0x235d(%rip), %rsi      # 0x5152
movq %rsp, %rbx
movq %rbx, %rdi
callq 0x21f0
pushq $0x10
popq %rdi
callq 0x20c0
movq %rax, %r14
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2120
movq 0x51c3(%rip), %rsi      # 0x7fe0
movq 0x51a4(%rip), %rdx      # 0x7fc8
movq %r14, %rdi
callq 0x2250
jmp 0x2e30
jmp 0x2e30
movq %rax, %rbx
movq %rsp, %rdi
callq 0x22c8
movq %rbx, %rdi
callq 0x2260
nop