// File: /workspace/github_c_makefile_star2_O1/sharpyfox[P]citrusleaf-client/src/cl_cluster.c
// Function: citrusleaf_cluster_get_or_create
cl_cluster *
citrusleaf_cluster_get_or_create(char *host, short port, int timeout_ms)
{
	if (! g_clust_initialized )    return(0);
#ifdef DEBUG
        cf_debug("get or create for host %s:%d",host, (int)port);
#endif
	cl_cluster *asc = NULL;

	// Check if the host and port exists in the linked list of hosts
	pthread_mutex_lock(&cluster_ll_LOCK);
	cf_ll_element *cur_element = cf_ll_get_head(&cluster_ll);
	char *hostp;
	short portp;
	while(cur_element) {
		asc = (cl_cluster *) cur_element;
		pthread_mutex_lock(&asc->LOCK);
		for (uint32_t i=0; i<cf_vector_size(&asc->host_str_v); i++) {
			hostp = (char*) cf_vector_pointer_get(&asc->host_str_v, i);
			portp = (int ) cf_vector_integer_get(&asc->host_port_v, i);
			if ((strncmp(host,hostp,strlen(host)+1) == 0) && (port == portp)) {
				// Found the cluster object.
				// Increment the reference count
				#ifdef DEBUG
				cf_debug("host already added on a cluster object. Increment ref_count (%d) and returning pointer - %p", asc->ref_count, asc);
				#endif
				asc->ref_count++;
				pthread_mutex_unlock(&asc->LOCK);
				pthread_mutex_unlock(&cluster_ll_LOCK);
				return(asc);
			}
		}
		pthread_mutex_unlock(&asc->LOCK);
		cur_element = cf_ll_get_next(cur_element);
	}
	pthread_mutex_unlock(&cluster_ll_LOCK);

	// Cluster object for this host does not exist. Create new.
	asc = citrusleaf_cluster_create();
	if (!asc) {
		cf_error("get_or_create - could not create cluster");
		return(0);
	}

	// Add the host to the created cluster object	
	int ret = citrusleaf_cluster_add_host(asc, host, port, timeout_ms);
	if (0 != ret) {
		cf_error("get_or_create - add_host failed with error %d", ret);
		citrusleaf_cluster_release_or_destroy(&asc);
		return(0);
	}

	return(asc);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
leaq 0x126d9(%rip), %rax     # 0x193a8
cmpl $0x0, (%rax)
je 0x6e83
movl %esi, %ebp
movq %rdi, %r14
movl %edx, 0xc(%rsp)
movq $0x0, (%rsp)
leaq 0x126c0(%rip), %rdi     # 0x193b0
callq 0x23b0
leaq 0x126dc(%rip), %rax     # 0x193d8
movq (%rax), %rbx
testq %rbx, %rbx
movswl %bp, %eax
movl %eax, 0x8(%rsp)
je 0x6df5
leaq 0x18(%rsp), %r12
movq %rbx, (%rsp)
leaq 0x158(%rbx), %rdi
callq 0x23b0
movq (%rsp), %rdi
cmpl $0x0, 0x24(%rdi)
setne %bpl
je 0x6dd2
movq %rbx, 0x10(%rsp)
xorl %r13d, %r13d
addq $0x18, %rdi
movl %r13d, %esi
movq %r12, %rdx
callq 0xec6f
movq 0x18(%rsp), %rbx
movq (%rsp), %rdi
addq $0x60, %rdi
movl %r13d, %esi
movq %r12, %rdx
callq 0xec6f
movl 0x18(%rsp), %r15d
movq %r14, %rdi
callq 0x20e0
leaq 0x1(%rax), %rdx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x20f0
testl %eax, %eax
jne 0x6d8f
movswl %r15w, %eax
cmpl 0x8(%rsp), %eax
je 0x6da2
incl %r13d
movq (%rsp), %rdi
cmpl 0x24(%rdi), %r13d
setb %bpl
jb 0x6d3e
jmp 0x6dcd
movq (%rsp), %rdi
incl 0x150(%rdi)
addq $0x158, %rdi            # imm = 0x158
callq 0x2190
leaq 0x125f1(%rip), %rdi     # 0x193b0
callq 0x2190
movq (%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x10(%rsp), %rbx
testb $0x1, %bpl
jne 0x6e55
movq (%rsp), %rdi
movl $0x158, %eax            # imm = 0x158
addq %rax, %rdi
callq 0x2190
movq (%rbx), %rbx
testq %rbx, %rbx
jne 0x6d14
leaq 0x125b4(%rip), %rdi     # 0x193b0
callq 0x2190
callq 0x6bbc
movq %rax, (%rsp)
testq %rax, %rax
je 0x6e5c
movq %rax, %rdi
movq %r14, %rsi
movl 0x8(%rsp), %edx
movl 0xc(%rsp), %ecx
callq 0x6e9d
testl %eax, %eax
je 0x6e97
leaq 0x1049b(%rip), %rcx     # 0x172c8
cmpl $0x0, (%rcx)
js 0x6e4b
leaq 0x10497(%rip), %rcx     # 0x172d0
movq (%rcx), %rcx
leaq 0x9b06(%rip), %rsi      # 0x10949
xorl %edi, %edi
movl %eax, %edx
xorl %eax, %eax
callq *%rcx
movq %rsp, %rdi
callq 0x70fa
jmp 0x6e83
movq 0x20(%rsp), %rbx
jmp 0x6e85
leaq 0x10465(%rip), %rax     # 0x172c8
cmpl $0x0, (%rax)
js 0x6e83
leaq 0x10461(%rip), %rax     # 0x172d0
movq (%rax), %rcx
leaq 0x9aa7(%rip), %rsi      # 0x10920
xorl %ebx, %ebx
xorl %edi, %edi
xorl %eax, %eax
callq *%rcx
jmp 0x6e85
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rsp), %rbx
jmp 0x6e85