// File: /workspace/github_c_makefile_star2_O1/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 0x4693
movq %rax, %rbx
movq %rax, %rdi
xorl %esi, %esi
callq 0x2530
testl %eax, %eax
je 0x45ac
movl %eax, %edi
callq 0x2520
leaq 0x919d(%rip), %rdi      # 0xd72f
movq %rax, %rsi
xorl %eax, %eax
callq 0xad37
callq 0x20a0
movl $0x0, (%rax)
jmp 0x468b
movq %rbx, %rdi
callq 0x2550
testl %eax, %eax
je 0x45e0
movl %eax, %edi
callq 0x2520
leaq 0x9180(%rip), %rdi      # 0xd746
movq %rax, %rsi
xorl %eax, %eax
callq 0xad37
callq 0x20a0
movl $0x0, (%rax)
jmp 0x4683
leaq 0x30(%rbx), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x2350
testl %eax, %eax
je 0x4617
movl %eax, %edi
callq 0x2520
leaq 0x915d(%rip), %rdi      # 0xd75d
movq %rax, %rsi
xorl %eax, %eax
callq 0xad37
callq 0x20a0
movl $0x0, (%rax)
jmp 0x467b
movl $0x0, 0x68(%rbx)
movq $0x0, 0x60(%rbx)
movq %r12, 0x70(%rbx)
movq %r15, 0x80(%rbx)
movl %ebp, 0x78(%rbx)
movq %rbx, %rdi
addq $0x28, %rdi
leaq 0x92(%rip), %rdx        # 0x46d4
xorl %esi, %esi
movq %rbx, %rcx
callq 0x2420
testl %eax, %eax
je 0x46a1
movl %eax, %edi
callq 0x2520
leaq 0x9115(%rip), %rdi      # 0xd773
movq %rax, %rsi
xorl %eax, %eax
callq 0xad37
callq 0x20a0
movl $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 0x4695
movl %eax, %edi
callq 0x2520
leaq 0x90cb(%rip), %rdi      # 0xd786
xorl %ebx, %ebx
movq %rax, %rsi
xorl %eax, %eax
callq 0xad37
callq 0x20a0
movl $0x0, (%rax)
jmp 0x4695