// File: /workspace/github_c_makefile_star2_O0/Tarsnap[P]kivaloo/liball/../lib/proto_dynamodb_kv/proto_dynamodb_kv_server.c
// Function: proto_dynamodb_kv_request_parse
static int
proto_dynamodb_kv_request_parse(const struct wire_packet * P,
    struct proto_ddbkv_request * R)
{
	size_t pos = 0;
	size_t buflen;
	size_t i;

	/* Store request ID. */
	R->ID = P->ID;

	/* Initialize pointers to NULL to make cleanup easier. */
	R->key = NULL;
	R->buf = NULL;
	R->buf2 = NULL;

	/* Extract the request type. */
	if (P->len < pos + 4)
		goto err0;
	R->type = be32dec(&P->buf[pos]);
	pos += 4;

	/* Extract key length (appears in every request type). */
	if (P->len < pos + 1)
		goto err0;
	buflen = P->buf[pos++];

	/* Sanity-check key. */
	if (P->len < pos + buflen)
		goto err0;
	for (i = 0; i < buflen; i++)
		if (P->buf[pos + i] == '\0')
			goto err0;

	/* Extract key into newly allocated buffer. */
	if ((R->key = malloc(buflen + 1)) == NULL)
		goto err0;
	memcpy(R->key, &P->buf[pos], buflen);
	R->key[buflen] = '\0';
	pos += buflen;

	/*
	 * PUT and CREATE requests have one value, while ICAS requests have two
	 * values.  GET, GETC, and DELETE requests have no values.
	 */
	switch (R->type) {
	case PROTO_DDBKV_PUT:
	case PROTO_DDBKV_ICAS:
	case PROTO_DDBKV_CREATE:
		/* Parse the first (or only) value. */
		if (P->len < pos + 4)
			goto err1;
		R->len = be32dec(&P->buf[pos]);
		pos += 4;
		if (P->len < pos + R->len)
			goto err1;
		if ((R->buf = malloc(R->len)) == NULL)
			goto err1;
		memcpy(R->buf, &P->buf[pos], R->len);
		pos += R->len;

		/* ICAS requests continue and parse a second value. */
		if (R->type != PROTO_DDBKV_ICAS)
			break;
		if (P->len < pos + 4)
			goto err1;
		R->len2 = be32dec(&P->buf[pos]);
		pos += 4;
		if (P->len < pos + R->len2)
			goto err1;
		if ((R->buf2 = malloc(R->len2)) == NULL)
			goto err1;
		memcpy(R->buf2, &P->buf[pos], R->len2);
		pos += R->len2;
		break;
	case PROTO_DDBKV_GET:
	case PROTO_DDBKV_GETC:
	case PROTO_DDBKV_DELETE:
		break;
	default:
		goto err1;
	}

	/* Check that we processed the entire request record. */
	if (P->len != pos)
		goto err1;

	/* Success! */
	return (0);

err1:
	free(R->buf2);
	free(R->buf);
	free(R->key);
err0:
	/* Failure! */
	return (-1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movq $0x0, 0x10(%rax)
movq -0x18(%rbp), %rax
movq $0x0, 0x20(%rax)
movq -0x18(%rbp), %rax
movq $0x0, 0x30(%rax)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x20(%rbp), %rcx
addq $0x4, %rcx
cmpq %rcx, %rax
jae 0x14164
jmp 0x1446e
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
addq -0x20(%rbp), %rdi
callq 0x14710
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x20(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x20(%rbp), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jae 0x141a4
jmp 0x1446e
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x20(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x20(%rbp)
movzbl (%rax,%rcx), %eax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x20(%rbp), %rcx
addq -0x28(%rbp), %rcx
cmpq %rcx, %rax
jae 0x141dd
jmp 0x1446e
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x28(%rbp), %rax
jae 0x1421d
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x20(%rbp), %rcx
addq -0x30(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x1420d
jmp 0x1446e
jmp 0x1420f
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x141e5
movq -0x28(%rbp), %rdi
addq $0x1, %rdi
callq 0x34c0
movq -0x18(%rbp), %rcx
movq %rax, 0x10(%rcx)
cmpq $0x0, %rax
jne 0x1423d
jmp 0x1446e
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x20(%rbp), %rax
addq %rax, %rsi
movq -0x28(%rbp), %rdx
callq 0x32c0
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x28(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x28(%rbp), %rcx
movq -0x20(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x34(%rbp)
addl $0xfffeff00, %eax       # imm = 0xFFFEFF00
subl $0x3, %eax
jb 0x142b8
jmp 0x14292
movl -0x34(%rbp), %eax
addl $0xfffefef0, %eax       # imm = 0xFFFEFEF0
subl $0x2, %eax
jb 0x1442a
jmp 0x142a5
movl -0x34(%rbp), %eax
subl $0x10120, %eax          # imm = 0x10120
je 0x1442a
jmp 0x1442c
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x20(%rbp), %rcx
addq $0x4, %rcx
cmpq %rcx, %rax
jae 0x142d2
jmp 0x14447
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
addq -0x20(%rbp), %rdi
callq 0x14710
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x20(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x20(%rbp), %rcx
movq -0x18(%rbp), %rdx
movl 0x18(%rdx), %edx
addq %rdx, %rcx
cmpq %rcx, %rax
jae 0x14318
jmp 0x14447
movq -0x18(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, %edi
callq 0x34c0
movq -0x18(%rbp), %rcx
movq %rax, 0x20(%rcx)
cmpq $0x0, %rax
jne 0x14339
jmp 0x14447
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
addq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, %edx
callq 0x32c0
movq -0x18(%rbp), %rax
movl 0x18(%rax), %eax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x10101, 0x8(%rax)     # imm = 0x10101
je 0x1437c
jmp 0x1442e
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x20(%rbp), %rcx
addq $0x4, %rcx
cmpq %rcx, %rax
jae 0x14396
jmp 0x14447
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
addq -0x20(%rbp), %rdi
callq 0x14710
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x28(%rax)
movq -0x20(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x20(%rbp), %rcx
movq -0x18(%rbp), %rdx
movl 0x28(%rdx), %edx
addq %rdx, %rcx
cmpq %rcx, %rax
jae 0x143d9
jmp 0x14447
movq -0x18(%rbp), %rax
movl 0x28(%rax), %eax
movl %eax, %edi
callq 0x34c0
movq -0x18(%rbp), %rcx
movq %rax, 0x30(%rcx)
cmpq $0x0, %rax
jne 0x143f7
jmp 0x14447
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
addq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rax
movl 0x28(%rax), %eax
movl %eax, %edx
callq 0x32c0
movq -0x18(%rbp), %rax
movl 0x28(%rax), %eax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0x1442e
jmp 0x1442e
jmp 0x14447
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
cmpq -0x20(%rbp), %rax
je 0x1443e
jmp 0x14447
movl $0x0, -0x4(%rbp)
jmp 0x14475
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x3460
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x3460
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x3460
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nop