// File: /workspace/github_c_makefile_star2_O0/Tarsnap[P]kivaloo/liball/../lib/dynamodb/dynamodb_kv.c
// Function: dynamodb_kv_extractv
int
dynamodb_kv_extractv(const uint8_t * inbuf, size_t inlen,
    uint8_t ** outbuf, uint32_t * outlen)
{
	const uint8_t * p = inbuf;
	const uint8_t * end = &inbuf[inlen];
	size_t slen;
	size_t vlen;

	/* If we have no response body, there is no value. */
	if (inbuf == NULL)
		goto novalue;

	/**
	 * We need to locate B64VALUE in the string
	 * {"Item":{"V":{"B":"dmFsdWUK"},"K":{"S":"key"}}}
	 * so we look for the json object associated with "Item"; then look
	 * for the json object associated with "V" inside that; then look
	 * for the json object associated with "B" inside that.
	 */
	p = json_find(p, end, "Item");
	p = json_find(p, end, "V");
	p = json_find(p, end, "B");

	/* We should be pointing at the opening '"' of a string. */
	if (p == end)
		goto novalue;
	if (*p++ != '"')
		goto novalue;

	/* How long is it? */
	for (slen = 0; &p[slen] != end; slen++) {
		if (p[slen] == '"')
			break;
	}

	/* We should have found a terminating '"'. */
	if (&p[slen] == end)
		goto novalue;

	/* Bail if the value of "B" is less than 4 characters. */
	if (slen < 4)
		goto novalue;

	/* Allocate a buffer. */
	if ((*outbuf = malloc((slen / 4) * 3)) == NULL)
		goto err0;

	/* Attempt to parse the base64-encoded data. */
	if (b64decode((const char *)p, slen, *outbuf, &vlen))
		goto novalue1;

	/* Record the size of the returned value. */
	if (vlen >= (uint32_t)(-1))
		goto novalue1;
	*outlen = (uint32_t)vlen;

	/* Success! */
	return (0);

novalue1:
	free(*outbuf);
novalue:
	/* We have no value. */
	*outbuf = NULL;

	/* Success!  (Or at least, no internal error.) */
	return (0);

err0:
	/* Failure! */
	return (-1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
addq -0x18(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x8098
jmp 0x81ca
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
leaq 0x160d6(%rip), %rdx     # 0x1e17d
callq 0x104a0
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
leaq 0x167e2(%rip), %rdx     # 0x1e8a1
callq 0x104a0
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
leaq 0x167cc(%rip), %rdx     # 0x1e8a3
callq 0x104a0
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x38(%rbp), %rax
jne 0x80ef
jmp 0x81ca
movq -0x30(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x30(%rbp)
movzbl (%rax), %eax
cmpl $0x22, %eax
je 0x810b
jmp 0x81ca
movq $0x0, -0x40(%rbp)
movq -0x30(%rbp), %rax
addq -0x40(%rbp), %rax
cmpq -0x38(%rbp), %rax
je 0x8144
movq -0x30(%rbp), %rax
movq -0x40(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x22, %eax
jne 0x8134
jmp 0x8144
jmp 0x8136
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x8113
movq -0x30(%rbp), %rax
addq -0x40(%rbp), %rax
cmpq -0x38(%rbp), %rax
jne 0x8154
jmp 0x81ca
cmpq $0x4, -0x40(%rbp)
jae 0x815d
jmp 0x81ca
movq -0x40(%rbp), %rax
shrq $0x2, %rax
imulq $0x3, %rax, %rdi
callq 0x34c0
movq -0x20(%rbp), %rcx
movq %rax, (%rcx)
cmpq $0x0, %rax
jne 0x817d
jmp 0x81de
movq -0x30(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x20(%rbp), %rax
movq (%rax), %rdx
leaq -0x48(%rbp), %rcx
callq 0x102b0
cmpl $0x0, %eax
je 0x819c
jmp 0x81be
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, -0x48(%rbp)
jb 0x81a9
jmp 0x81be
movq -0x48(%rbp), %rax
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0x81e5
movq -0x20(%rbp), %rax
movq (%rax), %rdi
callq 0x3460
movq -0x20(%rbp), %rax
movq $0x0, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0x81e5
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nop