// File: /workspace/github_c_makefile_star2_O0/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
subq $0x140, %rsp            # imm = 0x140
movq %rdi, -0x10(%rbp)
movb $0x0, %al
callq 0x2910
leaq 0x1ae33(%rip), %rcx     # 0x1e300
movl 0x30(%rcx), %ecx
xorl %edx, %edx
divq %rcx
movl %edx, %eax
movl %eax, -0x14(%rbp)
movb $0x0, %al
callq 0x2910
andq $0x3, %rax
movl %eax, -0x18(%rbp)
leaq 0x1ae11(%rip), %rax     # 0x1e300
movq 0x48(%rax), %rdi
leaq -0x14(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x4430
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x3bd2
leaq 0x1aded(%rip), %rax     # 0x1e300
movl 0x34(%rax), %eax
incl %eax
movq %rsp, %rcx
movq %rcx, -0x28(%rbp)
movq %rax, %rcx
addq $0xf, %rcx
andq $-0x10, %rcx
movq %rsp, %rdi
subq %rcx, %rdi
movq %rdi, -0x128(%rbp)
movq %rdi, %rsp
movq %rax, -0x30(%rbp)
movl -0x14(%rbp), %eax
movl %eax, %esi
leaq 0x1adb6(%rip), %rax     # 0x1e300
movl 0x34(%rax), %edx
callq 0x3060
movq -0x128(%rbp), %rsi
leaq -0x50(%rbp), %rdi
callq 0x54a0
leaq 0x1ad97(%rip), %rax     # 0x1e300
movq 0x18(%rax), %rdi
leaq -0x50(%rbp), %rsi
leaq -0x64(%rbp), %rdx
callq 0x9550
leaq 0x1ad7f(%rip), %rax     # 0x1e300
movq 0x40(%rax), %rcx
movl -0x14(%rbp), %eax
movl %eax, %edx
movq $-0x1, %rax
cmpq (%rcx,%rdx,8), %rax
jne 0x35e7
movl -0x14(%rbp), %edi
leaq -0x50(%rbp), %rsi
leaq -0x64(%rbp), %rdx
callq 0x30e0
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x35cd
leaq 0x1ad4a(%rip), %rax     # 0x1e300
testb $0x1, 0x2a(%rax)
je 0x35cb
movl $0x4, -0xd4(%rbp)
jmp 0x3ba8
jmp 0x35cd
leaq 0x1ad2c(%rip), %rax     # 0x1e300
movq 0x68(%rax), %rdi
movl $0x1, %esi
callq 0x26f0
jmp 0x3b8a
leaq 0x1ad12(%rip), %rax     # 0x1e300
movq 0x40(%rax), %rcx
movl -0x14(%rbp), %eax
movl %eax, %edx
movq $-0x2, %rax
cmpq (%rcx,%rdx,8), %rax
jne 0x372b
movq $0x0, -0x70(%rbp)
leaq 0x1ace9(%rip), %rax     # 0x1e300
movq 0x78(%rax), %rdi
leaq 0x1acde(%rip), %rax     # 0x1e300
movq 0x10(%rax), %rsi
leaq 0x1acd3(%rip), %rax     # 0x1e300
movq 0x18(%rax), %rdx
leaq 0x1acc8(%rip), %rax     # 0x1e300
movl 0x74(%rax), %eax
leaq -0x50(%rbp), %rcx
leaq -0x70(%rbp), %r8
leaq -0x74(%rbp), %r9
xorl %r10d, %r10d
subq $0x10, %rsp
movl %eax, (%rsp)
movq $0x0, 0x8(%rsp)
callq 0x8f80
addq $0x10, %rsp
movl %eax, -0x1c(%rbp)
cmpl $0x2, -0x1c(%rbp)
je 0x36b0
movq -0x128(%rbp), %rcx
movq 0x1a966(%rip), %rax     # 0x1dfe0
movq (%rax), %rdi
movl -0x1c(%rbp), %edx
movq -0x64(%rbp), %r8
leaq 0x14e73(%rip), %rsi     # 0x184fe
movb $0x0, %al
callq 0x23b0
leaq 0x1ac67(%rip), %rax     # 0x1e300
testb $0x1, 0x2a(%rax)
je 0x36ae
movl $0x4, -0xd4(%rbp)
jmp 0x3ba8
jmp 0x36b0
cmpq $0x0, -0x70(%rbp)
je 0x36c0
movq -0x70(%rbp), %rdi
callq 0x22e0
leaq 0x1ac39(%rip), %rax     # 0x1e300
movq 0x50(%rax), %rdi
movl $0x1, %esi
callq 0x26f0
cmpl $0x2, -0x18(%rbp)
jae 0x3726
movl -0x14(%rbp), %edi
leaq -0x50(%rbp), %rsi
leaq -0x64(%rbp), %rdx
callq 0x30e0
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x3711
leaq 0x1ac06(%rip), %rax     # 0x1e300
testb $0x1, 0x2a(%rax)
je 0x370f
movl $0x4, -0xd4(%rbp)
jmp 0x3ba8
jmp 0x3711
leaq 0x1abe8(%rip), %rax     # 0x1e300
movq 0x68(%rax), %rdi
movl $0x1, %esi
callq 0x26f0
jmp 0x3b88
leaq 0x1abce(%rip), %rax     # 0x1e300
movq %rax, -0x138(%rbp)
movq 0x20(%rax), %rsi
leaq -0xc0(%rbp), %rdi
callq 0x2270
leaq -0xa0(%rbp), %rdi
callq 0x5470
movq -0x138(%rbp), %rax
movl 0x38(%rax), %eax
incl %eax
movq %rsp, %rcx
movq %rcx, -0xc8(%rbp)
movq %rax, %rcx
addq $0xf, %rcx
andq $-0x10, %rcx
movq %rsp, %rdi
subq %rcx, %rdi
movq %rdi, -0x130(%rbp)
movq %rdi, %rsp
movq %rax, -0xd0(%rbp)
leaq 0x1ab6c(%rip), %rax     # 0x1e300
movq 0x40(%rax), %rax
movl -0x14(%rbp), %ecx
movq (%rax,%rcx,8), %rsi
leaq 0x1ab5a(%rip), %rax     # 0x1e300
movl 0x38(%rax), %edx
callq 0x3060
movq -0x130(%rbp), %rsi
leaq -0xc0(%rbp), %rdi
addq $0x20, %rdi
callq 0x54a0
leaq 0x1ab34(%rip), %rax     # 0x1e300
movq 0x78(%rax), %rdi
leaq 0x1ab29(%rip), %rax     # 0x1e300
movq 0x10(%rax), %rsi
leaq 0x1ab1e(%rip), %rax     # 0x1e300
movq 0x18(%rax), %rdx
leaq -0xc0(%rbp), %r8
leaq 0x1ab0c(%rip), %rax     # 0x1e300
movl 0x74(%rax), %eax
leaq -0x50(%rbp), %rcx
movl $0x1, %r9d
xorl %r10d, %r10d
subq $0x10, %rsp
movl %eax, (%rsp)
movq $0x0, 0x8(%rsp)
callq 0x9340
addq $0x10, %rsp
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x3869
movq 0x1a7b3(%rip), %rax     # 0x1dfe0
movq (%rax), %rdi
movl -0x1c(%rbp), %edx
movl -0x14(%rbp), %ecx
movq -0x64(%rbp), %r8
leaq 0x14d13(%rip), %rsi     # 0x18554
movb $0x0, %al
callq 0x23b0
leaq 0x1aab1(%rip), %rax     # 0x1e300
testb $0x1, 0x2a(%rax)
je 0x3864
movl $0x4, -0xd4(%rbp)
jmp 0x3b70
jmp 0x396f
cmpl $0x3, -0xa0(%rbp)
je 0x38bc
movq 0x1a767(%rip), %rax     # 0x1dfe0
movq (%rax), %rdi
movl -0xa0(%rbp), %edx
leaq 0x14d12(%rip), %rsi     # 0x1859b
movb $0x0, %al
callq 0x23b0
leaq 0x1aa69(%rip), %rax     # 0x1e300
testb $0x1, 0x2a(%rax)
je 0x38b7
movq $-0x1, %rax
movq %rax, -0x8(%rbp)
movl $0x1, -0xd4(%rbp)
jmp 0x3b70
jmp 0x394a
movq -0x130(%rbp), %rsi
movq -0x90(%rbp), %rdi
callq 0x2380
cmpl $0x0, %eax
je 0x3948
movq 0x1a705(%rip), %rax     # 0x1dfe0
movq (%rax), %rdi
leaq 0x14ceb(%rip), %rsi     # 0x185d0
movb $0x0, %al
callq 0x23b0
movq -0x130(%rbp), %rdx
movq 0x1a6e6(%rip), %rax     # 0x1dfe0
movq (%rax), %rdi
leaq 0x14bde(%rip), %rsi     # 0x184e2
movb $0x0, %al
callq 0x23b0
movq 0x1a6ce(%rip), %rax     # 0x1dfe0
movq (%rax), %rdi
movq -0x90(%rbp), %rdx
leaq 0x14bd0(%rip), %rsi     # 0x184f3
movb $0x0, %al
callq 0x23b0
leaq 0x1a9cf(%rip), %rax     # 0x1e300
testb $0x1, 0x2a(%rax)
je 0x3946
movl $0x4, -0xd4(%rbp)
jmp 0x3b70
jmp 0x3948
jmp 0x394a
leaq -0xc0(%rbp), %rdi
addq $0x20, %rdi
callq 0x56a0
leaq 0x1a99f(%rip), %rax     # 0x1e300
movq 0x50(%rax), %rdi
movl $0x1, %esi
callq 0x26f0
cmpl $0x2, -0x18(%rbp)
jae 0x39bb
movl -0x14(%rbp), %edi
leaq -0x50(%rbp), %rsi
leaq -0x64(%rbp), %rdx
callq 0x30e0
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x39b6
leaq 0x1a96c(%rip), %rax     # 0x1e300
testb $0x1, 0x2a(%rax)
je 0x39b4
movq $-0x1, %rax
movq %rax, -0x8(%rbp)
movl $0x1, -0xd4(%rbp)
jmp 0x3b70
jmp 0x39b6
jmp 0x3b66
cmpl $0x2, -0x18(%rbp)
jne 0x3b64
leaq 0x1a934(%rip), %rax     # 0x1e300
movq 0x78(%rax), %rdi
leaq 0x1a929(%rip), %rax     # 0x1e300
movq 0x10(%rax), %rsi
leaq 0x1a91e(%rip), %rax     # 0x1e300
movq 0x18(%rax), %rdx
leaq -0x50(%rbp), %rcx
xorl %eax, %eax
movl %eax, %r8d
callq 0x9470
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x3a3d
movq 0x1a5dc(%rip), %rax     # 0x1dfe0
movq (%rax), %rdi
movl -0x1c(%rbp), %edx
movl -0x14(%rbp), %ecx
movq -0x64(%rbp), %r8
leaq 0x14bde(%rip), %rsi     # 0x185f6
movb $0x0, %al
callq 0x23b0
leaq 0x1a8da(%rip), %rax     # 0x1e300
testb $0x1, 0x2a(%rax)
je 0x3a3b
movl $0x4, -0xd4(%rbp)
jmp 0x3b70
jmp 0x3a3d
leaq -0x120(%rbp), %rdi
leaq 0x1a8b5(%rip), %rax     # 0x1e300
movq 0x20(%rax), %rsi
callq 0x2270
leaq -0x120(%rbp), %rdi
addq $0x20, %rdi
callq 0x5470
leaq 0x1a895(%rip), %rax     # 0x1e300
movq 0x78(%rax), %rdi
leaq 0x1a88a(%rip), %rax     # 0x1e300
movq 0x10(%rax), %rsi
leaq 0x1a87f(%rip), %rax     # 0x1e300
movq 0x18(%rax), %rdx
leaq -0x120(%rbp), %r8
leaq 0x1a86d(%rip), %rax     # 0x1e300
movl 0x74(%rax), %eax
leaq -0x50(%rbp), %rcx
movl $0x1, %r9d
xorl %r10d, %r10d
subq $0x10, %rsp
movl %eax, (%rsp)
movq $0x0, 0x8(%rsp)
callq 0x7320
addq $0x10, %rsp
movl %eax, -0x1c(%rbp)
cmpl $0x2, -0x1c(%rbp)
je 0x3aff
movq 0x1a514(%rip), %rax     # 0x1dfe0
movq (%rax), %rdi
movl -0x1c(%rbp), %edx
movq -0x64(%rbp), %rcx
leaq 0x14b55(%rip), %rsi     # 0x18632
movb $0x0, %al
callq 0x23b0
leaq 0x1a815(%rip), %rax     # 0x1e300
testb $0x1, 0x2a(%rax)
je 0x3afd
movl $0x4, -0xd4(%rbp)
jmp 0x3b70
jmp 0x3aff
leaq -0x120(%rbp), %rdi
addq $0x20, %rdi
callq 0x56a0
leaq 0x1a7ea(%rip), %rax     # 0x1e300
movq 0x40(%rax), %rax
movl -0x14(%rbp), %ecx
movq $-0x2, (%rax,%rcx,8)
leaq 0x1a7d4(%rip), %rax     # 0x1e300
movq 0x50(%rax), %rdi
movl $0x1, %esi
callq 0x26f0
leaq 0x1a7bf(%rip), %rax     # 0x1e300
movq 0x60(%rax), %rdi
movl $0x1, %esi
callq 0x26f0
leaq 0x1a7aa(%rip), %rax     # 0x1e300
movq 0x68(%rax), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x26f0
jmp 0x3b66
movl $0x0, -0xd4(%rbp)
movq -0xc8(%rbp), %rax
movq %rax, %rsp
movl -0xd4(%rbp), %eax
testl %eax, %eax
jne 0x3ba8
jmp 0x3b86
jmp 0x3b88
jmp 0x3b8a
leaq 0x1a76f(%rip), %rax     # 0x1e300
movq 0x48(%rax), %rdi
leaq -0x14(%rbp), %rsi
callq 0x4990
movl $0x0, -0xd4(%rbp)
movq -0x28(%rbp), %rax
movq %rax, %rsp
movl -0xd4(%rbp), %eax
movl %eax, -0x13c(%rbp)
testl %eax, %eax
je 0x3bd0
jmp 0x3bc1
movl -0x13c(%rbp), %eax
subl $0x1, %eax
je 0x3be7
jmp 0x3bce
jmp 0x3be2
jmp 0x3bd2
jmp 0x3bd4
movb $0x1, %al
testb $0x1, %al
jne 0x34bf
jmp 0x3be0
jmp 0x3be2
callq 0x2180
movq -0x8(%rbp), %rax
movq %rbp, %rsp
popq %rbp
retq