// File: /workspace/github_c_makefile_star2_O0/sharpyfox[P]citrusleaf-client/src/cl_shm.c
// Function: cl_shm_node_ping
static int
cl_shm_node_ping(cl_seed_node* seed)
{
	// cf_debug("Ping %s", seed->name);

	// Set partition_count only once.
	if (g_shm_pt->partition_count == 0) {
		cl_shm_request_n_partitions(seed->address_array, seed->address_count, &g_shm_pt->partition_count);
	}

	// Request node information.
	cl_node_info request;

	if (cl_shm_request_node_info(seed->address_array, seed->address_count, &request) != SHM_OK) {
		return -1;
	}

	shm_ninfo* shared = cl_shm_find_node_from_name(seed->name);
	bool add = false;

	if (shared == 0) {
		add = true;
		shared = cl_shm_add_node(seed);

		if (shared == 0) {
			cl_node_info_free(&request);
			return -2;
		}
	}

	cl_shm_node_lock(shared);

	if (seed->address_count != shared->address_count) {
		cl_shm_copy_addresses(seed, shared);
	}

	// Set node name.
	cl_strncpy(shared->node_name, request.node_name, sizeof(shared->node_name));

	// Set partition generation after determining if replicas should be requested.
	bool request_replicas = false;
	if (shared->partition_generation != request.partition_generation) {
		shared->partition_generation = request.partition_generation;
		request_replicas = true;
	}

	if (cl_strncpy(shared->services, request.services, sizeof(shared->services))) {
		cf_warn("Shared memory services full: size=%d", sizeof(shared->services));
	}
	shared->dun = request.dun;

	cl_shm_node_unlock(shared);
	cl_node_info_free(&request);

	if (add) {
		// A new node was added, increase the count
		g_shm_pt->node_count++;
	}

	// Request replicas only if necessary.
	if (request_replicas) {
		cl_replicas replicas;

		if (cl_shm_request_replicas(seed->address_array, seed->address_count, &replicas) != SHM_OK) {
			return -3;
		}

		cl_shm_node_lock(shared);

		if (cl_strncpy(shared->write_replicas, replicas.write_replicas, sizeof(shared->write_replicas))) {
			cf_warn("Shared memory write replicas buffer full: size=%d", sizeof(shared->write_replicas));
		}

		if (cl_strncpy(shared->read_replicas, replicas.read_replicas, sizeof(shared->read_replicas))) {
			cf_warn("Shared memory read replicas buffer full: size=%d", sizeof(shared->read_replicas));
		}

		cl_shm_node_unlock(shared);
		cl_replicas_free(&replicas);
	}
	return SHM_OK;
}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x58(%rsp)
movq 0xe880(%rip), %rax      # 0x20610
cmpl $0x0, 0xc(%rax)
jne 0x11db7
movq 0x58(%rsp), %rdi
addq $0x14, %rdi
movq 0x58(%rsp), %rax
movl 0x54(%rax), %esi
movq 0xe862(%rip), %rdx      # 0x20610
addq $0xc, %rdx
callq 0x12040
movq 0x58(%rsp), %rdi
addq $0x14, %rdi
movq 0x58(%rsp), %rax
movl 0x54(%rax), %esi
leaq 0x28(%rsp), %rdx
callq 0x120b0
cmpl $0x0, %eax
je 0x11de4
movl $0xffffffff, 0x64(%rsp) # imm = 0xFFFFFFFF
jmp 0x12033
movq 0x58(%rsp), %rdi
callq 0x118e0
movq %rax, 0x20(%rsp)
movb $0x0, 0x1f(%rsp)
cmpq $0x0, 0x20(%rsp)
jne 0x11e35
movb $0x1, 0x1f(%rsp)
movq 0x58(%rsp), %rdi
callq 0x12120
movq %rax, 0x20(%rsp)
cmpq $0x0, 0x20(%rsp)
jne 0x11e33
leaq 0x28(%rsp), %rdi
callq 0x12770
movl $0xfffffffe, 0x64(%rsp) # imm = 0xFFFFFFFE
jmp 0x12033
jmp 0x11e35
movq 0x20(%rsp), %rdi
callq 0x11820
movq 0x58(%rsp), %rax
movl 0x54(%rax), %eax
movq 0x20(%rsp), %rcx
cmpl 0x68(%rcx), %eax
je 0x11e60
movq 0x58(%rsp), %rdi
movq 0x20(%rsp), %rsi
callq 0x12280
movq 0x20(%rsp), %rdi
addq $0x70, %rdi
leaq 0x28(%rsp), %rsi
addq $0x8, %rsi
movl $0x14, %edx
callq 0x12370
movb $0x0, 0x1e(%rsp)
movq 0x20(%rsp), %rax
movl 0x6c(%rax), %eax
cmpl 0x50(%rsp), %eax
je 0x11ea0
movl 0x50(%rsp), %ecx
movq 0x20(%rsp), %rax
movl %ecx, 0x6c(%rax)
movb $0x1, 0x1e(%rsp)
movq 0x20(%rsp), %rdi
addq $0x84, %rdi
movq 0x48(%rsp), %rsi
movl $0xfe1, %edx            # imm = 0xFE1
callq 0x12370
testb $0x1, %al
jne 0x11ec1
jmp 0x11ef4
leaq 0xc410(%rip), %rax      # 0x1e2d8
movl (%rax), %ecx
movl $0x1, %eax
cmpl %ecx, %eax
jg 0x11ef2
leaq 0xc406(%rip), %rax      # 0x1e2e0
movq (%rax), %rcx
movl $0x1, %edi
leaq 0x775b(%rip), %rsi      # 0x19644
movl $0xfe1, %edx            # imm = 0xFE1
movb $0x0, %al
callq *%rcx
jmp 0x11ef4
movb 0x54(%rsp), %cl
movq 0x20(%rsp), %rax
andb $0x1, %cl
movb %cl, 0x2f9067(%rax)
movq 0x20(%rsp), %rdi
callq 0x118b0
leaq 0x28(%rsp), %rdi
callq 0x12770
testb $0x1, 0x1f(%rsp)
je 0x11f31
movq 0xe6e8(%rip), %rax      # 0x20610
movl 0x8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x8(%rax)
testb $0x1, 0x1e(%rsp)
je 0x1202b
movq 0x58(%rsp), %rdi
addq $0x14, %rdi
movq 0x58(%rsp), %rax
movl 0x54(%rax), %esi
movq %rsp, %rdx
callq 0x12300
cmpl $0x0, %eax
je 0x11f67
movl $0xfffffffd, 0x64(%rsp) # imm = 0xFFFFFFFD
jmp 0x12033
movq 0x20(%rsp), %rdi
callq 0x11820
movq 0x20(%rsp), %rdi
addq $0x1065, %rdi           # imm = 0x1065
movq 0x8(%rsp), %rsi
movl $0x17c001, %edx         # imm = 0x17C001
callq 0x12370
testb $0x1, %al
jne 0x11f92
jmp 0x11fc5
leaq 0xc33f(%rip), %rax      # 0x1e2d8
movl (%rax), %ecx
movl $0x1, %eax
cmpl %ecx, %eax
jg 0x11fc3
leaq 0xc335(%rip), %rax      # 0x1e2e0
movq (%rax), %rcx
movl $0x1, %edi
leaq 0x76af(%rip), %rsi      # 0x19669
movl $0x17c001, %edx         # imm = 0x17C001
movb $0x0, %al
callq *%rcx
jmp 0x11fc5
movq 0x20(%rsp), %rdi
addq $0x17d066, %rdi         # imm = 0x17D066
movq 0x10(%rsp), %rsi
movl $0x17c001, %edx         # imm = 0x17C001
callq 0x12370
testb $0x1, %al
jne 0x11fe6
jmp 0x12019
leaq 0xc2eb(%rip), %rax      # 0x1e2d8
movl (%rax), %ecx
movl $0x1, %eax
cmpl %ecx, %eax
jg 0x12017
leaq 0xc2e1(%rip), %rax      # 0x1e2e0
movq (%rax), %rcx
movl $0x1, %edi
leaq 0x768d(%rip), %rsi      # 0x1969b
movl $0x17c001, %edx         # imm = 0x17C001
movb $0x0, %al
callq *%rcx
jmp 0x12019
movq 0x20(%rsp), %rdi
callq 0x118b0
movq %rsp, %rdi
callq 0x12a20
movl $0x0, 0x64(%rsp)
movl 0x64(%rsp), %eax
addq $0x68, %rsp
retq
nopl (%rax)