// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x58, %rsp
movw %si, %ax
movq %rdi, 0x48(%rsp)
movw %ax, 0x46(%rsp)
movl %edx, 0x40(%rsp)
leaq 0x163ec(%rip), %rax     # 0x203b8
cmpl $0x0, (%rax)
jne 0x9fdf
movq $0x0, 0x50(%rsp)
jmp 0xa203
movq $0x0, 0x38(%rsp)
leaq 0x163d1(%rip), %rdi     # 0x203c0
callq 0x23e0
leaq 0x163ed(%rip), %rdi     # 0x203e8
callq 0xa210
movq %rax, 0x30(%rsp)
cmpq $0x0, 0x30(%rsp)
je 0xa144
movq 0x30(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rdi
addq $0x158, %rdi            # imm = 0x158
callq 0x23e0
movl $0x0, 0x20(%rsp)
movl 0x20(%rsp), %eax
movl %eax, 0x18(%rsp)
movq 0x38(%rsp), %rdi
addq $0x18, %rdi
callq 0x9da0
movl %eax, %ecx
movl 0x18(%rsp), %eax
cmpl %ecx, %eax
jae 0xa11f
movq 0x38(%rsp), %rdi
addq $0x18, %rdi
movl 0x20(%rsp), %esi
callq 0x9db0
movq %rax, 0x28(%rsp)
movq 0x38(%rsp), %rdi
addq $0x60, %rdi
movl 0x20(%rsp), %esi
callq 0xa220
movw %ax, 0x26(%rsp)
movq 0x48(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x28(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x48(%rsp), %rdi
callq 0x2100
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq %rax, %rdx
addq $0x1, %rdx
callq 0x2120
cmpl $0x0, %eax
jne 0xa10d
movswl 0x46(%rsp), %eax
movswl 0x26(%rsp), %ecx
cmpl %ecx, %eax
jne 0xa10d
movq 0x38(%rsp), %rax
movl 0x150(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x150(%rax)
movq 0x38(%rsp), %rdi
addq $0x158, %rdi            # imm = 0x158
callq 0x21c0
leaq 0x162c7(%rip), %rdi     # 0x203c0
callq 0x21c0
movq 0x38(%rsp), %rax
movq %rax, 0x50(%rsp)
jmp 0xa203
jmp 0xa10f
movl 0x20(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x20(%rsp)
jmp 0xa034
movq 0x38(%rsp), %rdi
addq $0x158, %rdi            # imm = 0x158
callq 0x21c0
movq 0x30(%rsp), %rdi
callq 0xa250
movq %rax, 0x30(%rsp)
jmp 0xa005
leaq 0x16275(%rip), %rdi     # 0x203c0
callq 0x21c0
callq 0x9de0
movq %rax, 0x38(%rsp)
cmpq $0x0, 0x38(%rsp)
jne 0xa193
leaq 0x1416f(%rip), %rax     # 0x1e2d8
movl (%rax), %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jg 0xa188
leaq 0x14168(%rip), %rax     # 0x1e2e0
movq (%rax), %rcx
xorl %edi, %edi
leaq 0xe806(%rip), %rsi      # 0x1898a
movb $0x0, %al
callq *%rcx
movq $0x0, 0x50(%rsp)
jmp 0xa203
movq 0x38(%rsp), %rdi
movq 0x48(%rsp), %rsi
movw 0x46(%rsp), %ax
movl 0x40(%rsp), %ecx
movswl %ax, %edx
callq 0xa260
movl %eax, 0x1c(%rsp)
xorl %eax, %eax
cmpl 0x1c(%rsp), %eax
je 0xa1f9
leaq 0x14117(%rip), %rax     # 0x1e2d8
movl (%rax), %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jg 0xa1e4
leaq 0x14110(%rip), %rax     # 0x1e2e0
movq (%rax), %rcx
movl 0x1c(%rsp), %edx
xorl %edi, %edi
leaq 0xe7d3(%rip), %rsi      # 0x189b3
movb $0x0, %al
callq *%rcx
leaq 0x38(%rsp), %rdi
callq 0xa620
movq $0x0, 0x50(%rsp)
jmp 0xa203
movq 0x38(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x50(%rsp), %rax
addq $0x58, %rsp
retq
nopl (%rax)