// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl $0xb0, %edi
callq 0x23a0
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
jne 0x4eec
jmp 0x50a9
movq -0x28(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2540
movl %eax, -0x2c(%rbp)
cmpl $0x0, %eax
je 0x4f2c
jmp 0x4f03
movl -0x2c(%rbp), %edi
callq 0x2530
movq %rax, %rsi
leaq 0xd9ba(%rip), %rdi      # 0x128cf
movb $0x0, %al
callq 0xf2c0
callq 0x20a0
movl $0x0, (%rax)
jmp 0x50a0
movq -0x28(%rbp), %rdi
callq 0x2560
movl %eax, -0x2c(%rbp)
cmpl $0x0, %eax
je 0x4f68
jmp 0x4f3f
movl -0x2c(%rbp), %edi
callq 0x2530
movq %rax, %rsi
leaq 0xd995(%rip), %rdi      # 0x128e6
movb $0x0, %al
callq 0xf2c0
callq 0x20a0
movl $0x0, (%rax)
jmp 0x5097
movq -0x28(%rbp), %rdi
addq $0x30, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2370
movl %eax, -0x2c(%rbp)
cmpl $0x0, %eax
je 0x4fac
jmp 0x4f83
movl -0x2c(%rbp), %edi
callq 0x2530
movq %rax, %rsi
leaq 0xd968(%rip), %rdi      # 0x128fd
movb $0x0, %al
callq 0xf2c0
callq 0x20a0
movl $0x0, (%rax)
jmp 0x508e
movq -0x28(%rbp), %rax
movl $0x0, 0x68(%rax)
movq -0x28(%rbp), %rax
movl $0x0, 0x64(%rax)
movq -0x28(%rbp), %rax
movl $0x0, 0x60(%rax)
movq -0x10(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x70(%rax)
movq -0x18(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x80(%rax)
movl -0x1c(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x78(%rax)
movq -0x28(%rbp), %rdi
addq $0x28, %rdi
movq -0x28(%rbp), %rcx
xorl %eax, %eax
movl %eax, %esi
leaq 0xb7(%rip), %rdx        # 0x50c0
callq 0x2440
movl %eax, -0x2c(%rbp)
cmpl $0x0, %eax
je 0x503e
jmp 0x5018
movl -0x2c(%rbp), %edi
callq 0x2530
movq %rax, %rsi
leaq 0xd8e9(%rip), %rdi      # 0x12913
movb $0x0, %al
callq 0xf2c0
callq 0x20a0
movl $0x0, (%rax)
jmp 0x5081
movq -0x28(%rbp), %rdi
callq 0x2390
movl %eax, -0x2c(%rbp)
cmpl $0x0, %eax
je 0x5077
jmp 0x5051
movl -0x2c(%rbp), %edi
callq 0x2530
movq %rax, %rsi
leaq 0xd8c3(%rip), %rdi      # 0x12926
movb $0x0, %al
callq 0xf2c0
callq 0x20a0
movl $0x0, (%rax)
jmp 0x50a9
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x50b1
movq -0x28(%rbp), %rdi
addq $0x30, %rdi
callq 0x2470
movq -0x28(%rbp), %rdi
callq 0x2390
movq -0x28(%rbp), %rdi
callq 0x21f0
movq -0x28(%rbp), %rdi
callq 0x2040
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax,%rax)