// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r9, %rbx
movq %r8, 0x30(%rsp)
movq %rcx, %r13
movq %rdx, 0x20(%rsp)
movq %rsi, %r14
movq %rdi, 0x8(%rsp)
callq 0x3190
movq %rax, %r12
movq %r14, 0x18(%rsp)
movq %r14, %rdi
callq 0x3190
movq %rax, %rsi
leaq 0x2(%rbx), %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
mulq %rcx
movq %rdx, %r15
movq %rsi, 0x10(%rsp)
leaq (%r12,%rsi), %r14
addq $0x22, %r14
shrq %r15
movq %r13, 0x28(%rsp)
leaq 0x2(%r13), %rax
mulq %rcx
movq %rdx, %r13
addq %rdx, %r13
andq $-0x4, %r13
leaq (,%r15,8), %rax
addq %r13, %rax
leaq (%rax,%r14), %rdi
addq $0x9c, %rdi
callq 0x34c0
movq %rax, %rbp
testq %rax, %rax
je 0x5d48
movq %rbx, (%rsp)
movq %r12, %rbx
addq $0x22, %rbx
movabsq $0x223a22656d614e65, %rax # imm = 0x223A22656D614E65
movq %rax, 0x6(%rbp)
movabsq $0x4e656c626154227b, %rax # imm = 0x4E656C626154227B
movq %rax, (%rbp)
leaq 0xe(%rbp), %rdi
movq 0x8(%rsp), %rsi
movq %r12, %rdx
callq 0x3280
movups 0xb997(%rip), %xmm0     # 0x115c4
movups %xmm0, 0xe(%rbp,%r12)
movl $0x223a2253, 0x1e(%rbp,%r12) # imm = 0x223A2253
addq %rbp, %rbx
movq %rbx, %rdi
movq 0x18(%rsp), %rsi
movq 0x10(%rsp), %rdx
callq 0x3280
movabsq $0x7b3a2256222c7d22, %rax # imm = 0x7B3A2256222C7D22
movq %rax, (%rbp,%r14)
movabsq $0x223a2242227b3a22, %rax # imm = 0x223A2242227B3A22
movq %rax, 0x5(%rbp,%r14)
leaq 0xd(%rbp,%r14), %rsi
movq 0x30(%rsp), %r12
movq %r12, %rdi
movq (%rsp), %rdx
callq 0xb144
leaq (%r14,%r15,4), %rbx
addq $0xd, %rbx
movups 0xb998(%rip), %xmm0     # 0x1162c
movups %xmm0, 0x1f(%rbp,%rbx)
movups 0xb97d(%rip), %xmm0     # 0x1161d
movups %xmm0, 0x10(%rbp,%rbx)
movups 0xb961(%rip), %xmm0     # 0x1160d
movups %xmm0, (%rbp,%rbx)
movups 0xb985(%rip), %xmm0     # 0x1163d
movups %xmm0, 0x2f(%rbp,%rbx)
movups 0xb989(%rip), %xmm0     # 0x1164d
movups %xmm0, 0x3f(%rbp,%rbx)
movups 0xb987(%rip), %xmm0     # 0x11657
movups %xmm0, 0x49(%rbp,%rbx)
leaq (%rbx,%rbp), %rsi
addq $0x59, %rsi
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rdx
callq 0xb144
leaq (%rbx,%r13), %rax
addq $0x59, %rax
leaq (%rbp,%rax), %rbx
movups 0xb968(%rip), %xmm0     # 0x11668
movups %xmm0, (%rbp,%rax)
leaq (%rax,%rbp), %rsi
addq $0x10, %rsi
movq %r12, %rdi
movq (%rsp), %rdx
callq 0xb144
movabsq $0x7d224c41544f5422, %rax # imm = 0x7D224C41544F5422
movq %rax, 0x2d(%rbx,%r15,4)
movups 0xb8c8(%rip), %xmm0     # 0x115f7
movups %xmm0, 0x20(%rbx,%r15,4)
movups 0xb8ab(%rip), %xmm0     # 0x115e7
movups %xmm0, 0x10(%rbx,%r15,4)
movb $0x0, 0x35(%rbx,%r15,4)
movq %rbp, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq