// File: /workspace/github_c_makefile_star2_O2/Tarsnap[P]kivaloo/liball/../lib/dynamodb/dynamodb_kv.c
// Function: dynamodb_kv_create
char *
dynamodb_kv_create(const char * table, const char * key,
    const uint8_t * buf, size_t len)
{
	/**
	 * A CREATE is a PutItem request with a body (with spaces added) of:
	 * { "TableName": "TABLE",
	 *   "Item": {
	 *     "K": { "S": "KEY" },
	 *     "V": { "B": "BASE64NEW" }
	 *   },
	 *   "ConditionExpression": "(attribute_not_exists(V)) OR (V = :new)",
	 *   "ExpressionAttributeValues": {
	 *       ":new": { "B": "BASE64NEW" }
	 *   },
	 *   "ReturnConsumedCapacity": "TOTAL"
	 * }
	 */
	const char * s1 = "{\"TableName\":\"";
	const char * s2 = "\",\"Item\":{\"K\":{\"S\":\"";
	const char * s3 = "\"},\"V\":{\"B\":\"";
	const char * s4 = "\"}},\"ConditionExpression\":\"(attribute_not_exists(V))OR(V=:new)\",";
	const char * s5 = "\"ExpressionAttributeValues\":{\":new\":{\"B\":\"";
	const char * s6 = "\"}},\"ReturnConsumedCapacity\":\"TOTAL\"}";
	size_t slen = strlen(s1) + strlen(table) + strlen(s2) + strlen(key) +
	    strlen(s3) + b64len(len) + strlen(s4) + strlen(s5) + b64len(len) +
	    strlen(s6);
	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(buf, &s[spos], len);
	spos += b64len(len);
	COPYANDINCR(s, spos, s4);
	COPYANDINCR(s, spos, s5);
	b64encode(buf, &s[spos], len);
	spos += b64len(len);
	COPYANDINCR(s, spos, s6);
	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 $0x28, %rsp
movq %rcx, %r14
movq %rdx, 0x20(%rsp)
movq %rsi, %r15
movq %rdi, %rbx
callq 0x3190
movq %rax, %r13
movq %r15, 0x18(%rsp)
movq %r15, %rdi
callq 0x3190
movq %rax, 0x10(%rsp)
leaq (%rax,%r13), %rbp
addq $0x22, %rbp
leaq 0x2(%r14), %rax
pushq $0x3
popq %rcx
xorl %edx, %edx
divq %rcx
movq %rax, %r15
leaq 0x9d(,%rax,8), %rdi
addq %rbp, %rdi
callq 0x34d0
movq %rax, %r12
testq %rax, %rax
je 0x5bc3
movq %r14, 0x8(%rsp)
movq %r13, %r14
addq $0x22, %r14
movabsq $0x223a22656d614e65, %rax # imm = 0x223A22656D614E65
movq %rax, 0x6(%r12)
movabsq $0x4e656c626154227b, %rax # imm = 0x4E656C626154227B
movq %rax, (%r12)
leaq 0xe(%r12), %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x3290
movups 0xaadd(%rip), %xmm0     # 0x10594
movups %xmm0, 0xe(%r12,%r13)
movl $0x223a2253, 0x1e(%r12,%r13) # imm = 0x223A2253
addq %r12, %r14
movq %r14, %rdi
movq 0x18(%rsp), %rsi
movq 0x10(%rsp), %rdx
callq 0x3290
movabsq $0x7b3a2256222c7d22, %rax # imm = 0x7B3A2256222C7D22
movq %rax, (%r12,%rbp)
movabsq $0x223a2242227b3a22, %rax # imm = 0x223A2242227B3A22
movq %rax, 0x5(%r12,%rbp)
leaq 0xd(%r12,%rbp), %rsi
movq 0x20(%rsp), %r14
movq %r14, %rdi
movq 0x8(%rsp), %r13
movq %r13, %rdx
callq 0xa614
leaq 0xd(,%r15,4), %rax
addq %rbp, %rax
leaq (%r12,%rax), %rbx
movups 0xab51(%rip), %xmm0     # 0x10679
movups %xmm0, 0x30(%r12,%rax)
movups 0xab34(%rip), %xmm0     # 0x10669
movups %xmm0, 0x20(%r12,%rax)
movups 0xab17(%rip), %xmm0     # 0x10659
movups %xmm0, 0x10(%r12,%rax)
movups 0xaafa(%rip), %xmm0     # 0x10649
movups %xmm0, (%r12,%rax)
movups 0xab2f(%rip), %xmm0     # 0x1068a
movups %xmm0, 0x40(%r12,%rax)
movups 0xab32(%rip), %xmm0     # 0x1069a
movups %xmm0, 0x50(%r12,%rax)
movups 0xab2f(%rip), %xmm0     # 0x106a4
movups %xmm0, 0x5a(%r12,%rax)
leaq (%r12,%rax), %rsi
addq $0x6a, %rsi
movq %r14, %rdi
movq %r13, %rdx
callq 0xa614
movabsq $0x7d224c41544f5422, %rax # imm = 0x7D224C41544F5422
movq %rax, 0x87(%rbx,%r15,4)
movups 0xaa20(%rip), %xmm0     # 0x105c7
movups %xmm0, 0x7a(%rbx,%r15,4)
movups 0xaa03(%rip), %xmm0     # 0x105b7
movups %xmm0, 0x6a(%rbx,%r15,4)
movb $0x0, 0x8f(%rbx,%r15,4)
movq %r12, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq