// File: /workspace/github_c_makefile_star2_O3/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 0x46af
movq %rax, %rbx
movq %rax, %rdi
xorl %esi, %esi
callq 0x2530
testl %eax, %eax
je 0x45c8
movl %eax, %edi
callq 0x2520
leaq 0x9101(%rip), %rdi      # 0xd6af
movq %rax, %rsi
xorl %eax, %eax
callq 0xadf7
callq 0x20a0
movl $0x0, (%rax)
jmp 0x46a7
movq %rbx, %rdi
callq 0x2550
testl %eax, %eax
je 0x45fc
movl %eax, %edi
callq 0x2520
leaq 0x90e4(%rip), %rdi      # 0xd6c6
movq %rax, %rsi
xorl %eax, %eax
callq 0xadf7
callq 0x20a0
movl $0x0, (%rax)
jmp 0x469f
leaq 0x30(%rbx), %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x2350
testl %eax, %eax
je 0x4633
movl %eax, %edi
callq 0x2520
leaq 0x90c1(%rip), %rdi      # 0xd6dd
movq %rax, %rsi
xorl %eax, %eax
callq 0xadf7
callq 0x20a0
movl $0x0, (%rax)
jmp 0x4697
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        # 0x46f0
xorl %esi, %esi
movq %rbx, %rcx
callq 0x2420
testl %eax, %eax
je 0x46bd
movl %eax, %edi
callq 0x2520
leaq 0x9079(%rip), %rdi      # 0xd6f3
movq %rax, %rsi
xorl %eax, %eax
callq 0xadf7
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 0x46b1
movl %eax, %edi
callq 0x2520
leaq 0x902f(%rip), %rdi      # 0xd706
xorl %ebx, %ebx
movq %rax, %rsi
xorl %eax, %eax
callq 0xadf7
callq 0x20a0
movl $0x0, (%rax)
jmp 0x46b1