// File: /workspace/github_c_makefile_star2_O3/Tarsnap[P]kivaloo/lbs/dispatch.c
// Function: gotrequest
static int
gotrequest(void * cookie, int status)
{
	struct dispatch_state * D = cookie;
	struct proto_lbs_request * R;

	/* We're no longer waiting for a packet to arrive. */
	D->read_cookie = NULL;

	/* If the wait failed, the connection is dead. */
	if (status)
		goto drop;

	/* Read packets until there are no more or an error occurs. */
	do {
		/* Allocate space for a request. */
		if ((R = malloc(sizeof(struct proto_lbs_request))) == NULL)
			goto err0;

		/* Attempt to read a request. */
		if (proto_lbs_request_read(D->readq, R))
			goto drop1;

		/* If we have no request, stop looping. */
		if (R->type == PROTO_LBS_NONE)
			break;

		/* We owe a response to the client. */
		D->npending += 1;

		/* Handle and free the request. */
		switch (R->type) {
		case PROTO_LBS_PARAMS:
			/* PARAMS is not allowed while APPEND is in progress. */
			if (D->writer_busy != 0)
				goto drop1;
			if (dispatch_request_params(D, R))
				goto err0;
			break;
		case PROTO_LBS_PARAMS2:
			/* PARAMS is not allowed while APPEND is in progress. */
			if (D->writer_busy != 0)
				goto drop1;
			if (dispatch_request_params2(D, R))
				goto err0;
			break;
		case PROTO_LBS_GET:
			if (dispatch_request_get(D, R))
				goto err0;
			break;
		case PROTO_LBS_APPEND:
			/* Make sure the (implied) block length is correct. */
			if (R->r.append.blklen != D->blocklen) {
				free(R->r.append.buf);
				goto drop1;
			}
			if (dispatch_request_append(D, R))
				goto err0;
			break;
		case PROTO_LBS_FREE:
			if (dispatch_request_free(D, R))
				goto err0;
			break;
		default:
			/* proto_lbs_request_read broke. */
			assert(0);
		}
	} while (1);

	/* Free the (unused) request structure. */
	free(R);

	/* Wait for more requests to arrive. */
	if ((D->read_cookie = wire_readpacket_wait(D->readq,
	    gotrequest, D)) == NULL) {
		warnp("Error reading request from connection");
		goto err0;
	}

	/* Success! */
	return (0);

drop1:
	free(R);
drop:
	/* We didn't get a valid request.  Drop the connection. */
	dropconnection(D);

	/* All is good. */
	return (0);

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq $0x0, 0x68(%rdi)
testl %esi, %esi
je 0x3fb2
movq %rbx, %rdi
callq 0x3f4c
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movl $0x28, %edi
callq 0x2380
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x3fa5
movq %rax, %r14
leaq 0x9370(%rip), %r15      # 0xd340
movq 0x60(%rbx), %rdi
movq %r14, %rsi
callq 0xaf1c
testl %eax, %eax
jne 0x40e3
movl 0x8(%r14), %eax
cmpl $-0x1, %eax
je 0x408d
incq 0x70(%rbx)
cmpl $0x4, %eax
ja 0x4108
movl %eax, %eax
movslq (%r15,%rax,4), %rax
addq %r15, %rax
jmpq *%rax
cmpl $0x0, 0x10(%rbx)
jne 0x40e3
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4128
jmp 0x406a
cmpl $0x0, 0x10(%rbx)
jne 0x40e3
movq %rbx, %rdi
movq %r14, %rsi
callq 0x41a2
jmp 0x406a
movl 0x14(%r14), %eax
cmpq %rax, 0x28(%rbx)
jne 0x40da
movq %rbx, %rdi
movq %r14, %rsi
callq 0x433f
jmp 0x406a
movq %rbx, %rdi
movq %r14, %rsi
callq 0x43eb
jmp 0x406a
movq %rbx, %rdi
movq %r14, %rsi
callq 0x422e
testl %eax, %eax
jne 0x3fa5
movl $0x28, %edi
callq 0x2380
movq %rax, %r14
testq %rax, %rax
jne 0x3fd0
jmp 0x3fa5
movq %r14, %rdi
callq 0x2040
movq 0x60(%rbx), %rdi
leaq -0x11b(%rip), %rsi      # 0x3f85
movq %rbx, %rdx
callq 0xb44a
movq %rax, 0x68(%rbx)
xorl %ebp, %ebp
testq %rax, %rax
jne 0x3fa5
callq 0x20a0
cmpl $0x0, (%rax)
je 0x40f0
movq %rax, %rbx
leaq 0x945d(%rip), %rdi      # 0xd528
xorl %eax, %eax
callq 0xacd8
movl $0x0, (%rbx)
jmp 0x40fe
movq 0x20(%r14), %rdi
callq 0x2040
movq %r14, %rdi
callq 0x2040
jmp 0x3f9b
leaq 0x9431(%rip), %rdi      # 0xd528
xorl %eax, %eax
callq 0xadf7
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x3fa5
leaq 0x9710(%rip), %rdi      # 0xd81f
leaq 0x92ce(%rip), %rsi      # 0xd3e4
leaq 0x9431(%rip), %rcx      # 0xd54e
movl $0xa8, %edx
callq 0x2220
nop