// File: /workspace/github_c_makefile_star2_O1/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 0x1465c(%rip), %r15     # 0x16fe0
movq (%r15), %rcx
leaq 0xdc8f(%rip), %rdi      # 0x1061d
pushq $0xe
popq %rsi
pushq $0x1
popq %rdx
callq 0x2540
leaq 0x14950(%rip), %rbp     # 0x172f0
movl 0x2c(%rbp), %r8d
addl %r8d, %r8d
leaq 0x48(%rbp), %rdi
leaq 0x1071(%rip), %rsi      # 0x3a23
pushq $0x4
popq %rdx
xorl %ecx, %ecx
movl %edx, %r9d
callq 0x3a28
callq 0x6bbc
movq %rax, 0x78(%rbp)
movq (%rbp), %rsi
movswl 0x8(%rbp), %edx
movq %rax, %rdi
xorl %ecx, %ecx
callq 0x6e9d
cmpb $0x0, 0x29(%rbp)
jne 0x29eb
movq 0x78(%rbp), %rdi
xorl %esi, %esi
callq 0x7bc3
movl 0x30(%rbp), %ebx
leaq (,%rbx,8), %rdi
callq 0x22e0
movq %rax, 0x40(%rbp)
testq %rax, %rax
jne 0x2a1f
movq (%r15), %rdi
shll $0x3, %ebx
leaq 0xdc1b(%rip), %rsi      # 0x1062c
movl %ebx, %edx
xorl %eax, %eax
callq 0x2380
jmp 0x2b41
cmpl $0x0, 0x30(%rbp)
je 0x2a3b
xorl %eax, %eax
movq 0x40(%rbp), %rcx
orq $-0x1, (%rcx,%rax,8)
incq %rax
movl 0x30(%rbp), %ecx
cmpq %rcx, %rax
jb 0x2a27
xorl %edi, %edi
callq 0x2ddc
movq %rax, 0x50(%rbp)
xorl %edi, %edi
callq 0x2ddc
movq %rax, 0x58(%rbp)
xorl %edi, %edi
callq 0x2ddc
movq %rax, 0x60(%rbp)
xorl %edi, %edi
callq 0x2ddc
movq %rax, 0x68(%rbp)
movq 0x50(%rbp), %rdi
movq 0x58(%rbp), %rsi
movq 0x60(%rbp), %rdx
movq %rax, %rcx
callq 0x2e90
movq %rax, %rbx
movl 0x2c(%rbp), %edi
shlq $0x3, %rdi
callq 0x22e0
movq %rax, %r14
movq (%r15), %rcx
leaq 0xdbba(%rip), %rdi      # 0x10651
pushq $0x1a
popq %rsi
pushq $0x1
popq %rdx
callq 0x2540
cmpl $0x0, 0x2c(%rbp)
je 0x2ad3
xorl %r13d, %r13d
leaq 0xa18(%rip), %r15       # 0x34ca
movq %r14, %r12
movq %r12, %rdi
xorl %esi, %esi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x24e0
incq %r13
movl 0x2c(%rbp), %eax
addq $0x8, %r12
cmpq %rax, %r13
jb 0x2ab5
cmpl $0x0, 0x2c(%rbp)
je 0x2b1f
movq %rsp, %r15
leaq 0xdb89(%rip), %r12      # 0x1066c
xorl %r13d, %r13d
movq (%r14,%r13,8), %rdi
movq %r15, %rsi
callq 0x2220
movl (%rsp), %ecx
testl %ecx, %ecx
jne 0x2b06
incq %r13
movl 0x2c(%rbp), %eax
cmpq %rax, %r13
jb 0x2ae6
jmp 0x2b1f
movq 0x144d3(%rip), %rax     # 0x16fe0
movq (%rax), %rdi
movq %r12, %rsi
movl %r13d, %edx
xorl %eax, %eax
callq 0x2380
jmp 0x2af9
movq 0x40(%rbp), %rdi
callq 0x22c0
movq %r14, %rdi
callq 0x22c0
movq 0x78(%rbp), %rdi
callq 0x7163
movq %rbx, %rdi
callq 0x2eea
pushq $-0x1
popq %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq