// File: /workspace/github_c_makefile_star2_O1/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 0xe015(%rip), %rdi      # 0x19600
addq $0x10, %rdi
callq 0x23b0
cmpb $0x1, 0xdff5(%rip)      # 0x195f0
je 0xbc79
movl %eax, %ebx
testl %eax, %eax
je 0xb623
cmpl $0x82, %ebx
jne 0xbc56
movq 0xdfe6(%rip), %rdi      # 0x19600
addq $0x10, %rdi
callq 0x21f0
leaq 0xbc9e(%rip), %rax      # 0x172c8
movl (%rax), %eax
cmpl $0x3, %eax
jl 0xb655
leaq 0xbc98(%rip), %rax      # 0x172d0
movq (%rax), %r14
callq 0x23a0
leaq 0x5f05(%rip), %rsi      # 0x1154c
movl $0x3, %edi
movl %eax, %edx
movl %ebx, %ecx
xorl %eax, %eax
callq *%r14
movb $0x1, 0xdfb4(%rip)      # 0x19610
cmpb $0x0, 0xdf8d(%rip)      # 0x195f0
jne 0xbc4f
movzbl 0xdf88(%rip), %edi      # 0x195f8
callq 0x2180
cmpb $0x0, 0xdf74(%rip)      # 0x195f0
jne 0xbc4f
leaq 0xdd4f(%rip), %rax      # 0x193d8
movq (%rax), %r14
testq %r14, %r14
je 0xbc42
callq 0x23a0
cltq
movq 0xdf5d(%rip), %rcx      # 0x19600
movq %rax, (%rcx)
leaq 0x158(%r14), %r15
movq %r15, %rdi
callq 0x23b0
movslq 0x104(%r14), %rbx
testq %rbx, %rbx
movq %r14, 0x38(%rsp)
jle 0xbc2d
movq %r15, 0x8(%rsp)
cmpl %ebx, 0xdf4b(%rip)      # 0x19620
jge 0xb6fe
movq 0xdf3a(%rip), %rdi      # 0x19618
testq %rdi, %rdi
je 0xb6e8
callq 0x22c0
imulq $0x58, %rbx, %rdi
callq 0x22e0
movq %rax, 0xdf20(%rip)      # 0x19618
movl %ebx, 0xdf22(%rip)      # 0x19620
leaq 0xf8(%r14), %rax
movq %rax, 0x10(%rsp)
movq 0xdf07(%rip), %rax      # 0x19618
cmpl $0x2, %ebx
movl $0x1, %ecx
cmovgel %ebx, %ecx
movq %rcx, 0x30(%rsp)
movq %rax, 0x28(%rsp)
leaq 0x14(%rax), %r15
movq %r15, 0x18(%rsp)
xorl %r12d, %r12d
movq 0x10(%rsp), %rdi
movl %r12d, %esi
leaq 0x58(%rsp), %rdx
callq 0xec6f
movq 0x58(%rsp), %r13
imulq $0x58, %r12, %rbx
movq 0x28(%rsp), %r14
leaq (%r14,%rbx), %rbp
movq %rbp, %rdi
movq %r13, %rsi
movl $0x14, %edx
callq 0xbe84
movl 0x2c(%r13), %ecx
movl %ecx, 0x54(%r14,%rbx)
cmpl $0x5, %ecx
jl 0xb7a7
leaq 0xbb4d(%rip), %rax      # 0x172c8
movl (%rax), %eax
cmpl $0x3, %eax
jl 0xb7a0
leaq 0xbb47(%rip), %rax      # 0x172d0
movq (%rax), %r8
movl $0x3, %edi
leaq 0x5df6(%rip), %rsi      # 0x1158e
movq %r13, %rdx
xorl %eax, %eax
callq *%r8
movl $0x4, 0x54(%rbp)
cmpl $0x0, 0x54(%rbp)
jle 0xb7de
addq $0x20, %r13
movq %r15, %r14
xorl %ebx, %ebx
movq %r13, %rdi
movl %ebx, %esi
callq 0xeccf
movq (%rax), %rcx
movq 0x8(%rax), %rax
movq %rax, 0x8(%r14)
movq %rcx, (%r14)
incq %rbx
movslq 0x54(%rbp), %rax
addq $0x10, %r14
cmpq %rax, %rbx
jl 0xb7b6
incq %r12
addq $0x58, %r15
cmpq 0x30(%rsp), %r12
jne 0xb732
movq 0x8(%rsp), %rdi
callq 0x2190
movq 0x28(%rsp), %rax
leaq 0x24(%rax), %r13
xorl %r12d, %r12d
imulq $0x58, %r12, %rbp
addq 0x28(%rsp), %rbp
movq 0xddea(%rip), %rbx      # 0x19600
cmpl $0x0, 0xc(%rbx)
je 0xb991
leaq 0x14(%rbp), %rax
movq %rax, 0x10(%rsp)
movslq 0x54(%rbp), %r14
testq %r14, %r14
setle %al
jle 0xb877
movq 0x10(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0xbf60
testl %eax, %eax
je 0xb87f
movl $0x1, %ecx
movq %r13, %rbx
movq %rcx, %r15
cmpq %rcx, %r14
je 0xb871
movq %rbx, %rdi
leaq 0x58(%rsp), %rsi
callq 0xbf60
leaq 0x1(%r15), %rcx
addq $0x10, %rbx
testl %eax, %eax
jne 0xb850
cmpq %r14, %r15
setae %al
testb %al, %al
jne 0xbc06
movq %rbp, %rdi
callq 0xbcf6
movq %rax, %rbx
testq %rax, %rax
movq %rax, %r15
jne 0xba00
movq 0xdd63(%rip), %rax      # 0x19600
movslq 0x8(%rax), %rcx
movl 0xdd2d(%rip), %edx      # 0x195d4
cmpl %edx, %ecx
jge 0xb9d1
imulq $0x2f9068, %rcx, %rcx   # imm = 0x2F9068
leaq 0x38(%rax,%rcx), %r15
movl 0x54(%rbp), %eax
movl %eax, 0x68(%r15)
cmpl $0x0, 0x54(%rbp)
leaq 0x40(%rsp), %r14
movq 0x18(%rsp), %rdi
jle 0xb8f8
xorl %eax, %eax
xorl %ecx, %ecx
movq (%rdi,%rax), %rdx
movq 0x8(%rdi,%rax), %rsi
movq %rsi, 0x8(%r15,%rax)
movq %rdx, (%r15,%rax)
incq %rcx
movslq 0x54(%rbp), %rdx
addq $0x10, %rax
cmpq %rdx, %rcx
jl 0xb8d6
callq 0x23a0
cltq
movq 0xdcfa(%rip), %rcx      # 0x19600
cmpq %rax, (%rcx)
jne 0xb9f7
movq %r14, %rdi
callq 0x2050
movq %r14, %rdi
movl $0x1, %esi
callq 0x2300
movq %r14, %rdi
movl $0x1, %esi
callq 0x21e0
leaq 0x40(%r15), %rdi
movq %r14, %rsi
callq 0x2400
testl %eax, %eax
je 0xbc20
movl %eax, 0x20(%rsp)
leaq 0xb978(%rip), %rax      # 0x172c8
cmpl $0x0, (%rax)
jle 0xb980
leaq 0xb974(%rip), %rax      # 0x172d0
movq %rbx, 0x8(%rsp)
movq (%rax), %rbx
callq 0x23a0
movl $0x1, %edi
leaq 0x5cf6(%rip), %rsi      # 0x1166b
movl %eax, %edx
xorl %eax, %eax
callq *%rbx
movq 0x8(%rsp), %rbx
movq %r14, %rdi
callq 0x23f0
cmpl $0x0, 0x20(%rsp)
jne 0xb9f4
jmp 0xb9f7
movslq 0x54(%rbp), %r14
testq %r14, %r14
jle 0xb820
addq $0xc, %rbx
decq %r14
movq 0x18(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0xc4c3
subq $0x1, %r14
setb %cl
testl %eax, %eax
je 0xb820
addq $0x10, %r15
testb %cl, %cl
je 0xb9aa
jmp 0xb820
leaq 0xb8f0(%rip), %rax      # 0x172c8
cmpl $0x0, (%rax)
js 0xb9f4
leaq 0xb8ec(%rip), %rax      # 0x172d0
movq (%rax), %rcx
xorl %edi, %edi
leaq 0x5c55(%rip), %rsi      # 0x11645
xorl %eax, %eax
callq *%rcx
xorl %r15d, %r15d
testq %r15, %r15
je 0xbbfc
movq %rbx, 0x8(%rsp)
movq %r15, %rdi
callq 0xbc80
movl 0x54(%rbp), %eax
cmpl 0x68(%r15), %eax
movq 0x18(%rsp), %rdi
je 0xba4b
movl %eax, 0x68(%r15)
cmpl $0x0, 0x54(%rbp)
jle 0xba4b
xorl %eax, %eax
xorl %ecx, %ecx
movq (%rdi,%rax), %rdx
movq 0x8(%rdi,%rax), %rsi
movq %rsi, 0x8(%r15,%rax)
movq %rdx, (%r15,%rax)
incq %rcx
movslq 0x54(%rbp), %rdx
addq $0x10, %rax
cmpq %rdx, %rcx
jl 0xba29
leaq 0x70(%r15), %rdi
leaq 0x60(%rsp), %rsi
movl $0x14, %edx
callq 0xbe84
movl 0x6c(%r15), %r14d
movl 0x80(%rsp), %ebx
cmpl %ebx, %r14d
je 0xba72
movl %ebx, 0x6c(%r15)
leaq 0x84(%r15), %rdi
movq 0x78(%rsp), %rsi
movl $0xfe1, %edx            # imm = 0xFE1
callq 0xbe84
testb %al, %al
je 0xbab7
leaq 0xb835(%rip), %rax      # 0x172c8
cmpl $0x0, (%rax)
jle 0xbab7
leaq 0xb831(%rip), %rax      # 0x172d0
movq (%rax), %rcx
movl $0xfe1, %edx            # imm = 0xFE1
movl $0x1, %edi
leaq 0x5b0a(%rip), %rsi      # 0x115bd
xorl %eax, %eax
callq *%rcx
movb 0x84(%rsp), %al
movb %al, 0x2f9067(%r15)
leaq 0x40(%r15), %rdi
movq %rdi, 0x20(%rsp)
callq 0x2190
leaq 0x58(%rsp), %rdi
callq 0xc0d3
cmpq $0x0, 0x8(%rsp)
jne 0xbaef
movq 0xdb14(%rip), %rax      # 0x19600
incl 0x8(%rax)
cmpl %ebx, %r14d
je 0xbc06
movslq 0x54(%rbp), %r14
testq %r14, %r14
setle %al
jle 0xbb46
movq 0x10(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0xc1cd
testl %eax, %eax
je 0xbb4e
movl $0x1, %ecx
movq %r13, %rbx
movq %rcx, %rbp
cmpq %rcx, %r14
je 0xbb40
movq %rbx, %rdi
leaq 0x40(%rsp), %rsi
callq 0xc1cd
leaq 0x1(%rbp), %rcx
addq $0x10, %rbx
testl %eax, %eax
jne 0xbb1f
cmpq %r14, %rbp
setae %al
testb %al, %al
jne 0xbc06
movq %r15, %rdi
callq 0xbc80
leaq 0x1065(%r15), %rdi
movq 0x48(%rsp), %rsi
movl $0x17c001, %edx         # imm = 0x17C001
callq 0xbe84
testb %al, %al
je 0xbb9b
leaq 0xb751(%rip), %rax      # 0x172c8
cmpl $0x0, (%rax)
jle 0xbb9b
leaq 0xb74d(%rip), %rax      # 0x172d0
movq (%rax), %rcx
movl $0x17c001, %edx         # imm = 0x17C001
movl $0x1, %edi
leaq 0x5a4b(%rip), %rsi      # 0x115e2
xorl %eax, %eax
callq *%rcx
addq $0x17d066, %r15         # imm = 0x17D066
movq 0x50(%rsp), %rsi
movq %r15, %rdi
movl $0x17c001, %edx         # imm = 0x17C001
callq 0xbe84
testb %al, %al
leaq 0x40(%rsp), %rbx
je 0xbbe8
leaq 0xb704(%rip), %rax      # 0x172c8
cmpl $0x0, (%rax)
jle 0xbbe8
leaq 0xb700(%rip), %rax      # 0x172d0
movq (%rax), %rcx
movl $0x17c001, %edx         # imm = 0x17C001
movl $0x1, %edi
leaq 0x5a30(%rip), %rsi      # 0x11614
xorl %eax, %eax
callq *%rcx
movq 0x20(%rsp), %rdi
callq 0x2190
movq %rbx, %rdi
callq 0xc2e0
jmp 0xbc06
leaq 0x58(%rsp), %rdi
callq 0xc0d3
incq %r12
addq $0x58, 0x18(%rsp)
addq $0x58, %r13
cmpq 0x30(%rsp), %r12
jne 0xb806
jmp 0xbc35
movq %r14, %rdi
callq 0x23f0
jmp 0xb9f7
movq %r15, %rdi
callq 0x2190
movq 0x38(%rsp), %r14
movq (%r14), %r14
jmp 0xb68c
cmpb $0x1, 0xd9a7(%rip)      # 0x195f0
jne 0xb669
callq 0xbe57
jmp 0xbc79
leaq 0xb66b(%rip), %rax      # 0x172c8
cmpl $0x0, (%rax)
js 0xbc79
leaq 0xb667(%rip), %rax      # 0x172d0
movq (%rax), %rcx
leaq 0x589c(%rip), %rsi      # 0x1150f
xorl %edi, %edi
xorl %eax, %eax
callq *%rcx
xorl %edi, %edi
callq 0x24c0