// File: /workspace/github_c_makefile_star2_O2/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 %r12
pushq %rbx
movq %rdi, %rbx
andq $0x0, 0x68(%rdi)
testl %esi, %esi
je 0x398b
movq %rbx, %rdi
callq 0x3932
xorl %eax, %eax
jmp 0x3a7c
pushq $0x28
popq %r14
pushq $-0x1
popq %rbp
leaq 0x89e3(%rip), %r12      # 0xc37c
movq %r14, %rdi
callq 0x2380
testq %rax, %rax
je 0x3a4f
movq %rax, %r15
movq 0x60(%rbx), %rdi
movq %rax, %rsi
callq 0xa04c
testl %eax, %eax
jne 0x3aae
movl 0x8(%r15), %eax
cmpl $-0x1, %eax
je 0x3a53
incq 0x70(%rbx)
cmpl $0x4, %eax
ja 0x3acb
movl %eax, %eax
movslq (%r12,%rax,4), %rax
addq %r12, %rax
jmpq *%rax
cmpl $0x0, 0x10(%rbx)
jne 0x3aae
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3aec
jmp 0x3a47
cmpl $0x0, 0x10(%rbx)
jne 0x3aae
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3b62
jmp 0x3a47
movl 0x14(%r15), %eax
cmpq %rax, 0x28(%rbx)
jne 0x3aa5
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3cec
jmp 0x3a47
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3d8e
jmp 0x3a47
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3be9
testl %eax, %eax
je 0x3999
movl %ebp, %eax
jmp 0x3a7c
movq %r15, %rdi
callq 0x2040
movq 0x60(%rbx), %rdi
leaq -0xfe(%rip), %rsi       # 0x3968
movq %rbx, %rdx
callq 0xa4e1
movq %rax, %rcx
movq %rax, 0x68(%rbx)
xorl %eax, %eax
testq %rcx, %rcx
je 0x3a85
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
callq 0x20a0
cmpl $0x0, (%rax)
je 0x3abb
movq %rax, %rbx
leaq 0x8acb(%rip), %rdi      # 0xc564
xorl %eax, %eax
callq 0x9d39
andl $0x0, (%rbx)
jmp 0x3a4f
movq 0x20(%r15), %rdi
callq 0x2040
movq %r15, %rdi
callq 0x2040
jmp 0x397c
leaq 0x8aa2(%rip), %rdi      # 0xc564
xorl %eax, %eax
callq 0x9ec8
jmp 0x3a4f
leaq 0x8d89(%rip), %rdi      # 0xc85b
leaq 0x8947(%rip), %rsi      # 0xc420
leaq 0x8aaa(%rip), %rcx      # 0xc58a
movl $0xa8, %edx
callq 0x2220
nop