// File: /workspace/github_c_makefile_star2_O2/sharpyfox[P]citrusleaf-client/tests/key_c/src/key.c
// Function: make_key_value
static key_value *make_key_value(uint seed, uint key_len, uint value_len)
{
	int i;
	size_t	sz = sizeof(key_value) + key_len + value_len + 2 + value_len;
	key_value *kv = malloc(sz);
	if (!kv)	return(0);

	// save before molesting
	kv->key_int = kv->value_int = seed * g_config.value_factor;
	
	// a little hinky, pointing internally to local memory, but so much more efficient
	kv->key_str = ((char *)kv)+ sizeof(key_value);
	kv->value_str = ((char *)kv)+ sizeof(key_value) + key_len + 1;
	kv->value_blob = kv->value_str + value_len + 1;
	kv->value_blob_len = value_len;
	
	// generate the string key
	kv->key_str[key_len] = 0;
	for (i = key_len-1; i >= 0; i--) {
		kv->key_str[i] = (seed % 10) + '0';
		seed = seed / 10;
	}
	
	// build a string out of the value, might be different from key
	// (optimization: don't build if integer test, or if value_factor == 1
	char value_str_short[key_len];
	seed = kv->value_int;
	value_str_short[key_len] = 0;
	for (i = key_len-1; i >= 0; i--) {
		value_str_short[i] = (seed % 10) + '0';
		seed = seed / 10;
	}
	
	
	// longer value likely required: multiple copies of value_str_short
	i=0;
	while (i < value_len) {
		if (value_len - i > key_len) {
			memcpy(&kv->value_str[i], value_str_short, key_len);
			i += key_len;
		}
		else {
			memcpy(&kv->value_str[i], value_str_short, value_len - i);
			i += (value_len - i);
		}
	}	
	kv->value_str[value_len] = 0;

	// And how's about a fine blob!
	uint64_t t = kv->value_int;
	memcpy(kv->value_blob, &t, sizeof(t)); // this will make sure some nulls, always a good idea
	memcpy(kv->value_blob + sizeof(t), kv->value_str,kv->value_blob_len - sizeof(t));

	
#ifdef DEBUG_VERBOSE
	fprintf(stderr, "make key value: key_len %d key %s value_len %d value_str %s value_int %"PRIu64"\n",key_len,kv->key,value_len,kv->value_str,kv->value_int);
#endif
	
	return(kv);	
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, %eax
movl %esi, %r14d
movl %edi, %r13d
movl %edx, %r12d
movl %esi, %r15d
leaq 0x32(%r14,%rax,2), %rdi
movq %rax, -0x30(%rbp)
callq 0x22f0
movq %rax, %rbx
testq %rax, %rax
je 0x3ac9
leaq 0x1696d(%rip), %rax     # 0x1a330
leaq 0x30(%rbx), %rcx
movl 0x44(%rax), %eax
imull %r13d, %eax
movq %rax, 0x28(%rbx)
movq %rax, (%rbx)
movq %rcx, 0x8(%rbx)
leaq 0x31(%rbx,%r14), %rcx
leaq 0x30(%rbx,%r14), %rax
movq %rcx, 0x10(%rbx)
movq -0x30(%rbp), %rcx
leaq 0x2(%rcx,%rax), %rax
leal -0x1(%r15), %ecx
movq %rax, 0x20(%rbx)
movl %r12d, 0x18(%rbx)
movb $0x0, 0x30(%rbx,%r14)
pushq $0xa
popq %rsi
movl %ecx, %edi
testl %edi, %edi
js 0x3a27
movl %r13d, %eax
xorl %edx, %edx
movl %edi, %r9d
decl %edi
divl %esi
movq 0x8(%rbx), %r8
orb $0x30, %dl
movl %eax, %r13d
movb %dl, (%r8,%r9)
jmp 0x3a07
leaq 0xf(%r14), %rax
movq %rsp, %r13
movq %rsp, -0x38(%rbp)
andq $-0x10, %rax
subq %rax, %r13
movq %r13, %rsp
movl 0x28(%rbx), %eax
movb $0x0, (%r14,%r13)
testl %ecx, %ecx
js 0x3a5a
xorl %edx, %edx
movl %ecx, %edi
decl %ecx
divl %esi
orb $0x30, %dl
movb %dl, (%r13,%rdi)
jmp 0x3a44
movq %r14, -0x40(%rbp)
xorl %r14d, %r14d
movl %r12d, %eax
subl %r14d, %eax
jbe 0x3a95
movslq %r14d, %rdi
addq 0x10(%rbx), %rdi
cmpl %r15d, %eax
jbe 0x3a86
movq -0x40(%rbp), %rdx
movq %r13, %rsi
callq 0x2180
addl %r15d, %r14d
jmp 0x3a61
movl %eax, %edx
movq %r13, %rsi
callq 0x2180
movl %r12d, %r14d
jmp 0x3a61
movq 0x10(%rbx), %rax
movq -0x30(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq 0x20(%rbx), %rax
movq 0x28(%rbx), %rcx
movq %rcx, (%rax)
movq 0x20(%rbx), %rdi
movslq 0x18(%rbx), %rdx
movq 0x10(%rbx), %rsi
addq $0x8, %rdi
addq $-0x8, %rdx
callq 0x2180
movq -0x38(%rbp), %rsp
movq %rbx, %rax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq