// File: /workspace/github_c_makefile_star2_O0/Tarsnap[P]kivaloo/lbs-s3/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;

		/* Handle the request. */
		switch (R->type) {
		case PROTO_LBS_PARAMS:
			warn0("PROTO_LBS_PARAMS is not implemented in lbs-s3");
			warn0("Update to a newer version of kvlds");
			goto drop1;
		case PROTO_LBS_PARAMS2:
			if (proto_lbs_response_params2(D->writeq, R->ID,
			    D->S->blklen, D->S->nextblk, D->S->lastblk))
				goto err1;
			free(R);
			break;
		case PROTO_LBS_GET:
			D->npending += 1;
			if (s3state_get(D->S, R, callback_get, D))
				goto err1;
			break;
		case PROTO_LBS_APPEND:
			if (R->r.append.blklen != D->S->blklen)
				goto drop2;
			if ((R->r.append.blkno != D->S->nextblk) ||
			    (D->appendip != 0)) {
				if (proto_lbs_response_append(D->writeq,
				    R->ID, 1, 0))
					goto err2;
				break;
			}
			D->npending += 1;
			D->appendip = 1;
			if (s3state_append(D->S, R, callback_append, D))
				goto err1;
			break;
		case PROTO_LBS_FREE:
			if (s3state_gc(D->S, 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 $0x30, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq $0x0, 0x20(%rax)
cmpl $0x0, -0x14(%rbp)
je 0x39ee
jmp 0x3cbb
jmp 0x39f0
movl $0x28, %edi
callq 0x2290
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
jne 0x3a09
jmp 0x3ce3
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
callq 0xe290
cmpl $0x0, %eax
je 0x3a24
jmp 0x3cb2
movq -0x28(%rbp), %rax
cmpl $-0x1, 0x8(%rax)
jne 0x3a33
jmp 0x3c34
movq -0x28(%rbp), %rax
movl 0x8(%rax), %eax
movq %rax, -0x30(%rbp)
subq $0x4, %rax
ja 0x3c07
movq -0x30(%rbp), %rax
leaq 0x109f5(%rip), %rcx     # 0x14448
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
jmp 0x3a5e
leaq 0x10b0d(%rip), %rdi     # 0x14572
movb $0x0, %al
callq 0xe050
callq 0x20a0
movl $0x0, (%rax)
jmp 0x3a79
leaq 0x10b20(%rip), %rdi     # 0x145a0
movb $0x0, %al
callq 0xe050
callq 0x20a0
movl $0x0, (%rax)
jmp 0x3cb2
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x28(%rbp), %rax
movq (%rax), %rsi
movq -0x20(%rbp), %rax
movq (%rax), %rax
movl (%rax), %edx
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rcx
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %r8
callq 0xe6f0
cmpl $0x0, %eax
je 0x3ad4
jmp 0x3cda
movq -0x28(%rbp), %rdi
callq 0x2040
jmp 0x3c26
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x28(%rax)
movq -0x20(%rbp), %rax
movq (%rax), %rdi
movq -0x28(%rbp), %rsi
movq -0x20(%rbp), %rcx
leaq 0x1f8(%rip), %rdx       # 0x3d00
callq 0x4060
cmpl $0x0, %eax
je 0x3b17
jmp 0x3cda
jmp 0x3c26
movq -0x28(%rbp), %rax
movl 0x14(%rax), %eax
movq -0x20(%rbp), %rcx
movq (%rcx), %rcx
cmpl (%rcx), %eax
je 0x3b33
jmp 0x3ca5
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x20(%rbp), %rcx
movq (%rcx), %rcx
cmpq 0x8(%rcx), %rax
jne 0x3b52
movq -0x20(%rbp), %rax
cmpl $0x0, 0x30(%rax)
je 0x3b7e
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x28(%rbp), %rax
movq (%rax), %rsi
movl $0x1, %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0xe870
cmpl $0x0, %eax
je 0x3b79
jmp 0x3ccd
jmp 0x3c26
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x28(%rax)
movq -0x20(%rbp), %rax
movl $0x1, 0x30(%rax)
movq -0x20(%rbp), %rax
movq (%rax), %rdi
movq -0x28(%rbp), %rsi
movq -0x20(%rbp), %rcx
leaq 0x201(%rip), %rdx       # 0x3db0
callq 0x4200
cmpl $0x0, %eax
je 0x3bbe
jmp 0x3cda
jmp 0x3c26
movq -0x20(%rbp), %rax
movq (%rax), %rdi
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x4410
cmpl $0x0, %eax
je 0x3bde
jmp 0x3cda
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x28(%rbp), %rax
movq (%rax), %rsi
callq 0xe940
cmpl $0x0, %eax
je 0x3bfc
jmp 0x3cda
movq -0x28(%rbp), %rdi
callq 0x2040
jmp 0x3c26
leaq 0x11a56(%rip), %rdi     # 0x15664
leaq 0x10859(%rip), %rsi     # 0x1446e
movl $0x84, %edx
leaq 0x109a2(%rip), %rcx     # 0x145c3
callq 0x21c0
jmp 0x3c28
movb $0x1, %al
testb $0x1, %al
jne 0x39f0
jmp 0x3c34
movq -0x28(%rbp), %rdi
callq 0x2040
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rdx
leaq -0x290(%rip), %rsi      # 0x39c0
callq 0xfef0
movq -0x20(%rbp), %rcx
movq %rax, 0x20(%rcx)
cmpq $0x0, %rax
jne 0x3c9c
jmp 0x3c65
callq 0x20a0
cmpl $0x0, (%rax)
je 0x3c8a
leaq 0x108d6(%rip), %rdi     # 0x1454c
movb $0x0, %al
callq 0xde00
callq 0x20a0
movl $0x0, (%rax)
jmp 0x3c98
leaq 0x108bb(%rip), %rdi     # 0x1454c
movb $0x0, %al
callq 0xe050
jmp 0x3c9a
jmp 0x3ce3
movl $0x0, -0x4(%rbp)
jmp 0x3cea
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x2040
movq -0x28(%rbp), %rdi
callq 0x2040
movq -0x20(%rbp), %rdi
callq 0x3980
movl $0x0, -0x4(%rbp)
jmp 0x3cea
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 $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)