// File: /workspace/github_c_makefile_star2_O0/Tarsnap[P]kivaloo/dynamodb-kv/dispatch.c
// Function: gotrequest
static int
gotrequest(void * cookie, int status)
{
	struct dispatch_state * D = cookie;
	struct request * R;
	struct dynamodb_request_queue * Q;
	const char * op;
	size_t maxrlen;
	int prio;

	/* 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 request))) == NULL)
			goto err0;
		R->D = D;

		/* Attempt to read a request. */
		if (proto_dynamodb_kv_request_read(D->readq, &R->R))
			goto drop1;

		/* If we have no request, stop looping. */
		if (R->R.type == PROTO_DDBKV_NONE)
			break;

		/* Translate this to a DynamoDB request. */
		switch (R->R.type) {
		case PROTO_DDBKV_PUT:
			Q = D->QW;
			op = "PutItem";
			maxrlen = 1024;
			prio = 0;
			if ((R->body = dynamodb_kv_put(D->table, R->R.key,
			    R->R.buf, R->R.len)) == NULL)
				goto err1;
			break;
		case PROTO_DDBKV_ICAS:
			Q = D->QW;
			op = "PutItem";
			maxrlen = 1024;
			prio = 0;
			if ((R->body = dynamodb_kv_icas(D->table, R->R.key,
			    R->R.buf, R->R.len, R->R.buf2, R->R.len2)) == NULL)
				goto err1;
			break;
		case PROTO_DDBKV_CREATE:
			Q = D->QW;
			op = "PutItem";
			maxrlen = 1024;
			prio = 0;
			if ((R->body = dynamodb_kv_create(D->table, R->R.key,
			    R->R.buf, R->R.len)) == NULL)
				goto err1;
			break;
		case PROTO_DDBKV_GET:
			Q = D->QR;
			op = "GetItem";
			prio = 0;
			maxrlen = 1048576;
			if ((R->body =
			    dynamodb_kv_get(D->table, R->R.key)) == NULL)
				goto err1;
			break;
		case PROTO_DDBKV_GETC:
			Q = D->QR;
			op = "GetItem";
			prio = 0;
			maxrlen = 1048576;
			if ((R->body =
			    dynamodb_kv_getc(D->table, R->R.key)) == NULL)
				goto err1;
			break;
		case PROTO_DDBKV_DELETE:
			Q = D->QW;
			op = "DeleteItem";
			maxrlen = 1024;
			prio = 1;
			if ((R->body =
			    dynamodb_kv_delete(D->table, R->R.key)) == NULL)
				goto err1;
			break;
		default:
			/* proto_dynamodb_kv_request_read broke. */
			assert(0);
		}

		/* Add the request to the appropriate DynamoDB queue. */
		if (dynamodb_request_queue(Q, prio, op, R->body, maxrlen,
		    R->R.key, callback_response, R))
			goto err2;

		/* Add to the linked list. */
		if ((R->prev = D->ip_tail) == NULL) {
			D->ip_head = R;
		} else {
			R->prev->next = R;
		}
		R->next = NULL;
		D->ip_tail = R;
	} 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);

err2:
	free(R->body);
err1:
	free(R);
