// File: /workspace/github_c_makefile_star2_O3/sharpyfox[P]citrusleaf-client/tests/loop_c/src/loop.c
// Function: work_fn
void *
work_fn(void *gcc_is_ass)
{
	// Forever,
	do {
		// Pick a key to use. Look it up to see if anyone else is using it.
		uint32_t	key = rand_64() % g_config.n_keys;
		
		uint32_t    die = rand_64() & 0x03;
		
		if (SHASH_OK == shash_put_unique(g_config.in_progress_hash, &key, 0) ) 
		{
			cl_rv rv;
		
			// Make the key into a string
			char key_s[g_config.key_len+1];
			my_itoa(key_s, key, g_config.key_len);
			
			// Make an cl_object that represents the key
			cl_object key_o;
			citrusleaf_object_init_str(&key_o, key_s);
			

			cf_digest d;
			citrusleaf_calculate_digest(g_config.set, &key_o, &d);

			if (VALUE_UNINIT == g_config.values[key]) {

				// simply set the value to something - can't really check anything because we don't know the state				
				if (0 != write_new_value(key, &key_o, &d)) {
					if (g_config.strict)   					goto Fail;
				}
				atomic_int_add(g_config.key_counter, 1);
			}
			else if (VALUE_DELETED == g_config.values[key]) {
				
				// Shouldn't exist
				cl_bin *cl_v = 0;
				int		cl_v_len;
				rv = citrusleaf_get_all(g_config.asc, g_config.ns, g_config.set, &key_o, &cl_v, &cl_v_len, g_config.timeout_ms, NULL);
				if (rv != CITRUSLEAF_FAIL_NOTFOUND) {
					fprintf(stderr, "Get after delete returned improper value when should be deleted %d key %s digest %"PRIx64"\n",rv,key_s, *(uint64_t *)&d);
					if (g_config.strict)    goto Fail;
				}
				if (cl_v)	free(cl_v);

				atomic_int_add(g_config.read_counter, 1);  // did two ops here						
				
				// write a new value
				if (die < 2) {
					if (0 != write_new_value(key, &key_o, &d)) {
						if (g_config.strict)   goto Fail;
					}
					atomic_int_add(g_config.key_counter, 1);
				}
			}
			// Value is well known. Check to see that it's still right.
			else {			
				
				cl_bin values[1];
				strcpy(values[0].bin_name, g_config.bin);
				citrusleaf_object_init(&values[0].object);
				
				// Make string version of old value for checking
				char new_value_str[g_config.value_len+1];
				my_itoa(new_value_str, g_config.values[key], g_config.value_len); 
				citrusleaf_object_init_str(&values[0].object, new_value_str);
				
				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, "Get returned improper value %d when should be set : key %d digest %"PRIx64"\n",rv,key, *(uint64_t *)&d);
					if (g_config.strict)   goto Fail;
					goto V1;
				}
				
				// test!
				if (values[0].object.type != CL_STR) {
					fprintf(stderr, "read value has wrong type: expect string (3) got %d\n",(int)values[0].object.type);  
					if (g_config.strict)   return((void *)-1);
				}
				else if (strcmp(values[0].object.u.str, new_value_str) != 0) {
					fprintf(stderr, "read value does not match set value.\n");
					fprintf(stderr, "  expecting: %s\n",new_value_str);
					fprintf(stderr, "  got: %s\n",values[0].object.u.str);
					if (g_config.strict)   goto Fail;
				}
				
				citrusleaf_object_free(&values[0].object);
				atomic_int_add(g_config.read_counter, 1);
				
				// Delete, write new value, what's your pleasure?
			V1:				
				if (die < 2) {
					if (0 != write_new_value(key, &key_o, &d)) {
						if (g_config.strict)   return((void *)-1);
					}
				}
				// Delete!
				else if (die == 2) {
					rv = citrusleaf_delete_verify(g_config.asc, g_config.ns, g_config.set, &key_o, 0);
					if (rv != 0) {
						fprintf(stderr, "Delete returned improper value %d, fail: key %d digest %"PRIx64"\n",rv, key, *(uint64_t *)&d);
						if (g_config.strict)   goto Fail;
					}

					cl_bin values[1];
					strcpy(values[0].bin_name, g_config.bin);
					citrusleaf_object_init(&values[0].object);
					
					rv = citrusleaf_get(g_config.asc, g_config.ns, g_config.set, &key_o, values, 1, g_config.timeout_ms, NULL);
					if (rv != CITRUSLEAF_FAIL_NOTFOUND) {
						fprintf(stderr, "Get after delete returned improper value %d digest %"PRIx64"\n",rv, *(uint64_t *)&d);
						if (g_config.strict)   goto Fail;
					}
					
					citrusleaf_object_free(&values[0].object);
					
					g_config.values[key] = VALUE_DELETED;
					atomic_int_add(g_config.read_counter, 1);  // did two ops here
					atomic_int_add(g_config.delete_counter, 1);
					atomic_int_add(g_config.key_counter, -1);
					
				}
				
			}
			
			// remove my lock on this key
			shash_delete(g_config.in_progress_hash, &key);
			

		}		
	} while (1);
	
	
