// File: /workspace/github_c_makefile_star2_O0/Tarsnap[P]kivaloo/lbs/worker.c
// Function: workthread
static void *
workthread(void * cookie)
{
	struct workctl * ctl = cookie;
	int rc;

	/* Grab the mutex. */
	if ((rc = pthread_mutex_lock(&ctl->mtx)) != 0) {
		warn0("pthread_mutex_lock: %s", strerror(rc));
		exit(1);
	}

	/* Infinite loop doing work until told to suicide. */
	do {
		/*
		 * Sleep until we have work which we haven't done yet or
		 * we need to kill ourself.
		 */
		while (((ctl->haswork == 0) || (ctl->workdone != 0)) &&
		    (ctl->suicide == 0)) {
			/* Sleep until we're woken up. */
			if ((rc = pthread_cond_wait(&ctl->cv,
			    &ctl->mtx)) != 0) {
				warn0("pthread_cond_wait: %s", strerror(rc));
				exit(1);
			}
		}

		/* If we need to kill ourself, stop looping. */
		if (ctl->suicide)
			break;

		/* Do the work. */
		switch (ctl->op) {
		case 0:	/* Read */
			if ((ctl->nblks = (size_t)storage_read(ctl->sstate,
			    ctl->blkno, ctl->buf)) == (size_t)(-1)) {
				warnp("Failure reading block");
				exit(1);
			}
			break;
		case 1:	/* Write */
			if (storage_write(ctl->sstate,
			    ctl->blkno, ctl->nblks, ctl->buf)) {
				warnp("Failure writing blocks");
				exit(1);
			}
			break;
		case 2:	/* Delete */
			if (storage_delete(ctl->sstate, ctl->blkno)) {
				warnp("Failure deleting blocks");
				exit(1);
			}
			break;
		default:
			warn0("Invalid op: %d", ctl->op);
		}

		/* We've done the work; notify the master thread. */
		ctl->workdone = 1;
		if (noeintr_write(ctl->wakeupsock, &ctl->ID, sizeof(size_t)) <
		    (ssize_t)sizeof(size_t)) {
			warnp("Error writing to wakeup socket");
			exit(1);
		}
	} while (1);

	/* Release the mutex and die. */
	if ((rc = pthread_mutex_unlock(&ctl->mtx)) != 0) {
		warn0("pthread_mutex_unlock: %s", strerror(rc));
		exit(1);
	}
	return (NULL);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2560
movl %eax, -0x14(%rbp)
cmpl $0x0, %eax
je 0x5115
jmp 0x50e7
movl -0x14(%rbp), %edi
callq 0x2530
movq %rax, %rsi
leaq 0xd7ed(%rip), %rdi      # 0x128e6
movb $0x0, %al
callq 0xf2c0
callq 0x20a0
movl $0x0, (%rax)
movl $0x1, %edi
callq 0x24e0
jmp 0x5117
jmp 0x5119
movq -0x10(%rbp), %rax
cmpl $0x0, 0x60(%rax)
je 0x5132
movq -0x10(%rbp), %rcx
xorl %eax, %eax
cmpl $0x0, 0x64(%rcx)
movb %al, -0x15(%rbp)
je 0x5140
movq -0x10(%rbp), %rax
cmpl $0x0, 0x68(%rax)
sete %al
movb %al, -0x15(%rbp)
movb -0x15(%rbp), %al
testb $0x1, %al
jne 0x5149
jmp 0x5194
movq -0x10(%rbp), %rdi
addq $0x30, %rdi
movq -0x10(%rbp), %rsi
callq 0x2180
movl %eax, -0x14(%rbp)
cmpl $0x0, %eax
je 0x5192
jmp 0x5164
movl -0x14(%rbp), %edi
callq 0x2530
movq %rax, %rsi
leaq 0xd90f(%rip), %rdi      # 0x12a85
movb $0x0, %al
callq 0xf2c0
callq 0x20a0
movl $0x0, (%rax)
movl $0x1, %edi
callq 0x24e0
jmp 0x5119
movq -0x10(%rbp), %rax
cmpl $0x0, 0x68(%rax)
je 0x51a3
jmp 0x53d3
movq -0x10(%rbp), %rax
movl 0x88(%rax), %eax
movl %eax, -0x1c(%rbp)
testl %eax, %eax
je 0x51d5
jmp 0x51b6
movl -0x1c(%rbp), %eax
subl $0x1, %eax
je 0x5254
jmp 0x51c4
movl -0x1c(%rbp), %eax
subl $0x2, %eax
je 0x52d0
jmp 0x5333
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x90(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0xa0(%rax), %rdx
callq 0x5c80
cltq
movq -0x10(%rbp), %rcx
movq %rax, 0x98(%rcx)
cmpq $-0x1, %rax
jne 0x524f
jmp 0x5210
callq 0x20a0
cmpl $0x0, (%rax)
je 0x5235
leaq 0xd87a(%rip), %rdi      # 0x12a9b
movb $0x0, %al
callq 0xf070
callq 0x20a0
movl $0x0, (%rax)
jmp 0x5243
leaq 0xd85f(%rip), %rdi      # 0x12a9b
movb $0x0, %al
callq 0xf2c0
jmp 0x5245
movl $0x1, %edi
callq 0x24e0
jmp 0x535a
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x90(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x98(%rax), %rdx
movq -0x10(%rbp), %rax
movq 0xa0(%rax), %rcx
callq 0x5e60
cmpl $0x0, %eax
je 0x52cb
jmp 0x528c
callq 0x20a0
cmpl $0x0, (%rax)
je 0x52b1
leaq 0xd814(%rip), %rdi      # 0x12ab1
movb $0x0, %al
callq 0xf070
callq 0x20a0
movl $0x0, (%rax)
jmp 0x52bf
leaq 0xd7f9(%rip), %rdi      # 0x12ab1
movb $0x0, %al
callq 0xf2c0
jmp 0x52c1
movl $0x1, %edi
callq 0x24e0
jmp 0x535a
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x90(%rax), %rsi
callq 0x6160
cmpl $0x0, %eax
je 0x5331
jmp 0x52f2
callq 0x20a0
cmpl $0x0, (%rax)
je 0x5317
leaq 0xd7c5(%rip), %rdi      # 0x12ac8
movb $0x0, %al
callq 0xf070
callq 0x20a0
movl $0x0, (%rax)
jmp 0x5325
leaq 0xd7aa(%rip), %rdi      # 0x12ac8
movb $0x0, %al
callq 0xf2c0
jmp 0x5327
movl $0x1, %edi
callq 0x24e0
jmp 0x535a
jmp 0x5335
movq -0x10(%rbp), %rax
movl 0x88(%rax), %esi
leaq 0xd79a(%rip), %rdi      # 0x12ae0
movb $0x0, %al
callq 0xf2c0
callq 0x20a0
movl $0x0, (%rax)
jmp 0x535a
movq -0x10(%rbp), %rax
movl $0x1, 0x64(%rax)
movq -0x10(%rbp), %rax
movl 0x78(%rax), %edi
movq -0x10(%rbp), %rsi
addq $0x70, %rsi
movl $0x8, %edx
callq 0xd2e0
cmpq $0x8, %rax
jge 0x53c5
jmp 0x5386
callq 0x20a0
cmpl $0x0, (%rax)
je 0x53ab
leaq 0xd758(%rip), %rdi      # 0x12aef
movb $0x0, %al
callq 0xf070
callq 0x20a0
movl $0x0, (%rax)
jmp 0x53b9
leaq 0xd73d(%rip), %rdi      # 0x12aef
movb $0x0, %al
callq 0xf2c0
jmp 0x53bb
movl $0x1, %edi
callq 0x24e0
jmp 0x53c7
movb $0x1, %al
testb $0x1, %al
jne 0x5117
jmp 0x53d3
movq -0x10(%rbp), %rdi
callq 0x2390
movl %eax, -0x14(%rbp)
cmpl $0x0, %eax
je 0x5414
jmp 0x53e6
movl -0x14(%rbp), %edi
callq 0x2530
movq %rax, %rsi
leaq 0xd52e(%rip), %rdi      # 0x12926
movb $0x0, %al
callq 0xf2c0
callq 0x20a0
movl $0x0, (%rax)
movl $0x1, %edi
callq 0x24e0
xorl %eax, %eax
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax)