// File: /workspace/github_c_makefile_star2_O3/sharpyfox[P]citrusleaf-client/src/cl_shm.c
// Function: cl_shm_updater_fn
void*
cl_shm_updater_fn(void* gas)
{
	//Take Lock - only one process can update
	int status = pthread_mutex_lock(&(g_shm_pt->shm_lock));

	if (g_shm_info.update_thread_end_cond) {
		pthread_exit(0);
	}

	/* There are only two valid cases when we can access the protected data
	 * 1. We get the lock without any error and
	 * 2. The thread holding the lock died without releasing it */
	if (status != 0) {
		/* Make the lock consistent if the last owner of the lock died while holding the lock */
		/* We should ideally clean the memory here and then make the lock consistent */
		if (status == EOWNERDEAD) {
			pthread_mutex_consistent_np(&(g_shm_pt->shm_lock));
		}
		else {
			/* With Robust mutexes the lock gets in not recoverable state when the process holding the lock
			 * dies and the other process that gets the lock unlocks it without making it consistent
			 * (via pthread_mutex_consistent function) */
			cf_error("Failed to lock shared memory in tend thread. Exiting thread.");
			pthread_exit(0);
		}
	}

	cf_debug("Process %d took over control with pthread_mutex_lock returning %d", getpid(), status);
	g_shm_updater = true;

	do {
		/* Check if the thread is set to exit or not. If it is, gracefully exit*/
		if (g_shm_info.update_thread_end_cond) {
			cl_shm_free_seed_array();
			pthread_exit(0);
		}

		sleep(g_shm_info.update_period);

		if (g_shm_info.update_thread_end_cond) {
			cl_shm_free_seed_array();
			pthread_exit(0);
		}

		// Tend all clusters.
		cf_ll_element *e = cf_ll_get_head(&cluster_ll);

		while(e) {
			cl_shm_update((cl_cluster*)e);
			e = cf_ll_get_next(e);
		}
	} while(1);

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq 0xd34f(%rip), %rdi      # 0x18600
addq $0x10, %rdi
callq 0x23b0
cmpb $0x1, 0xd32f(%rip)      # 0x185f0
je 0xb904
movl %eax, %ebx
testl %eax, %eax
je 0xb2e9
cmpl $0x82, %ebx
jne 0xb8e1
movq 0xd320(%rip), %rdi      # 0x18600
addq $0x10, %rdi
callq 0x21f0
leaq 0xafd8(%rip), %rax      # 0x162c8
movl (%rax), %eax
cmpl $0x3, %eax
jl 0xb31b
leaq 0xafd2(%rip), %rax      # 0x162d0
movq (%rax), %r14
callq 0x23a0
movl %eax, %edx
leaq 0x525d(%rip), %rsi      # 0x1056c
movl $0x3, %edi
movl %ebx, %ecx
xorl %eax, %eax
callq *%r14
movb $0x1, 0xd2ee(%rip)      # 0x18610
cmpb $0x0, 0xd2c7(%rip)      # 0x185f0
jne 0xb8da
movzbl 0xd2c2(%rip), %edi      # 0x185f8
callq 0x2180
cmpb $0x0, 0xd2ae(%rip)      # 0x185f0
jne 0xb8da
leaq 0xd089(%rip), %rax      # 0x183d8
movq (%rax), %rbx
testq %rbx, %rbx
je 0xb32f
callq 0x23a0
movq 0xd29d(%rip), %rcx      # 0x18600
leaq 0x158(%rbx), %r15
cltq
movq %r15, %rdi
movq %rax, (%rcx)
callq 0x23b0
movslq 0x104(%rbx), %r14
movq %rbx, 0x30(%rsp)
testq %r14, %r14
jle 0xb8bc
cmpl %r14d, 0xd28d(%rip)     # 0x18620
movq 0xd27e(%rip), %rbp      # 0x18618
movq %r15, 0x18(%rsp)
jge 0xb3c8
testq %rbp, %rbp
je 0xb3ae
movq %rbp, %rdi
callq 0x22c0
imulq $0x58, %r14, %rdi
callq 0x22e0
movq %rax, %rbp
movq %rax, 0xd257(%rip)      # 0x18618
movl %r14d, 0xd258(%rip)     # 0x18620
leaq 0xf8(%rbx), %rax
leaq 0x14(%rbp), %r15
xorl %r12d, %r12d
movq %rbp, 0x20(%rsp)
movq %r14, 0x28(%rsp)
movq %rax, 0x8(%rsp)
movq %r15, 0x10(%rsp)
movq 0x8(%rsp), %rdi
movl %r12d, %esi
leaq 0x58(%rsp), %rdx
callq 0xe7d4
movq 0x58(%rsp), %r13
imulq $0x58, %r12, %r14
movl $0x14, %edx
leaq (%rbp,%r14), %rbx
movq %rbx, %rdi
movq %r13, %rsi
callq 0xbac4
movl 0x2c(%r13), %ecx
cmpl $0x5, %ecx
movl %ecx, 0x54(%rbp,%r14)
jl 0xb45d
leaq 0xae99(%rip), %rax      # 0x162c8
movl (%rax), %eax
cmpl $0x3, %eax
jl 0xb454
leaq 0xae93(%rip), %rax      # 0x162d0
movl $0x3, %edi
leaq 0x5165(%rip), %rsi      # 0x105ae
movq %r13, %rdx
movq (%rax), %r8
xorl %eax, %eax
callq *%r8
movl $0x4, 0x54(%rbx)
jmp 0xb461
testl %ecx, %ecx
jle 0xb492
addq $0x20, %r13
movq %r15, %r14
xorl %ebp, %ebp
movq %r13, %rdi
movl %ebp, %esi
callq 0xe834
movq (%rax), %rcx
movq 0x8(%rax), %rax
incq %rbp
movq %rax, 0x8(%r14)
movq %rcx, (%r14)
addq $0x10, %r14
movslq 0x54(%rbx), %rax
cmpq %rax, %rbp
jl 0xb46a
movq 0x28(%rsp), %r14
movq 0x20(%rsp), %rbp
incq %r12
addq $0x58, %r15
cmpq %r14, %r12
jne 0xb3ea
movq 0x18(%rsp), %rdi
callq 0x2190
leaq 0x24(%rbp), %rax
xorl %r12d, %r12d
movq %rax, 0x8(%rsp)
movq 0xd137(%rip), %rbx      # 0x18600
imulq $0x58, %r12, %r13
addq %rbp, %r13
cmpl $0x0, 0xc(%rbx)
je 0xb73d
movslq 0x54(%r13), %r14
testq %r14, %r14
jle 0xb88e
leaq 0x14(%r13), %rdi
leaq 0x58(%rsp), %rsi
movq %rdi, 0x18(%rsp)
callq 0xbb9e
testl %eax, %eax
je 0xb533
movq 0x8(%rsp), %rbx
leaq -0x1(%r14), %r15
xorl %ebp, %ebp
cmpq %rbp, %r15
je 0xb88e
movq %rbx, %rdi
leaq 0x58(%rsp), %rsi
callq 0xbb9e
addq $0x10, %rbx
incq %rbp
testl %eax, %eax
jne 0xb509
cmpq %r14, %rbp
jae 0xb88e
movq %r13, %rdi
callq 0xb981
movq %rax, %rbp
testq %rax, %rax
movq %rax, %rbx
je 0xb77d
movq %rbx, %rdi
callq 0xb90b
movl 0x54(%r13), %eax
movq 0x10(%rsp), %rdi
cmpl 0x68(%rbx), %eax
je 0xb58d
testl %eax, %eax
movl %eax, 0x68(%rbx)
jle 0xb58d
xorl %eax, %eax
xorl %ecx, %ecx
movq (%rdi,%rax), %rdx
movq 0x8(%rdi,%rax), %rsi
incq %rcx
movq %rsi, 0x8(%rbx,%rax)
movq %rdx, (%rbx,%rax)
addq $0x10, %rax
movslq 0x54(%r13), %rdx
cmpq %rdx, %rcx
jl 0xb56b
leaq 0x70(%rbx), %rdi
leaq 0x60(%rsp), %rsi
movl $0x14, %edx
callq 0xbac4
movl 0x6c(%rbx), %r14d
movl 0x80(%rsp), %r15d
cmpl %r15d, %r14d
je 0xb5b5
movl %r15d, 0x6c(%rbx)
movq 0x78(%rsp), %rsi
leaq 0x84(%rbx), %rdi
movl $0xfe1, %edx            # imm = 0xFE1
callq 0xbac4
testb %al, %al
je 0xb5fa
leaq 0xacf2(%rip), %rax      # 0x162c8
cmpl $0x0, (%rax)
jle 0xb5fa
leaq 0xacee(%rip), %rax      # 0x162d0
movl $0xfe1, %edx            # imm = 0xFE1
movl $0x1, %edi
leaq 0x4fea(%rip), %rsi      # 0x105dd
movq (%rax), %rcx
xorl %eax, %eax
callq *%rcx
movb 0x84(%rsp), %al
leaq 0x40(%rbx), %rdi
movq %rdi, 0x38(%rsp)
movb %al, 0x2f9067(%rbx)
callq 0x2190
leaq 0x58(%rsp), %rdi
callq 0xbd06
testq %rbp, %rbp
jne 0xb62e
movq 0xcfd5(%rip), %rax      # 0x18600
incl 0x8(%rax)
cmpl %r15d, %r14d
je 0xb88e
movslq 0x54(%r13), %r14
testq %r14, %r14
jle 0xb88e
movq 0x18(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0xbe00
testl %eax, %eax
je 0xb68c
movq 0x8(%rsp), %r15
leaq -0x1(%r14), %r13
xorl %ebp, %ebp
cmpq %rbp, %r13
je 0xb88e
movq %r15, %rdi
leaq 0x40(%rsp), %rsi
callq 0xbe00
addq $0x10, %r15
incq %rbp
testl %eax, %eax
jne 0xb662
cmpq %r14, %rbp
jae 0xb88e
movq %rbx, %rdi
callq 0xb90b
movq 0x48(%rsp), %rsi
leaq 0x1065(%rbx), %rdi
movl $0x17c001, %edx         # imm = 0x17C001
callq 0xbac4
testb %al, %al
je 0xb6d9
leaq 0xac13(%rip), %rax      # 0x162c8
cmpl $0x0, (%rax)
jle 0xb6d9
leaq 0xac0f(%rip), %rax      # 0x162d0
movl $0x17c001, %edx         # imm = 0x17C001
movl $0x1, %edi
leaq 0x4f30(%rip), %rsi      # 0x10602
movq (%rax), %rcx
xorl %eax, %eax
callq *%rcx
movq 0x50(%rsp), %rsi
addq $0x17d066, %rbx         # imm = 0x17D066
movl $0x17c001, %edx         # imm = 0x17C001
movq %rbx, %rdi
callq 0xbac4
testb %al, %al
leaq 0x40(%rsp), %rbx
je 0xb726
leaq 0xabc6(%rip), %rax      # 0x162c8
cmpl $0x0, (%rax)
jle 0xb726
leaq 0xabc2(%rip), %rax      # 0x162d0
movl $0x17c001, %edx         # imm = 0x17C001
movl $0x1, %edi
leaq 0x4f15(%rip), %rsi      # 0x10634
movq (%rax), %rcx
xorl %eax, %eax
callq *%rcx
movq 0x38(%rsp), %rdi
callq 0x2190
movq %rbx, %rdi
callq 0xbf11
jmp 0xb88e
movslq 0x54(%r13), %r14
testq %r14, %r14
jle 0xb4da
movq 0x10(%rsp), %r15
addq $0xc, %rbx
decq %r14
movq %r15, %rdi
movq %rbx, %rsi
callq 0xc0ed
subq $0x1, %r14
setb %cl
testl %eax, %eax
je 0xb4da
addq $0x10, %r15
testb %cl, %cl
je 0xb756
jmp 0xb4da
movq 0xce7c(%rip), %rax      # 0x18600
movl 0xce4a(%rip), %edx      # 0x185d4
movslq 0x8(%rax), %rcx
cmpl %edx, %ecx
jge 0xb861
imulq $0x2f9068, %rcx, %rcx   # imm = 0x2F9068
movq 0x10(%rsp), %rdi
leaq 0x38(%rax,%rcx), %rbx
movl 0x54(%r13), %ecx
testl %ecx, %ecx
movl %ecx, 0x68(%rbx)
jle 0xb7d8
xorl %eax, %eax
xorl %ecx, %ecx
movq (%rdi,%rax), %rdx
movq 0x8(%rdi,%rax), %rsi
incq %rcx
movq %rsi, 0x8(%rbx,%rax)
movq %rdx, (%rbx,%rax)
addq $0x10, %rax
movslq 0x54(%r13), %rdx
cmpq %rdx, %rcx
jl 0xb7b6
callq 0x23a0
movq 0xce1c(%rip), %rcx      # 0x18600
cltq
cmpq %rax, (%rcx)
jne 0xb54a
leaq 0x40(%rsp), %r14
movq %r14, %rdi
callq 0x2050
movq %r14, %rdi
movl $0x1, %esi
callq 0x2300
movq %r14, %rdi
movl $0x1, %esi
callq 0x21e0
leaq 0x40(%rbx), %rdi
movq %r14, %rsi
callq 0x2400
testl %eax, %eax
je 0xb8af
leaq 0xaa97(%rip), %rax      # 0x162c8
cmpl $0x0, (%rax)
jle 0xb857
leaq 0xaa93(%rip), %rax      # 0x162d0
movq (%rax), %rbx
callq 0x23a0
movl %eax, %edx
movl $0x1, %edi
leaq 0x4e38(%rip), %rsi      # 0x1068b
xorl %eax, %eax
callq *%rbx
movq %r14, %rdi
callq 0x23f0
jmp 0xb884
leaq 0xaa60(%rip), %rax      # 0x162c8
cmpl $0x0, (%rax)
js 0xb884
leaq 0xaa5c(%rip), %rax      # 0x162d0
xorl %edi, %edi
leaq 0x4de8(%rip), %rsi      # 0x10665
movq (%rax), %rcx
xorl %eax, %eax
callq *%rcx
leaq 0x58(%rsp), %rdi
callq 0xbd06
incq %r12
addq $0x58, 0x10(%rsp)
addq $0x58, 0x8(%rsp)
movq 0x20(%rsp), %rbp
cmpq 0x28(%rsp), %r12
jne 0xb4c2
jmp 0xb8c4
movq %r14, %rdi
callq 0x23f0
jmp 0xb54a
movq %r15, %rdi
callq 0x2190
movq 0x30(%rsp), %rbx
movq (%rbx), %rbx
testq %rbx, %rbx
jne 0xb357
jmp 0xb322
callq 0xba98
jmp 0xb904
leaq 0xa9e0(%rip), %rax      # 0x162c8
cmpl $0x0, (%rax)
js 0xb904
leaq 0xa9dc(%rip), %rax      # 0x162d0
leaq 0x4c34(%rip), %rsi      # 0x1052f
xorl %edi, %edi
movq (%rax), %rcx
xorl %eax, %eax
callq *%rcx
xorl %edi, %edi
callq 0x24c0