// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq $0x0, 0x28(%rax)
cmpl $0x0, -0x14(%rbp)
je 0x384e
jmp 0x3b50
jmp 0x3850
movl $0x28, %edi
callq 0x2280
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
jne 0x3869
jmp 0x3b78
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x28(%rbp), %rsi
callq 0xe390
cmpl $0x0, %eax
je 0x3884
jmp 0x3b47
movq -0x28(%rbp), %rax
cmpl $-0x1, 0x8(%rax)
jne 0x3893
jmp 0x3ac9
movq -0x28(%rbp), %rax
movl 0x8(%rax), %eax
movq %rax, -0x48(%rbp)
subq $0x4, %rax
ja 0x3a9c
movq -0x48(%rbp), %rax
leaq 0xfaa9(%rip), %rcx      # 0x1335c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
jmp 0x38be
leaq 0xfbc1(%rip), %rdi      # 0x13486
movb $0x0, %al
callq 0xd260
callq 0x20a0
movl $0x0, (%rax)
jmp 0x38d9
leaq 0xfbca(%rip), %rdi      # 0x134aa
movb $0x0, %al
callq 0xd260
callq 0x20a0
movl $0x0, (%rax)
jmp 0x3b47
movq -0x20(%rbp), %rax
cmpl $0x0, 0x38(%rax)
je 0x3906
jmp 0x3b47
movq -0x20(%rbp), %rax
movq (%rax), %rdi
leaq -0x2c(%rbp), %rsi
leaq -0x38(%rbp), %rdx
leaq -0x40(%rbp), %rcx
callq 0x3f70
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rax
movq (%rax), %rsi
movl -0x2c(%rbp), %edx
movq -0x40(%rbp), %rcx
movq -0x38(%rbp), %r8
callq 0xe7f0
cmpl $0x0, %eax
je 0x3947
jmp 0x3b6f
movq -0x28(%rbp), %rdi
callq 0x2040
jmp 0x3abb
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x30(%rax)
movq -0x20(%rbp), %rax
movq (%rax), %rdi
movq -0x28(%rbp), %rsi
movq -0x20(%rbp), %rcx
leaq 0x215(%rip), %rdx       # 0x3b90
callq 0x3fb0
cmpl $0x0, %eax
je 0x398a
jmp 0x3b6f
jmp 0x3abb
movq -0x20(%rbp), %rax
movq (%rax), %rdi
leaq -0x2c(%rbp), %rsi
leaq -0x38(%rbp), %rdx
leaq -0x40(%rbp), %rcx
callq 0x3f70
movq -0x28(%rbp), %rax
movl 0x14(%rax), %eax
cmpl -0x2c(%rbp), %eax
je 0x39b8
jmp 0x3b3a
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
cmpq -0x40(%rbp), %rax
jne 0x39d0
movq -0x20(%rbp), %rax
cmpl $0x0, 0x38(%rax)
je 0x3a12
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rax
movq (%rax), %rsi
movl $0x1, %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0xe970
cmpl $0x0, %eax
je 0x39f7
jmp 0x3b62
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x2040
movq -0x28(%rbp), %rdi
callq 0x2040
jmp 0x3abb
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x30(%rax)
movq -0x20(%rbp), %rax
movl $0x1, 0x38(%rax)
movq -0x20(%rbp), %rax
movq (%rax), %rdi
movq -0x28(%rbp), %rsi
movq -0x20(%rbp), %rcx
leaq 0x1fd(%rip), %rdx       # 0x3c40
callq 0x4230
cmpl $0x0, %eax
je 0x3a52
jmp 0x3b6f
jmp 0x3abb
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x4910
cmpl $0x0, %eax
je 0x3a73
jmp 0x3b6f
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rax
movq (%rax), %rsi
callq 0xea40
cmpl $0x0, %eax
je 0x3a91
jmp 0x3b6f
movq -0x28(%rbp), %rdi
callq 0x2040
jmp 0x3abb
leaq 0x10f09(%rip), %rdi     # 0x149ac
leaq 0xf8d8(%rip), %rsi      # 0x13382
movl $0x90, %edx
leaq 0xfa17(%rip), %rcx      # 0x134cd
callq 0x21b0
jmp 0x3abd
movb $0x1, %al
testb $0x1, %al
jne 0x3850
jmp 0x3ac9
movq -0x28(%rbp), %rdi
callq 0x2040
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x20(%rbp), %rdx
leaq -0x2c5(%rip), %rsi      # 0x3820
callq 0xee20
movq -0x20(%rbp), %rcx
movq %rax, 0x28(%rcx)
cmpq $0x0, %rax
jne 0x3b31
jmp 0x3afa
callq 0x20a0
cmpl $0x0, (%rax)
je 0x3b1f
leaq 0xf955(%rip), %rdi      # 0x13460
movb $0x0, %al
callq 0xd010
callq 0x20a0
movl $0x0, (%rax)
jmp 0x3b2d
leaq 0xf93a(%rip), %rdi      # 0x13460
movb $0x0, %al
callq 0xd260
jmp 0x3b2f
jmp 0x3b78
movl $0x0, -0x4(%rbp)
jmp 0x3b7f
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x2040
movq -0x28(%rbp), %rdi
callq 0x2040
movq -0x20(%rbp), %rdi
callq 0x37e0
movl $0x0, -0x4(%rbp)
jmp 0x3b7f
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x2040
movq -0x28(%rbp), %rdi
callq 0x2040
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax,%rax)