// File: /workspace/github_c_makefile_star2_O0/Tarsnap[P]kivaloo/lbs/dispatch_response.c
// Function: dispatch_response_send
int
dispatch_response_send(struct dispatch_state * dstate, struct workctl * thread)
{
	int op;
	uint64_t blkno;
	size_t nblks;
	uint8_t * buf;
	uint64_t reqID;
	int status;

	/* Figure out what work was completed. */
	if (worker_getdone(thread, &op, &blkno, &nblks, &buf, &reqID))
		goto err0;

	/* Different types of work get handled differently. */
	switch (op) {
	case 0:	/* read operation. */
		/* Sanity check. */
		assert(dstate->blocklen <= UINT32_MAX);

		/* If we read a block, our status is 0; otherwise, 1. */
		if (nblks == 1)
			status = 0;
		else
			status = 1;

		/* Send a response. */
		dstate->npending--;
		if (proto_lbs_response_get(dstate->writeq, reqID, status,
		    (uint32_t)dstate->blocklen, buf))
			goto err1;

		/* Free the buffer holding read data. */
		free(buf);

		break;
	case 1:	/* write operation. */
		/* Figure out what the next available block number is. */
		if ((blkno = storage_nextblock(dstate->sstate)) ==
		    (uint64_t)(-1))
			goto err1;

		/*
		 * Send a response back, with status = 0 since we will only
		 * end up here if the requested write position was correct.
		 */
		dstate->npending--;
		if (proto_lbs_response_append(dstate->writeq, reqID, 0, blkno))
			goto err1;

		/* Free the buffer holding written data. */
		free(buf);

		break;
	case 2:	/* delete operation. */
		/*
		 * We have nothing to do in this case, since the FREE command
		 * is merely advisory and a response was sent from request.c
		 * before the work was assigned to a thread.
		 */
		break;
	default:
		warn0("invalid work type: %d", op);
		goto err0;
	}

	/* Success! */
	return (0);

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x18(%rbp), %rdi
leaq -0x1c(%rbp), %rsi
leaq -0x28(%rbp), %rdx
leaq -0x30(%rbp), %rcx
leaq -0x38(%rbp), %r8
leaq -0x40(%rbp), %r9
callq 0x55a0
cmpl $0x0, %eax
je 0x4d67
jmp 0x4ea6
movl -0x1c(%rbp), %eax
movl %eax, -0x48(%rbp)
testl %eax, %eax
je 0x4d92
jmp 0x4d73
movl -0x48(%rbp), %eax
subl $0x1, %eax
je 0x4e20
jmp 0x4d81
movl -0x48(%rbp), %eax
subl $0x2, %eax
je 0x4e72
jmp 0x4e74
movq -0x10(%rbp), %rax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpq %rcx, 0x28(%rax)
ja 0x4da3
jmp 0x4dc2
leaq 0xd9e0(%rip), %rdi      # 0x1278a
leaq 0xdaae(%rip), %rsi      # 0x1285f
movl $0x25, %edx
leaq 0xdab6(%rip), %rcx      # 0x12873
callq 0x2240
cmpq $0x1, -0x30(%rbp)
jne 0x4dd2
movl $0x0, -0x44(%rbp)
jmp 0x4dd9
movl $0x1, -0x44(%rbp)
movq -0x10(%rbp), %rax
movq 0x70(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0x70(%rax)
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rdi
movq -0x40(%rbp), %rsi
movl -0x44(%rbp), %edx
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl %eax, %ecx
movq -0x38(%rbp), %r8
callq 0xfa00
cmpl $0x0, %eax
je 0x4e15
jmp 0x4e9d
movq -0x38(%rbp), %rdi
callq 0x2040
jmp 0x4e94
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x5c20
movq %rax, -0x28(%rbp)
cmpq $-0x1, %rax
jne 0x4e39
jmp 0x4e9d
movq -0x10(%rbp), %rax
movq 0x70(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0x70(%rax)
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rdi
movq -0x40(%rbp), %rsi
movq -0x28(%rbp), %rcx
xorl %edx, %edx
callq 0xfae0
cmpl $0x0, %eax
je 0x4e67
jmp 0x4e9d
movq -0x38(%rbp), %rdi
callq 0x2040
jmp 0x4e94
jmp 0x4e94
jmp 0x4e76
movl -0x1c(%rbp), %esi
leaq 0xda39(%rip), %rdi      # 0x128b9
movb $0x0, %al
callq 0xf2c0
callq 0x20a0
movl $0x0, (%rax)
jmp 0x4ea6
movl $0x0, -0x4(%rbp)
jmp 0x4ead
movq -0x38(%rbp), %rdi
callq 0x2040
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)