// File: /workspace/github_c_makefile_star2_O3/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, %rsi
leaq 0x2(%r14), %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
mulq %rcx
movq %rdx, %r15
movq %rsi, 0x10(%rsp)
leaq (%rsi,%r13), %rbp
addq $0x22, %rbp
shrq %r15
leaq 0x9d(,%r15,8), %rdi
addq %rbp, %rdi
callq 0x34c0
movq %rax, %r12
testq %rax, %rax
je 0x5f1a
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 0x3280
movups 0xb7b6(%rip), %xmm0     # 0x115c4
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 0x3280
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 0xb144
leaq 0xd(,%r15,4), %rax
addq %rbp, %rax
leaq (%r12,%rax), %rbx
movups 0xb82a(%rip), %xmm0     # 0x116a9
movups %xmm0, 0x30(%r12,%rax)
movups 0xb80d(%rip), %xmm0     # 0x11699
movups %xmm0, 0x20(%r12,%rax)
movups 0xb7f0(%rip), %xmm0     # 0x11689
movups %xmm0, 0x10(%r12,%rax)
movups 0xb7d3(%rip), %xmm0     # 0x11679
movups %xmm0, (%r12,%rax)
movups 0xb808(%rip), %xmm0     # 0x116ba
movups %xmm0, 0x40(%r12,%rax)
movups 0xb80b(%rip), %xmm0     # 0x116ca
movups %xmm0, 0x50(%r12,%rax)
movups 0xb808(%rip), %xmm0     # 0x116d4
movups %xmm0, 0x5a(%r12,%rax)
leaq (%r12,%rax), %rsi
addq $0x6a, %rsi
movq %r14, %rdi
movq %r13, %rdx
callq 0xb144
movabsq $0x7d224c41544f5422, %rax # imm = 0x7D224C41544F5422
movq %rax, 0x87(%rbx,%r15,4)
movups 0xb6f9(%rip), %xmm0     # 0x115f7
movups %xmm0, 0x7a(%rbx,%r15,4)
movups 0xb6dc(%rip), %xmm0     # 0x115e7
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