// File: /workspace/github_c_makefile_star2_O2/Tarsnap[P]kivaloo/lbs/worker.c
// Function: worker_create
struct workctl *
worker_create(size_t ID, struct storage_state * sstate, int wakeupsock)
{
	struct workctl * ctl;
	int rc;

	/* Allocate a worker structure. */
	if ((ctl = malloc(sizeof(struct workctl))) == NULL)
		goto err0;

	/*
	 * Create and lock mutex.  Locking the mutex here is arguably rather
	 * silly, since we're the only thread with access to the workctl
	 * structure right now; but theoretically pthread_create could launch
	 * a new thread on a different CPU without any memory barriers, which
	 * would -- given sufficient re-ordering of memory accesses -- result
	 * in it reading pre-initialization values from the structure.
	 */
	if ((rc = pthread_mutex_init(&ctl->mtx, NULL)) != 0) {
		warn0("pthread_mutex_init: %s", strerror(rc));
		goto err1;
	}
	if ((rc = pthread_mutex_lock(&ctl->mtx)) != 0) {
		warn0("pthread_mutex_lock: %s", strerror(rc));
		goto err2;
	}

	/* Create has-work condition variable. */
	if ((rc = pthread_cond_init(&ctl->cv, NULL)) != 0) {
		warn0("pthread_cond_init: %s", strerror(rc));
		goto err3;
	}

	/* No work to do, no work finished yet, no need to suicide. */
	ctl->haswork = ctl->workdone = ctl->suicide = 0;

	/* Static state data. */
	ctl->ID = ID;
	ctl->sstate = sstate;
	ctl->wakeupsock = wakeupsock;

	/* Create the thread. */
	if ((rc = pthread_create(&ctl->thr, NULL, workthread, ctl)) != 0) {
		warn0("pthread_create: %s", strerror(rc));
		goto err4;
	}

	/* Unlock the mutex. */
	if ((rc = pthread_mutex_unlock(&ctl->mtx)) != 0) {
		warn0("pthread_mutex_unlock: %s", strerror(rc));
		goto err0;
	}

	/* Success! */
	return (ctl);

err4:
	pthread_cond_destroy(&ctl->cv);
err3:
	pthread_mutex_unlock(&ctl->mtx);
err2:
	pthread_mutex_destroy(&ctl->mtx);
err1:
	free(ctl);
err0:
	/* Failure! */
	return (NULL);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %edx, %ebp
movq %rsi, %r15
movq %rdi, %r12
movl $0xb0, %edi
callq 0x2380
testq %rax, %rax
je 0x4031
movq %rax, %rbx
movq %rax, %rdi
xorl %esi, %esi
callq 0x2530
testl %eax, %eax
je 0x3f59
movl %eax, %edi
callq 0x2520
leaq 0x87a9(%rip), %rdi      # 0xc6eb
movq %rax, %rsi
xorl %eax, %eax
callq 0x9ec8
callq 0x20a0
andl $0x0, (%rax)
jmp 0x4029
movq %rbx, %rdi
callq 0x2550
testl %eax, %eax
je 0x3f8a
movl %eax, %edi
callq 0x2520
leaq 0x878f(%rip), %rdi      # 0xc702
movq %rax, %rsi
xorl %eax, %eax
callq 0x9ec8
callq 0x20a0
andl $0x0, (%rax)
jmp 0x4021
leaq 0x30(%rbx), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x2350
testl %eax, %eax
je 0x3fbe
movl %eax, %edi
callq 0x2520
leaq 0x876f(%rip), %rdi      # 0xc719
movq %rax, %rsi
xorl %eax, %eax
callq 0x9ec8
callq 0x20a0
andl $0x0, (%rax)
jmp 0x4019
andl $0x0, 0x68(%rbx)
andq $0x0, 0x60(%rbx)
movq %r12, 0x70(%rbx)
movq %r15, 0x80(%rbx)
movl %ebp, 0x78(%rbx)
movq %rbx, %rdi
addq $0x28, %rdi
leaq 0x8c(%rip), %rdx        # 0x406f
xorl %esi, %esi
movq %rbx, %rcx
callq 0x2420
testl %eax, %eax
je 0x403f
movl %eax, %edi
callq 0x2520
leaq 0x8730(%rip), %rdi      # 0xc72f
movq %rax, %rsi
xorl %eax, %eax
callq 0x9ec8
callq 0x20a0
andl $0x0, (%rax)
movq %r14, %rdi
callq 0x2450
movq %rbx, %rdi
callq 0x2370
movq %rbx, %rdi
callq 0x21d0
movq %rbx, %rdi
callq 0x2040
xorl %ebx, %ebx
movq %rbx, %rax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0x2370
testl %eax, %eax
je 0x4033
movl %eax, %edi
callq 0x2520
leaq 0x86e9(%rip), %rdi      # 0xc742
xorl %ebx, %ebx
movq %rax, %rsi
xorl %eax, %eax
callq 0x9ec8
callq 0x20a0
andl $0x0, (%rax)
jmp 0x4033