// File: /workspace/github_c_makefile_star2_O1/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 0x3faf
movq %rbx, %rdi
callq 0x3f49
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 0x3fa2
movq %rax, %r14
leaq 0x93f3(%rip), %r15      # 0xd3c0
movq 0x60(%rbx), %rdi
movq %r14, %rsi
callq 0xae5c
testl %eax, %eax
jne 0x40e0
movl 0x8(%r14), %eax
cmpl $-0x1, %eax
je 0x408a
incq 0x70(%rbx)
cmpl $0x4, %eax
ja 0x4105
movl %eax, %eax
movslq (%r15,%rax,4), %rax
addq %r15, %rax
jmpq *%rax
cmpl $0x0, 0x10(%rbx)
jne 0x40e0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4124
jmp 0x4067
cmpl $0x0, 0x10(%rbx)
jne 0x40e0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4195
jmp 0x4067
movl 0x14(%r14), %eax
cmpq %rax, 0x28(%rbx)
jne 0x40d7
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4329
jmp 0x4067
movq %rbx, %rdi
movq %r14, %rsi
callq 0x43cf
jmp 0x4067
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4218
testl %eax, %eax
jne 0x3fa2
movl $0x28, %edi
callq 0x2380
movq %rax, %r14
testq %rax, %rax
jne 0x3fcd
jmp 0x3fa2
movq %r14, %rdi
callq 0x2040
movq 0x60(%rbx), %rdi
leaq -0x11b(%rip), %rsi      # 0x3f82
movq %rbx, %rdx
callq 0xb391
movq %rax, 0x68(%rbx)
xorl %ebp, %ebp
testq %rax, %rax
jne 0x3fa2
callq 0x20a0
cmpl $0x0, (%rax)
je 0x40ed
movq %rax, %rbx
leaq 0x94e0(%rip), %rdi      # 0xd5a8
xorl %eax, %eax
callq 0xac18
movl $0x0, (%rbx)
jmp 0x40fb
movq 0x20(%r14), %rdi
callq 0x2040
movq %r14, %rdi
callq 0x2040
jmp 0x3f98
leaq 0x94b4(%rip), %rdi      # 0xd5a8
xorl %eax, %eax
callq 0xad37
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x3fa2
leaq 0x9793(%rip), %rdi      # 0xd89f
leaq 0x9351(%rip), %rsi      # 0xd464
leaq 0x94b4(%rip), %rcx      # 0xd5ce
movl $0xa8, %edx
callq 0x2220