Fail:	
	abort();
	return((void *)-1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
leaq 0x12e1d(%rip), %r14     # 0x162f0
leaq -0x2c(%rbp), %r15
movabsq $-0x3333333333333333, %r12 # imm = 0xCCCCCCCCCCCCCCCD
xorl %eax, %eax
callq 0x2f19
movl 0x30(%r14), %ecx
xorl %edx, %edx
divq %rcx
xorl %eax, %eax
movl %edx, -0x2c(%rbp)
callq 0x2f19
movq 0x48(%r14), %rdi
movq %r15, %rsi
xorl %edx, %edx
movq %rax, %rbx
callq 0x3c91
testl %eax, %eax
movl $0x0, %ecx
jne 0x387a
movl 0x34(%r14), %eax
movq %rsp, %r15
movq %rsp, -0x38(%rbp)
incl %eax
addq $0xf, %rax
andq $-0x10, %rax
subq %rax, %r15
movq %r15, %rsp
movl 0x34(%r14), %eax
movl -0x2c(%rbp), %ecx
movb $0x0, (%rax,%r15)
decl %eax
js 0x3568
movl %eax, %esi
movq %rcx, %rax
mulq %r12
shrq $0x3, %rdx
leal (%rdx,%rdx), %eax
leal (%rax,%rax,4), %eax
subl %eax, %ecx
orb $0x30, %cl
movb %cl, (%r15,%rsi)
addq $-0x1, %rsi
movq %rdx, %rcx
jb 0x3546
leaq -0x70(%rbp), %r13
movq %r15, %rsi
andl $0x3, %ebx
movq %r13, %rdi
callq 0x4629
movq 0x18(%r14), %rdi
movq %r13, %rsi
leaq -0x50(%rbp), %rdx
callq 0x675d
movq 0x40(%r14), %rax
movl -0x2c(%rbp), %edi
movq (%rax,%rdi,8), %rax
cmpq $-0x2, %rax
je 0x35cf
cmpq $-0x1, %rax
jne 0x3670
leaq -0x70(%rbp), %rsi
leaq -0x50(%rbp), %rdx
callq 0x326e
testl %eax, %eax
je 0x365d
cmpb $0x0, 0x2a(%r14)
movl $0x4, %ecx
je 0x365d
jmp 0x3793
movl 0x74(%r14), %eax
movq 0x78(%r14), %rdi
movq 0x10(%r14), %rsi
movq 0x18(%r14), %rdx
xorl %r10d, %r10d
leaq -0x70(%rbp), %rcx
leaq -0xb0(%rbp), %r8
leaq -0xf0(%rbp), %r9
movq %r10, -0xb0(%rbp)
pushq %r10
pushq %rax
callq 0x646d
addq $0x10, %rsp
cmpl $0x2, %eax
jne 0x3887
movq -0xb0(%rbp), %rdi
testq %rdi, %rdi
je 0x3621
callq 0x22c0
movq 0x50(%r14), %rdi
movl $0x1, %esi
callq 0x2e2f
cmpl $0x1, %ebx
ja 0x3861
movl -0x2c(%rbp), %edi
leaq -0x70(%rbp), %rsi
leaq -0x50(%rbp), %rdx
callq 0x326e
testl %eax, %eax
je 0x365d
cmpb $0x0, 0x2a(%r14)
je 0x365d
movl $0x4, %ecx
jmp 0x3793
movq 0x68(%r14), %rdi
movl $0x1, %esi
callq 0x2e2f
jmp 0x3861
movq 0x20(%r14), %rsi
leaq -0xb0(%rbp), %rdi
callq 0x2240
leaq -0x90(%rbp), %rdi
callq 0x4618
movl 0x38(%r14), %eax
movq %rsp, %r15
movq %rsp, %r13
incl %eax
addq $0xf, %rax
andq $-0x10, %rax
subq %rax, %r15
movq %r15, %rsp
movq 0x40(%r14), %rax
movl -0x2c(%rbp), %ecx
movq (%rax,%rcx,8), %rcx
movl 0x38(%r14), %eax
movb $0x0, (%rax,%r15)
decl %eax
js 0x36e2
movl %eax, %esi
movq %rcx, %rax
mulq %r12
shrq $0x3, %rdx
leal (%rdx,%rdx), %eax
leal (%rax,%rax,4), %eax
subl %eax, %ecx
orb $0x30, %cl
movb %cl, (%r15,%rsi)
addq $-0x1, %rsi
movq %rdx, %rcx
jb 0x36c0
leaq -0x90(%rbp), %rdi
movq %r15, %rsi
callq 0x4629
movl 0x74(%r14), %eax
movq 0x78(%r14), %rdi
movq 0x10(%r14), %rsi
movq 0x18(%r14), %rdx
leaq -0x70(%rbp), %rcx
leaq -0xb0(%rbp), %r8
movl $0x1, %r9d
pushq $0x0
pushq %rax
callq 0x6666
addq $0x10, %rsp
testl %eax, %eax
jne 0x38b8
movl -0x90(%rbp), %edx
cmpl $0x3, %edx
jne 0x38ee
movq -0x80(%rbp), %rdi
movq %r15, %rsi
callq 0x2350
testl %eax, %eax
jne 0x391b
leaq -0x90(%rbp), %rdi
callq 0x46d9
movq 0x50(%r14), %rdi
movl $0x1, %esi
callq 0x2e2f
cmpl $0x1, %ebx
ja 0x37a0
movl -0x2c(%rbp), %edi
leaq -0x70(%rbp), %rsi
leaq -0x50(%rbp), %rdx
callq 0x326e
testl %eax, %eax
je 0x385e
cmpb $0x0, 0x2a(%r14)
movl $0x1, %ecx
je 0x385e
movq %r13, %rsp
movq -0x38(%rbp), %rbx
leaq -0x2c(%rbp), %r15
jmp 0x3877
cmpl $0x2, %ebx
jne 0x385e
movq 0x78(%r14), %rdi
movq 0x10(%r14), %rsi
movq 0x18(%r14), %rdx
leaq -0x70(%rbp), %rcx
xorl %r8d, %r8d
callq 0x6710
testl %eax, %eax
jne 0x3939
movq 0x20(%r14), %rsi
leaq -0xf0(%rbp), %r15
movq %r15, %rdi
callq 0x2240
leaq -0xd0(%rbp), %rbx
movq %rbx, %rdi
callq 0x4618
movl 0x74(%r14), %eax
movq 0x78(%r14), %rdi
movq 0x10(%r14), %rsi
movq 0x18(%r14), %rdx
leaq -0x70(%rbp), %rcx
movq %r15, %r8
movl $0x1, %r9d
pushq $0x0
pushq %rax
callq 0x5653
addq $0x10, %rsp
cmpl $0x2, %eax
jne 0x396f
movq %rbx, %rdi
callq 0x46d9
movq 0x40(%r14), %rax
movl -0x2c(%rbp), %ecx
movl $0x1, %esi
movq $-0x2, (%rax,%rcx,8)
movq 0x50(%r14), %rdi
callq 0x2e2f
movq 0x60(%r14), %rdi
movl $0x1, %esi
callq 0x2e2f
movq 0x68(%r14), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x2e2f
movq %r13, %rsp
movq 0x48(%r14), %rdi
movq -0x38(%rbp), %rbx
leaq -0x2c(%rbp), %r15
movq %r15, %rsi
callq 0x3fa3
xorl %ecx, %ecx
movq %rbx, %rsp
testl %ecx, %ecx
je 0x34e1
jmp 0x39a2
movq 0x12752(%rip), %rcx     # 0x15fe0
movq -0x50(%rbp), %r8
movl %eax, %edx
leaq 0xbc16(%rip), %rsi      # 0xf4b1
xorl %eax, %eax
movq (%rcx), %rdi
movq %r15, %rcx
callq 0x2380
cmpb $0x0, 0x2a(%r14)
je 0x3610
jmp 0x3653
movq 0x12721(%rip), %rcx     # 0x15fe0
movq -0x50(%rbp), %r8
movl %eax, %edx
leaq 0xbc3b(%rip), %rsi      # 0xf507
xorl %eax, %eax
movq (%rcx), %rdi
movl -0x2c(%rbp), %ecx
callq 0x2380
cmpb $0x0, 0x2a(%r14)
movl $0x4, %ecx
je 0x3763
jmp 0x3790
movq 0x126eb(%rip), %rax     # 0x15fe0
leaq 0xbc52(%rip), %rsi      # 0xf54e
movq (%rax), %rdi
xorl %eax, %eax
callq 0x2380
cmpb $0x0, 0x2a(%r14)
movl $0x1, %ecx
je 0x3749
jmp 0x3790
movq %r15, %rdi
leaq -0x80(%rbp), %rsi
callq 0x2bc2
movl $0x4, %ecx
testb $0x1, %al
je 0x3749
jmp 0x3790
movq 0x126a0(%rip), %rcx     # 0x15fe0
movq -0x50(%rbp), %r8
movl %eax, %edx
leaq 0xbc5c(%rip), %rsi      # 0xf5a9
xorl %eax, %eax
movq (%rcx), %rdi
movl -0x2c(%rbp), %ecx
callq 0x2380
cmpb $0x0, 0x2a(%r14)
movl $0x4, %ecx
jne 0x3790
jmp 0x37c9
movq 0x1266a(%rip), %rcx     # 0x15fe0
movl %eax, %edx
leaq 0xbc66(%rip), %rsi      # 0xf5e5
xorl %eax, %eax
movq (%rcx), %rdi
movq -0x50(%rbp), %rcx
callq 0x2380
cmpb $0x0, 0x2a(%r14)
je 0x381d
movl $0x4, %ecx
jmp 0x3790
cmpl $0x1, %ecx
jne 0x39bd
movq $-0x1, %rax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2150