// File: /workspace/github_c_makefile_star2_O0/Tarsnap[P]kivaloo/lbs/dispatch.c
// Function: workdone
static int
workdone(void * cookie, ssize_t lenread)
{
	struct dispatch_state * D = cookie;

	/* If we failed to read a thread ID, something is seriously wrong. */
	if (lenread != sizeof(size_t)) {
		warnp("workdone failed to read thread ID");
		goto err0;
	}

	/* Sanity-check the thread ID. */
	assert(D->wakeupID <= D->nreaders + 2);

	/* Send a response for whatever work was finished. */
	if (dispatch_response_send(D, D->workers[D->wakeupID]))
		goto err0;

	/* Mark the thread as available for more work. */
	if (D->wakeupID == D->nreaders + 1) {
		D->deleter_busy = 0;
	} else if (D->wakeupID == D->nreaders) {
		D->writer_busy = 0;
	} else {
		D->readers_idle[D->nreaders_idle++] = D->wakeupID;
	}

	/*
	 * If this was a read thread, check if there is pending work which
	 * should now be scheduled for this thread.
	 */
	if ((D-> wakeupID < D->nreaders) && dispatch_request_pokereadq(D))
		goto err0;

	/* Read the ID of another thread with completed work. */
	if ((D->wakeup_cookie = network_read(D->spair[0],
	    (uint8_t *)&D->wakeupID, sizeof(size_t), sizeof(size_t),
	    workdone, D)) == NULL) {
		warnp("Error reading thread ID from socket");
		goto err0;
	}

	/* Success! */
	return (0);

err0:
	/* Failure! */
	return (-1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x20(%rbp)
cmpq $0x8, -0x18(%rbp)
je 0x3dcb
jmp 0x3d91
callq 0x20a0
cmpl $0x0, (%rax)
je 0x3db6
leaq 0xe8c7(%rip), %rdi      # 0x12669
movb $0x0, %al
callq 0xf070
callq 0x20a0
movl $0x0, (%rax)
jmp 0x3dc4
leaq 0xe8ac(%rip), %rdi      # 0x12669
movb $0x0, %al
callq 0xf2c0
jmp 0x3dc6
jmp 0x3f32
movq -0x20(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x8(%rcx), %rcx
addq $0x2, %rcx
cmpq %rcx, %rax
ja 0x3de6
jmp 0x3e05
leaq 0xe89e(%rip), %rdi      # 0x1268b
leaq 0xe7c8(%rip), %rsi      # 0x125bc
movl $0x27, %edx
leaq 0xe8aa(%rip), %rcx      # 0x126aa
callq 0x2240
movq -0x20(%rbp), %rdi
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x40(%rcx), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x4d30
cmpl $0x0, %eax
je 0x3e2b
jmp 0x3f32
movq -0x20(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x8(%rcx), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jne 0x3e51
movq -0x20(%rbp), %rax
movl $0x0, 0x14(%rax)
jmp 0x3e99
movq -0x20(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x20(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x3e70
movq -0x20(%rbp), %rax
movl $0x0, 0x10(%rax)
jmp 0x3e97
movq -0x20(%rbp), %rax
movq 0x40(%rax), %rdx
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x20(%rbp), %rsi
movq 0x18(%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, 0x18(%rsi)
movq %rdx, (%rax,%rcx,8)
jmp 0x3e99
movq -0x20(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x20(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x3ebb
movq -0x20(%rbp), %rdi
callq 0x4a20
cmpl $0x0, %eax
je 0x3ebb
jmp 0x3f32
movq -0x20(%rbp), %rax
movl 0x38(%rax), %edi
movq -0x20(%rbp), %rsi
addq $0x40, %rsi
movq -0x20(%rbp), %r9
movl $0x8, %ecx
leaq -0x16a(%rip), %r8       # 0x3d70
movq %rcx, %rdx
callq 0xac80
movq -0x20(%rbp), %rcx
movq %rax, 0x48(%rcx)
cmpq $0x0, %rax
jne 0x3f29
jmp 0x3ef2
callq 0x20a0
cmpl $0x0, (%rax)
je 0x3f17
leaq 0xe65b(%rip), %rdi      # 0x1255e
movb $0x0, %al
callq 0xf070
callq 0x20a0
movl $0x0, (%rax)
jmp 0x3f25
leaq 0xe640(%rip), %rdi      # 0x1255e
movb $0x0, %al
callq 0xf2c0
jmp 0x3f27
jmp 0x3f32
movl $0x0, -0x4(%rbp)
jmp 0x3f39
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)