// File: /workspace/github_c_makefile_star2_O3/sharpyfox[P]citrusleaf-client/tests/loop_c/src/loop.c
// Function: do_loop_test
int 
do_loop_test ( )
{
	fprintf(stderr, "starting test\n");
	
	// this hash is the rendez-vous for all the worker threads, to make sure they're not working
	// on the same keys at the same time. It starts out empty. When a worker wants to use a key, it
	// drops an element in the hash unique.
	shash_create(&g_config.in_progress_hash, progress_hash_fn, sizeof(uint32_t), 0, g_config.n_threads * 2, SHASH_CR_MT_BIGLOCK);

	// Create the aerospike cluster
	g_config.asc = citrusleaf_cluster_create();
	citrusleaf_cluster_add_host(g_config.asc, g_config.host, g_config.port, 0);

	if (g_config.follow == false) 
		citrusleaf_cluster_follow(g_config.asc, false);
	
	
	// This array is the current value of a given key. Starts out as uninitialized.
	g_config.values = malloc( sizeof(uint64_t) * g_config.n_keys);
	if (g_config.values == 0) {
		fprintf(stderr, " could not malloc %d, use fewer keys",(int)(sizeof(uint64_t)*g_config.n_keys));
		return(-1);
	}
	for (uint i=0;i<g_config.n_keys;i++)
		g_config.values[i] = VALUE_UNINIT;

	g_config.read_counter = atomic_int_create(0);
	g_config.write_counter = atomic_int_create(0);
	g_config.delete_counter = atomic_int_create(0);
	g_config.key_counter = atomic_int_create(0);
	
	void *counter_control = start_counter_thread( g_config.read_counter, g_config.write_counter, g_config.delete_counter, g_config.key_counter);
	
	// Create the threads and send them on their way
	pthread_t	*thr_array = malloc(sizeof(pthread_t) * g_config.n_threads);

	fprintf(stderr, "starting threads for test\n");
	for (uint i=0;i<g_config.n_threads;i++)
		pthread_create(&thr_array[i], 0, work_fn, 0); 
	
	for (uint i=0;i<g_config.n_threads;i++) {
		void *value_ptr;
		pthread_join(thr_array[i], &value_ptr);
		if ( ((int)(ssize_t)value_ptr) )
			fprintf(stderr, "thread %d returned value %d\n",i,(int) (ssize_t) value_ptr);
	}
	
	free(g_config.values);
	free(thr_array);
	citrusleaf_cluster_destroy(g_config.asc);
	
	stop_counter_thread(counter_control);
	
	return(-1);	
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq 0x13653(%rip), %r15     # 0x15fe0
leaq 0xcc89(%rip), %rdi      # 0xf61d
movq (%r15), %rcx
pushq $0xe
popq %rsi
pushq $0x1
popq %rdx
callq 0x2540
leaq 0x13947(%rip), %rbp     # 0x162f0
leaq 0x1012(%rip), %rsi      # 0x39c2
movl 0x2c(%rbp), %r8d
leaq 0x48(%rbp), %rdi
addl %r8d, %r8d
pushq $0x4
popq %rdx
xorl %ecx, %ecx
movl %edx, %r9d
callq 0x39c8
callq 0x6aae
movq %rax, 0x78(%rbp)
movq %rax, %rdi
xorl %ecx, %ecx
movq (%rbp), %rsi
movswl 0x8(%rbp), %edx
callq 0x6d6c
cmpb $0x0, 0x29(%rbp)
jne 0x29f4
movq 0x78(%rbp), %rdi
xorl %esi, %esi
callq 0x7a4e
movl 0x30(%rbp), %ebx
movq %rbx, %rdi
shlq $0x3, %rdi
callq 0x22e0
testq %rax, %rax
movq %rax, 0x40(%rbp)
jne 0x2a29
movq (%r15), %rdi
leal (,%rbx,8), %edx
leaq 0xcc0f(%rip), %rsi      # 0xf62c
xorl %eax, %eax
callq 0x2380
jmp 0x2b47
testl %ebx, %ebx
je 0x2a43
xorl %eax, %eax
movq 0x40(%rbp), %rcx
orq $-0x1, (%rcx,%rax,8)
incq %rax
movl 0x30(%rbp), %ecx
cmpq %rcx, %rax
jb 0x2a2f
xorl %edi, %edi
callq 0x2dec
xorl %edi, %edi
movq %rax, 0x50(%rbp)
callq 0x2dec
xorl %edi, %edi
movq %rax, 0x58(%rbp)
callq 0x2dec
xorl %edi, %edi
movq %rax, 0x60(%rbp)
callq 0x2dec
movq %rax, 0x68(%rbp)
movq %rax, %rcx
movq 0x50(%rbp), %rdi
movq 0x58(%rbp), %rsi
movq 0x60(%rbp), %rdx
callq 0x2ea0
movl 0x2c(%rbp), %edi
movq %rax, %rbx
shlq $0x3, %rdi
callq 0x22e0
movq (%r15), %rcx
movq %rax, %r14
leaq 0xcbb2(%rip), %rdi      # 0xf651
pushq $0x1a
popq %rsi
pushq $0x1
popq %rdx
callq 0x2540
cmpl $0x0, 0x2c(%rbp)
je 0x2b25
xorl %r13d, %r13d
leaq 0x9fe(%rip), %r15       # 0x34b8
movq %r14, %r12
movq %r12, %rdi
xorl %esi, %esi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x24e0
movl 0x2c(%rbp), %eax
incq %r13
addq $0x8, %r12
cmpq %rax, %r13
jb 0x2abd
testl %eax, %eax
je 0x2b25
movq %rsp, %r15
leaq 0xcb83(%rip), %r12      # 0xf66c
xorl %r13d, %r13d
movq (%r14,%r13,8), %rdi
movq %r15, %rsi
callq 0x2220
movl (%rsp), %ecx
testl %ecx, %ecx
jne 0x2b0c
movl 0x2c(%rbp), %eax
incq %r13
cmpq %rax, %r13
jb 0x2aec
jmp 0x2b25
movq 0x134cd(%rip), %rax     # 0x15fe0
movq %r12, %rsi
movl %r13d, %edx
movq (%rax), %rdi
xorl %eax, %eax
callq 0x2380
jmp 0x2aff
movq 0x40(%rbp), %rdi
callq 0x22c0
movq %r14, %rdi
callq 0x22c0
movq 0x78(%rbp), %rdi
callq 0x7029
movq %rbx, %rdi
callq 0x2efa
pushq $-0x1
popq %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq