// File: /workspace/github_c_makefile_star2_O2/sharpyfox[P]citrusleaf-client/tests/loop_c/src/loop.c
// Function: write_new_value
int
write_new_value(uint32_t key, cl_object *key_o, cf_digest *d)
{
	uint64_t new_value_int;
	do {
		new_value_int = rand_64();
	} while (new_value_int == VALUE_UNINIT || new_value_int == VALUE_DELETED);
	
	g_config.values[key] = new_value_int;
	char new_value_str[g_config.value_len+1];
	my_itoa(new_value_str, new_value_int, g_config.value_len); 
	
	cl_bin values[1];
	strcpy(values[0].bin_name, g_config.bin);
	citrusleaf_object_init_str(&values[0].object, new_value_str);

	cl_write_parameters cl_w_p;	
	cl_write_parameters_set_default(&cl_w_p);
	cl_w_p.timeout_ms = g_config.timeout_ms;
	
	int rv;
	rv = citrusleaf_put(g_config.asc, g_config.ns, g_config.set, key_o, values, 1, &cl_w_p);
	if (rv != 0) {
		fprintf(stderr, "aerospike put returned error %d, fail digest %"PRIx64"\n",rv, *(uint64_t *)d);
		if (g_config.strict)
			return(-1);
	}
	
	citrusleaf_object_init(&values[0].object);
	
	rv = citrusleaf_verify(g_config.asc, g_config.ns, g_config.set, key_o, values, 1, g_config.timeout_ms, NULL);
	if (rv != 0) {
		fprintf(stderr, "aerospike get returned error %d digest %"PRIx64"\n",rv, *(uint64_t *)d);
		if (g_config.strict)
			return(-1);
	}

	// test!
	if (values[0].object.type != CL_STR) {
		fprintf(stderr, "read value has wrong type: expect string (3) got %d, fail digest %"PRIx64"\n",(int)values[0].object.type, *(uint64_t *)d);
		if (g_config.strict)
			return(-1);
	}
	if (strcmp(values[0].object.u.str, new_value_str) != 0) {
		fprintf(stderr, "read value does not match set value. digest %"PRIx64"\n", *(uint64_t *)d);
		fprintf(stderr, "  expecting: %s\n",new_value_str);
		fprintf(stderr, "  got: %s\n",values[0].object.u.str);
		if (g_config.strict)
			return( -1);
	}
	
	citrusleaf_object_free(&values[0].object);
	
	atomic_int_add(g_config.read_counter, 1);
	atomic_int_add(g_config.write_counter, 1);

	
	return(0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rsi, %rbx
movl %edi, %r14d
movq %rdx, -0x30(%rbp)
xorl %eax, %eax
callq 0x27f3
cmpq $-0x3, %rax
ja 0x2e36
leaq 0x124a6(%rip), %r13     # 0x152f0
movl %r14d, %edx
movq %rsp, %r15
movq 0x40(%r13), %rcx
movq %rax, (%rcx,%rdx,8)
movl 0x38(%r13), %edx
leal 0x1(%rdx), %ecx
addq $0xf, %rcx
andq $-0x10, %rcx
subq %rcx, %r15
movq %r15, %rsp
movq %r15, %rdi
movq %rax, %rsi
callq 0x2dec
movq 0x20(%r13), %rsi
leaq -0x70(%rbp), %r12
movq %r12, %rdi
callq 0x2240
leaq -0x50(%rbp), %r14
movq %r15, %rsi
movq %r14, %rdi
callq 0x42b2
movabsq $0x200000000, %rax      # imm = 0x200000000
leaq -0x88(%rbp), %r10
movq 0x78(%r13), %rdi
movq 0x10(%r13), %rsi
movq 0x18(%r13), %rdx
movq %rax, 0x10(%r10)
movl 0x74(%r13), %eax
andl $0x0, (%r10)
movb $0x0, 0x4(%r10)
movl %eax, 0xc(%r10)
subq $0x8, %rsp
pushq $0x1
popq %r9
movq %rbx, %rcx
movq %r12, %r8
pushq %r10
callq 0x5853
addq $0x10, %rsp
testl %eax, %eax
pushq $-0x1
popq %r12
jne 0x2f7b
movq %r14, %rdi
callq 0x42a4
movl 0x74(%r13), %eax
movq 0x78(%r13), %rdi
movq 0x10(%r13), %rsi
movq 0x18(%r13), %rdx
leaq -0x70(%rbp), %r8
pushq $0x1
popq %r9
movq %rbx, %rcx
pushq $0x0
pushq %rax
callq 0x6203
addq $0x10, %rsp
testl %eax, %eax
jne 0x2fa9
movl -0x50(%rbp), %edx
cmpl $0x3, %edx
jne 0x2fd7
movq -0x40(%rbp), %rdi
movq %r15, %rsi
callq 0x2350
testl %eax, %eax
jne 0x3006
movq %r14, %rdi
callq 0x434d
movq 0x50(%r13), %rdi
pushq $0x1
popq %rbx
movl %ebx, %esi
callq 0x269d
movq 0x58(%r13), %rdi
movl %ebx, %esi
callq 0x269d
xorl %r12d, %r12d
movl %r12d, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1205e(%rip), %rcx     # 0x14fe0
movq -0x30(%rbp), %rsi
movl %eax, %edx
xorl %eax, %eax
movq (%rcx), %rdi
movq (%rsi), %rcx
leaq 0xb429(%rip), %rsi      # 0xe3c0
callq 0x2380
cmpb $0x0, 0x2a(%r13)
je 0x2eee
jmp 0x2f69
movq 0x12030(%rip), %rcx     # 0x14fe0
movq -0x30(%rbp), %rsi
movl %eax, %edx
xorl %eax, %eax
movq (%rcx), %rdi
movq (%rsi), %rcx
leaq 0xb42d(%rip), %rsi      # 0xe3f2
callq 0x2380
cmpb $0x0, 0x2a(%r13)
je 0x2f25
jmp 0x2f69
movq 0x12002(%rip), %rax     # 0x14fe0
leaq 0xb439(%rip), %rsi      # 0xe41e
movq (%rax), %rdi
movq -0x30(%rbp), %rax
movq (%rax), %rcx
xorl %eax, %eax
callq 0x2380
cmpb $0x0, 0x2a(%r13)
je 0x2f31
jmp 0x2f69
movq 0x11fd3(%rip), %rbx     # 0x14fe0
movq -0x30(%rbp), %rax
leaq 0xb44c(%rip), %rsi      # 0xe464
movq (%rax), %rdx
movq (%rbx), %rdi
xorl %eax, %eax
callq 0x2380
movq (%rbx), %rdi
leaq 0xb466(%rip), %rsi      # 0xe495
movq %r15, %rdx
xorl %eax, %eax
callq 0x2380
movq (%rbx), %rdi
movq -0x40(%rbp), %rdx
leaq 0xb45f(%rip), %rsi      # 0xe4a6
xorl %eax, %eax
callq 0x2380
cmpb $0x0, 0x2a(%r13)
je 0x2f45
jmp 0x2f69