// File: /workspace/github_c_makefile_star2_O0/Tarsnap[P]kivaloo/liball/../lib/dynamodb/dynamodb_kv.c
// Function: dynamodb_kv_icas
char *
dynamodb_kv_icas(const char * table, const char * key,
    const uint8_t * buf, size_t len, const uint8_t * buf2, size_t len2)
{
	/**
	 * An ICAS is a PutItem request with a body (with spaces added) of:
	 * { "TableName": "TABLE",
	 *   "Item": {
	 *     "K": { "S": "KEY" },
	 *     "V": { "B": "BASE64NEW" }
	 *   },
	 *   "ConditionExpression": "(V = :old) OR (V = :new)",
	 *   "ExpressionAttributeValues": {
	 *       ":old": { "B": "BASE64OLD" },
	 *       ":new": { "B": "BASE64NEW" }
	 *   },
	 *   "ReturnConsumedCapacity": "TOTAL"
	 * }
	 */
	const char * s1 = "{\"TableName\":\"";
	const char * s2 = "\",\"Item\":{\"K\":{\"S\":\"";
	const char * s3 = "\"},\"V\":{\"B\":\"";
	const char * s4 = "\"}},\"ConditionExpression\":\"(V=:old)OR(V=:new)\",";
	const char * s5 = "\"ExpressionAttributeValues\":{\":old\":{\"B\":\"";
	const char * s6 = "\"},\":new\":{\"B\":\"";
	const char * s7 = "\"}},\"ReturnConsumedCapacity\":\"TOTAL\"}";
	size_t slen = strlen(s1) + strlen(table) + strlen(s2) + strlen(key) +
	    strlen(s3) + b64len(len2) + strlen(s4) + strlen(s5) +
	    b64len(len) + strlen(s6) + b64len(len2) + strlen(s7);
	size_t spos = 0;
	char * s;

	/* Allocate request string. */
	if ((s = malloc(slen + 1)) == NULL)
		goto done;

	/* Construct the request, piece by piece. */
	COPYANDINCR(s, spos, s1);
	COPYANDINCR(s, spos, table);
	COPYANDINCR(s, spos, s2);
	COPYANDINCR(s, spos, key);
	COPYANDINCR(s, spos, s3);
	b64encode(buf2, &s[spos], len2);
	spos += b64len(len2);
	COPYANDINCR(s, spos, s4);
	COPYANDINCR(s, spos, s5);
	b64encode(buf, &s[spos], len);
	spos += b64len(len);
	COPYANDINCR(s, spos, s6);
	b64encode(buf2, &s[spos], len2);
	spos += b64len(len2);
	COPYANDINCR(s, spos, s7);
	s[spos] = '\0';

	/* Check that we got the buffer size right. */
	assert(slen == spos);

done:
	/* Return string (or NULL if allocation failed). */
	return (s);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x170, %rsp            # imm = 0x170
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
leaq 0x1767b(%rip), %rax     # 0x1e575
movq %rax, -0x38(%rbp)
leaq 0x1767f(%rip), %rax     # 0x1e584
movq %rax, -0x40(%rbp)
leaq 0x17689(%rip), %rax     # 0x1e599
movq %rax, -0x48(%rbp)
leaq 0x17728(%rip), %rax     # 0x1e643
movq %rax, -0x50(%rbp)
leaq 0x1774d(%rip), %rax     # 0x1e673
movq %rax, -0x58(%rbp)
leaq 0x1776d(%rip), %rax     # 0x1e69e
movq %rax, -0x60(%rbp)
leaq 0x1766b(%rip), %rax     # 0x1e5a7
movq %rax, -0x68(%rbp)
movq -0x38(%rbp), %rdi
callq 0x31a0
movq %rax, -0xd8(%rbp)
movq -0x8(%rbp), %rdi
callq 0x31a0
movq %rax, %rcx
movq -0xd8(%rbp), %rax
addq %rcx, %rax
movq %rax, -0xd0(%rbp)
movq -0x40(%rbp), %rdi
callq 0x31a0
movq %rax, %rcx
movq -0xd0(%rbp), %rax
addq %rcx, %rax
movq %rax, -0xc8(%rbp)
movq -0x10(%rbp), %rdi
callq 0x31a0
movq %rax, %rcx
movq -0xc8(%rbp), %rax
addq %rcx, %rax
movq %rax, -0xc0(%rbp)
movq -0x48(%rbp), %rdi
callq 0x31a0
movq %rax, %rcx
movq -0xc0(%rbp), %rax
addq %rcx, %rax
movq %rax, -0xb8(%rbp)
movq -0x30(%rbp), %rax
addq $0x2, %rax
movl $0x3, %ecx
xorl %edx, %edx
divq %rcx
movq %rax, %rcx
movq -0xb8(%rbp), %rax
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0xb0(%rbp)
movq -0x50(%rbp), %rdi
callq 0x31a0
movq %rax, %rcx
movq -0xb0(%rbp), %rax
addq %rcx, %rax
movq %rax, -0xa8(%rbp)
movq -0x58(%rbp), %rdi
callq 0x31a0
movq %rax, %rcx
movq -0xa8(%rbp), %rax
addq %rcx, %rax
movq %rax, -0xa0(%rbp)
movq -0x20(%rbp), %rax
addq $0x2, %rax
movl $0x3, %ecx
xorl %edx, %edx
divq %rcx
movq %rax, %rcx
movq -0xa0(%rbp), %rax
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x98(%rbp)
movq -0x60(%rbp), %rdi
callq 0x31a0
movq %rax, %rcx
movq -0x98(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x90(%rbp)
movq -0x30(%rbp), %rax
addq $0x2, %rax
movl $0x3, %ecx
xorl %edx, %edx
divq %rcx
movq %rax, %rcx
movq -0x90(%rbp), %rax
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x88(%rbp)
movq -0x68(%rbp), %rdi
callq 0x31a0
movq %rax, %rcx
movq -0x88(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movq $0x0, -0x78(%rbp)
movq -0x70(%rbp), %rdi
addq $0x1, %rdi
callq 0x34c0
movq %rax, -0x80(%rbp)
cmpq $0x0, %rax
jne 0x70d7
jmp 0x744f
jmp 0x70d9
movq -0x80(%rbp), %rax
addq -0x78(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq -0x38(%rbp), %rdi
callq 0x31a0
movq -0xe8(%rbp), %rdi
movq -0xe0(%rbp), %rsi
movq %rax, %rdx
callq 0x32c0
movq -0x38(%rbp), %rdi
callq 0x31a0
addq -0x78(%rbp), %rax
movq %rax, -0x78(%rbp)
jmp 0x7125
movq -0x80(%rbp), %rax
addq -0x78(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq -0x8(%rbp), %rdi
callq 0x31a0
movq -0xf8(%rbp), %rdi
movq -0xf0(%rbp), %rsi
movq %rax, %rdx
callq 0x32c0
movq -0x8(%rbp), %rdi
callq 0x31a0
addq -0x78(%rbp), %rax
movq %rax, -0x78(%rbp)
jmp 0x7171
movq -0x80(%rbp), %rax
addq -0x78(%rbp), %rax
movq %rax, -0x108(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x100(%rbp)
movq -0x40(%rbp), %rdi
callq 0x31a0
movq -0x108(%rbp), %rdi
movq -0x100(%rbp), %rsi
movq %rax, %rdx
callq 0x32c0
movq -0x40(%rbp), %rdi
callq 0x31a0
addq -0x78(%rbp), %rax
movq %rax, -0x78(%rbp)
jmp 0x71bd
movq -0x80(%rbp), %rax
addq -0x78(%rbp), %rax
movq %rax, -0x118(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x110(%rbp)
movq -0x10(%rbp), %rdi
callq 0x31a0
movq -0x118(%rbp), %rdi
movq -0x110(%rbp), %rsi
movq %rax, %rdx
callq 0x32c0
movq -0x10(%rbp), %rdi
callq 0x31a0
addq -0x78(%rbp), %rax
movq %rax, -0x78(%rbp)
jmp 0x7209
movq -0x80(%rbp), %rax
addq -0x78(%rbp), %rax
movq %rax, -0x128(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x120(%rbp)
movq -0x48(%rbp), %rdi
callq 0x31a0
movq -0x128(%rbp), %rdi
movq -0x120(%rbp), %rsi
movq %rax, %rdx
callq 0x32c0
movq -0x48(%rbp), %rdi
callq 0x31a0
addq -0x78(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x28(%rbp), %rdi
movq -0x80(%rbp), %rsi
addq -0x78(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x101a0
movq -0x30(%rbp), %rax
addq $0x2, %rax
movl $0x3, %ecx
xorl %edx, %edx
divq %rcx
shlq $0x2, %rax
addq -0x78(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x80(%rbp), %rax
addq -0x78(%rbp), %rax
movq %rax, -0x138(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x130(%rbp)
movq -0x50(%rbp), %rdi
callq 0x31a0
movq -0x138(%rbp), %rdi
movq -0x130(%rbp), %rsi
movq %rax, %rdx
callq 0x32c0
movq -0x50(%rbp), %rdi
callq 0x31a0
addq -0x78(%rbp), %rax
movq %rax, -0x78(%rbp)
jmp 0x72d2
movq -0x80(%rbp), %rax
addq -0x78(%rbp), %rax
movq %rax, -0x148(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x140(%rbp)
movq -0x58(%rbp), %rdi
callq 0x31a0
movq -0x148(%rbp), %rdi
movq -0x140(%rbp), %rsi
movq %rax, %rdx
callq 0x32c0
movq -0x58(%rbp), %rdi
callq 0x31a0
addq -0x78(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x18(%rbp), %rdi
movq -0x80(%rbp), %rsi
addq -0x78(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x101a0
movq -0x20(%rbp), %rax
addq $0x2, %rax
movl $0x3, %ecx
xorl %edx, %edx
divq %rcx
shlq $0x2, %rax
addq -0x78(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x80(%rbp), %rax
addq -0x78(%rbp), %rax
movq %rax, -0x158(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x150(%rbp)
movq -0x60(%rbp), %rdi
callq 0x31a0
movq -0x158(%rbp), %rdi
movq -0x150(%rbp), %rsi
movq %rax, %rdx
callq 0x32c0
movq -0x60(%rbp), %rdi
callq 0x31a0
addq -0x78(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x28(%rbp), %rdi
movq -0x80(%rbp), %rsi
addq -0x78(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x101a0
movq -0x30(%rbp), %rax
addq $0x2, %rax
movl $0x3, %ecx
xorl %edx, %edx
divq %rcx
shlq $0x2, %rax
addq -0x78(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x80(%rbp), %rax
addq -0x78(%rbp), %rax
movq %rax, -0x168(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x160(%rbp)
movq -0x68(%rbp), %rdi
callq 0x31a0
movq -0x168(%rbp), %rdi
movq -0x160(%rbp), %rsi
movq %rax, %rdx
callq 0x32c0
movq -0x68(%rbp), %rdi
callq 0x31a0
addq -0x78(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x80(%rbp), %rax
movq -0x78(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x70(%rbp), %rax
cmpq -0x78(%rbp), %rax
jne 0x742e
jmp 0x744d
leaq 0x17198(%rip), %rdi     # 0x1e5cd
leaq 0x1719e(%rip), %rsi     # 0x1e5da
movl $0x81, %edx
leaq 0x17267(%rip), %rcx     # 0x1e6af
callq 0x3240
jmp 0x744f
movq -0x80(%rbp), %rax
addq $0x170, %rsp            # imm = 0x170
popq %rbp
retq
nopl (%rax)