// File: /workspace/github_c_makefile_star2_O2/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
subq $0x18, %rsp
movq 0x11a84(%rip), %rbp     # 0x14fe0
leaq 0xb0ba(%rip), %rdi      # 0xe61d
movq (%rbp), %rcx
pushq $0xe
popq %rsi
pushq $0x1
popq %rdx
callq 0x2540
leaq 0x11d77(%rip), %rbx     # 0x152f0
leaq -0x3c(%rip), %rsi       # 0x3544
movl 0x2c(%rbx), %r8d
leaq 0x48(%rbx), %rdi
addl %r8d, %r8d
pushq $0x4
popq %rdx
xorl %ecx, %ecx
movl %edx, %r9d
callq 0x372c
callq 0x66dd
movq %rax, 0x78(%rbx)
movq %rax, %rdi
xorl %ecx, %ecx
movq (%rbx), %rsi
movswl 0x8(%rbx), %edx
callq 0x6967
cmpb $0x0, 0x29(%rbx)
jne 0x35c3
movq 0x78(%rbx), %rdi
xorl %esi, %esi
callq 0x7482
movl 0x30(%rbx), %r14d
movq %r14, %rdi
shlq $0x3, %rdi
callq 0x22e0
testq %rax, %rax
movq %rax, 0x40(%rbx)
jne 0x35fb
movq (%rbp), %rdi
leal (,%r14,8), %edx
leaq 0xb03d(%rip), %rsi      # 0xe62c
xorl %eax, %eax
callq 0x2380
jmp 0x3717
xorl %eax, %eax
movl %r14d, %ecx
cmpq %rcx, %rax
jae 0x3617
movq 0x40(%rbx), %rcx
orq $-0x1, (%rcx,%rax,8)
incq %rax
movl 0x30(%rbx), %r14d
jmp 0x35fd
xorl %edi, %edi
xorl %r13d, %r13d
callq 0x265c
xorl %edi, %edi
movq %rax, 0x50(%rbx)
callq 0x265c
xorl %edi, %edi
movq %rax, 0x58(%rbx)
callq 0x265c
xorl %edi, %edi
movq %rax, 0x60(%rbx)
callq 0x265c
movq %rax, 0x68(%rbx)
movq %rax, %rcx
movq 0x50(%rbx), %rdi
movq 0x58(%rbx), %rsi
movq 0x60(%rbx), %rdx
callq 0x277f
movl 0x2c(%rbx), %edi
movq %rax, 0x8(%rsp)
shlq $0x3, %rdi
callq 0x22e0
movq (%rbp), %rcx
movq %rax, %r14
leaq 0xafd8(%rip), %rdi      # 0xe651
pushq $0x1a
popq %rsi
pushq $0x1
popq %rdx
callq 0x2540
leaq -0x62d(%rip), %r15      # 0x305e
movq %r14, %r12
movl 0x2c(%rbx), %eax
cmpq %rax, %r13
jae 0x36ae
movq %r12, %rdi
xorl %esi, %esi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x24e0
incq %r13
addq $0x8, %r12
jmp 0x368e
leaq 0x10(%rsp), %r15
leaq 0xafb2(%rip), %r12      # 0xe66c
xorl %r13d, %r13d
movl %eax, %eax
cmpq %rax, %r13
jae 0x36f3
movq (%r14,%r13,8), %rdi
movq %r15, %rsi
callq 0x2220
movl 0x10(%rsp), %ecx
testl %ecx, %ecx
jne 0x36e0
movl 0x2c(%rbx), %eax
incq %r13
jmp 0x36bd
movq (%rbp), %rdi
movq %r12, %rsi
movl %r13d, %edx
xorl %eax, %eax
callq 0x2380
jmp 0x36d8
movq 0x40(%rbx), %rdi
callq 0x22c0
movq %r14, %rdi
callq 0x22c0
movq 0x78(%rbx), %rdi
callq 0x6b9b
movq 0x8(%rsp), %rdi
callq 0x27d4
pushq $-0x1
popq %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)