err0:
	/* Failure! */
	return (-1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq $0x0, 0x40(%rax)
cmpl $0x0, -0x14(%rbp)
je 0x57ee
jmp 0x5bd1
jmp 0x57f0
movl $0x58, %edi
callq 0x34c0
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
jne 0x5809
jmp 0x5bf9
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rdi
movq -0x28(%rbp), %rsi
addq $0x18, %rsi
callq 0x14080
cmpl $0x0, %eax
je 0x5833
jmp 0x5bc8
movq -0x28(%rbp), %rax
cmpl $-0x1, 0x20(%rax)
jne 0x5842
jmp 0x5b57
movq -0x28(%rbp), %rax
movl 0x20(%rax), %eax
addl $0xfffeff00, %eax       # imm = 0xFFFEFF00
movl %eax, %ecx
movq %rcx, -0x50(%rbp)
subl $0x20, %eax
ja 0x5a9e
movq -0x50(%rbp), %rax
leaq 0x1dd7c(%rip), %rcx     # 0x235e4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
leaq 0x1df9a(%rip), %rax     # 0x2381d
movq %rax, -0x38(%rbp)
movq $0x400, -0x40(%rbp)     # imm = 0x400
movl $0x0, -0x44(%rbp)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rsi
movq -0x28(%rbp), %rax
movq 0x38(%rax), %rdx
movq -0x28(%rbp), %rax
movl 0x30(%rax), %eax
movl %eax, %ecx
callq 0x10490
movq -0x28(%rbp), %rcx
movq %rax, 0x50(%rcx)
cmpq $0x0, %rax
jne 0x58cf
jmp 0x5bf0
jmp 0x5abd
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
leaq 0x1df37(%rip), %rax     # 0x2381d
movq %rax, -0x38(%rbp)
movq $0x400, -0x40(%rbp)     # imm = 0x400
movl $0x0, -0x44(%rbp)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rsi
movq -0x28(%rbp), %rax
movq 0x38(%rax), %rdx
movq -0x28(%rbp), %rax
movl 0x30(%rax), %eax
movl %eax, %ecx
movq -0x28(%rbp), %rax
movq 0x48(%rax), %r8
movq -0x28(%rbp), %rax
movl 0x40(%rax), %eax
movl %eax, %r9d
callq 0x107f0
movq -0x28(%rbp), %rcx
movq %rax, 0x50(%rcx)
cmpq $0x0, %rax
jne 0x5944
jmp 0x5bf0
jmp 0x5abd
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
leaq 0x1dec2(%rip), %rax     # 0x2381d
movq %rax, -0x38(%rbp)
movq $0x400, -0x40(%rbp)     # imm = 0x400
movl $0x0, -0x44(%rbp)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rsi
movq -0x28(%rbp), %rax
movq 0x38(%rax), %rdx
movq -0x28(%rbp), %rax
movl 0x30(%rax), %eax
movl %eax, %ecx
callq 0x10d80
movq -0x28(%rbp), %rcx
movq %rax, 0x50(%rcx)
cmpq $0x0, %rax
jne 0x59a7
jmp 0x5bf0
jmp 0x5abd
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x30(%rbp)
leaq 0x1de66(%rip), %rax     # 0x23825
movq %rax, -0x38(%rbp)
movl $0x0, -0x44(%rbp)
movq $0x100000, -0x40(%rbp)  # imm = 0x100000
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rsi
callq 0x11230
movq -0x28(%rbp), %rcx
movq %rax, 0x50(%rcx)
cmpq $0x0, %rax
jne 0x59fa
jmp 0x5bf0
jmp 0x5abd
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x30(%rbp)
leaq 0x1de13(%rip), %rax     # 0x23825
movq %rax, -0x38(%rbp)
movl $0x0, -0x44(%rbp)
movq $0x100000, -0x40(%rbp)  # imm = 0x100000
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rsi
callq 0x114a0
movq -0x28(%rbp), %rcx
movq %rax, 0x50(%rcx)
cmpq $0x0, %rax
jne 0x5a4d
jmp 0x5bf0
jmp 0x5abd
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
leaq 0x1ddcc(%rip), %rax     # 0x2382d
movq %rax, -0x38(%rbp)
movq $0x400, -0x40(%rbp)     # imm = 0x400
movl $0x1, -0x44(%rbp)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rsi
callq 0x11710
movq -0x28(%rbp), %rcx
movq %rax, 0x50(%rcx)
cmpq $0x0, %rax
jne 0x5a9c
jmp 0x5bf0
jmp 0x5abd
leaq 0x1e44a(%rip), %rdi     # 0x23eef
leaq 0x1dbce(%rip), %rsi     # 0x2367a
movl $0xcd, %edx
leaq 0x1dd80(%rip), %rcx     # 0x23838
callq 0x3240
movq -0x30(%rbp), %rdi
movl -0x44(%rbp), %esi
movq -0x38(%rbp), %rdx
movq -0x28(%rbp), %rax
movq 0x50(%rax), %rcx
movq -0x40(%rbp), %r8
movq -0x28(%rbp), %rax
movq 0x28(%rax), %r9
movq -0x28(%rbp), %rax
leaq 0x2a9(%rip), %r10       # 0x5d90
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x12320
cmpl $0x0, %eax
je 0x5aff
jmp 0x5be3
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x28(%rbp), %rcx
movq %rax, 0x8(%rcx)
cmpq $0x0, %rax
jne 0x5b23
movq -0x28(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x18(%rax)
jmp 0x5b33
movq -0x28(%rbp), %rcx
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq %rcx, 0x10(%rax)
movq -0x28(%rbp), %rax
movq $0x0, 0x10(%rax)
movq -0x28(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x20(%rax)
movb $0x1, %al
testb $0x1, %al
jne 0x57f0
jmp 0x5b57
movq -0x28(%rbp), %rdi
callq 0x3460
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rdi
movq -0x20(%rbp), %rdx
leaq -0x3b3(%rip), %rsi      # 0x57c0
callq 0x15720
movq -0x20(%rbp), %rcx
movq %rax, 0x40(%rcx)
cmpq $0x0, %rax
jne 0x5bbf
jmp 0x5b88
callq 0x3040
cmpl $0x0, (%rax)
je 0x5bad
leaq 0x1dbd4(%rip), %rdi     # 0x2376d
movb $0x0, %al
callq 0x10000
callq 0x3040
movl $0x0, (%rax)
jmp 0x5bbb
leaq 0x1dbb9(%rip), %rdi     # 0x2376d
movb $0x0, %al
callq 0x10250
jmp 0x5bbd
jmp 0x5bf9
movl $0x0, -0x4(%rbp)
jmp 0x5c00
movq -0x28(%rbp), %rdi
callq 0x3460
movq -0x20(%rbp), %rdi
callq 0x5740
movl $0x0, -0x4(%rbp)
jmp 0x5c00
movq -0x28(%rbp), %rax
movq 0x50(%rax), %rdi
callq 0x3460
movq -0x28(%rbp), %rdi
callq 0x3460
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)