// File: /workspace/github_c_makefile_star2_O2/Tarsnap[P]kivaloo/lbs-dynamodb/dispatch.c
// Function: gotrequest
static int
gotrequest(void * cookie, int status)
{
	struct dispatch_state * D = cookie;
	struct proto_lbs_request * R;
	uint32_t blklen;
	uint64_t lastblk;
	uint64_t nextblk;

	/* 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;

		/* Handle the request. */
		switch (R->type) {
		case PROTO_LBS_PARAMS:
			warn0("PROTO_LBS_PARAMS is not implemented");
			warn0("Update to a newer version of kvlds");
			goto drop1;
		case PROTO_LBS_PARAMS2:
			if (D->appendip != 0)
				goto drop1;
			state_params(D->S, &blklen, &lastblk, &nextblk);
			if (proto_lbs_response_params2(D->writeq, R->ID,
			    blklen, nextblk, lastblk))
				goto err1;
			free(R);
			break;
		case PROTO_LBS_GET:
			D->npending += 1;
			if (state_get(D->S, R, callback_get, D))
				goto err1;
			break;
		case PROTO_LBS_APPEND:
			state_params(D->S, &blklen, &lastblk, &nextblk);
			if (R->r.append.blklen != blklen)
				goto drop2;
			if ((R->r.append.blkno != nextblk) ||
			    (D->appendip != 0)) {
				if (proto_lbs_response_append(D->writeq,
				    R->ID, 1, 0))
					goto err2;
				free(R->r.append.buf);
				free(R);
				break;
			}
			D->npending += 1;
			D->appendip = 1;
			if (state_append(D->S, R, callback_append, D))
				goto err1;
			break;
		case PROTO_LBS_FREE:
			if (deleteto_deleteto(D->D, R->r.free.blkno))
				goto err1;
			if (proto_lbs_response_free(D->writeq, R->ID))
				goto err1;
			free(R);
			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);

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

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

err2:
	free(R->r.append.buf);
err1:
	free(R);
err0:
	/* Failure! */
	return (-1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
andq $0x0, 0x28(%rdi)
testl %esi, %esi
je 0x319b
movq %rbx, %rdi
callq 0x3157
xorl %eax, %eax
jmp 0x3320
pushq $0x28
popq %r15
leaq 0x9126(%rip), %rbp      # 0xc2cc
leaq 0x4(%rsp), %r13
leaq 0x10(%rsp), %r12
movq %r15, %rdi
callq 0x2270
testq %rax, %rax
je 0x331d
movq %rax, %r14
movq 0x20(%rbx), %rdi
movq %rax, %rsi
callq 0x9434
testl %eax, %eax
jne 0x33b1
movl 0x8(%r14), %eax
incl %eax
cmpl $0x5, %eax
ja 0x33d1
movslq (%rbp,%rax,4), %rax
addq %rbp, %rax
jmpq *%rax
incq 0x30(%rbx)
movq (%rbx), %rdi
movq %r14, %rsi
leaq 0x1ee(%rip), %rdx       # 0x33f0
movq %rbx, %rcx
callq 0x3642
testl %eax, %eax
je 0x31b0
jmp 0x3315
cmpl $0x0, 0x38(%rbx)
jne 0x33b1
movq (%rbx), %rdi
movq %r13, %rsi
movq %r12, %rdx
leaq 0x8(%rsp), %rcx
callq 0x362f
movq 0x18(%rbx), %rdi
movq (%r14), %rsi
movl 0x4(%rsp), %edx
movq 0x8(%rsp), %rcx
movq 0x10(%rsp), %r8
callq 0x95c1
jmp 0x326d
movq 0x8(%rbx), %rdi
movq 0x10(%r14), %rsi
callq 0x3b63
testl %eax, %eax
jne 0x3315
movq 0x18(%rbx), %rdi
movq (%r14), %rsi
callq 0x975c
testl %eax, %eax
je 0x32e3
jmp 0x3315
movq (%rbx), %rdi
movq %r13, %rsi
movq %r12, %rdx
leaq 0x8(%rsp), %rcx
callq 0x362f
movl 0x14(%r14), %eax
cmpl 0x4(%rsp), %eax
jne 0x33a8
movq 0x18(%r14), %rax
cmpq 0x8(%rsp), %rax
jne 0x32a8
cmpl $0x0, 0x38(%rbx)
je 0x32f0
movq 0x18(%rbx), %rdi
movq (%r14), %rsi
pushq $0x1
popq %rdx
xorl %ecx, %ecx
callq 0x96c8
movq %r15, %rbp
movq %r12, %r15
movq %r13, %r12
movl %eax, %r13d
movq 0x20(%r14), %rdi
callq 0x2040
testl %r13d, %r13d
movq %r12, %r13
movq %r15, %r12
movq %rbp, %r15
leaq 0x8feb(%rip), %rbp      # 0xc2cc
jne 0x3315
movq %r14, %rdi
callq 0x2040
jmp 0x31b0
incq 0x30(%rbx)
movl $0x1, 0x38(%rbx)
movq (%rbx), %rdi
movq %r14, %rsi
leaq 0x146(%rip), %rdx       # 0x344e
movq %rbx, %rcx
callq 0x37b9
jmp 0x320a
movq %r14, %rdi
callq 0x2040
pushq $-0x1
popq %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x90c4(%rip), %rdi      # 0xc3fa
xorl %eax, %eax
callq 0x88e8
callq 0x20a0
movq %rax, %r15
andl $0x0, (%rax)
leaq 0x90cf(%rip), %rdi      # 0xc41e
xorl %eax, %eax
callq 0x88e8
andl $0x0, (%r15)
jmp 0x33b1
movq %r14, %rdi
callq 0x2040
movq 0x20(%rbx), %rdi
leaq -0x1fd(%rip), %rsi      # 0x3172
movq %rbx, %rdx
callq 0x98c9
movq %rax, %rcx
movq %rax, 0x28(%rbx)
xorl %eax, %eax
testq %rcx, %rcx
jne 0x3320
callq 0x20a0
cmpl $0x0, (%rax)
je 0x33be
movq %rax, %rbx
leaq 0x903b(%rip), %rdi      # 0xc3d4
xorl %eax, %eax
callq 0x8759
andl $0x0, (%rbx)
jmp 0x331d
movq 0x20(%r14), %rdi
callq 0x2040
movq %r14, %rdi
callq 0x2040
jmp 0x318c
leaq 0x900f(%rip), %rdi      # 0xc3d4
xorl %eax, %eax
callq 0x88e8
jmp 0x331d
leaq 0x9c5b(%rip), %rdi      # 0xd033
leaq 0x8f17(%rip), %rsi      # 0xc2f6
leaq 0x905b(%rip), %rcx      # 0xc441
movl $0x90, %edx
callq 0x21a0