// File: /workspace/github_c_makefile_star2_O0/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
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, 0x68(%rax)
cmpl $0x0, -0x14(%rbp)
je 0x459e
jmp 0x4786
jmp 0x45a0
movl $0x28, %edi
callq 0x23a0
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
jne 0x45b9
jmp 0x4798
movq -0x20(%rbp), %rax
movq 0x60(%rax), %rdi
movq -0x28(%rbp), %rsi
callq 0xf500
cmpl $0x0, %eax
je 0x45d4
jmp 0x477d
movq -0x28(%rbp), %rax
cmpl $-0x1, 0x8(%rax)
jne 0x45e3
jmp 0x470c
movq -0x20(%rbp), %rax
movq 0x70(%rax), %rcx
incq %rcx
movq %rcx, 0x70(%rax)
movq -0x28(%rbp), %rax
movl 0x8(%rax), %eax
movq %rax, -0x30(%rbp)
subq $0x4, %rax
ja 0x46df
movq -0x30(%rbp), %rax
leaq 0xdf06(%rip), %rcx      # 0x12518
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x20(%rbp), %rax
cmpl $0x0, 0x10(%rax)
je 0x462a
jmp 0x477d
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x47b0
cmpl $0x0, %eax
je 0x4641
jmp 0x4798
jmp 0x46fe
movq -0x20(%rbp), %rax
cmpl $0x0, 0x10(%rax)
je 0x4655
jmp 0x477d
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x4870
cmpl $0x0, %eax
je 0x466c
jmp 0x4798
jmp 0x46fe
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x4950
cmpl $0x0, %eax
je 0x4688
jmp 0x4798
jmp 0x46fe
movq -0x28(%rbp), %rax
movl 0x14(%rax), %eax
movq -0x20(%rbp), %rcx
cmpq 0x28(%rcx), %rax
je 0x46ad
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x2040
jmp 0x477d
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x4b30
cmpl $0x0, %eax
je 0x46c4
jmp 0x4798
jmp 0x46fe
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x4c60
cmpl $0x0, %eax
je 0x46dd
jmp 0x4798
jmp 0x46fe
leaq 0xe359(%rip), %rdi      # 0x12a3f
leaq 0xdecf(%rip), %rsi      # 0x125bc
movl $0xa8, %edx
leaq 0xe075(%rip), %rcx      # 0x1276e
callq 0x2240
jmp 0x4700
movb $0x1, %al
testb $0x1, %al
jne 0x45a0
jmp 0x470c
movq -0x28(%rbp), %rdi
callq 0x2040
movq -0x20(%rbp), %rax
movq 0x60(%rax), %rdi
movq -0x20(%rbp), %rdx
leaq -0x1b8(%rip), %rsi      # 0x4570
callq 0xff90
movq -0x20(%rbp), %rcx
movq %rax, 0x68(%rcx)
cmpq $0x0, %rax
jne 0x4774
jmp 0x473d
callq 0x20a0
cmpl $0x0, (%rax)
je 0x4762
leaq 0xdffa(%rip), %rdi      # 0x12748
movb $0x0, %al
callq 0xf070
callq 0x20a0
movl $0x0, (%rax)
jmp 0x4770
leaq 0xdfdf(%rip), %rdi      # 0x12748
movb $0x0, %al
callq 0xf2c0
jmp 0x4772
jmp 0x4798
movl $0x0, -0x4(%rbp)
jmp 0x479f
movq -0x28(%rbp), %rdi
callq 0x2040
movq -0x20(%rbp), %rdi
callq 0x44e0
movl $0x0, -0x4(%rbp)
jmp 0x479f
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax,%rax)